コード例 #1
0
ファイル: FlexGrid.cpp プロジェクト: ZoogieZork/HoverRace
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));
	}
}
コード例 #2
0
ファイル: Slider.cpp プロジェクト: HoverRace/HoverRace
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;
	}
}
コード例 #3
0
ファイル: Button.cpp プロジェクト: ZoogieZork/HoverRace
bool Button::OnNavigate(const Control::Nav &nav)
{
	if (nav.AsDigital() != Control::Nav::NEUTRAL) {
		RelinquishFocus(nav);
		return true;
	}
	else {
		return false;
	}
}
コード例 #4
0
ファイル: FlexGrid.cpp プロジェクト: ZoogieZork/HoverRace
bool FlexGrid::TryFocus(const Control::Nav &nav)
{
	using Nav = Control::Nav;

	if (IsFocused()) return true;
	if (IsEmpty() || !IsVisible()) return false;

	size_t row;
	size_t col;

	auto dir = nav.AsDigital();
	switch (dir) {
		case Nav::NEUTRAL:
		case Nav::DOWN:
		case Nav::RIGHT:
		case Nav::NEXT:
			row = 0;
			col = 0;
			break;

		case Nav::UP:
			row = rows.size() - 1;
			col = 0;
			break;

		case Nav::LEFT:
			row = 0;
			col = defaultCols.size() - 1;
			break;

		case Nav::PREV:
			row = rows.size() - 1;
			col = defaultCols.size() - 1;
			break;

		default:
			throw UnimplementedExn(boost::str(
				boost::format("FlexGrid::TryFocus: Unhandled: %s") % nav));
	}

	auto &cols = rows[row];
	if (col < cols.size()) {
		auto &cell = cols[col];
		if (cell && cell->TryFocus(nav)) {
			SetFocusedCell(row, col);
			return true;
		}
	}

	// Search for a focusable cell.
	switch (dir) {
		case Nav::UP:
			return FocusUpFrom(row, col, nav);

		case Nav::DOWN:
			return FocusDownFrom(row, col, nav);

		case Nav::LEFT:
			return FocusLeftFrom(row, col, nav);

		case Nav::RIGHT:
			return FocusRightFrom(row, col, nav);

		case Nav::PREV:
			return FocusPrevFrom(row, col, nav);

		case Nav::NEUTRAL:
		case Nav::NEXT:
			return FocusNextFrom(row, col, nav);

		default:
			throw UnimplementedExn(boost::str(
				boost::format("FlexGrid::TryFocus: Unhandled: %s") % nav));
	}
}