Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
menu_model.h
Go to the documentation of this file.
1
5#pragma once
6
7// standard includes
8#include <cstddef>
9#include <limits>
10#include <string>
11#include <string_view>
12#include <vector>
13
14// local includes
16
17namespace ui {
18
22 struct MenuItem {
23 std::string id;
24 std::string label;
25 std::string description;
26 bool enabled;
27 };
28
41
45 class MenuModel {
46 public:
50 static constexpr std::size_t npos = std::numeric_limits<std::size_t>::max();
51
57 explicit MenuModel(std::vector<MenuItem> items = {});
58
64 void set_items(std::vector<MenuItem> items);
65
71 [[nodiscard]] const std::vector<MenuItem> &items() const;
72
78 [[nodiscard]] std::size_t selected_index() const;
79
85 [[nodiscard]] const MenuItem *selected_item() const;
86
93 bool select_item_by_id(std::string_view itemId);
94
102
103 private:
104 bool move_selection(int direction);
105 [[nodiscard]] std::size_t find_first_enabled_index() const;
106
107 std::vector<MenuItem> items_;
108 std::size_t selectedIndex_ = npos;
109 };
110
111} // namespace ui
Menu state that supports controller and keyboard navigation.
Definition menu_model.h:45
MenuUpdate handle_command(input::UiCommand command)
Apply a UI command to the menu.
Definition menu_model.cpp:50
MenuModel(std::vector< MenuItem > items={})
Construct a menu from a list of items.
Definition menu_model.cpp:13
const MenuItem * selected_item() const
Return the selected item or nullptr when none is selectable.
Definition menu_model.cpp:30
bool select_item_by_id(std::string_view itemId)
Select a specific enabled item by its stable identifier.
Definition menu_model.cpp:38
static constexpr std::size_t npos
Sentinel index used when no menu item is selectable.
Definition menu_model.h:50
std::size_t selected_index() const
Return the selected item index or npos when none is selectable.
Definition menu_model.cpp:26
void set_items(std::vector< MenuItem > items)
Replace the menu items and select the first enabled entry.
Definition menu_model.cpp:17
const std::vector< MenuItem > & items() const
Return the configured items.
Definition menu_model.cpp:22
Declares controller navigation input handling.
UiCommand
Abstract UI command emitted by controller or keyboard input.
Definition navigation_input.h:12
Item shown in a focus-driven menu.
Definition menu_model.h:22
bool enabled
True when the item can be selected and activated.
Definition menu_model.h:26
std::string id
Stable identifier used by reducers and view builders.
Definition menu_model.h:23
std::string label
User-facing label shown in the menu.
Definition menu_model.h:24
std::string description
Helper copy explaining what the item changes or activates.
Definition menu_model.h:25
Result of applying a UI command to a menu.
Definition menu_model.h:32
bool overlayToggleRequested
True when the caller should toggle the diagnostics overlay.
Definition menu_model.h:38
bool nextPageRequested
True when the caller should move to the next page.
Definition menu_model.h:37
bool backRequested
True when the caller should navigate back.
Definition menu_model.h:35
bool activationRequested
True when the selected item should be activated.
Definition menu_model.h:34
bool selectionChanged
True when the focused item changed.
Definition menu_model.h:33
bool previousPageRequested
True when the caller should move to the previous page.
Definition menu_model.h:36
std::string activatedItemId
Stable identifier for the activated item, when any.
Definition menu_model.h:39