bool Container::navigate(Navigation nav)
{
- if(input_focus && input_focus->navigate(nav))
- return true;
-
- if(nav==NAV_UP || nav==NAV_DOWN || nav==NAV_LEFT || nav==NAV_RIGHT)
- {
- int x = geom.w/2;
- int y = geom.h/2;
- if(input_focus)
- {
- const Geometry &fgeom = input_focus->get_geometry();
- x = fgeom.x+fgeom.w/2;
- y = fgeom.y+fgeom.h/2;
- }
- else if(nav==NAV_UP)
- y = 0;
- else if(nav==NAV_DOWN)
- y = geom.h;
- else if(nav==NAV_RIGHT)
- x = 0;
- else if(nav==NAV_LEFT)
- x = geom.w;
-
- Widget *sibling = 0;
- int best_score = 0;
- for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
- {
- if((*i)->widget==input_focus || !(*i)->widget->is_focusable())
- continue;
-
- const Geometry &cgeom = (*i)->widget->get_geometry();
- int dx = cgeom.x+cgeom.w/2-x;
- int dy = cgeom.y+cgeom.h/2-y;
-
- int score = -1;
- if(nav==NAV_UP && dy>0)
- score = dy+abs(dx)*4;
- else if(nav==NAV_DOWN && dy<0)
- score = -dy+abs(dx)*4;
- else if(nav==NAV_RIGHT && dx>0)
- score = dx+abs(dy)*4;
- else if(nav==NAV_LEFT && dx<0)
- score = -dx+abs(dy)*4;
-
- if(score>0 && (!sibling || score<best_score))
- {
- sibling = (*i)->widget;
- best_score = score;
- }
- }
-
- if(sibling)
- {
- set_input_focus(sibling);
- if(Container *container = dynamic_cast<Container *>(sibling))
- container->navigate(nav);
- return true;
- }
- }
-
- return false;
+ if(input_focus)
+ return input_focus->navigate(nav);
+ else
+ return false;
}
void Container::on_reparent()
}
}
+bool Panel::navigate(Navigation nav)
+{
+ if(Container::navigate(nav))
+ return true;
+
+ if(nav==NAV_UP || nav==NAV_DOWN || nav==NAV_LEFT || nav==NAV_RIGHT)
+ {
+ int x = geom.w/2;
+ int y = geom.h/2;
+ if(input_focus)
+ {
+ const Geometry &fgeom = input_focus->get_geometry();
+ x = fgeom.x+fgeom.w/2;
+ y = fgeom.y+fgeom.h/2;
+ }
+ else if(nav==NAV_UP)
+ y = 0;
+ else if(nav==NAV_DOWN)
+ y = geom.h;
+ else if(nav==NAV_RIGHT)
+ x = 0;
+ else if(nav==NAV_LEFT)
+ x = geom.w;
+
+ Widget *sibling = 0;
+ int best_score = 0;
+ for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
+ {
+ if((*i)->widget==input_focus || !(*i)->widget->is_focusable())
+ continue;
+
+ const Geometry &cgeom = (*i)->widget->get_geometry();
+ int dx = cgeom.x+cgeom.w/2-x;
+ int dy = cgeom.y+cgeom.h/2-y;
+
+ int score = -1;
+ if(nav==NAV_UP && dy>0)
+ score = dy+abs(dx)*4;
+ else if(nav==NAV_DOWN && dy<0)
+ score = -dy+abs(dx)*4;
+ else if(nav==NAV_RIGHT && dx>0)
+ score = dx+abs(dy)*4;
+ else if(nav==NAV_LEFT && dx<0)
+ score = -dx+abs(dy)*4;
+
+ if(score>0 && (!sibling || score<best_score))
+ {
+ sibling = (*i)->widget;
+ best_score = score;
+ }
+ }
+
+ if(sibling)
+ {
+ set_input_focus(sibling);
+ if(Panel *panel = dynamic_cast<Panel *>(sibling))
+ panel->navigate(nav);
+ return true;
+ }
+ }
+
+ return false;
+}
+
void Panel::on_geometry_change()
{
if(layout)
virtual void autosize_special(const Part &, Geometry &) const;
virtual void render_special(const Part &, GL::Renderer &) const;
+public:
+ virtual bool navigate(Navigation);
+
+protected:
virtual void on_geometry_change();
virtual void on_child_added(Widget &);
virtual void on_child_removed(Widget &);