Skip to main content

UiTransformSystem Class

Computes screen positions for UI elements based on layout configuration. More...

Declaration

class helios::engine::modules::ui::transform::systems::UiTransformSystem { ... }

Base class

classSystem

Abstract base class for game systems. More...

Public Member Functions Index

voidupdate (helios::engine::runtime::world::UpdateContext &updateContext) noexcept override

Computes and applies screen positions for all UI elements. More...

Private Member Functions Index

helios::math::vec3fanchor (const helios::math::vec3f unanchored, helios::math::vec3f size, const helios::engine::modules::ui::layout::Anchor pivot)

Adjusts position based on pivot point and element size. More...

Description

Computes screen positions for UI elements based on layout configuration.

This system processes entities with UiTransformComponent and computes their final screen positions. The positioning algorithm considers:

  • **Anchor:** Where the element attaches to its parent (Center, TopLeft, etc.)
  • **Pivot:** The element's own reference point for positioning
  • **Offsets:** Margins from the anchor point (top, right, bottom, left)
  • **Viewport:** Current viewport dimensions for root-level elements
  • **Parent bounds:** For nested UI elements via HierarchyComponent

## Hierarchy Support

For elements with a HierarchyComponent, the system uses the parent entity's AABB and transform to compute relative positioning. Root elements (those attached to the scene root) use viewport dimensions as their parent bounds.

## Required Components

| Component | Purpose | |-----------|---------| | `UiTransformComponent` | Layout configuration (anchor, pivot, offsets) | | `TranslationStateComponent` | Receives computed position | | `ComposeTransformComponent` | Transform composition | | `ModelAabbComponent` | Element bounds for size calculations | | `SceneNodeComponent` | Scene graph integration | | `Active` | Lifecycle tag |

See Also

UiTransformComponent

See Also

Anchor

See Also

HierarchyComponent

Definition at line 68 of file UiTransformSystem.ixx.

Public Member Functions

update()

void helios::engine::modules::ui::transform::systems::UiTransformSystem::update (helios::engine::runtime::world::UpdateContext & updateContext)
inline noexcept virtual

Computes and applies screen positions for all UI elements.

Iterates over all entities with UI layout components and computes their final screen positions. For each entity:

1. Finds the matching viewport snapshot by viewportId 2. Determines parent bounds (viewport for root, parent AABB otherwise) 3. Computes anchor position based on anchor type and offsets 4. Adjusts for pivot point 5. Updates TranslationStateComponent with final position

Parameters
updateContext

The current frame's update context.

Definition at line 123 of file UiTransformSystem.ixx.

123 void update(helios::engine::runtime::world::UpdateContext& updateContext) noexcept override {
124
125 for (auto [entity, tc, tsc, ctc, mbc, snc, active] : gameWorld_->view<
132 >().whereEnabled()) {
133
134 if (!tc->viewportId()) {
135 continue;
136 }
137
138 for (const auto& snapshot : updateContext.viewportSnapshots()) {
139 if (snapshot.viewportId != tc->viewportId()) {
140 continue;
141 }
142
143 auto pivot = tc->pivot();
144
145 auto sceneNode = snc->sceneNode();
146
147 float viewportWidth;
148 float viewportHeight;
149
150 auto uiRect = helios::math::vec4f(
151 mbc->aabb().min()[0], mbc->aabb().min()[1],
152 mbc->aabb().size()[0], mbc->aabb().size()[1]
153 );
154 auto worldRect = helios::math::vec4f(
155 uiRect[0] + uiRect[0] / 2.0f,
156 uiRect[1] + uiRect[1] / 2.0f,
157 uiRect[2], uiRect[3]
158 );
159
160
161 auto parentUiRect = helios::math::vec4f{};
162 auto parentWorldRect = helios::math::vec4f{};
163
164 const auto offsets = tc->offsets();
165
166 if (sceneNode->parent()->isRoot()) {
167 viewportWidth = snapshot.absoluteBounds[2];
168 viewportHeight = snapshot.absoluteBounds[3];
169
170 parentUiRect = helios::math::vec4f(0, 0, viewportWidth, viewportHeight);
171
172 parentWorldRect = helios::math::vec4f(
173 viewportWidth / 2.0f,
174 viewportHeight /2.0f,
175 viewportWidth,
176 viewportHeight
177 );
178
179 } else {
180
182
183 if (!hc || !hc->parent()) {
184 continue;
185 }
186
187 // we rely on the parent entity so we do not have to wait for the SceneGraph sync
188 if (auto parentGo = gameWorld_->find(hc->parent().value())) {
189 auto* pmaabbcc = parentGo->get<rendering::model::components::ModelAabbComponent>();
191
192 auto size = pmaabbcc->aabb().size() * pctc->localScaling();
193
194 parentUiRect = helios::math::vec4f(
195 -(size[0] * 0.5f),
196 -(size[1] * 0.5f),
197 size[0],
198 size[1]
199 );
200 }
201 }
202
203
204 switch (tc->anchor()) {
205
207 auto anchored = helios::math::vec3f(
208 parentUiRect[0] + parentUiRect[2]/2.0f - offsets[1] ,
209 parentUiRect[1] + parentUiRect[3]/2.0f - offsets[0], 0.0f
210 );
211 anchored = anchor(anchored, mbc->aabb().size(), pivot);
212 tsc->setTranslation(anchored);
213 }
214 break;
215
217 auto anchored = helios::math::vec3f(
218 parentUiRect[0] + parentUiRect[2] - offsets[1],
219 parentUiRect[1] + parentUiRect[3] - offsets[0],
220 0.0f
221 );
222 anchored = anchor(anchored, mbc->aabb().size(), pivot);
223 tsc->setTranslation(anchored);
224 }
225 break;
226
228 auto anchored = helios::math::vec3f(
229 parentUiRect[0] + offsets[3],
230 parentUiRect[1] + parentUiRect[3] - offsets[0],
231 0.0f
232 );
233 anchored = anchor(anchored, mbc->aabb().size(), pivot);
234 tsc->setTranslation(anchored);
235 }
236 break;
237
239 auto anchored = helios::math::vec3f(
240 parentUiRect[0] + offsets[3],
241 parentUiRect[1] + offsets[2],
242 0.0f
243 );
244 anchored = anchor(anchored, mbc->aabb().size(), pivot);
245 tsc->setTranslation(anchored);
246 }
247 break;
248
249 }
250 }
251 }
252 }

References helios::engine::modules::ui::layout::BottomLeft, helios::engine::modules::ui::layout::Center, helios::engine::ecs::System::gameWorld_, helios::engine::modules::ui::layout::TopLeft and helios::engine::modules::ui::layout::TopRight.

Private Member Functions

anchor()

helios::math::vec3f helios::engine::modules::ui::transform::systems::UiTransformSystem::anchor (const helios::math::vec3f unanchored, helios::math::vec3f size, const helios::engine::modules::ui::layout::Anchor pivot)
inline

Adjusts position based on pivot point and element size.

Transforms a position from anchor-relative to pivot-relative coordinates. The pivot determines which point of the element is placed at the anchor position.

Parameters
unanchored

The position before pivot adjustment.

size

The size of the element.

pivot

The pivot point to apply.

Returns

The adjusted position accounting for pivot offset.

Definition at line 83 of file UiTransformSystem.ixx.

84 const helios::math::vec3f unanchored,
87
88 switch (pivot) {
89
91 return unanchored - size * 0.5f;
92
94 return unanchored - size;
95
97 return unanchored.withY(unanchored[1] - size[1]);
98
100 return unanchored;
101 }
102
103 assert(false && "Unreachable!");
104 std::unreachable();
105 }

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.