diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2016-05-28 10:25:43 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2016-05-31 15:30:45 -0400 |
commit | 0baedac4f4c2f10291e90505dbda759fb6673b10 (patch) | |
tree | 15fd0da91b94e7f0ff7afb10bd3e6fb1bbe9a63f /libs/gtkmm2ext | |
parent | 229b02635668e6031d2f29045176872f255ea956 (diff) |
fix pane behaviour when children are hidden/shown
Diffstat (limited to 'libs/gtkmm2ext')
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/pane.h | 1 | ||||
-rw-r--r-- | libs/gtkmm2ext/pane.cc | 49 |
2 files changed, 44 insertions, 6 deletions
diff --git a/libs/gtkmm2ext/gtkmm2ext/pane.h b/libs/gtkmm2ext/gtkmm2ext/pane.h index 6c67c82196..f1d5bed092 100644 --- a/libs/gtkmm2ext/gtkmm2ext/pane.h +++ b/libs/gtkmm2ext/gtkmm2ext/pane.h @@ -100,6 +100,7 @@ class LIBGTKMM2EXT_API Pane : public Gtk::Container Dividers dividers; int divider_width; void add_divider (); + void handle_child_visibility (); }; class LIBGTKMM2EXT_API HPane : public Pane diff --git a/libs/gtkmm2ext/pane.cc b/libs/gtkmm2ext/pane.cc index 7f1c4ea742..760c8404ee 100644 --- a/libs/gtkmm2ext/pane.cc +++ b/libs/gtkmm2ext/pane.cc @@ -123,12 +123,21 @@ Pane::add_divider () } void +Pane::handle_child_visibility () +{ + reallocate (get_allocation()); +} + +void Pane::on_add (Widget* w) { children.push_back (Child (w, 0)); w->set_parent (*this); + w->signal_show().connect (sigc::mem_fun (*this, &Pane::handle_child_visibility)); + w->signal_hide().connect (sigc::mem_fun (*this, &Pane::handle_child_visibility)); + while (dividers.size() < (children.size() - 1)) { add_divider (); } @@ -137,14 +146,14 @@ Pane::on_add (Widget* w) void Pane::on_remove (Widget* w) { - w->unparent (); - for (Children::iterator c = children.begin(); c != children.end(); ++c) { if (c->w == w) { children.erase (c); break; } } + + w->unparent (); } void @@ -182,11 +191,30 @@ Pane::reallocate (Gtk::Allocation const & alloc) Children::iterator next; Dividers::iterator div; - for (child = children.begin(), div = dividers.begin(); child != children.end(); ) { + child = children.begin(); + + /* skip initial hidden children */ + + while (child != children.end()) { + if (child->w->is_visible()) { + break; + } + ++child; + } + + for (div = dividers.begin(); child != children.end(); ) { Gtk::Allocation child_alloc; + next = child; - ++next; + + /* Move on to next *visible* child */ + + while (++next != children.end()) { + if (next->w->is_visible()) { + break; + } + } child_alloc.set_x (xpos); child_alloc.set_y (ypos); @@ -223,13 +251,14 @@ Pane::reallocate (Gtk::Allocation const & alloc) } child->w->size_allocate (child_alloc); - ++child; - if (child == children.end()) { + if (next == children.end()) { /* done, no more children, no need for a divider */ break; } + child = next; + /* add a divider between children */ Gtk::Allocation divider_allocation; @@ -250,6 +279,14 @@ Pane::reallocate (Gtk::Allocation const & alloc) } (*div)->size_allocate (divider_allocation); + (*div)->show (); + ++div; + } + + /* hide all remaining dividers */ + + while (div != dividers.end()) { + (*div)->hide (); ++div; } } |