ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
ZenitUI::UIContext Struct Reference

Per-instance UI context: backends, theme, text engine, frame state, and routing. More...

#include <UIContext.hpp>

Public Member Functions

 UIContext (const UIContext &)=delete
UIContext & operator= (const UIContext &)=delete
 UIContext (UIContext &&)=delete
UIContext & operator= (UIContext &&)=delete
void attachBackend (IRenderer *r, IPlatform *p, IAssetProvider *a, UIContext **ownerSlot=nullptr)
 Attach renderer, platform, and asset backends to this context.
void detachBackend ()
 Flush pooled render targets while the renderer is still valid and clear backend pointers.
FontHandle loadFont (std::string_view name, std::string_view path)
 Load a TTF/OTF font from disk under logical name.
FontHandle loadFontFromMemory (std::string_view name, const void *data, size_t size)
 Load a TTF/OTF font from memory under logical name (copies bytes).
void unloadFont (std::string_view name)
 Unload a font by logical name.
FontHandle getFont (std::string_view name) const
 Look up a loaded font by logical name ({0} if not found).
void setDefaultFont (FontHandle h)
 Set the fallback font used when a node specifies no font or an unknown font name.
FontHandle defaultFont () const
 Return the current default font handle ({0} if none).
TextureHandle loadTexture (std::string_view name, std::string_view path)
 Load a 2D texture from disk under logical name.
TextureHandle loadTextureFromMemory (std::string_view name, const void *data, size_t size)
 Load a 2D texture from encoded image bytes (PNG/JPG/BMP/...) under logical name.
void unloadTexture (std::string_view name)
 Unload a 2D texture by logical name.
TextureHandle getTexture (std::string_view name) const
 Look up a loaded 2D texture by logical name ({0} if not found).
EffectHandle loadEffect (std::string_view name, std::string_view fsPath, std::string_view vsPath={})
 Load a fragment (and optional vertex) shader from disk under logical name.
EffectHandle loadEffectFromMemory (std::string_view name, std::string_view fsSource, std::string_view vsSource={})
 Load a shader effect from in-memory source strings under logical name.
EffectHandle loadEffectAsset (std::string_view name, std::string_view baseDir, std::string_view fileStem)
 Load a shader effect by stem fileStem under baseDir, automatically resolving the file extension for the active renderer's ShaderLanguage.
void unloadEffect (std::string_view name)
 Unload a shader effect by logical name.
EffectHandle getEffect (std::string_view name) const
 Look up a loaded shader effect by logical name ({0} if not found).
void consumeClick (MouseButton b)
 Mark b as consumed; subsequent handlers in the same frame will skip it.
bool wasConsumed (MouseButton b) const
 true if b was already consumed this frame.
ZMarkup::Registry & markupRegistry ()
 Return this context's isolated ZMarkup::Registry, lazily initialized with built-in widgets.
const ZMarkup::Registry * markupRegistryPtr () const noexcept
 Return this context's ZMarkup::Registry if initialized, or nullptr without allocating.
void invalidateStyles ()
 Force style-cache invalidation across the tree.
bool isPressTarget (const Layout *n) const
 true if n is the current press target.
bool isValidClick () const
 true if press and release targets agree (a valid click).
bool isDragging () const noexcept
 true while a drag gesture has crossed dragThreshold and is active.
bool hasPendingDrag () const noexcept
 true while a press on a draggable node is waiting to cross dragThreshold.
void clearDragState ()
 Reset all pending/active drag state and destroy any active drag ghost without invoking callbacks.
std::shared_ptr< Layout > dragGhost () const
 Return the currently active drag ghost node, or nullptr if none.
void applyCursor (CursorShape shape)
 Apply shape to the active platform backend, deduplicating unchanged requests.
void setTextInputRect (Rect inputRect, float cursorXOffset=0.0f)
 Forward the active text-input IME rect to the platform, deduplicating unchanged rects.
void resetImeRectState ()
 Clear cached IME rect state (e.g.
Rect getCullingClip () const
 Active screen-space clip rect used by Layout::draw() for off-screen culling.
void pushLayerTarget (TargetHandle t, float targetScale=1.0f)
 Push an off-screen target while preserving the root screen-space culling clip.
void popLayerTarget ()
 Pop an off-screen target pushed via pushLayerTarget.
void beginFrame (float delta_time)
 Advance the frame: pull platform state and reset one-shot flags.
void endFrame ()
 End-of-frame housekeeping (trims idle pooled render targets).
void requestFocus (std::shared_ptr< Layout > n)
 Set n as the focused node; null clears focus.
void mount (Layout &root)
 Attach a root Layout subtree to this context and set it as the primary root.
void mount (const std::shared_ptr< Layout > &root)
void unmount (Layout &root)
 Detach a previously mounted root Layout subtree from this context.
void unmount (const std::shared_ptr< Layout > &root)
void unmount ()
 Detach the currently mounted primary root, if any.
Layout * mountedRoot () const
 Return the primary root set by mount(), or nullptr if none.
void detachAllRoots ()
 Detach every root currently attached to this context.
void runFrame (float dt)
 Run one full update/measure/arrange frame on the mounted primary root.
void renderFrame ()
 Render the mounted primary root (beginFrame, draw, endFrame).
void runFrame (Layout &root, float dt)
 Run one full update/measure/arrange frame on root using this context.
void renderFrame (Layout &root)
 Render root (beginFrame, draw, endFrame) using this context.
void releaseFocus ()
 Clear focus.
bool hasFocus (const Layout *n) const
 true if n is the current focused node.

Public Attributes

IRenderer * renderer {nullptr}
IPlatform * platform {nullptr}
IAssetProvider * assets {nullptr}
PointerState pointer
float dt {0.0f}
double time {0.0}
float dpiScale {1.0f}
EdgeInsets safeArea
ModifierState modifiers
bool wheelConsumedThisFrame {false}
std::array< bool,(size_t) MouseButton::Count > buttonConsumed {}
Vec2 viewport {1280.0f, 720.0f}
 Current logical viewport dimensions.
InputEvents inputEvents
std::weak_ptr< Layout > focusedNode
std::weak_ptr< Layout > pointerCapture
FilterRegistry filters
 Per-context post-processing filter definitions (preloaded with builtins).
Theme theme
 Per-context stylesheet (rules, keyframes, and :root style).
TextEngine textEngine
 Per-context FreeType/HarfBuzz shaper, glyph atlas, and layout cache.
uint32_t viewportGeneration {0}
Layout * topmostConsumer {nullptr}
Layout * hoverTarget {nullptr}
Layout * pressTarget {nullptr}
Layout * releaseTarget {nullptr}
CursorShape activeCursor {CursorShape::Default}
ActiveDrag activeDrag
float dragThreshold {5.0f}
std::function< std::shared_ptr< Layout >(const DragPayload &)> dragGhostFactory
std::vector< std::weak_ptr< Layout > > activePortals
std::vector< std::weak_ptr< Layout > > framePortals
std::mt19937 rng
RenderStats renderStats
TargetPool targetPool
std::vector< Rect > cullingClipStack
std::vector< float > targetScaleStack_

Friends

class Layout

Detailed Description

Member Function Documentation

◆ attachBackend()

void ZenitUI::UIContext::attachBackend ( IRenderer * r,
IPlatform * p,
IAssetProvider * a,
UIContext ** ownerSlot = nullptr )
inline

Attach renderer, platform, and asset backends to this context.

Parameters
rRenderer backend (non-owning).
pPlatform backend (non-owning).
aAsset provider backend (non-owning).
ownerSlotOptional pointer to an IBackend::boundCtx_ slot kept in sync on detach.

◆ beginFrame()

void ZenitUI::UIContext::beginFrame ( float delta_time)
inline

Advance the frame: pull platform state and reset one-shot flags.

Called once at the top of Layout::runFrame. On viewport or safe-area change, viewportGeneration is bumped so every cached style key changes and everything re-resolves.

Parameters
delta_timeSeconds since the previous frame.

◆ markupRegistry()

ZMarkup::Registry & ZenitUI::UIContext::markupRegistry ( )

Return this context's isolated ZMarkup::Registry, lazily initialized with built-in widgets.

Prefabs and custom tags registered here are scoped strictly to this UIContext and never leak to other contexts or the global registry.

Examples
06_prefabs_slots/main.cpp, 09_drag_drop/main.cpp, 14_desktop_workspace/main.cpp, 15_grid_dashboard/main.cpp, and 16_data_table/main.cpp.

◆ resetImeRectState()

void ZenitUI::UIContext::resetImeRectState ( )
inline

Clear cached IME rect state (e.g.

on backend switch or test reset).


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