Skip to main content

MenuItemConfig.ixx File

Fluent configuration for menu item GameObjects. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacebuilder

Fluent builder pattern for constructing GameObjects. More...

namespacegameObject

Factory and prototype classes for GameObject construction. More...

namespacebuilders

Domain-specific builders for configuring different aspects of GameObjects. More...

namespaceconfigs

Fine-grained configuration classes for component setup. More...

Classes Index

classMenuItemConfig

Fluent configuration for menu item GameObjects. More...

Description

Fluent configuration for menu item GameObjects.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file MenuItemConfig.ixx
3 * @brief Fluent configuration for menu item GameObjects.
4 */
5module;
6
7#include <cassert>
8#include <optional>
9
10export module helios.engine.builder.gameObject.builders.configs.MenuItemConfig;
11
12import helios.engine.ecs.GameObject;
13
14import helios.engine.core.data;
15
16import helios.engine.modules.ui.widgets.components.MenuComponent;
17import helios.engine.modules.ui.widgets.components.UiStyleComponent;
18import helios.engine.modules.ui.widgets.components.UiStateComponent;
19import helios.engine.modules.ui.widgets.components.UiActionComponent;
20
21import helios.math;
22
23
25
26 /**
27 * @brief Fluent configuration for menu item GameObjects.
28 *
29 * Provides a builder-style interface for configuring menu items including
30 * styling, selection state, and action binding. Automatically attaches
31 * the item to the parent menu.
32 */
34
35 /**
36 * @brief The GameObject being configured.
37 */
39
40 /**
41 * @brief Pointer to the parent menu GameObject.
42 */
43 helios::engine::ecs::GameObject* parentMenu_ = nullptr;
44
45 /**
46 * @brief Optional index position in the menu.
47 */
48 std::optional<size_t> index_ = std::nullopt;
49
50 /**
51 * @brief Whether this item is selected.
52 */
53 bool isSelected_ = false;
54
55 /**
56 * @brief Attaches this item to the parent menu.
57 */
58 void attach() {
59 assert(parentMenu_ != nullptr);
60
62
63 assert(mc != nullptr && "Unexpected nullptr for MenuComponent");
64
65 mc->addMenuItem(gameObject_);
66 }
67 public:
68
69 /**
70 * @brief Constructs a MenuItemConfig for the given GameObject.
71 *
72 * Automatically adds UiStyleComponent and UiStateComponent,
73 * and attaches the item to the parent menu.
74 *
75 * @param gameObject The GameObject to configure.
76 * @param parentMenu The parent menu GameObject (must have MenuComponent).
77 */
78 explicit MenuItemConfig(
81 ) : gameObject_(gameObject), parentMenu_(&parentMenu) {
82
83
86
87
89 "parent menu must have MenuComponent");
90
91 attach();
92 }
93
94 /**
95 * @brief Sets the selected state.
96 *
97 * @param isSelected True if this item should be selected.
98 *
99 * @return Reference to this config for method chaining.
100 */
101 MenuItemConfig& selected(const bool isSelected) {
102
103 if (!isSelected_) {
104 return *this;
105
106 }
107 if (index_) {
109 ->setSelectedIndex(index_.value());
110 } else {
111 isSelected_ = isSelected;
112 }
113
114 return *this;
115 }
116
117 /**
118 * @brief Sets the normal state color.
119 *
120 * @param color The RGBA color.
121 *
122 * @return Reference to this config for method chaining.
123 */
126 ->setNormalColor(color);
127
128 return *this;
129 }
130
131 /**
132 * @brief Sets the normal state scale.
133 *
134 * @param scale The scale factor.
135 *
136 * @return Reference to this config for method chaining.
137 */
138 MenuItemConfig& normalScale(const float scale) {
140 ->setNormalScale(scale);
141
142 return *this;
143 }
144
145 /**
146 * @brief Sets the selected state color.
147 *
148 * @param color The RGBA color.
149 *
150 * @return Reference to this config for method chaining.
151 */
154 ->setSelectedColor(color);
155
156 return *this;
157 }
158
159 /**
160 * @brief Sets the selected state scale.
161 *
162 * @param scale The scale factor.
163 *
164 * @return Reference to this config for method chaining.
165 */
166 MenuItemConfig& selectedScale(const float scale) {
168 ->setSelectedScale(scale);
169
170 return *this;
171 }
172
173 /**
174 * @brief Sets the action ID for this menu item.
175 *
176 * @param actionId The action to trigger when activated.
177 *
178 * @return Reference to this config for method chaining.
179 */
181
183
184 return *this;
185 }
186
187 /**
188 * @brief Sets the index position in the parent menu.
189 *
190 * @param index The index position.
191 *
192 * @return Reference to this config for method chaining.
193 */
194 MenuItemConfig& index(const size_t index) {
195
197 ->insert(gameObject_, index);
198
199 if (isSelected_) {
201 ->setSelectedIndex(index);
202 }
203
204 index_ = index;
205
206 return *this;
207 }
208
209
210 };
211
212}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.