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 { ... }

Public Member Typedefs Index

usingEngineRoleTag = helios::engine::common::tags::SystemRole

Public Member Functions Index

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

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 70 of file UiTransformSystem.ixx.

Public Member Typedefs

EngineRoleTag

using helios::engine::modules::ui::transform::systems::UiTransformSystem::EngineRoleTag = helios::engine::common::tags::SystemRole

Public Member Functions

update()

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

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 128 of file UiTransformSystem.ixx.

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

References helios::engine::modules::ui::layout::BottomLeft, helios::engine::modules::ui::layout::Center, 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 85 of file UiTransformSystem.ixx.

86 const helios::math::vec3f unanchored,
89
90 switch (pivot) {
91
93 return unanchored - size * 0.5f;
94
96 return unanchored - size;
97
99 return unanchored.withY(unanchored[1] - size[1]);
100
102 return unanchored;
103 }
104
105 assert(false && "Unreachable!");
106 std::unreachable();
107 }

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.