10#include <unordered_map>
74 void SetUIScale(
float scale)
noexcept { m_uiScale = scale > 0.0f ? scale : 1.0f; }
78 int32_t
Px(int32_t cssPx)
const noexcept {
return int32_t(
Px(
float(cssPx))); }
79 float Px(
float cssPx)
const noexcept;
185 uint16_t variable = 0) noexcept;
219 uint32_t
Generation() const noexcept {
return m_generation; }
225 float m_uiScale = 1.0f;
227 void RegisterFallbackStyle() noexcept;
230 StyleRef RegisterImpl(const Style& s,
StyleUnits units,
bool distinct) noexcept;
231 std::unordered_map<uint32_t, ChildStyleRefs> m_childStyles;
234 uint64_t hash) const noexcept;
237 LayoutStyleIndex RegisterLayoutStyle(const LayoutStyle& layoutStyle,
bool distinct) noexcept;
238 VisualTextStyleIndex RegisterVisualTextStyles(const VisualTextStyle (&states)[Style::kStateCount],
239 uint64_t hash) noexcept;
241 uint16_t RegisterShadows(const BoxShadow (&layers)[
kMaxBoxShadows], const BoxShadow& ring, const BoxShadow& ringUnder, BoxCorners radius,
242 float opacity) noexcept;
244 GradientManager& m_gradientManager;
245 uint32_t m_generation = 0;
247 std::unordered_map<uint64_t, StyleRef> m_textOfVariants;
250 std::deque<LayoutStyle> m_layoutStyles;
251 std::vector<VisualBoxStyle> m_visualBoxStyles;
253 std::vector<uint8_t> m_boxFlags;
254 static constexpr uint8_t kBoxOpaqueBackground = 1, kBoxBlank = 2;
255 std::vector<VisualTextStyle> m_visualTextStyles;
256 std::vector<VisualColorStyle> m_visualColorStyles;
257 std::vector<VisualShadowStyle> m_visualShadowStyles;
260 std::vector<Outline> m_outlines;
263 std::vector<GradientHandle> m_visualColorStyleHandles;
265 bool visualColorStylesModified =
false;
266 bool visualBoxStylesModified =
false;
269 std::unordered_map<uint64_t, std::vector<LayoutStyleIndex>> m_layoutHashMap;
270 std::unordered_map<uint64_t, std::vector<VisualBoxStyleIndex>> m_visualBoxHashMap;
271 std::unordered_map<uint64_t, std::vector<VisualTextStyleIndex>> m_visualTextHashMap;
272 std::unordered_map<uint64_t, std::vector<VisualColorStyleIndex>> m_visualColorHashMap;
279 std::vector<VisualColorStyleIndex> indices;
280 std::vector<VisualColorStyle> registeredAs;
281 std::vector<GradientHandle> registeredHandles;
283 std::unordered_map<uint16_t, VariableFills> m_variableColors;
285 std::unordered_map<uint16_t, ColorStyle> m_variableValues;
288 std::vector<VisualColorStyleIndex> m_freeColorStyleSlots;
A fill: solid color, gradient or texture, as used for backgrounds, borders, text and icons.
Definition gui_style.h:527
The atlas that the colors of color styles are baked into: pages of 2D textures, one row per gradient,...
Definition gui_gradient_manager.h:65
StyleRef WithTextOf(StyleRef base, StyleRef from, tachyon::ElementState state, bool padding=true) noexcept
A variant of base whose text is set as from's is in state: its font, text layout (alignment,...
StyleRef WithFlexWrap(StyleRef base, FlexWrap wrap) noexcept
A variant of base whose flex container wraps as wrap says (a tab bar that puts its tabs on several ro...
Style ToPixels(const Style &s) const noexcept
A CSS-pixel style at the UI scale, as Register would store it.
const VisualBoxStyleStates * GetVisualBoxStyles(VisualBoxStyleIndex index) const noexcept
All state variants of a box style.
size_t LayoutStyleCount() const noexcept
Number of registered (deduplicated) styles in each pool.
Definition gui_style_manager.h:143
VisualColorStyleIndex CreateColorStyle(const ColorStyle &s, std::span< const color4b > row={}) noexcept
A color style of its own that can be changed later (UpdateColorStyle); never shared with other regist...
void ResetVisualColorStylesModified() noexcept
Called by the renderer after uploading the color styles.
Definition gui_style_manager.h:165
float GetUIScale() const noexcept
see SetUIScale
Definition gui_style_manager.h:75
static void ApplyStateLayer(Style &style) noexcept
For Style::stateLayer Content (Register does it): each hovered and pressed slot gets the slot's text ...
const VisualColorStyle * GetVisualColorStyle(VisualColorStyleIndex index) const noexcept
All state variants of a box style.
const VisualBoxStyle * GetVisualBoxStyle(VisualBoxStyleIndex index, tachyon::ElementState state) const noexcept
All state variants of a box style.
VisualColorStyleIndex RegisterVisualColorStyle(const VisualColorStyle &s, GradientHandle incomingHandle, uint16_t variable=0) noexcept
Takes ownership of incomingHandle: released on a dedup hit, otherwise stored with the slot.
const VisualBoxStyle * GetVisualBoxStyleAt(uint32_t gpuStyleIndex) const noexcept
A box style's state by its flat GPU index; nullptr out of range.
size_t VisualBoxStyleCount() const noexcept
Number of registered (deduplicated) styles in each pool.
Definition gui_style_manager.h:145
int32_t GetBorderBoxWidth(LayoutStyleIndex layoutStyleIndex) const noexcept
Horizontal padding plus border widths of a layout style, in pixels; 0 for an invalid index.
Definition gui_style_manager.h:154
StyleRef FallbackStyle() const noexcept
The style registered first, again after every ClearAll: the one a box drawn without a style (GPU box ...
Definition gui_style_manager.h:47
GradientManager & GetGradientManager() noexcept
The renderer resolves logical page indices to physical bindless slots through it.
Definition gui_style_manager.h:222
void SetUIScale(float scale) noexcept
UI scale applied to every style as it's registered (see Register).
Definition gui_style_manager.h:74
void ClearAll() noexcept
Releases every atlas slot and clears every style, for a theme reload; every index and StyleRef handed...
const VisualTextStyleStates * GetVisualTextStyles(VisualTextStyleIndex index) const noexcept
All state variants of a text style.
const VisualTextStyle * GetSelectionVisualTextStyle(VisualTextStyleIndex index, tachyon::ElementState state=tachyon::ElementState::None) const noexcept
The variant for state plus Selection (selected text / ranges).
bool AreVisualColorStylesModified() const noexcept
Color styles modified since the last upload.
Definition gui_style_manager.h:162
const LayoutStyle * GetLayoutStyle(LayoutStyleIndex index) const noexcept
All state variants of a box style.
const VisualTextStyle * GetVisualTextStyle(VisualTextStyleIndex index, tachyon::ElementState state) const noexcept
All state variants of a box style.
VisualBoxStyleIndex RegisterOutline(BoxEdges widths, BoxCorners radius, color4b color) noexcept
A border-only box style in pixels: widths and radius with a color border and no background,...
bool HasChildStyles() const noexcept
Whether any style has child styles (a quick test before looking one up).
Definition gui_style_manager.h:66
int32_t Px(int32_t cssPx) const noexcept
A size given in code (CSS px) at the UI scale: whole pixels, and a non-zero size stays at least 1.
Definition gui_style_manager.h:78
const VisualBoxStyle * GetSelectionVisualBoxStyle(VisualBoxStyleIndex index, tachyon::ElementState state=tachyon::ElementState::None) const noexcept
The variant for state plus Selection (selected text / ranges).
uint32_t Generation() const noexcept
Bumped by ClearAll.
Definition gui_style_manager.h:219
StyleManager(GradientManager &gm) noexcept
Gradients of registered color styles are allocated from gm, which must outlive it.
float GetOpacity(uint32_t gpuStyleIndex) const noexcept
The CSS opacity of a flat GPU style index (style and state); below 0 when not set.
StyleRef RegisterWithChildStyles(const Style &s, const Style &first, const Style &last, const Style &only, StyleUnits units=StyleUnits::Css) noexcept
Registers s as a style of its own (never shared, so its variants are its alone) with the styles its e...
const VisualShadowStyle * GetVisualShadowStyle(uint32_t gpuStyleIndex) const noexcept
The shadows of a box style by its flat GPU index (ComputeGPUStyleIndex); nullptr if none.
TextStyle ToPixels(const TextStyle &t) const noexcept
A CSS-pixel text style at the UI scale.
size_t VisualColorStyleCount() const noexcept
Number of registered (deduplicated) styles in each pool.
Definition gui_style_manager.h:149
const ChildStyleRefs * GetChildStyles(LayoutStyleIndex index) const noexcept
The child styles of a style registered with them, by its layout style; nullptr for others.
void UpdateColorStyle(VisualColorStyleIndex idx, const ColorStyle &s, std::span< const color4b > row={}) noexcept
Replaces the CreateColorStyle style at idx in place.
std::span< const tachyon::VisualColorStyle > GetVisualColorStylesSpan() noexcept
The color style pool, for GPU upload.
Definition gui_style_manager.h:179
bool IsBoxBackgroundOpaque(uint32_t gpuStyleIndex) const noexcept
Whether the box style's background, by its flat GPU index, hides what's under it: a color or gradient...
bool SetVariableColor(uint16_t variable, const ColorStyle &s) noexcept
Writes s into every registered fill of the theme variable variable (ColorStyle::variable): what's dra...
bool IsBoxBlank(uint32_t gpuStyleIndex) const noexcept
Whether a box in the style, by its flat GPU index, draws nothing: its background and every bordered e...
VisualColorStyleIndex RegisterColorStyle(const ColorStyle &s, ImageIndex textureIndex=ImageIndex::Invalid) noexcept
Bakes s and registers it, reusing an identical entry; the usual way to register a color.
void DestroyColorStyle(VisualColorStyleIndex idx) noexcept
Frees a CreateColorStyle style and its atlas slot; idx may be reused later.
StyleRef WithTextOverride(StyleRef base, const TextOverride &textOverride) noexcept
A variant of base whose text uses another font and/or language, for one element's text (e....
StyleRef Register(const Style &s, StyleUnits units=StyleUnits::Css) noexcept
Bakes s into the pools, reusing identical entries, and returns its indices.
float Px(float cssPx) const noexcept
see Px(int32_t)
bool AreVisualBoxStylesModified() const noexcept
Box styles modified since the last upload.
Definition gui_style_manager.h:169
void ResetVisualBoxStylesModified() noexcept
Called by the renderer after uploading the box styles.
Definition gui_style_manager.h:172
size_t VisualTextStyleCount() const noexcept
Number of registered (deduplicated) styles in each pool.
Definition gui_style_manager.h:147
std::span< const tachyon::VisualBoxStyle > GetVisualBoxStylesSpan() noexcept
The flat box style pool (kStateCount entries per style), for GPU upload.
Definition gui_style_manager.h:176
What text is measured and laid out from: font, metrics and decoration lines.
Definition gui_style_text.h:260
GPU form of a ColorStyle, uploaded as is: the gradient is baked into an atlas slot that colorUV / gra...
Definition gui_style.h:591
ImageIndex
Index of an image in the graphics context's image set, as the shaders sample it.
Definition gui_image.h:99
@ Invalid
Definition gui_image.h:99
VisualTextStyleIndex
Index into StyleManager's visual text style pool; Invalid (0) = none.
Definition gui_style_ref.h:19
LayoutStyleIndex
Index into StyleManager's layout style pool; Invalid (0) = none.
Definition gui_style_ref.h:15
StyleUnits
Units of a style's metrics: CSS pixels (scaled to the UI) or final pixels.
Definition gui_style_manager.h:32
VisualColorStyleIndex
Index into StyleManager's color style pool; Invalid (0) draws nothing (transparent).
Definition gui_style.h:33
FontID
Handle for a font family registered with ITextSystem::RegisterFontFamily().
Definition gui_style_text.h:20
constexpr int kMaxBoxShadows
CSS box-shadow layers per state; the first is drawn on top.
Definition gui_style.h:114
VisualBoxStyleIndex
Index into StyleManager's visual box style pool; Invalid (0) = none.
Definition gui_style_ref.h:17
FlexWrap
Whether flex items wrap onto more lines (CSS: flex-wrap).
Definition gui_style.h:173
ElementState
Interaction state bits of an element; they pick the Style::states variant it draws with.
Definition gui_style.h:42
VisualBoxStyle[Style::kStateCount] VisualBoxStyleStates
A box style's variants, one per visual element state (Style::kStateCount).
Definition gui_style_manager.h:20
VisualTextStyle[Style::kStateCount] VisualTextStyleStates
A text style's variants, one per visual element state (Style::kStateCount).
Definition gui_style_manager.h:22
@ Css
Definition gui_style_manager.h:32
@ Invalid
Definition gui_style_text.h:20
Definition gui_logging.h:24
Per-corner values (border radius).
Definition gui_style.h:90
Per-side values of the box model (margin, padding, border widths).
Definition gui_style.h:64
Handle to a reference-counted GradientManager atlas slot.
Definition gui_gradient_manager.h:27
A BCP 47 language tag ("ja", "zh-Hant", "ko-KR") stored inline, so text styles stay plain values.
Definition gui_style_text.h:29
The layout part of a registered Style, in pixels; shared by every style with the same values.
Definition gui_style.h:772
int32_t GetBorderBoxWidth() const noexcept
Horizontal padding plus border widths, in pixels.
Definition gui_style.h:886
A size in device pixels, used as is (not scaled by the UI scale).
Definition gui_units.h:28
A style's variants for where an element is among its parent's children.
Definition gui_style_manager.h:56
StyleRef first
Definition gui_style_manager.h:56
StyleRef last
Definition gui_style_manager.h:56
StyleRef only
Definition gui_style_manager.h:56
A registered style, as StyleManager::Register returns it: indices into the shared style pools,...
Definition gui_style_ref.h:25
A complete style, as parsed from CSS or built in code: layout properties plus the visual properties o...
Definition gui_style.h:699
static constexpr int kStateCount
one per state slot
Definition gui_style.h:705
Per-element text overrides for StyleManager::WithTextOverride.
Definition gui_style_manager.h:26
FontID font
Invalid = keep the base font.
Definition gui_style_manager.h:27
LanguageTag language
empty = keep the base language
Definition gui_style_manager.h:28
The box part of one state of a registered Style, in pixels; uploaded to the GPU as is (32 bytes).
Definition gui_style.h:923
What a state draws on the CPU only: its shadows and its opacity.
Definition gui_style.h:910
The text part of one state of a registered Style, in pixels.
Definition gui_style.h:973
Definition gui_base_types.h:383