void FlexGrid::OnChildRelinquishedFocus(UiViewModel&, const Control::Nav &nav) { using Nav = Control::Nav; if (!focusedCell) { RelinquishFocus(nav); return; } auto row = focusedCell->first; auto col = focusedCell->second; rows[row][col]->DropFocus(); focusedCell = boost::none; auto dir = nav.AsDigital(); switch (dir) { case Nav::NEUTRAL: RelinquishFocus(nav); break; case Nav::UP: if (!FocusUpFrom(row, col, nav)) { RelinquishFocus(nav); } break; case Nav::DOWN: if (!FocusDownFrom(row, col, nav)) { RelinquishFocus(nav); } break; case Nav::LEFT: if (!FocusLeftFrom(row, col, nav)) { RelinquishFocus(nav); } break; case Nav::RIGHT: if (!FocusRightFrom(row, col, nav)) { RelinquishFocus(nav); } break; case Nav::PREV: if (!FocusPrevFrom(row, col, nav)) { RelinquishFocus(nav); } break; case Nav::NEXT: if (!FocusNextFrom(row, col, nav)) { RelinquishFocus(nav); } break; default: throw UnimplementedExn(boost::str(boost::format( "FlexGrid::OnChildRelinquishedFocus(%s)") % nav)); } }
bool Slider::OnNavigate(const Control::Nav &nav) { using Nav = Control::Nav; auto dir = nav.AsDigital(); switch (dir) { case Nav::NEUTRAL: return true; case Nav::UP: case Nav::DOWN: RelinquishFocus(nav); return true; case Nav::LEFT: SetValue(value - step); return true; case Nav::RIGHT: SetValue(value + step); return true; default: HR_LOG(warning) << "Unhandled navigation direction: " << dir; return false; } }
bool Button::OnNavigate(const Control::Nav &nav) { if (nav.AsDigital() != Control::Nav::NEUTRAL) { RelinquishFocus(nav); return true; } else { return false; } }
void FlexGrid::Clear() { if (focusedCell) { rows[focusedCell->first][focusedCell->second]->DropFocus(); focusedCell = boost::none; RelinquishFocus(Control::Nav::NEUTRAL); } defaultCols.clear(); rows.clear(); SUPER::Clear(); }
void FlexGrid::OnChildRequestedFocus(UiViewModel &child) { if (!IsFocused()) { RequestFocus(); } if (IsFocused()) { // Switch focus to the new child, if possible. if (focusedCell) { rows[focusedCell->first][focusedCell->second]->DropFocus(); focusedCell = boost::none; } if (child.TryFocus()) { //TODO: Track focus on the cell, and track coords in the cell. focusedCell = FindChild(&child); SetFocused(true); } else { // The child that requested focus refused to take the focus. RelinquishFocus(Control::Nav::NEUTRAL); } } }