fix pane behaviour when children are hidden/shown

This commit is contained in:
Paul Davis 2016-05-28 10:25:43 -04:00
parent 229b026356
commit 0baedac4f4
2 changed files with 44 additions and 6 deletions

View file

@ -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

View file

@ -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;
}
}