diff options
Diffstat (limited to 'src/ui/widget.cc')
-rw-r--r-- | src/ui/widget.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/ui/widget.cc b/src/ui/widget.cc index 540fd6c..9ae2f32 100644 --- a/src/ui/widget.cc +++ b/src/ui/widget.cc @@ -10,6 +10,8 @@ #include "ui/ui.h" #include "ui/widget.h" +#include <cassert> + namespace ui { @@ -146,6 +148,18 @@ void Widget::show() void Widget::hide() { widget_visible = false; + + if (parent() && focus()) { + + Widget *sibling = next_sibling(); + + while (sibling && ((sibling == this) || !sibling->visible())) { + sibling = sibling->next_sibling(); + } + if (sibling) + sibling->set_focus(); + } + /* if (parent() && focus()) { Widget::Children::reverse_iterator it = parent()->children().rbegin(); @@ -160,6 +174,7 @@ void Widget::hide() } } } + */ } @@ -268,6 +283,33 @@ void Widget::set_height(const float h) widget_size[1] = h; } +Widget *Widget::next_sibling() +{ + if (!parent() || (parent()->children().size() < 2)) { + return 0; + } + + // find this widget in the parent's children + Children::iterator it = parent()->children().begin(); + while (it != parent()->children().end() && (*it) != this) { + it++; + } + + // assert this widget is a child of its parent + assert (it != parent()->children().end()); + + // next sibling + it++; + if (it == parent()->children().end()) { + it = parent()->children().begin(); + } + if ((*it) == this) { + return 0; + } else { + return (*it); + } +} + Widget::Children::iterator Widget::find_child(Widget *child) { Children::iterator it; |