10#include <unordered_map>
73 void SetUIScale(
float scale)
noexcept { m_uiScale = scale > 0.0f ? scale : 1.0f; }
77 int32_t
Px(int32_t cssPx)
const noexcept {
return int32_t(
Px(
float(cssPx))); }
78 float Px(
float cssPx)
const noexcept;
201 uint32_t
Generation() const noexcept {
return m_generation; }
207 float m_uiScale = 1.0f;
209 void RegisterFallbackStyle() noexcept;
212 StyleRef RegisterImpl(const Style& s,
StyleUnits units,
bool distinct) noexcept;
213 std::unordered_map<uint32_t, ChildStyleRefs> m_childStyles;
216 uint64_t hash) const noexcept;
219 LayoutStyleIndex RegisterLayoutStyle(const LayoutStyle& layoutStyle,
bool distinct) noexcept;
220 VisualTextStyleIndex RegisterVisualTextStyles(const VisualTextStyle (&states)[Style::kStateCount],
221 uint64_t hash) noexcept;
223 uint16_t RegisterShadows(const BoxShadow (&layers)[
kMaxBoxShadows], const BoxShadow& ring, BoxCorners radius,
224 float opacity) noexcept;
226 GradientManager& m_gradientManager;
227 uint32_t m_generation = 0;
229 std::unordered_map<uint64_t, StyleRef> m_textOfVariants;
232 std::deque<LayoutStyle> m_layoutStyles;
233 std::vector<VisualBoxStyle> m_visualBoxStyles;
234 std::vector<
bool> m_opaqueBoxBackgrounds;
235 std::vector<VisualTextStyle> m_visualTextStyles;
236 std::vector<VisualColorStyle> m_visualColorStyles;
237 std::vector<VisualShadowStyle> m_visualShadowStyles;
238 struct Outline { BoxEdges widths; BoxCorners radius; color4b color;
VisualBoxStyleIndex index; };
239 std::vector<Outline> m_outlines;
242 std::vector<GradientHandle> m_visualColorStyleHandles;
244 bool visualColorStylesModified =
false;
245 bool visualBoxStylesModified =
false;
248 std::unordered_map<uint64_t, std::vector<LayoutStyleIndex>> m_layoutHashMap;
249 std::unordered_map<uint64_t, std::vector<VisualBoxStyleIndex>> m_visualBoxHashMap;
250 std::unordered_map<uint64_t, std::vector<VisualTextStyleIndex>> m_visualTextHashMap;
251 std::unordered_map<uint64_t, std::vector<VisualColorStyleIndex>> m_visualColorHashMap;
254 std::vector<VisualColorStyleIndex> m_freeColorStyleSlots;
A fill: solid color, gradient or texture, as used for backgrounds, borders, text and icons.
Definition gui_style.h:524
The atlas that the colors of color styles are baked into: pages of 2D textures, one row per gradient,...
Definition gui_gradient_manager.h:64
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.
VisualColorStyleIndex RegisterVisualColorStyle(const VisualColorStyle &s, GradientHandle incomingHandle) noexcept
Takes ownership of incomingHandle: released on a dedup hit, otherwise stored with the slot.
size_t LayoutStyleCount() const noexcept
Number of registered (deduplicated) styles in each pool.
Definition gui_style_manager.h:134
void ResetVisualColorStylesModified() noexcept
Called by the renderer after uploading the color styles.
Definition gui_style_manager.h:156
float GetUIScale() const noexcept
see SetUIScale
Definition gui_style_manager.h:74
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.
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:136
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:145
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:204
void SetUIScale(float scale) noexcept
UI scale applied to every style as it's registered (see Register).
Definition gui_style_manager.h:73
VisualColorStyleIndex CreateColorStyle(const ColorStyle &s) noexcept
A color style of its own that can be changed later (UpdateColorStyle); never shared with other regist...
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:153
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:65
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:77
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:201
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:140
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) 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:170
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...
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:160
void ResetVisualBoxStylesModified() noexcept
Called by the renderer after uploading the box styles.
Definition gui_style_manager.h:163
size_t VisualTextStyleCount() const noexcept
Number of registered (deduplicated) styles in each pool.
Definition gui_style_manager.h:138
std::span< const tachyon::VisualBoxStyle > GetVisualBoxStylesSpan() noexcept
The flat box style pool (kStateCount entries per style), for GPU upload.
Definition gui_style_manager.h:167
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:580
ImageIndex
Index of an image in the graphics context's image set, as the shaders sample it.
Definition gui_image.h:37
@ Invalid
Definition gui_image.h:37
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:26
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:755
int32_t GetBorderBoxWidth() const noexcept
Horizontal padding plus border widths, in pixels.
Definition gui_style.h:897
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:687
static constexpr int kStateCount
one per state slot
Definition gui_style.h:693
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:933
What a state draws on the CPU only: its shadows and its opacity.
Definition gui_style.h:921
The text part of one state of a registered Style, in pixels.
Definition gui_style.h:983
Definition gui_base_types.h:384