ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
Style.hpp File Reference

The Style / ComputedStyle pair and all style-related value types. More...

#include "Common.hpp"
#include "Easing.hpp"
#include "Unit.hpp"
#include "UIEnums.hpp"
#include <ostream>
#include <atomic>
#include <cstdint>
#include <initializer_list>

Go to the source code of this file.

Classes

struct  ZenitUI::Opt< T >
 Optional wrapper with value semantics used for all style fields. More...
class  ZenitUI::SharedPropMap
 8-byte Copy-on-Write wrapper around std::unordered_map<std::string, std::string>. More...
class  ZenitUI::SharedVector< T >
 8-byte Copy-on-Write wrapper around std::vector<T> for cold style arrays. More...
struct  ZenitUI::Spacing
 Four-sided Value tuple used for padding, margin and border-width. More...
struct  ZenitUI::TransitionSpec
 One entry in the transitions list of a Style. More...
struct  ZenitUI::AnimationRef
 One entry in the animations list of a Style. More...
struct  ZenitUI::ZIndex
 CSS z-index with an explicit "auto" state. More...
struct  ZenitUI::TextureRef
 Reference to a texture asset with optional nine-slice insets. More...
struct  ZenitUI::SimpleSelector
 One component of a CSS selector chain. More...
struct  ZenitUI::SimpleSelector::NegatedItem
 Single compound argument inside a :not(...) pseudo-class. More...
struct  ZenitUI::SimpleSelector::Negation
 One :not(a, b, ...) clause; matches when none of items match. More...
struct  ZenitUI::FilterRef
 One filter in the filters list of a Style. More...
struct  ZenitUI::BoxShadow
 CSS box-shadow payload. More...
struct  ZenitUI::GridTrack
 One track definition in grid-template-columns or grid-template-rows. More...
struct  ZenitUI::GridPlacement
 Item placement along one grid axis (grid-column or grid-row). More...
struct  ZenitUI::Style
 Sparse style: every property is Opt<T>, unset by default. More...
struct  ZenitUI::ComputedStyle
 Dense style: every property has a concrete value. More...
struct  ZenitUI::PropDesc

Macros

#define BUBBLE_STYLE_PROPS(X)
#define X(T, name, def)
#define X(T, name, def)
#define X(T, n, def)
#define X(T, name, def)
#define X(T, name, def)
#define X(T, name, def)
#define X(T, name, def)
#define X(T, name, def)
#define X(T, name, def)
#define X(T, name, def)
#define X(T, name, def)
#define X(T, name, def)
#define X(T, n, def)
#define X(T, n, def)
#define X(T, name, def)

Typedefs

using ZenitUI::PropValue

Enumerations

enum class  ZenitUI::Position : uint8_t { Static , Relative , Absolute }
 CSS-style position modes supported by the layout system.
enum class  ZenitUI::Overflow : uint8_t { Visible , Hidden , Scroll , Auto }
 CSS overflow modes for one axis.
enum class  ZenitUI::WhiteSpace : uint8_t { Normal , Nowrap }
 CSS white-space values relevant to text layout.
enum class  ZenitUI::TextOverflow : uint8_t { Visible , Ellipsis }
 CSS text-overflow modes supported by the text renderer.
enum class  ZenitUI::SelectorCombinator : uint8_t { SelectorCombinator::Descendant , SelectorCombinator::Child , SelectorCombinator::AdjacentSibling , SelectorCombinator::GeneralSibling }
 Relationship between a selector and the preceding selector in a chain. More...
enum class  Direction : uint8_t { Auto , Row , Column }

Functions

std::ostream & ZenitUI::operator<< (std::ostream &os, const FontStack &stack)
 std::ostream operator for FontStack, used by debug output.
bool ZenitUI::operator== (const std::vector< FilterRef > &a, const std::vector< FilterRef > &b)
bool ZenitUI::operator!= (const std::vector< FilterRef > &a, const std::vector< FilterRef > &b)
bool ZenitUI::operator== (const std::vector< GridTrack > &a, const std::vector< GridTrack > &b)
bool ZenitUI::operator!= (const std::vector< GridTrack > &a, const std::vector< GridTrack > &b)
bool ZenitUI::isInheritedProp (std::string_view name)
 true if the named property inherits from parent to child.
bool ZenitUI::clearStyleProp (Style &s, std::string_view name)
 Clear the property named name on s.
std::string ZenitUI::kebabToCamel (std::string_view s)
std::string ZenitUI::camelToKebab (std::string_view s)
bool ZenitUI::operator== (const ComputedStyle &a, const ComputedStyle &b)
 Field-wise equality; used to detect layout-affecting style changes.
bool ZenitUI::operator!= (const ComputedStyle &a, const ComputedStyle &b)
float ZenitUI::lerpProp (float a, float b, float t)
Color ZenitUI::lerpProp (const Color &a, const Color &b, float t)
FontStack ZenitUI::lerpProp (const FontStack &a, const FontStack &b, float t)
Value ZenitUI::lerpProp (const Value &a, const Value &b, float t)
Spacing ZenitUI::lerpProp (const Spacing &a, const Spacing &b, float t)
template<typename E, typename = std::enable_if_t<std::is_enum_v<E>>>
E ZenitUI::lerpProp (E a, E b, float t)
ZIndex ZenitUI::lerpProp (const ZIndex &a, const ZIndex &b, float t)
std::string ZenitUI::lerpProp (const std::string &a, const std::string &b, float t)
SharedVector< FilterRef > ZenitUI::lerpProp (const SharedVector< FilterRef > &a, const SharedVector< FilterRef > &b, float t)
TextureRef ZenitUI::lerpProp (const TextureRef &a, const TextureRef &b, float t)
BoxShadow ZenitUI::lerpProp (const BoxShadow &a, const BoxShadow &b, float t)
SharedVector< GridTrack > ZenitUI::lerpProp (const SharedVector< GridTrack > &a, const SharedVector< GridTrack > &b, float t)
GridPlacement ZenitUI::lerpProp (const GridPlacement &a, const GridPlacement &b, float t)
ComputedStyle ZenitUI::lerpStyle (const ComputedStyle &a, const ComputedStyle &b, float t)
 Field-wise lerp of two ComputedStyle.
ComputedStyle ZenitUI::lerpStyleTimed (const ComputedStyle &a, const ComputedStyle &b, float realElapsed)
 Field-wise lerp using per-property durations from b's transition list.
bool ZenitUI::stylesDiffer (const Style &a, const Style &b)
 Compare two sparse Style values for "would this change anything".
template<typename T>
Opt< T > ZenitUI::lerpOpt (const Opt< T > &a, const Opt< T > &b, float t)
Style ZenitUI::lerpStyleParts (const Style &a, const Style &b, float t)
void ZenitUI::overlayComputed (ComputedStyle &dst, const Style &src)
template<typename F>
void ZenitUI::forEachSetStyleProp (const Style &s, F &&fn)
bool ZenitUI::copyStyleProp (Style &dst, const Style &src, std::string_view name)
bool ZenitUI::hasStyleProp (const Style &s, std::string_view name)
const std::vector< PropDesc > & ZenitUI::propTable ()
const PropDesc * ZenitUI::findProp (std::string_view name)
PropValue ZenitUI::lerpValue (const PropValue &a, const PropValue &b, float t)

Detailed Description

The Style / ComputedStyle pair and all style-related value types.

Style is a "sparse" style: every property is wrapped in Opt<T> so the resolver can tell "unset" apart from "set to the default value". This lets stylesheet rules and inline overrides be layered with overlay() without losing the inheritance information.

ComputedStyle is the "dense" form: every property has a concrete value, either taken from the resolved Style, inherited from the parent, or defaulted. The layout and render code only ever sees ComputedStyle.

BUBBLE_STYLE_PROPS is the single source of truth for the property list. Adding a property there propagates to Style, ComputedStyle, lerp, equality, overlay, serialization, and the propTable() used by tooling.

Macro Definition Documentation

◆ X [1/15]

#define X ( T,
n,
def )
Value:
if (name == #n) \
return s.n.is_set;

◆ X [2/15]

#define X ( T,
n,
def )
Value:
if (name == #n) \
{ \
if (src.n.is_set) \
{ \
dst.n = src.n; \
return true; \
} \
return false; \
}

◆ X [3/15]

#define X ( T,
n,
def )
Value:
if (!cleared && normalized == #n) \
{ \
s.n.reset(); \
cleared = true; \
}

◆ X [4/15]

#define X ( T,
name,
def )
Value:
PropDesc{#name, #T, #def, \
[](const ComputedStyle &c) -> PropValue { return c.name; }, \
[](ComputedStyle &c, const PropValue &v) { if (const T* p = std::get_if<T>(&v)) c.name = *p; }},

◆ X [5/15]

#define X ( T,
name,
def )
Value:
if (s.name.is_set) \
fn(#name);

◆ X [6/15]

#define X ( T,
name,
def )
Value:
if (src.name.is_set) \
dst.name = src.name.value;

◆ X [7/15]

#define X ( T,
name,
def )
Value:
r.name = lerpOpt(a.name, b.name, t);

◆ X [8/15]

#define X ( T,
name,
def )
Value:
if (a.name.is_set != b.name.is_set) \
return true; \
if (a.name.is_set && !(a.name.value == b.name.value)) \
return true;

◆ X [9/15]

#define X ( T,
name,
def )
Value:
{ \
if (a.name == b.name) \
{ \
r.name = a.name; \
} \
else \
{ \
auto [dur, ease] = timingFor(#name); \
float tp = (dur > 0.0f) ? std::clamp(realElapsed / dur, 0.0f, 1.0f) : 1.0f; \
r.name = lerpProp(a.name, b.name, getRatio(tp, ease)); \
} \
}

◆ X [10/15]

#define X ( T,
name,
def )
Value:
r.name = lerpProp(a.name, b.name, t);

◆ X [11/15]

#define X ( T,
name,
def )
Value:
if (!(a.name == b.name)) \
return false;

◆ X [12/15]

#define X ( T,
name,
def )
Value:
if (s.name.is_set) \
c.name = s.name.value; \
else if (parent && isInheritedProp(#name)) \
c.name = parent->name; \
else if (root && root->name.is_set) \
c.name = root->name.value; \
else \
c.name = def;

◆ X [13/15]

#define X ( T,
name,
def )
Value:
T name = def;

◆ X [14/15]

#define X ( T,
name,
def )
Value:
if (o.name.is_set) \
{ \
name = o.name; \
if (hadUnresolved) \
eraseUnresolvedForProp_(#name); \
}

◆ X [15/15]

#define X ( T,
name,
def )
Value:
Opt<T> name;