From 51c275a52a1934b7ad62c551ccae5c04ca1396c3 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Tue, 25 Mar 2014 16:20:48 +0000 Subject: [PATCH] reworked resizing of widget tree --- Fltk/graphicWindow.cpp | 19 ++++++++++++++++++- Fltk/onelabGroup.cpp | 10 +++++----- Fltk/onelabGroup.h | 2 ++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index ed3ada25d6..434f3c8de7 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -2741,6 +2741,14 @@ static void message_browser_cb(Fl_Widget *w, void *data) g->copySelectedMessagesToClipboard(); } +static void tile_cb(Fl_Widget *w, void *data) +{ + if(Fl::event() == FL_RELEASE){ + // rebuild the tree when we relase the mouse after resizing + FlGui::instance()->rebuildTree(true); + } +} + // This dummy box class permits to define a box widget that will not eat the // FL_ENTER/FL_LEAVE events (the box widget in fltk > 1.1 does that, so that // gl->handle() was not called when the mouse moved) @@ -2993,11 +3001,13 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) if(main && !detachedMenu){ _onelab = new onelabGroup(0, mh, twidth, height - mh - sh); + _onelab->enableTreeWidgetResize(false); } else{ _onelab = 0; } + _tile->callback(tile_cb); _tile->end(); // resize the tiles to match the prescribed sizes @@ -3019,6 +3029,7 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu) _menuwin->callback(file_quit_cb); _menuwin->box(GMSH_WINDOW_BOX); _onelab = new onelabGroup(0, 0, _menuwin->w(), _menuwin->h()); + _onelab->enableTreeWidgetResize(true); _menuwin->position(CTX::instance()->menuPosition[0], CTX::instance()->menuPosition[1]); _menuwin->resizable(_onelab); @@ -3075,6 +3086,9 @@ void graphicWindow::detachMenu() _menuwin->size_range(_onelab->getMinWindowWidth(), _onelab->getMinWindowHeight()); _menuwin->end(); _menuwin->show(); + + _onelab->enableTreeWidgetResize(true); + _onelab->rebuildTree(true); } void graphicWindow::attachMenu() @@ -3099,6 +3113,9 @@ void graphicWindow::attachMenu() _tile->add(_onelab); _onelab->resize(_tile->x(), _tile->y(), w, _tile->h()); _tile->redraw(); + + _onelab->enableTreeWidgetResize(false); + _onelab->rebuildTree(true); } void graphicWindow::attachDetachMenu() @@ -3116,7 +3133,7 @@ void graphicWindow::showMenu() int maxw = _win->w(); if(width > maxw) width = maxw / 2; setMenuWidth(width); - // FIXME: this is necessary until resizing a 0-sized group works in fltk + // necessary until resizing of 0-sized groups works _onelab->rebuildTree(true); } } diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp index 069df9642f..4464c65022 100644 --- a/Fltk/onelabGroup.cpp +++ b/Fltk/onelabGroup.cpp @@ -1093,7 +1093,7 @@ static unsigned char gear_bits[] = { #endif onelabGroup::onelabGroup(int x, int y, int w, int h, const char *l) - : Fl_Group(x,y,w,h,l), _stop(false) + : Fl_Group(x,y,w,h,l), _stop(false), _enableTreeWidgetResize(false) { int col = FL_BACKGROUND2_COLOR; color(col); @@ -1221,7 +1221,7 @@ void onelabGroup::_addParameter(T &p) Fl_Group *grp = new Fl_Group(1, 1, ww, hh); Fl_Widget *widget = _addParameterWidget(p, ww, hh, n, highlight, c); grp->end(); - //grp->resizable(0); + if(!_enableTreeWidgetResize) grp->resizable(0); _treeWidgets.push_back(grp); widget->copy_label(p.getShortName().c_str()); std::string help = p.getLabel().size() ? p.getLabel() : p.getShortName(); @@ -1245,7 +1245,7 @@ void onelabGroup::_addMenu(const std::string &path, Fl_Callback *callback, void but->color(_tree->color()); but->selection_color(_tree->color()); grp->end(); - //grp->resizable(0); + if(!_enableTreeWidgetResize) grp->resizable(0); _treeWidgets.push_back(grp); std::string label = path; std::string::size_type last = path.find_last_of('/'); @@ -1266,7 +1266,7 @@ void onelabGroup::_addSolverMenu(int num) Fl_Group *grp = new Fl_Group(1, 1, ww, hh); new solverButton(1, 1, ww, hh, num, _tree->color()); grp->end(); - //grp->resizable(0); + if(!_enableTreeWidgetResize) grp->resizable(0); _treeWidgets.push_back(grp); n->widget(grp); _tree->end(); @@ -1283,7 +1283,7 @@ void onelabGroup::_addViewMenu(int num) Fl_Group *grp = new Fl_Group(1, 1, ww, hh); new viewButton(1, 1, ww, hh, num, _tree->color()); grp->end(); - //grp->resizable(0); + if(!_enableTreeWidgetResize) grp->resizable(0); _treeWidgets.push_back(grp); n->widget(grp); _tree->end(); diff --git a/Fltk/onelabGroup.h b/Fltk/onelabGroup.h index b96cef6f76..3373b24a4d 100644 --- a/Fltk/onelabGroup.h +++ b/Fltk/onelabGroup.h @@ -29,6 +29,7 @@ class onelabGroup : public Fl_Group{ int _minWindowWidth, _minWindowHeight; double _widgetLabelRatio; std::set<std::string> _manuallyClosed; + bool _enableTreeWidgetResize; void _computeWidths(); template <class T> void _addParameter(T &p); Fl_Widget *_addParameterWidget(onelab::number &p, int ww, int hh, @@ -48,6 +49,7 @@ class onelabGroup : public Fl_Group{ onelabGroup(int x, int y, int w, int h, const char *l=0); void rebuildSolverList(); void rebuildTree(bool deleteWidgets); + void enableTreeWidgetResize(bool value){ _enableTreeWidgetResize = value; } void redrawTree(){ _tree->redraw(); } void openTreeItem(const std::string &name); void setButtonVisibility(); -- GitLab