ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
StyleResolver.hpp
Go to the documentation of this file.
1#pragma once
2
12
13#include "Common.hpp"
14#include "CoreTypes.hpp"
15#include "UIEnums.hpp"
16#include "Style.hpp"
17#include "Theme.hpp"
18#include "AnimPrimitives.hpp"
19#include "StyleAttr.hpp"
20
21#include <memory>
22
23namespace ZenitUI
24{
28
29 class Layout;
30
36 {
46
49 {
52 uint64_t dirtyMask{0};
53 float timer{1.0f};
54 };
55
58 {
59 ComputedStyle style;
60 uint64_t key{0};
61 bool valid{false};
62 bool alignItemsSet{false};
63 };
64
70 {
71 bool initialized{false};
72 Style target;
73 Style current;
74 double startTime{0.0};
75 float duration{0.0f};
76 TransitionFunction ease{TransitionFunction::Linear};
77 bool active{false};
78 };
79
85 {
86 bool hovered{false};
87 bool pressed{false};
88 bool focused{false};
89 bool enabled{true};
90 bool checked{false};
91 FontStack font;
92 Value fontSize;
93 Color color;
94 Value letterSpacing;
95 Align textAlign{Align::Auto};
98 SharedPropMap customProps;
99 };
100
101 // ---- Hot inline state ----
104
105 // ---- Lazy inline style inputs ----
106 Style &ensureInlineDefaults()
107 {
108 if (!inlineDefaults_)
109 inlineDefaults_ = std::make_unique<Style>();
110 return *inlineDefaults_;
111 }
112 Style &ensureInlineBase()
113 {
114 if (!inlineBase_)
115 inlineBase_ = std::make_unique<Style>();
116 return *inlineBase_;
117 }
118 InlineStateStyles &ensureInlineStates()
119 {
120 if (!inlineStates_)
121 inlineStates_ = std::make_unique<InlineStateStyles>();
122 return *inlineStates_;
123 }
124
125 const Style *inlineDefaultsPtr() const noexcept { return inlineDefaults_.get(); }
126 const Style *inlineBasePtr() const noexcept { return inlineBase_.get(); }
127 const InlineStateStyles *inlineStatesPtr() const noexcept { return inlineStates_.get(); }
128
129 // ---- Transition state queries ----
130
132 const ComputedStyle &effectiveTargetStyle() const noexcept
133 {
134 return transition_ ? transition_->target : currentStyle;
135 }
136
138 bool isTransitioning() const noexcept
139 {
140 return transition_ && transition_->timer < 1.0f;
141 }
142
144 float transitionProgress() const noexcept
145 {
146 return transition_ ? transition_->timer : 1.0f;
147 }
148
151
154
159
163 Style partFor(Layout &node, const std::string &partName);
164
168 void beginStateTransition(Layout &node, UIState newState);
169
173 void resolvePendingTransition(Layout &node, bool instant = false);
174
180 void tick(Layout &node, float dt);
181
186
188 void invalidateCache() noexcept
189 {
190 if (themeCache_)
191 themeCache_->valid = false;
192 }
193
194 private:
195 std::unique_ptr<Style> inlineDefaults_;
196 std::unique_ptr<Style> inlineBase_;
197 std::unique_ptr<InlineStateStyles> inlineStates_;
198 std::unique_ptr<TransitionState> transition_;
199 std::unique_ptr<ThemeCache> themeCache_;
200 std::unique_ptr<std::unordered_map<std::string, PartTransition>> partTransitions_;
201 std::unique_ptr<InheritedSnapshot> lastInherited_;
202
203 void applyInlineOverlays(const Layout &node, ComputedStyle &result) const;
204
205 void applyStackAlignDefault(const Layout &node,
206 const Style *inlineBase,
207 bool alignItemsSet,
208 ComputedStyle &result) const;
209 };
210
211} // namespace ZenitUI
Low-level animation types: imperative tracks, CSS keyframes, and the per-instance active animation st...
Centralized standard library includes used throughout ZenitUI.
Small value types shared by the layout, rendering and input layers.
Parse a single CSS-like declaration (key: value) into a Style.
The Style / ComputedStyle pair and all style-related value types.
Global stylesheet storage and rule matching.
Small enumerations describing layout strategy and interaction state.
Ordered list of font family names to try, first match wins.
Definition CoreTypes.hpp:194
The base node type: tree, style, layout, input, scroll, render.
Definition Layout.hpp:154
8-byte Copy-on-Write wrapper around std::unordered_map<std::string, std::string>.
Definition Style.hpp:81
TransitionFunction
Timing function applied between two keyframe values.
Definition Easing.hpp:28
Align
Cross-axis alignment for flex items and content.
Definition CoreTypes.hpp:452
TextDirection
Inline / layout writing direction for Bidi text and RTL layout mirroring (ยง6.2).
Definition UIEnums.hpp:83
CursorShape
Standard OS cursor shapes requested via ZStyle cursor: and IPlatform::setCursor.
Definition UIEnums.hpp:61
UIState
Interaction state computed per node and consumed by the style resolver to select pseudo-class overlay...
Definition UIEnums.hpp:49
@ Auto
Defer to the parent's alignItems.
Definition CoreTypes.hpp:453
@ Auto
Infer paragraph direction from first strong Bidi character (fallback LTR).
Definition UIEnums.hpp:84
@ Auto
Inherit or fall back to Default.
Definition UIEnums.hpp:62
@ Idle
No interaction is active.
Definition UIEnums.hpp:50
8-bit-per-channel RGBA color, non-premultiplied.
Definition CoreTypes.hpp:78
Dense style: every property has a concrete value.
Definition Style.hpp:1036
Last-seen inherited values on container nodes with children.
Definition StyleResolver.hpp:85
Inline style overrides for interaction states (allocated lazily).
Definition StyleResolver.hpp:39
Style pressed
Applied on top of hover when pressed.
Definition StyleResolver.hpp:41
Style focus
Applied when the node has keyboard focus.
Definition StyleResolver.hpp:43
Style disabled
Applied instead of state overlays when enabled == false.
Definition StyleResolver.hpp:42
Style checked
Applied when the node is in the :checked state.
Definition StyleResolver.hpp:44
Style hover
Applied when the node is hovered or pressed.
Definition StyleResolver.hpp:40
Independent transition state for one pseudo-element (part).
Definition StyleResolver.hpp:70
Cached theme-only resolution result before inline overlays.
Definition StyleResolver.hpp:58
Active state-transition buffers (allocated only while transitioning).
Definition StyleResolver.hpp:49
ComputedStyle start
Style snapshot at timer == 0.
Definition StyleResolver.hpp:50
float timer
Normalized [0, 1]; 1 means "settled".
Definition StyleResolver.hpp:53
ComputedStyle target
Style the transition is heading toward.
Definition StyleResolver.hpp:51
uint64_t dirtyMask
Bit per property, 1 = currently transitioning.
Definition StyleResolver.hpp:52
Resolves, caches, and transitions the style of a single node.
Definition StyleResolver.hpp:36
bool isTransitioning() const noexcept
true while a property transition is actively interpolating.
Definition StyleResolver.hpp:138
void initImmediate(Layout &node)
Resolve and snap currentStyle immediately, clearing any transition buffer.
ComputedStyle currentStyle
The value consumed by layout and render.
Definition StyleResolver.hpp:102
Style partFor(Layout &node, const std::string &partName)
Resolve the style for pseudo-element partName on node.
ComputedStyle resolveFor(Layout &node)
Compute the fully resolved ComputedStyle for node.
void beginStateTransition(Layout &node, UIState newState)
Start a transition from the current style to newState's style.
void tick(Layout &node, float dt)
Advance the state transition by dt seconds.
const ComputedStyle & effectiveTargetStyle() const noexcept
Return the active transition target, or currentStyle when settled.
Definition StyleResolver.hpp:132
void invalidateCache() noexcept
Invalidate the theme style cache; called on selector/inline changes.
Definition StyleResolver.hpp:188
UIState currentState
Last observed interaction state.
Definition StyleResolver.hpp:103
void restartTransition()
Reset the transition timer to 0 and snapshot currentStyle as start.
float transitionProgress() const noexcept
Normalized transition progress in [0, 1] (1.0f when settled).
Definition StyleResolver.hpp:144
void resolvePendingTransition(Layout &node, bool instant=false)
Re-resolve the target style after a theme or ancestor change.
void propagateInheritance(Layout &node)
Propagate inherited property changes to children.
Sparse style: every property is Opt<T>, unset by default.
Definition Style.hpp:932
8-byte tagged length expression:
Definition Unit.hpp:58