Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
esengine::ecs::UISystem Class Reference

UI subsystem: owns layout tree + hit-test state. More...

#include <UISystem.hpp>

Public Member Functions

 UISystem ()
 ~UISystem ()
 UISystem (const UISystem &)=delete
UISystem & operator= (const UISystem &)=delete
bool layoutUpdate (Registry &registry, f32 boxLeft, f32 boxBottom, f32 boxRight, f32 boxTop, bool tsPropertyDirty)
 Rebuild layout tree and apply layout to all dirty nodes. The four bounds are the world-space box UI is laid out within: its size is what Yoga solves against, its center is where screen roots are placed.
void hitTestUpdate (Registry &registry, const PickRay &ray, const resource::ResourceManager *resources=nullptr)
 Run ray-vs-content hit-test, updating hitResult. A query: what a press or a hover MEANS is the interaction system's, and it is in TS.
void hitTestUpdate (Registry &registry, const PickRay &worldRay, const PickRay &screenRay, const resource::ResourceManager *resources)
 The same, with a ray per DOMAIN.
bool hitInputsChanged (Registry &registry, const resource::ResourceManager *resources)
u32 pick (Registry &registry, f32 worldX, f32 worldY)
 Editor pick: the most specific UI entity under the point. Unlike hitTestUpdate it ignores Interactable and mutates no state.
u32 pickAll (Registry &registry, f32 worldX, f32 worldY)
 All UI entities under the point, most specific first. Returns the count; read entries via pickResult.
u32 pickResult (u32 index) const
 Entry index of the last pickAll (or INVALID_ENTITY).
u32 getHitEntity () const
 Entity hit by the most recent hitTestUpdate (or INVALID_ENTITY).
u32 getPrevHitEntity () const
 Entity hit by the previous frame's hitTestUpdate.
const std::unordered_set< u32 > & screenDomain () const
 Every entity that belongs to the SCREEN, as opposed to the world.
const std::vector< u32 > & screenRoots () const
 The screen's root Canvases, in the order the UI tree draws them (each Canvas in its pool's order, as canvasRoots walks them). Rebuilt with the domain.
const std::vector< u32 > & screenRootByIndex () const
 screenRootOf for every entity at once, by entity index, for a reader that asks of many.
u32 screenRootOf (u32 entity) const
 Which screen root entity (an id in screenDomain()) draws under; for one outside the domain, nothing it says.
bool isScreenDomain (const Registry &registry, u32 entity) const

Public Attributes

UITree tree
UIHitTestResult hitResult
std::unique_ptr< LayoutCache > layoutCache_

Detailed Description

UI subsystem: owns layout tree + hit-test state.

Registered as a service on EstellaContext. All UI layout and hit-test state lives on this instance; no file-level globals.

auto& ui = ctx.require<ecs::UISystem>();
ui.layoutUpdate(registry, -960, -540, 960, 540);
ui.hitTestUpdate(registry, PickRay{cameraPos, pointerDir}, &resources);
auto hitEntity = ui.getHitEntity();
UI subsystem: owns layout tree + hit-test state.
Definition UISystem.hpp:56
bool layoutUpdate(Registry &registry, f32 boxLeft, f32 boxBottom, f32 boxRight, f32 boxTop, bool tsPropertyDirty)
Rebuild layout tree and apply layout to all dirty nodes. The four bounds are the world-space box UI i...
static EstellaContext & ctx()

Definition at line 56 of file UISystem.hpp.

Constructor & Destructor Documentation

◆ UISystem() [1/2]

esengine::ecs::UISystem::UISystem ( )
default

Referenced by UISystem(), and operator=().

◆ ~UISystem()

esengine::ecs::UISystem::~UISystem ( )
default

◆ UISystem() [2/2]

esengine::ecs::UISystem::UISystem ( const UISystem & )
delete

References UISystem().

Member Function Documentation

◆ getHitEntity()

u32 esengine::ecs::UISystem::getHitEntity ( ) const
inline

Entity hit by the most recent hitTestUpdate (or INVALID_ENTITY).

Definition at line 122 of file UISystem.hpp.

References hitResult.

◆ getPrevHitEntity()

u32 esengine::ecs::UISystem::getPrevHitEntity ( ) const
inline

Entity hit by the previous frame's hitTestUpdate.

Definition at line 125 of file UISystem.hpp.

References hitResult.

◆ hitInputsChanged()

◆ hitTestUpdate() [1/2]

void esengine::ecs::UISystem::hitTestUpdate ( Registry & registry,
const PickRay & ray,
const resource::ResourceManager * resources = nullptr )

Run ray-vs-content hit-test, updating hitResult. A query: what a press or a hover MEANS is the interaction system's, and it is in TS.

UI wins any overlap, topmost first; below it world content ranks by distance along the ray, sorting layer breaking a flat scene's tie. Without resources only inline mesh geometry can be hit.

Definition at line 31 of file UISystem.cpp.

References hitTestUpdate().

Referenced by hitTestUpdate().

◆ hitTestUpdate() [2/2]

void esengine::ecs::UISystem::hitTestUpdate ( Registry & registry,
const PickRay & worldRay,
const PickRay & screenRay,
const resource::ResourceManager * resources )

The same, with a ray per DOMAIN.

A pixel is in no domain until it is projected into one, so screen UI answers screenRay and world content worldRay — each entity through the projection it is DRAWN with. One ray for both draws the HUD where it should be and clicks somewhere else.

Definition at line 36 of file UISystem.cpp.

References esengine::ecs::Transform::ensureDecomposed(), esengine::ecs::Registry::get(), esengine::ecs::Registry::has(), hitResult, esengine::Entity::id(), esengine::INVALID_ENTITY, esengine::ecs::isClippedByMask(), esengine::ecs::Registry::isEntityActive(), esengine::ecs::pointInTransformedBox(), esengine::ecs::rayHitsPlaneZ(), tree, and esengine::ecs::Registry::tryGet().

◆ isScreenDomain()

bool esengine::ecs::UISystem::isScreenDomain ( const Registry & registry,
u32 entity ) const
inline

◆ layoutUpdate()

bool esengine::ecs::UISystem::layoutUpdate ( Registry & registry,
f32 boxLeft,
f32 boxBottom,
f32 boxRight,
f32 boxTop,
bool tsPropertyDirty )

Rebuild layout tree and apply layout to all dirty nodes. The four bounds are the world-space box UI is laid out within: its size is what Yoga solves against, its center is where screen roots are placed.

Parameters
tsPropertyDirtySet by the TS driver when any UINode/FlexContainer changed since the last pass (via change-tracking). Combined with the C++-detected structure/box/animation signals to skip the whole rebuild+solve on a fully static frame.

Definition at line 584 of file UILayoutSystem.cpp.

References esengine::ecs::LayoutRect::centerX(), esengine::ecs::LayoutRect::centerY(), esengine::ecs::LayoutRect::height(), esengine::ecs::Registry::instanceId(), esengine::ecs::invalidateTransformComposition(), layoutCache_, tree, esengine::ecs::Registry::view(), and esengine::ecs::LayoutRect::width().

◆ operator=()

UISystem & esengine::ecs::UISystem::operator= ( const UISystem & )
delete

References UISystem().

◆ pick()

u32 esengine::ecs::UISystem::pick ( Registry & registry,
f32 worldX,
f32 worldY )

Editor pick: the most specific UI entity under the point. Unlike hitTestUpdate it ignores Interactable and mutates no state.

Definition at line 311 of file UISystem.cpp.

References esengine::INVALID_ENTITY, and pickAll().

◆ pickAll()

u32 esengine::ecs::UISystem::pickAll ( Registry & registry,
f32 worldX,
f32 worldY )

◆ pickResult()

u32 esengine::ecs::UISystem::pickResult ( u32 index) const
inline

Entry index of the last pickAll (or INVALID_ENTITY).

Definition at line 117 of file UISystem.hpp.

References esengine::INVALID_ENTITY.

◆ screenDomain()

const std::unordered_set< u32 > & esengine::ecs::UISystem::screenDomain ( ) const
inline

Every entity that belongs to the SCREEN, as opposed to the world.

Resolved once at a subtree's root and inherited by all of it: a Canvas with no Transform parent IS the screen. The whole Transform subtree, not just the laid-out nodes — what decides the domain is where a transform composes FROM. Rebuilt by every layout pass.

Definition at line 135 of file UISystem.hpp.

Referenced by esengine::screenDomain().

◆ screenRootByIndex()

const std::vector< u32 > & esengine::ecs::UISystem::screenRootByIndex ( ) const
inline

screenRootOf for every entity at once, by entity index, for a reader that asks of many.

Definition at line 141 of file UISystem.hpp.

◆ screenRootOf()

u32 esengine::ecs::UISystem::screenRootOf ( u32 entity) const
inline

Which screen root entity (an id in screenDomain()) draws under; for one outside the domain, nothing it says.

Definition at line 144 of file UISystem.hpp.

References esengine::Entity::fromRaw(), and esengine::Entity::index().

◆ screenRoots()

const std::vector< u32 > & esengine::ecs::UISystem::screenRoots ( ) const
inline

The screen's root Canvases, in the order the UI tree draws them (each Canvas in its pool's order, as canvasRoots walks them). Rebuilt with the domain.

Definition at line 139 of file UISystem.hpp.

Member Data Documentation

◆ hitResult

UIHitTestResult esengine::ecs::UISystem::hitResult

Definition at line 67 of file UISystem.hpp.

Referenced by getHitEntity(), getPrevHitEntity(), and hitTestUpdate().

◆ layoutCache_

std::unique_ptr<LayoutCache> esengine::ecs::UISystem::layoutCache_

Definition at line 68 of file UISystem.hpp.

Referenced by layoutUpdate().

◆ tree

UITree esengine::ecs::UISystem::tree

Definition at line 66 of file UISystem.hpp.

Referenced by hitTestUpdate(), layoutUpdate(), and pickAll().


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