Short-term focus navigation fix

Addresses argilo's immediate problem navigating between fields in a row, issue #32.
This commit is contained in:
Jared Boone 2015-07-29 14:00:59 -07:00
parent 10e20ee763
commit 0ed607b6dd

View File

@ -100,7 +100,7 @@ void FocusManager::update(
const auto test_fn = [&center, event](ui::Widget* const w) -> test_result_t { const auto test_fn = [&center, event](ui::Widget* const w) -> test_result_t {
// if( w->visible() && w->focusable() ) { // if( w->visible() && w->focusable() ) {
if( w->focusable() ) { if( w->focusable() ) {
const Point p = w->screen_rect().center() - center; const Point delta = w->screen_rect().center() - center;
/* Heuristic to compute closeness. */ /* Heuristic to compute closeness. */
/* TODO: Look at metric involving overlap of current /* TODO: Look at metric involving overlap of current
@ -109,26 +109,42 @@ void FocusManager::update(
*/ */
switch(event) { switch(event) {
case KeyEvent::Right: case KeyEvent::Right:
if( p.x > 0 ) { if( delta.x > 0 ) {
return { w, p.x * (abs(p.y) + 1) }; if( delta.y == 0 ) {
return { w, delta.x };
} else {
return { w, delta.x * abs(delta.y) + 1000 };
}
} }
break; break;
case KeyEvent::Left: case KeyEvent::Left:
if( p.x < 0 ) { if( delta.x < 0 ) {
return { w, -p.x * (abs(p.y) + 1) }; if( delta.y == 0 ) {
return { w, -delta.x };
} else {
return { w, -delta.x * abs(delta.y) + 1000 };
}
} }
break; break;
case KeyEvent::Down: case KeyEvent::Down:
if( p.y > 0 ) { if( delta.y > 0 ) {
return { w, p.y * (abs(p.x) + 1) }; if( delta.x == 0 ) {
return { w, delta.y };
} else {
return { w, delta.y * abs(delta.x) + 1000 };
}
} }
break; break;
case KeyEvent::Up: case KeyEvent::Up:
if( p.y < 0 ) { if( delta.y < 0 ) {
return { w, -p.y * (abs(p.x) + 1) }; if( delta.x == 0 ) {
return { w, -delta.y };
} else {
return { w, -delta.y * abs(delta.x) + 1000 };
}
} }
break; break;