TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::StyleManager Class Reference

Bakes serializable Styles into deduplicated runtime layout/visual styles; a StyleRef holds indices into the (possibly shared) pools. More...

#include <gui_core/style/gui_style_manager.h>

Classes

struct  ChildStyleRefs
 A style's variants for where an element is among its parent's children. More...

Public Member Functions

 StyleManager (GradientManager &gm) noexcept
 Gradients of registered color styles are allocated from gm, which must outlive it.
StyleRef FallbackStyle () const noexcept
 The style registered first, again after every ClearAll: the one a box drawn without a style (GPU box style 0) gets.
 ~StyleManager ()
StyleRef Register (const Style &s, StyleUnits units=StyleUnits::Css) noexcept
 Bakes s into the pools, reusing identical entries, and returns its indices.
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 elements take as a first, last or only child (ElementStorage swaps them in when the parent's children are done).
const ChildStyleRefs * GetChildStyles (LayoutStyleIndex index) const noexcept
 The child styles of a style registered with them, by its layout style; nullptr for others.
bool HasChildStyles () const noexcept
 Whether any style has child styles (a quick test before looking one up).
Style ToPixels (const Style &s) const noexcept
 A CSS-pixel style at the UI scale, as Register would store it.
TextStyle ToPixels (const TextStyle &t) const noexcept
 A CSS-pixel text style at the UI scale.
void SetUIScale (float scale) noexcept
 UI scale applied to every style as it's registered (see Register).
float GetUIScale () const noexcept
 see SetUIScale
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.
float Px (float cssPx) const noexcept
 see Px(int32_t)
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.g.
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 rows, say); the box and text styles are shared.
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, trim), icon size and gap, and vertical padding (with padding), so at from's height the text sits as high; on one line and never cut short.
int32_t GetBorderBoxWidth (LayoutStyleIndex layoutStyleIndex) const noexcept
 Horizontal padding plus border widths of a layout style, in pixels; 0 for an invalid index.
bool AreVisualColorStylesModified () const noexcept
 Color styles modified since the last upload.
void ResetVisualColorStylesModified () noexcept
 Called by the renderer after uploading the color styles.
bool AreVisualBoxStylesModified () const noexcept
 Box styles modified since the last upload.
void ResetVisualBoxStylesModified () noexcept
 Called by the renderer after uploading the box styles.
std::span< const tachyon::VisualBoxStyle > GetVisualBoxStylesSpan () noexcept
 The flat box style pool (kStateCount entries per style), for GPU upload.
std::span< const tachyon::VisualColorStyle > GetVisualColorStylesSpan () noexcept
 The color style pool, for GPU upload.
VisualColorStyleIndex RegisterVisualColorStyle (const VisualColorStyle &s, GradientHandle incomingHandle) noexcept
 Takes ownership of incomingHandle: released on a dedup hit, otherwise stored with the slot.
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.
VisualColorStyleIndex CreateColorStyle (const ColorStyle &s) noexcept
 A color style of its own that can be changed later (UpdateColorStyle); never shared with other registrations.
void UpdateColorStyle (VisualColorStyleIndex idx, const ColorStyle &s) noexcept
 Replaces the CreateColorStyle style at idx in place.
void DestroyColorStyle (VisualColorStyleIndex idx) noexcept
 Frees a CreateColorStyle style and its atlas slot; idx may be reused later.
void ClearAll () noexcept
 Releases every atlas slot and clears every style, for a theme reload; every index and StyleRef handed out before is invalid, so holders re-register (see Generation).
uint32_t Generation () const noexcept
 Bumped by ClearAll.
GradientManager & GetGradientManager () noexcept
 The renderer resolves logical page indices to physical bindless slots through it.

Lookups

Each returns nullptr for an out-of-range index.

The per-state getters ignore non-visual state bits; Disabled overrides every other state.

const LayoutStyle * GetLayoutStyle (LayoutStyleIndex index) const noexcept
 All state variants of a box style.
const VisualColorStyle * GetVisualColorStyle (VisualColorStyleIndex index) const noexcept
 All state variants of a box style.
const VisualBoxStyleStates * GetVisualBoxStyles (VisualBoxStyleIndex 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 * GetSelectionVisualBoxStyle (VisualBoxStyleIndex index, tachyon::ElementState state=tachyon::ElementState::None) const noexcept
 The variant for state plus Selection (selected text / ranges).
const VisualTextStyle * GetSelectionVisualTextStyle (VisualTextStyleIndex index, tachyon::ElementState state=tachyon::ElementState::None) const noexcept
 The variant for state plus Selection (selected text / ranges).
const VisualTextStyleStates * GetVisualTextStyles (VisualTextStyleIndex index) const noexcept
 All state variants of a text style.
const VisualTextStyle * GetVisualTextStyle (VisualTextStyleIndex index, tachyon::ElementState state) const noexcept
 All state variants of a box style.
const VisualShadowStyle * GetVisualShadowStyle (uint32_t gpuStyleIndex) const noexcept
 The shadows of a box style by its flat GPU index (ComputeGPUStyleIndex); nullptr if none.
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, registered once (until ClearAll).
float GetOpacity (uint32_t gpuStyleIndex) const noexcept
 The CSS opacity of a flat GPU style index (style and state); below 0 when not set.
const VisualBoxStyle * GetVisualBoxStyleAt (uint32_t gpuStyleIndex) const noexcept
 A box style's state by its flat GPU index; nullptr out of range.
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 with every stop opaque (not a texture).
static void ApplyStateLayer (Style &style) noexcept
 For Style::stateLayer Content (Register does it): each hovered and pressed slot gets the slot's text color over its background without hover and press, 8% and 14%.
size_t LayoutStyleCount () const noexcept
 Number of registered (deduplicated) styles in each pool.
size_t VisualBoxStyleCount () const noexcept
 Number of registered (deduplicated) styles in each pool.
size_t VisualTextStyleCount () const noexcept
 Number of registered (deduplicated) styles in each pool.
size_t VisualColorStyleCount () const noexcept
 Number of registered (deduplicated) styles in each pool.

Detailed Description

Bakes serializable Styles into deduplicated runtime layout/visual styles; a StyleRef holds indices into the (possibly shared) pools.

Each VisualColorStyle owns exactly one GradientHandle; Register / Create / Update / Destroy handle Acquire / Release, so callers never manage them.

Constructor & Destructor Documentation

◆ StyleManager()

tachyon::StyleManager::StyleManager ( GradientManager & gm)
explicitnoexcept

Gradients of registered color styles are allocated from gm, which must outlive it.

Registers the fallback style (FallbackStyle) first.

◆ ~StyleManager()

tachyon::StyleManager::~StyleManager ( )

Member Function Documentation

◆ FallbackStyle()

StyleRef tachyon::StyleManager::FallbackStyle ( ) const
inlinenoexcept

The style registered first, again after every ClearAll: the one a box drawn without a style (GPU box style 0) gets.

A plain blue-grey box, so a missing style shows.

◆ Register()

StyleRef tachyon::StyleManager::Register ( const Style & s,
StyleUnits units = StyleUnits::Css )
noexcept

Bakes s into the pools, reusing identical entries, and returns its indices.

s is in CSS px and stored at the UI scale (SetUIScale); StyleUnits::Pixels registers a style that is already at it (see ToPixels).

◆ RegisterWithChildStyles()

StyleRef tachyon::StyleManager::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 elements take as a first, last or only child (ElementStorage swaps them in when the parent's children are done).

◆ GetChildStyles()

const ChildStyleRefs * tachyon::StyleManager::GetChildStyles ( LayoutStyleIndex index) const
noexcept

The child styles of a style registered with them, by its layout style; nullptr for others.

◆ HasChildStyles()

bool tachyon::StyleManager::HasChildStyles ( ) const
inlinenoexcept

Whether any style has child styles (a quick test before looking one up).

◆ ToPixels() [1/2]

Style tachyon::StyleManager::ToPixels ( const Style & s) const
noexcept

A CSS-pixel style at the UI scale, as Register would store it.

◆ ToPixels() [2/2]

TextStyle tachyon::StyleManager::ToPixels ( const TextStyle & t) const
noexcept

A CSS-pixel text style at the UI scale.

◆ SetUIScale()

void tachyon::StyleManager::SetUIScale ( float scale)
inlinenoexcept

UI scale applied to every style as it's registered (see Register).

Changing it affects later registrations only; re-register (theme reload) after.

◆ GetUIScale()

float tachyon::StyleManager::GetUIScale ( ) const
inlinenoexcept

see SetUIScale

◆ Px() [1/2]

int32_t tachyon::StyleManager::Px ( int32_t cssPx) const
inlinenoexcept

A size given in code (CSS px) at the UI scale: whole pixels, and a non-zero size stays at least 1.

◆ Px() [2/2]

float tachyon::StyleManager::Px ( float cssPx) const
noexcept

see Px(int32_t)

◆ WithTextOverride()

StyleRef tachyon::StyleManager::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.g.

a text box). Unset fields keep the base style's values; layout and box styles are shared. Cheap to call every frame; a theme reload (ClearAll) drops the variants, so derive from the current base each frame.

◆ WithFlexWrap()

StyleRef tachyon::StyleManager::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 rows, say); the box and text styles are shared.

base itself when it already wraps that way. Cheap to call every frame; ClearAll drops the variants.

◆ WithTextOf()

StyleRef tachyon::StyleManager::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, trim), icon size and gap, and vertical padding (with padding), so at from's height the text sits as high; on one line and never cut short.

The colors and text shadows stay base's, and so does the rest of its layout and its box. For text shown again elsewhere, looking the same. Without padding, base's vertical padding: for the text's line alone. ClearAll drops the variants.

◆ GetLayoutStyle()

const LayoutStyle * tachyon::StyleManager::GetLayoutStyle ( LayoutStyleIndex index) const
noexcept

All state variants of a box style.

◆ GetVisualColorStyle()

const VisualColorStyle * tachyon::StyleManager::GetVisualColorStyle ( VisualColorStyleIndex index) const
noexcept

All state variants of a box style.

◆ GetVisualBoxStyles()

const VisualBoxStyleStates * tachyon::StyleManager::GetVisualBoxStyles ( VisualBoxStyleIndex index) const
noexcept

All state variants of a box style.

◆ GetVisualBoxStyle()

const VisualBoxStyle * tachyon::StyleManager::GetVisualBoxStyle ( VisualBoxStyleIndex index,
tachyon::ElementState state ) const
noexcept

All state variants of a box style.

◆ GetSelectionVisualBoxStyle()

const VisualBoxStyle * tachyon::StyleManager::GetSelectionVisualBoxStyle ( VisualBoxStyleIndex index,
tachyon::ElementState state = tachyon::ElementState::None ) const
noexcept

The variant for state plus Selection (selected text / ranges).

◆ GetSelectionVisualTextStyle()

const VisualTextStyle * tachyon::StyleManager::GetSelectionVisualTextStyle ( VisualTextStyleIndex index,
tachyon::ElementState state = tachyon::ElementState::None ) const
noexcept

The variant for state plus Selection (selected text / ranges).

◆ GetVisualTextStyles()

const VisualTextStyleStates * tachyon::StyleManager::GetVisualTextStyles ( VisualTextStyleIndex index) const
noexcept

All state variants of a text style.

◆ GetVisualTextStyle()

const VisualTextStyle * tachyon::StyleManager::GetVisualTextStyle ( VisualTextStyleIndex index,
tachyon::ElementState state ) const
noexcept

All state variants of a box style.

◆ GetVisualShadowStyle()

const VisualShadowStyle * tachyon::StyleManager::GetVisualShadowStyle ( uint32_t gpuStyleIndex) const
noexcept

The shadows of a box style by its flat GPU index (ComputeGPUStyleIndex); nullptr if none.

◆ RegisterOutline()

VisualBoxStyleIndex tachyon::StyleManager::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, registered once (until ClearAll).

◆ ApplyStateLayer()

void tachyon::StyleManager::ApplyStateLayer ( Style & style)
staticnoexcept

For Style::stateLayer Content (Register does it): each hovered and pressed slot gets the slot's text color over its background without hover and press, 8% and 14%.

◆ GetOpacity()

float tachyon::StyleManager::GetOpacity ( uint32_t gpuStyleIndex) const
noexcept

The CSS opacity of a flat GPU style index (style and state); below 0 when not set.

◆ GetVisualBoxStyleAt()

const VisualBoxStyle * tachyon::StyleManager::GetVisualBoxStyleAt ( uint32_t gpuStyleIndex) const
noexcept

A box style's state by its flat GPU index; nullptr out of range.

◆ IsBoxBackgroundOpaque()

bool tachyon::StyleManager::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 with every stop opaque (not a texture).

◆ LayoutStyleCount()

size_t tachyon::StyleManager::LayoutStyleCount ( ) const
inlinenoexcept

Number of registered (deduplicated) styles in each pool.

◆ VisualBoxStyleCount()

size_t tachyon::StyleManager::VisualBoxStyleCount ( ) const
inlinenoexcept

Number of registered (deduplicated) styles in each pool.

◆ VisualTextStyleCount()

size_t tachyon::StyleManager::VisualTextStyleCount ( ) const
inlinenoexcept

Number of registered (deduplicated) styles in each pool.

◆ VisualColorStyleCount()

size_t tachyon::StyleManager::VisualColorStyleCount ( ) const
inlinenoexcept

Number of registered (deduplicated) styles in each pool.

◆ GetBorderBoxWidth()

int32_t tachyon::StyleManager::GetBorderBoxWidth ( LayoutStyleIndex layoutStyleIndex) const
inlinenoexcept

Horizontal padding plus border widths of a layout style, in pixels; 0 for an invalid index.

◆ AreVisualColorStylesModified()

bool tachyon::StyleManager::AreVisualColorStylesModified ( ) const
inlinenoexcept

Color styles modified since the last upload.

◆ ResetVisualColorStylesModified()

void tachyon::StyleManager::ResetVisualColorStylesModified ( )
inlinenoexcept

Called by the renderer after uploading the color styles.

◆ AreVisualBoxStylesModified()

bool tachyon::StyleManager::AreVisualBoxStylesModified ( ) const
inlinenoexcept

Box styles modified since the last upload.

◆ ResetVisualBoxStylesModified()

void tachyon::StyleManager::ResetVisualBoxStylesModified ( )
inlinenoexcept

Called by the renderer after uploading the box styles.

◆ GetVisualBoxStylesSpan()

std::span< const tachyon::VisualBoxStyle > tachyon::StyleManager::GetVisualBoxStylesSpan ( )
inlinenoexcept

The flat box style pool (kStateCount entries per style), for GPU upload.

◆ GetVisualColorStylesSpan()

std::span< const tachyon::VisualColorStyle > tachyon::StyleManager::GetVisualColorStylesSpan ( )
inlinenoexcept

The color style pool, for GPU upload.

◆ RegisterVisualColorStyle()

VisualColorStyleIndex tachyon::StyleManager::RegisterVisualColorStyle ( const VisualColorStyle & s,
GradientHandle incomingHandle )
noexcept

Takes ownership of incomingHandle: released on a dedup hit, otherwise stored with the slot.

◆ RegisterColorStyle()

VisualColorStyleIndex tachyon::StyleManager::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.

The manager owns the atlas slot.

◆ CreateColorStyle()

VisualColorStyleIndex tachyon::StyleManager::CreateColorStyle ( const ColorStyle & s)
noexcept

A color style of its own that can be changed later (UpdateColorStyle); never shared with other registrations.

Valid until DestroyColorStyle or ClearAll.

◆ UpdateColorStyle()

void tachyon::StyleManager::UpdateColorStyle ( VisualColorStyleIndex idx,
const ColorStyle & s )
noexcept

Replaces the CreateColorStyle style at idx in place.

The GPU copy is re-uploaded only when the contents changed.

◆ DestroyColorStyle()

void tachyon::StyleManager::DestroyColorStyle ( VisualColorStyleIndex idx)
noexcept

Frees a CreateColorStyle style and its atlas slot; idx may be reused later.

◆ ClearAll()

void tachyon::StyleManager::ClearAll ( )
noexcept

Releases every atlas slot and clears every style, for a theme reload; every index and StyleRef handed out before is invalid, so holders re-register (see Generation).

The gradient atlas' GPU images are kept.

◆ Generation()

uint32_t tachyon::StyleManager::Generation ( ) const
inlinenoexcept

Bumped by ClearAll.

Anything that caches style indices across frames compares against it and re-registers when it changed.

◆ GetGradientManager()

GradientManager & tachyon::StyleManager::GetGradientManager ( )
inlinenoexcept

The renderer resolves logical page indices to physical bindless slots through it.


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