Skip to main content

MenuComponent Class

Manages a collection of menu items for UI navigation. More...

Declaration

class helios::engine::modules::ui::widgets::components::MenuComponent { ... }

Public Member Functions Index

voidsetMenuId (helios::engine::modules::ui::widgets::types::MenuId id) noexcept

Sets the menu identifier. More...

helios::engine::modules::ui::widgets::types::MenuIdmenuId () const noexcept

Returns the menu identifier. More...

voidsetSelectedIndex (const size_t index) noexcept

Sets the currently selected item index. More...

voidselectDefaultIndex ()

Resets selection to the default index. More...

size_tselectedIndex () const noexcept

Returns the currently selected item index. More...

voidaddMenuItem (const helios::engine::ecs::GameObject menuItem)

Adds a menu item to the end of the list. More...

std::span< helios::engine::ecs::EntityHandle >menuItems () noexcept

Returns a span of all menu item handles. More...

voidclearDirty ()

Clears the dirty flag. More...

voidmarkDirty ()

Marks the menu as dirty. More...

boolisDirty () const noexcept

Returns whether the menu state has changed. More...

size_tpreviousSelectedIndex () const noexcept

Returns the index of the previous selected menu index. More...

voidinsert (const helios::engine::ecs::GameObject menuItem, const size_t index)

Inserts a menu item at a specific index. More...

Private Member Attributes Index

std::vector< helios::engine::ecs::EntityHandle >menuItems_

Entity handles of the menu items. More...

helios::engine::modules::ui::widgets::types::MenuIdmenuId_ {}

Unique identifier for this menu. More...

size_tselectedIndex_ = 0

Currently selected item index. More...

size_tpreviousSelectedIndex_ = 0

Previously selected item index. More...

size_tdefaultSelectedIndex_ = 0

Default selection index when menu is focused. More...

boolisDirty_ = true

Whether the menu state has changed. More...

Description

Manages a collection of menu items for UI navigation.

Stores entity handles to menu items and tracks the currently selected item index. Supports dirty tracking for efficient updates.

See Also

MenuDisplaySystem

See Also

MenuNavigationSystem

Definition at line 27 of file MenuComponent.ixx.

Public Member Functions

addMenuItem()

void helios::engine::modules::ui::widgets::components::MenuComponent::addMenuItem (const helios::engine::ecs::GameObject menuItem)
inline

Adds a menu item to the end of the list.

Parameters
menuItem

The GameObject to add as a menu item.

Definition at line 116 of file MenuComponent.ixx.

117 markDirty();
118 menuItems_.push_back(menuItem.entityHandle());
119 }

References helios::engine::ecs::GameObject::entityHandle and markDirty.

clearDirty()

void helios::engine::modules::ui::widgets::components::MenuComponent::clearDirty ()
inline

Clears the dirty flag.

Definition at line 133 of file MenuComponent.ixx.

133 void clearDirty() {
134 isDirty_ = false;
135 }

insert()

void helios::engine::modules::ui::widgets::components::MenuComponent::insert (const helios::engine::ecs::GameObject menuItem, const size_t index)
inline

Inserts a menu item at a specific index.

Resizes the internal vector if necessary. If the item already exists at the index, no action is taken.

Parameters
menuItem

The GameObject to insert.

index

The index at which to insert.

Definition at line 171 of file MenuComponent.ixx.

171 void insert(const helios::engine::ecs::GameObject menuItem, const size_t index) {
172 if (index >= menuItems_.size()) {
173 menuItems_.resize(index + 1);
174 }
175
176 for (size_t i = 0; i < menuItems_.size(); i++) {
177 if (i == index && menuItems_[i] == menuItem.entityHandle()) {
178 return;
179 }
180 }
181
182 const auto old = menuItems_[index];
183 menuItems_[index] = menuItem.entityHandle();
184 menuItems_.push_back(old);
185 }

Reference helios::engine::ecs::GameObject::entityHandle.

isDirty()

bool helios::engine::modules::ui::widgets::components::MenuComponent::isDirty ()
inline nodiscard noexcept

Returns whether the menu state has changed.

Returns

True if dirty.

Definition at line 149 of file MenuComponent.ixx.

149 [[nodiscard]] bool isDirty() const noexcept {
150 return isDirty_;
151 }

markDirty()

void helios::engine::modules::ui::widgets::components::MenuComponent::markDirty ()
inline

Marks the menu as dirty.

Definition at line 140 of file MenuComponent.ixx.

140 void markDirty() {
141 isDirty_ = true;
142 }

Referenced by addMenuItem and setSelectedIndex.

menuId()

helios::engine::modules::ui::widgets::types::MenuId helios::engine::modules::ui::widgets::components::MenuComponent::menuId ()
inline nodiscard noexcept

Returns the menu identifier.

Returns

The MenuId for this menu.

Definition at line 75 of file MenuComponent.ixx.

76 return menuId_;
77 }

menuItems()

std::span< helios::engine::ecs::EntityHandle > helios::engine::modules::ui::widgets::components::MenuComponent::menuItems ()
inline nodiscard noexcept

Returns a span of all menu item handles.

Returns

Span of EntityHandle for all menu items.

Definition at line 126 of file MenuComponent.ixx.

126 [[nodiscard]] std::span<helios::engine::ecs::EntityHandle> menuItems() noexcept {
127 return menuItems_;
128 }

Referenced by helios::engine::modules::ui::widgets::systems::MenuNavigationSystem::update.

previousSelectedIndex()

size_t helios::engine::modules::ui::widgets::components::MenuComponent::previousSelectedIndex ()
inline nodiscard noexcept

Returns the index of the previous selected menu index.

Returns

The index of the previous selected menu item.

Definition at line 158 of file MenuComponent.ixx.

158 [[nodiscard]] size_t previousSelectedIndex() const noexcept {
159 return previousSelectedIndex_;
160 }

selectDefaultIndex()

void helios::engine::modules::ui::widgets::components::MenuComponent::selectDefaultIndex ()
inline

Resets selection to the default index.

Definition at line 97 of file MenuComponent.ixx.

98 setSelectedIndex(defaultSelectedIndex_);
99 }

Reference setSelectedIndex.

selectedIndex()

size_t helios::engine::modules::ui::widgets::components::MenuComponent::selectedIndex ()
inline nodiscard noexcept

Returns the currently selected item index.

Returns

The selected index.

Definition at line 106 of file MenuComponent.ixx.

106 [[nodiscard]] size_t selectedIndex() const noexcept {
107 return selectedIndex_;
108 }

Referenced by helios::engine::modules::ui::widgets::systems::MenuNavigationSystem::update.

setMenuId()

void helios::engine::modules::ui::widgets::components::MenuComponent::setMenuId (helios::engine::modules::ui::widgets::types::MenuId id)
inline noexcept

Sets the menu identifier.

Parameters
id

The menu ID.

Definition at line 66 of file MenuComponent.ixx.

67 menuId_ = id;
68 }

setSelectedIndex()

void helios::engine::modules::ui::widgets::components::MenuComponent::setSelectedIndex (const size_t index)
inline noexcept

Sets the currently selected item index.

Marks the menu as dirty if the index changes.

Parameters
index

The index to select.

Definition at line 86 of file MenuComponent.ixx.

86 void setSelectedIndex(const size_t index) noexcept {
87 if (index != selectedIndex_) {
88 markDirty();
89 }
90 previousSelectedIndex_ = selectedIndex_;
91 selectedIndex_ = index;;
92 }

Reference markDirty.

Referenced by selectDefaultIndex.

Private Member Attributes

defaultSelectedIndex_

size_t helios::engine::modules::ui::widgets::components::MenuComponent::defaultSelectedIndex_ = 0

Default selection index when menu is focused.

Definition at line 52 of file MenuComponent.ixx.

52 size_t defaultSelectedIndex_ = 0;

isDirty_

bool helios::engine::modules::ui::widgets::components::MenuComponent::isDirty_ = true

Whether the menu state has changed.

Definition at line 57 of file MenuComponent.ixx.

57 bool isDirty_ = true;

menuId_

helios::engine::modules::ui::widgets::types::MenuId helios::engine::modules::ui::widgets::components::MenuComponent::menuId_ {}

Unique identifier for this menu.

Definition at line 37 of file MenuComponent.ixx.

menuItems_

std::vector<helios::engine::ecs::EntityHandle> helios::engine::modules::ui::widgets::components::MenuComponent::menuItems_

Entity handles of the menu items.

Definition at line 32 of file MenuComponent.ixx.

32 std::vector<helios::engine::ecs::EntityHandle> menuItems_;

previousSelectedIndex_

size_t helios::engine::modules::ui::widgets::components::MenuComponent::previousSelectedIndex_ = 0

Previously selected item index.

Definition at line 47 of file MenuComponent.ixx.

47 size_t previousSelectedIndex_ = 0;

selectedIndex_

size_t helios::engine::modules::ui::widgets::components::MenuComponent::selectedIndex_ = 0

Currently selected item index.

Definition at line 42 of file MenuComponent.ixx.

42 size_t selectedIndex_ = 0;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.