From 4e927588c5ccb6cf05f7f0b54baf58cc6ae26774 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 22 Jun 2015 18:32:59 +0000
Subject: [PATCH] visibility by group

---
 Fltk/onelabGroup.cpp | 36 +++++++++++++++++++++++++++++++-----
 Fltk/viewButton.cpp  |  7 +++----
 2 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp
index ad65c6943a..44b0b03b4a 100644
--- a/Fltk/onelabGroup.cpp
+++ b/Fltk/onelabGroup.cpp
@@ -400,7 +400,8 @@ static void onelab_subtree_cb(Fl_Widget *w, void *data)
 
 void onelabGroup::_computeWidths()
 {
-  _baseWidth = _tree->w() - _tree->marginleft();
+  // "-FL_NORMAL_SIZE" to have space for a scrollbar to the right
+  _baseWidth = _tree->w() - _tree->marginleft() - FL_NORMAL_SIZE;
   // not sure why we have the "-2" correction at the end, but this is what is
   // needed to make things pixel-correct.
   _indent = _tree->connectorwidth() / 2. + _tree->openicon()->w() / 2. - 2.;
@@ -557,7 +558,6 @@ void onelabGroup::_addParameter(T &p)
 void onelabGroup::_addMenu(const std::string &path, Fl_Callback *callback, void *data)
 {
   Fl_Tree_Item *n = _tree->add(path.c_str());
-  //n->labelsize(FL_NORMAL_SIZE + 4);
   _tree->begin();
   int ww = (int)(_baseWidth - (n->depth() + 1) * _indent);
   int hh = n->labelsize() + 4;
@@ -1030,6 +1030,20 @@ static void onelab_region_input_cb(Fl_Widget *w, void *data)
   }
 }
 
+static void view_group_cb(Fl_Widget *w, void *data)
+{
+  if(!data) return;
+  std::string group((char*)data);
+  if(group.front() == '/') group = group.substr(1);
+  if(group.back() == '/') group.pop_back();
+  for(unsigned int i = 0; i < PView::list.size(); i++){
+    PViewOptions *opt = PView::list[i]->getOptions();
+    if(opt->group.find(group) == 0)
+      opt_view_visible(i, GMSH_SET | GMSH_GUI, !opt->visible);
+  }
+  drawContext::global()->draw();
+}
+
 Fl_Widget *onelabGroup::_addParameterWidget(onelab::region &p, int ww, int hh,
                                             Fl_Tree_Item *n, bool highlight, Fl_Color c)
 {
@@ -1160,17 +1174,29 @@ void onelabGroup::rebuildTree(bool deleteWidgets)
       int ww = (int)(_baseWidth - (n->depth() + 1) * _indent);
       int hh = n->labelsize() + 4;
       _tree->begin();
+      Fl_Widget *but;
 #if 0 // FIXME this can crash FLTK when submenus are intially closed (somehow
       // the widget is badly positioned and overlaps the open icon, leading to
       // a corrupted Fl_Tree_Item)
-      Fl_Button *but = new Fl_Button(1, 1, ww, hh);
+      but = new Fl_Button(1, 1, ww, hh);
       but->box(FL_NO_BOX);
       but->clear_visible_focus();
       but->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
       but->callback(onelab_subtree_cb, (void*)n);
 #else
-      Fl_Box *but = new Fl_Box(1, 1, ww, hh);
-      but->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
+      if(getPath(n).find("0Modules/Post-processing") != std::string::npos){
+        but = new Fl_Button(1, 1, ww, hh);
+        but->box(FL_NO_BOX);
+        but->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
+        but->tooltip("Toggle visibility of child views");
+        char *group = strdup(getPath(n).substr(24).c_str());
+        _treeStrings.push_back(group);
+        but->callback(view_group_cb, (void*)group);
+      }
+      else{
+        but = new Fl_Box(1, 1, ww, hh);
+        but->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
+      }
 #endif
       _treeWidgets.push_back(but);
       onelab::string o(n->label());
diff --git a/Fltk/viewButton.cpp b/Fltk/viewButton.cpp
index 4a6e77a216..a003528e17 100644
--- a/Fltk/viewButton.cpp
+++ b/Fltk/viewButton.cpp
@@ -268,8 +268,7 @@ viewButton::viewButton(int x, int y, int w, int h, int num, Fl_Color col)
   PViewData *data = view->getData();
   PViewOptions *opt = view->getOptions();
 
-  int ws = FL_NORMAL_SIZE - 2; // right margin to allow for scrollbar
-  _toggle = new Fl_Check_Button(x, y, w - popw - ws, h);
+  _toggle = new Fl_Check_Button(x, y, w - popw, h);
   _toggle->box(FL_FLAT_BOX);
   _toggle->color(col);
   _toggle->callback(view_toggle_cb, (void *)num);
@@ -281,13 +280,13 @@ viewButton::viewButton(int x, int y, int w, int h, int num, Fl_Color col)
   strcpy(_tooltip, data->getFileName().c_str());
   _toggle->tooltip(_tooltip);
 
-  _butt = new Fl_Button(x + w - popw - ws, y, popw, h, "@>");
+  _butt = new Fl_Button(x + w - popw, y, popw, h, "@>");
   _butt->align(FL_ALIGN_RIGHT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
   _butt->tooltip("Show view options (Shift+w)");
   _butt->box(FL_FLAT_BOX);
   _butt->color(col);
   _butt->selection_color(col);
-  _popup = new Fl_Menu_Button(x + w - popw - ws, y, popw, h);
+  _popup = new Fl_Menu_Button(x + w - popw, y, popw, h);
   _popup->type(Fl_Menu_Button::POPUP123);
 
   _popup->add("Options", 'o',
-- 
GitLab