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