From 0baedac4f4c2f10291e90505dbda759fb6673b10 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 28 May 2016 10:25:43 -0400 Subject: fix pane behaviour when children are hidden/shown --- libs/gtkmm2ext/pane.cc | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'libs/gtkmm2ext/pane.cc') 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 @@ -122,6 +122,12 @@ Pane::add_divider () dividers.push_back (d); } +void +Pane::handle_child_visibility () +{ + reallocate (get_allocation()); +} + void Pane::on_add (Widget* w) { @@ -129,6 +135,9 @@ Pane::on_add (Widget* w) 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; } } -- cgit v1.2.3