30#include <initializer_list>
54 Opt(
const T &v) : value(v), is_set(
true) {}
55 Opt(T &&v) : value(std::move(v)), is_set(
true) {}
56 Opt &operator=(
const T &v)
68 void reset() { is_set =
false; }
69 T get_or(
const T &fallback)
const {
return is_set ? value : fallback; }
83 using Map = std::unordered_map<std::string, std::string>;
84 using const_iterator = Map::const_iterator;
89 mutable std::atomic<uint32_t> refCount{1};
96 static uint64_t nextId()
noexcept
98 static std::atomic<uint64_t> counter{1};
99 return counter.fetch_add(1u, std::memory_order_relaxed);
102 static const Map &emptyMap()
noexcept
104 static const Map kEmpty{};
108 static void release(Data *p)
noexcept
110 if (p && p->refCount.fetch_sub(1u, std::memory_order_acq_rel) == 1u)
119 data_->id = nextId();
122 if (data_->refCount.load(std::memory_order_acquire) > 1u)
124 auto *copy =
new Data();
126 copy->map = data_->map;
131 data_->id = nextId();
135 SharedPropMap()
noexcept =
default;
136 SharedPropMap(
const Map &m)
141 data_->id = nextId();
145 SharedPropMap(Map &&m)
150 data_->id = nextId();
151 data_->map = std::move(m);
154 SharedPropMap(
const SharedPropMap &o) noexcept : data_(o.data_)
157 data_->refCount.fetch_add(1u, std::memory_order_relaxed);
159 SharedPropMap(SharedPropMap &&o) noexcept : data_(o.data_)
163 SharedPropMap &operator=(
const SharedPropMap &o)
noexcept
170 data_->refCount.fetch_add(1u, std::memory_order_relaxed);
174 SharedPropMap &operator=(SharedPropMap &&o)
noexcept
183 SharedPropMap &operator=(
const Map &m)
194 ~SharedPropMap()
noexcept { release(data_); }
196 bool empty()
const noexcept {
return !data_ || data_->map.empty(); }
197 size_t size()
const noexcept {
return data_ ? data_->map.size() : 0u; }
198 uint64_t versionId()
const noexcept {
return empty() ? 0ULL : data_->id; }
199 bool sharesStorageWith(
const SharedPropMap &o)
const noexcept {
return data_ == o.data_; }
201 const Map &asMap()
const noexcept {
return data_ ? data_->map : emptyMap(); }
202 operator const Map &()
const noexcept {
return asMap(); }
204 const_iterator begin()
const noexcept {
return asMap().begin(); }
205 const_iterator end()
const noexcept {
return asMap().end(); }
206 const_iterator cbegin()
const noexcept {
return asMap().cbegin(); }
207 const_iterator cend()
const noexcept {
return asMap().cend(); }
209 const_iterator find(
const std::string &k)
const {
return asMap().find(k); }
210 size_t count(
const std::string &k)
const {
return data_ ? data_->map.count(k) : 0u; }
211 bool contains(
const std::string &k)
const {
return data_ && data_->map.find(k) != data_->map.end(); }
212 const std::string &at(
const std::string &k)
const {
return asMap().at(k); }
214 std::string &operator[](
const std::string &k)
217 return data_->map[k];
219 std::string &operator[](std::string &&k)
222 return data_->map[std::move(k)];
225 template <
typename... Args>
226 auto emplace(Args &&...args)
229 return data_->map.emplace(std::forward<Args>(args)...);
232 template <
typename V>
233 auto insert_or_assign(
const std::string &k, V &&v)
236 return data_->map.insert_or_assign(k, std::forward<V>(v));
239 size_t erase(
const std::string &k)
241 if (!data_ || data_->map.find(k) == data_->map.end())
244 const size_t n = data_->map.erase(k);
245 if (data_->map.empty())
253 void clear()
noexcept
259 void mergeFrom(
const SharedPropMap &other)
268 if (data_ == other.data_)
271 for (
const auto &[k, v] : other.asMap())
275 bool operator==(
const SharedPropMap &o)
const
277 if (data_ == o.data_)
279 if (empty() && o.empty())
281 return asMap() == o.asMap();
283 bool operator!=(
const SharedPropMap &o)
const {
return !(*
this == o); }
286 static_assert(
sizeof(
SharedPropMap) ==
sizeof(
void *),
"SharedPropMap must remain pointer-sized");
292 template <
typename T>
296 using Vec = std::vector<T>;
297 using value_type = T;
298 using iterator =
typename Vec::iterator;
299 using const_iterator =
typename Vec::const_iterator;
304 mutable std::atomic<uint32_t> refCount{1};
308 Data *data_{
nullptr};
310 static const Vec &emptyVec()
noexcept
312 static const Vec kEmpty{};
316 static Vec &emptyMutVec()
noexcept
322 static void release(Data *p)
noexcept
324 if (p && p->refCount.fetch_sub(1u, std::memory_order_acq_rel) == 1u)
335 if (data_->refCount.load(std::memory_order_acquire) > 1u)
337 auto *copy =
new Data();
338 copy->vec = data_->vec;
346 SharedVector()
noexcept =
default;
347 SharedVector(
const Vec &v)
355 SharedVector(Vec &&v)
360 data_->vec = std::move(v);
363 SharedVector(std::initializer_list<T> init)
368 data_->vec.assign(init.begin(), init.end());
371 SharedVector(
const SharedVector &o) noexcept : data_(o.data_)
374 data_->refCount.fetch_add(1u, std::memory_order_relaxed);
376 SharedVector(SharedVector &&o) noexcept : data_(o.data_)
380 SharedVector &operator=(
const SharedVector &o)
noexcept
387 data_->refCount.fetch_add(1u, std::memory_order_relaxed);
391 SharedVector &operator=(SharedVector &&o)
noexcept
400 SharedVector &operator=(
const Vec &v)
410 SharedVector &operator=(Vec &&v)
417 detach() = std::move(v);
420 ~SharedVector()
noexcept { release(data_); }
422 bool empty()
const noexcept {
return !data_ || data_->vec.empty(); }
423 size_t size()
const noexcept {
return data_ ? data_->vec.size() : 0u; }
424 bool sharesStorageWith(
const SharedVector &o)
const noexcept {
return data_ == o.data_; }
426 const Vec &asVector()
const noexcept {
return data_ ? data_->vec : emptyVec(); }
427 operator const Vec &()
const noexcept {
return asVector(); }
429 const_iterator begin()
const noexcept {
return asVector().begin(); }
430 const_iterator end()
const noexcept {
return asVector().end(); }
431 const_iterator cbegin()
const noexcept {
return asVector().cbegin(); }
432 const_iterator cend()
const noexcept {
return asVector().cend(); }
434 iterator begin() {
return empty() ? emptyMutVec().begin() : detach().begin(); }
435 iterator end() {
return empty() ? emptyMutVec().end() : detach().end(); }
437 const T &operator[](
size_t i)
const {
return asVector()[i]; }
438 T &operator[](
size_t i) {
return detach()[i]; }
440 const T &front()
const {
return asVector().front(); }
441 T &front() {
return detach().front(); }
443 const T &back()
const {
return asVector().back(); }
444 T &back() {
return detach().back(); }
446 void push_back(
const T &v) { detach().push_back(v); }
447 void push_back(T &&v) { detach().push_back(std::move(v)); }
449 template <
typename... Args>
450 T &emplace_back(Args &&...args)
452 return detach().emplace_back(std::forward<Args>(args)...);
455 void reserve(
size_t n)
461 void clear()
noexcept
467 bool operator==(
const SharedVector &o)
const
469 if (data_ == o.data_)
471 if (empty() && o.empty())
473 return asVector() == o.asVector();
475 bool operator!=(
const SharedVector &o)
const {
return !(*
this == o); }
487 Value top{0.0f}, right{0.0f}, bottom{0.0f}, left{0.0f};
490 Spacing(
float all) : top(all), right(all), bottom(all), left(all) {}
491 Spacing(
Value all) : top(all), right(all), bottom(all), left(all) {}
492 Spacing(
Value v,
Value h) : top(v), right(h), bottom(v), left(h) {}
493 Spacing(
Value v,
Value h,
Value b) : top(v), right(h), bottom(b), left(h) {}
496 bool operator==(
const Spacing &o)
const
498 return top == o.top && right == o.right && bottom == o.bottom && left == o.left;
500 bool operator!=(
const Spacing &o)
const {
return !(*
this == o); }
507 for (
size_t i = 0; i < stack.size(); ++i)
527 float duration{0.15f};
541 float duration{1.0f};
545 bool alternate{
false};
546 bool fillForwards{
false};
547 bool blocksInput{
false};
567 ZIndex(
int v) : isAuto(
false), value(v) {}
569 static ZIndex Auto() {
return ZIndex(); }
571 bool operator==(
const ZIndex &o)
const {
return isAuto == o.isAuto && value == o.value; }
572 bool operator!=(
const ZIndex &o)
const {
return !(*
this == o); }
606 int16_t left{0}, top{0}, right{0}, bottom{0};
608 bool isNineSlice()
const {
return left || top || right || bottom; }
612 return name == o.name &&
613 left == o.left && top == o.top &&
614 right == o.right && bottom == o.bottom;
616 bool operator!=(
const TextureRef &o)
const {
return !(*
this == o); }
646 std::vector<std::pair<Kind, std::string>> extras;
648 bool requireHover{
false};
649 bool requirePressed{
false};
650 bool requireFocus{
false};
651 bool requireDisabled{
false};
652 bool requireChecked{
false};
658 std::vector<NegatedItem> items;
662 Kind kind{Kind::Tag};
665 std::vector<std::pair<Kind, std::string>> extras;
666 std::vector<Negation> negations;
668 bool requireHover{
false};
669 bool requirePressed{
false};
670 bool requireFocus{
false};
671 bool requireDisabled{
false};
672 bool requireChecked{
false};
681 std::vector<std::string> args;
683 bool operator==(
const FilterRef &o)
const {
return name == o.name && args == o.args; }
684 bool operator!=(
const FilterRef &o)
const {
return !(*
this == o); }
687 inline bool operator==(
const std::vector<FilterRef> &a,
const std::vector<FilterRef> &b)
689 if (a.size() != b.size())
691 for (
size_t i = 0; i < a.size(); ++i)
696 inline bool operator!=(
const std::vector<FilterRef> &a,
const std::vector<FilterRef> &b)
706 Value x{0.0f}, y{0.0f}, blur{0.0f};
707 Color color{Colors::Blank};
710 bool operator==(
const BoxShadow &o)
const
712 return x == o.x && y == o.y && blur == o.blur && color == o.color && enabled == o.enabled;
714 bool operator!=(
const BoxShadow &o)
const {
return !(*
this == o); }
717 enum class Direction : uint8_t
739 static GridTrack Fixed(Value v) {
return GridTrack{
Kind::Fixed, std::move(v), 0.0f}; }
740 static GridTrack Fr(
float f) {
return GridTrack{
Kind::Flex, Value::autoSize(), f}; }
742 bool operator==(
const GridTrack &o)
const
744 return kind == o.kind &&
size == o.size &&
fr == o.fr;
746 bool operator!=(
const GridTrack &o)
const {
return !(*
this == o); }
749 inline bool operator==(
const std::vector<GridTrack> &a,
const std::vector<GridTrack> &b)
751 if (a.size() != b.size())
753 for (
size_t i = 0; i < a.size(); ++i)
758 inline bool operator!=(
const std::vector<GridTrack> &a,
const std::vector<GridTrack> &b)
771 return GridPlacement{0,
static_cast<int16_t
>(sp < 1 ? 1 : sp)};
773 static GridPlacement Line(
int line,
int sp = 1)
775 return GridPlacement{
static_cast<int16_t
>(line),
static_cast<int16_t
>(sp < 1 ? 1 : sp)};
778 bool isAuto() const noexcept {
return start <= 0; }
780 bool operator==(
const GridPlacement &o)
const
782 return start == o.start &&
span == o.span;
784 bool operator!=(
const GridPlacement &o)
const {
return !(*
this == o); }
795#define BUBBLE_STYLE_PROPS(X) \
797 X(Spacing, margin, Spacing()) \
798 X(Spacing, padding, Spacing()) \
799 X(Spacing, borderWidth, Spacing()) \
800 X(BoxShadow, boxShadow, BoxShadow{}) \
801 X(TextureRef, backgroundTexture, TextureRef{}) \
802 X(std::string, effect, "") \
803 X(SharedVector<FilterRef>, filters, SharedVector<FilterRef>{}) \
804 X(SharedVector<GridTrack>, gridTemplateColumns, SharedVector<GridTrack>{}) \
805 X(SharedVector<GridTrack>, gridTemplateRows, SharedVector<GridTrack>{}) \
806 X(Value, width, Value::autoSize()) \
807 X(Value, height, Value::autoSize()) \
808 X(Value, minWidth, Value::autoSize()) \
809 X(Value, minHeight, Value::autoSize()) \
810 X(Value, maxWidth, Value::autoSize()) \
811 X(Value, maxHeight, Value::autoSize()) \
812 X(Value, flexBasis, Value::autoSize()) \
813 X(Value, gap, Value(0.0f)) \
814 X(Value, columnGap, Value::autoSize()) \
815 X(Value, rowGap, Value::autoSize()) \
816 X(Value, radius, Value(0.0f)) \
817 X(Value, translateX, Value(0.0f)) \
818 X(Value, translateY, Value(0.0f)) \
819 X(Value, fontSize, Value(20.0f)) \
820 X(Value, letterSpacing, Value(2.0f)) \
821 X(Value, top, Value::autoSize()) \
822 X(Value, left, Value::autoSize()) \
823 X(Value, right, Value::autoSize()) \
824 X(Value, bottom, Value::autoSize()) \
825 X(FontStack, font, FontStack{}) \
827 X(ZIndex, zIndex, ZIndex::Auto()) \
828 X(float, grow, 0.0f) \
829 X(float, shrink, 1.0f) \
830 X(float, opacity, 1.0f) \
831 X(float, scale, 1.0f) \
832 X(float, rotation, 0.0f) \
833 X(float, transitionTime, 0.0f) \
834 X(TransitionFunction, ease, TransitionFunction::Linear) \
835 X(Color, background, Colors::Blank) \
836 X(Color, color, Colors::White) \
837 X(Color, tint, Colors::White) \
838 X(Color, borderColor, Colors::Blank) \
840 X(GridPlacement, gridColumn, GridPlacement{}) \
841 X(GridPlacement, gridRow, GridPlacement{}) \
843 X(Align, alignH, Align::Auto) \
844 X(Align, alignV, Align::Auto) \
845 X(Align, alignItems, Align::Stretch) \
846 X(Align, verticalAlign, Align::Auto) \
847 X(Align, textAlign, Align::Auto) \
848 X(Justify, justify, Justify::Start) \
849 X(Overflow, overflowX, Overflow::Visible) \
850 X(Overflow, overflowY, Overflow::Visible) \
851 X(Position, position, Position::Static) \
852 X(WhiteSpace, whiteSpace, WhiteSpace::Normal) \
853 X(TextOverflow, textOverflow, TextOverflow::Visible) \
854 X(Direction, direction, Direction::Auto) \
855 X(CursorShape, cursor, CursorShape::Auto) \
856 X(TextDirection, dir, TextDirection::Auto) \
867 return name ==
"dir";
869 return name ==
"font";
871 return name ==
"color";
873 return name ==
"cursor";
875 return name ==
"fontSize";
877 return name ==
"textAlign";
879 return name ==
"letterSpacing";
888 inline std::string kebabToCamel(std::string_view s)
891 out.reserve(s.size());
892 bool upperNext =
false;
899 out.push_back(upperNext && c >=
'a' && c <=
'z'
900 ?
static_cast<char>(c -
'a' +
'A')
908 inline std::string camelToKebab(std::string_view s)
911 out.reserve(s.size() + 4);
914 if (c >=
'A' && c <=
'Z')
917 out.push_back(
static_cast<char>(c -
'A' +
'a'));
933#define X(T, name, def) Opt<T> name;
934 BUBBLE_STYLE_PROPS(X)
945 const bool hadUnresolved = !unresolvedProps.empty();
946#define X(T, name, def) \
951 eraseUnresolvedForProp_(#name); \
953 BUBBLE_STYLE_PROPS(X)
957 if (o.overflowX.is_set && o.overflowY.is_set)
958 unresolvedProps.erase(
"overflow");
959 if (o.grow.is_set && o.shrink.is_set && o.flexBasis.is_set)
960 unresolvedProps.erase(
"flex");
962 if (o.transitions.is_set)
963 transitions = o.transitions;
964 if (o.animations.is_set)
965 animations = o.animations;
967 if (!o.customProps.empty())
968 customProps.mergeFrom(o.customProps);
969 if (!o.unresolvedProps.empty())
970 for (
const auto &[k, v] : o.unresolvedProps)
972 unresolvedProps[k] = v;
980 void eraseUnresolvedForProp_(std::string_view camelName)
982 if (unresolvedProps.empty())
984 unresolvedProps.erase(std::string(camelName));
985 unresolvedProps.erase(camelToKebab(camelName));
986 if (camelName ==
"filters")
987 unresolvedProps.erase(
"filter");
988 else if (camelName ==
"direction")
989 unresolvedProps.erase(
"flex-direction");
999 if (name ==
"overflow")
1001 s.overflowX.reset();
1002 s.overflowY.reset();
1009 s.flexBasis.reset();
1013 std::string normalized = kebabToCamel(name);
1014 if (normalized ==
"filter")
1015 normalized =
"filters";
1016 else if (normalized ==
"flexDirection")
1017 normalized =
"direction";
1019 bool cleared =
false;
1020#define X(T, n, def) \
1021 if (!cleared && normalized == #n) \
1026 BUBBLE_STYLE_PROPS(X)
1037#define X(T, name, def) T name = def;
1038 BUBBLE_STYLE_PROPS(X)
1050 const Style *root =
nullptr)
1053#define X(T, name, def) \
1054 if (s.name.is_set) \
1055 c.name = s.name.value; \
1056 else if (parent && isInheritedProp(#name)) \
1057 c.name = parent->name; \
1058 else if (root && root->name.is_set) \
1059 c.name = root->name.value; \
1062 BUBBLE_STYLE_PROPS(X)
1064 if (c.overflowX == Overflow::Visible && c.overflowY != Overflow::Visible)
1065 c.overflowX = Overflow::Auto;
1066 else if (c.overflowY == Overflow::Visible && c.overflowX != Overflow::Visible)
1067 c.overflowY = Overflow::Auto;
1069 if (s.transitions.is_set)
1070 c.transitions = s.transitions.value;
1071 if (s.animations.is_set)
1072 c.animations = s.animations.value;
1075 c.customProps = parent->customProps;
1077 c.customProps = root->customProps;
1078 c.customProps.mergeFrom(s.customProps);
1086#define X(T, name, def) \
1087 if (!(a.name == b.name)) \
1089 BUBBLE_STYLE_PROPS(X)
1093 inline bool operator!=(
const ComputedStyle &a,
const ComputedStyle &b) {
return !(a == b); }
1097 inline float lerpProp(
float a,
float b,
float t) {
return a + (b - a) * t; }
1101 auto mix = [t](uint8_t x, uint8_t y)
1103 float v =
static_cast<float>(x) + (
static_cast<float>(y) -
static_cast<float>(x)) * t;
1104 return static_cast<uint8_t
>(std::clamp(std::lround(v), 0L, 255L));
1106 return {mix(a.r, b.r), mix(a.g, b.g), mix(a.b, b.b), mix(a.a, b.a)};
1111 return t > 0.0f ? b : a;
1116 if (a.isAuto() && b.isAuto())
1117 return Value::autoSize();
1118 if (a.isAuto() || b.isAuto())
1119 return t > 0.0f ? b : a;
1121 if (!a.isComplex() && !b.isComplex() && a.unit() == b.unit())
1122 return Value(a.scalar() + (b.scalar() - a.scalar()) * t, a.unit());
1124 if (a.getOp() != ValueOp::None || b.getOp() != ValueOp::None)
1125 return a + (b - a).mulWith(Value::number(t));
1127 float ca[7] = {0}, cb[7] = {0};
1128 for (
size_t i = 0; i < a.termCount(); ++i)
1130 const auto term = a.termAt(i);
1131 int idx =
static_cast<int>(term.unit);
1132 if (idx >= 0 && idx < 7)
1133 ca[idx] += term.coeff;
1135 for (
size_t i = 0; i < b.termCount(); ++i)
1137 const auto term = b.termAt(i);
1138 int idx =
static_cast<int>(term.unit);
1139 if (idx >= 0 && idx < 7)
1140 cb[idx] += term.coeff;
1145 for (
int i = 0; i < 7; ++i)
1147 float v = ca[i] + (cb[i] - ca[i]) * t;
1149 buf[count++] = {v,
static_cast<Unit
>(i)};
1151 return Value::fromLinearTerms(buf, count);
1156 return Spacing(lerpProp(a.top, b.top, t), lerpProp(a.right, b.right, t),
1157 lerpProp(a.bottom, b.bottom, t), lerpProp(a.left, b.left, t));
1160 template <
typename E,
typename = std::enable_if_t<std::is_enum_v<E>>>
1161 inline E lerpProp(E a, E b,
float t) {
return t > 0.0f ? b : a; }
1163 inline ZIndex lerpProp(
const ZIndex &a,
const ZIndex &b,
float t) {
return t > 0.0f ? b : a; }
1165 inline std::string lerpProp(
const std::string &a,
const std::string &b,
float t)
1167 return t > 0.0f ? b : a;
1174 return t > 0.0f ? b : a;
1179 return t > 0.0f ? b : a;
1184 return t > 0.0f ? b : a;
1191 return t > 0.0f ? b : a;
1196 return t > 0.0f ? b : a;
1203#define X(T, name, def) r.name = lerpProp(a.name, b.name, t);
1204 BUBBLE_STYLE_PROPS(X)
1206 r.transitions = b.transitions;
1207 r.customProps = b.customProps;
1218 auto timingFor = [&](
const char *propName) -> std::pair<float, TransitionFunction>
1220 for (
const auto &spec : b.transitions)
1222 if (spec.prop == propName || spec.prop ==
"all")
1223 return {spec.duration, spec.ease};
1225 return {b.transitionTime, b.ease};
1228#define X(T, name, def) \
1230 if (a.name == b.name) \
1236 auto [dur, ease] = timingFor(#name); \
1237 float tp = (dur > 0.0f) ? std::clamp(realElapsed / dur, 0.0f, 1.0f) : 1.0f; \
1238 r.name = lerpProp(a.name, b.name, getRatio(tp, ease)); \
1241 BUBBLE_STYLE_PROPS(X)
1244 r.transitions = b.transitions;
1245 r.customProps = b.customProps;
1254#define X(T, name, def) \
1255 if (a.name.is_set != b.name.is_set) \
1257 if (a.name.is_set && !(a.name.value == b.name.value)) \
1259 BUBBLE_STYLE_PROPS(X)
1262 if (a.animations.is_set != b.animations.is_set)
1264 if (a.animations.is_set)
1266 const auto &av = a.animations.value;
1267 const auto &bv = b.animations.value;
1268 if (av.size() != bv.size())
1270 for (
size_t i = 0; i < av.size(); ++i)
1272 if (av[i].name != bv[i].name ||
1273 av[i].duration != bv[i].duration ||
1274 av[i].delay != bv[i].delay ||
1275 av[i].iterations != bv[i].iterations ||
1276 av[i].alternate != bv[i].alternate ||
1277 av[i].fillForwards != bv[i].fillForwards ||
1278 av[i].ease != bv[i].ease)
1285 template <
typename T>
1286 inline Opt<T> lerpOpt(
const Opt<T> &a,
const Opt<T> &b,
float t)
1288 if (a.is_set && b.is_set)
1289 return Opt<T>(lerpProp(a.value, b.value, t));
1296#define X(T, name, def) r.name = lerpOpt(a.name, b.name, t);
1297 BUBBLE_STYLE_PROPS(X)
1299 r.transitions = b.transitions;
1300 r.animations = b.animations;
1301 r.customProps = b.customProps;
1302 r.unresolvedProps = b.unresolvedProps;
1308#define X(T, name, def) \
1309 if (src.name.is_set) \
1310 dst.name = src.name.value;
1311 BUBBLE_STYLE_PROPS(X)
1315 template <
typename F>
1316 inline void forEachSetStyleProp(
const Style &s, F &&fn)
1318#define X(T, name, def) \
1319 if (s.name.is_set) \
1321 BUBBLE_STYLE_PROPS(X)
1325 inline bool copyStyleProp(
Style &dst,
const Style &src, std::string_view name)
1327#define X(T, n, def) \
1337 BUBBLE_STYLE_PROPS(X)
1342 inline bool hasStyleProp(
const Style &s, std::string_view name)
1344#define X(T, n, def) \
1347 BUBBLE_STYLE_PROPS(X)
1368 inline const std::vector<PropDesc> &propTable()
1370 static const std::vector<PropDesc> table = {
1371#define X(T, name, def) PropDesc{#name, #T, #def, \
1372 [](const ComputedStyle &c) -> PropValue { return c.name; }, \
1373 [](ComputedStyle &c, const PropValue &v) { if (const T* p = std::get_if<T>(&v)) c.name = *p; }},
1374 BUBBLE_STYLE_PROPS(X)
1380 inline const PropDesc *findProp(std::string_view name)
1382 for (
const auto &d : propTable())
1390 inline PropValue lerpValue(
const PropValue &a,
const PropValue &b,
float t)
1392 return std::visit([&](
const auto &x) -> PropValue
1394 using T = std::decay_t<
decltype(x)>;
1395 if (
const T* y = std::get_if<T>(&b))
return lerpProp(x, *y, t);
Centralized standard library includes used throughout ZenitUI.
Easing curves used by transitions and CSS animations.
Small enumerations describing layout strategy and interaction state.
Length units and the compact 8-byte tagged Value expression representation.
Ordered list of font family names to try, first match wins.
Definition CoreTypes.hpp:194
8-byte Copy-on-Write wrapper around std::unordered_map<std::string, std::string>.
Definition Style.hpp:81
8-byte Copy-on-Write wrapper around std::vector<T> for cold style arrays.
Definition Style.hpp:294
TransitionFunction
Timing function applied between two keyframe values.
Definition Easing.hpp:28
Justify
Main-axis distribution for flex containers.
Definition CoreTypes.hpp:462
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
bool clearStyleProp(Style &s, std::string_view name)
Clear the property named name on s.
Definition Style.hpp:997
SelectorCombinator
Relationship between a selector and the preceding selector in a chain.
Definition Style.hpp:621
bool stylesDiffer(const Style &a, const Style &b)
Compare two sparse Style values for "would this change anything".
Definition Style.hpp:1252
TextOverflow
CSS text-overflow modes supported by the text renderer.
Definition Style.hpp:595
ComputedStyle lerpStyleTimed(const ComputedStyle &a, const ComputedStyle &b, float realElapsed)
Field-wise lerp using per-property durations from b's transition list.
Definition Style.hpp:1214
std::ostream & operator<<(std::ostream &os, const FontStack &stack)
std::ostream operator for FontStack, used by debug output.
Definition Style.hpp:504
Overflow
CSS overflow modes for one axis.
Definition Style.hpp:579
bool isInheritedProp(std::string_view name)
true if the named property inherits from parent to child.
Definition Style.hpp:862
ComputedStyle lerpStyle(const ComputedStyle &a, const ComputedStyle &b, float t)
Field-wise lerp of two ComputedStyle.
Definition Style.hpp:1200
WhiteSpace
CSS white-space values relevant to text layout.
Definition Style.hpp:588
Position
CSS-style position modes supported by the layout system.
Definition Style.hpp:552
@ GeneralSibling
A ~ B (any preceding sibling).
Definition Style.hpp:625
@ AdjacentSibling
A + B (immediately preceding sibling).
Definition Style.hpp:624
@ Descendant
A B (any ancestor).
Definition Style.hpp:622
@ Child
A > B (direct parent).
Definition Style.hpp:623
One entry in the animations list of a Style.
Definition Style.hpp:539
CSS box-shadow payload.
Definition Style.hpp:705
8-bit-per-channel RGBA color, non-premultiplied.
Definition CoreTypes.hpp:78
Dense style: every property has a concrete value.
Definition Style.hpp:1036
static ComputedStyle from(const Style &s, const ComputedStyle *parent=nullptr, const Style *root=nullptr)
Build a ComputedStyle from a sparse Style and its context.
Definition Style.hpp:1048
One filter in the filters list of a Style.
Definition Style.hpp:679
Item placement along one grid axis (grid-column or grid-row).
Definition Style.hpp:765
int16_t start
1-based start line (0 = auto-place).
Definition Style.hpp:766
int16_t span
Number of tracks spanned (>= 1).
Definition Style.hpp:767
One track definition in grid-template-columns or grid-template-rows.
Definition Style.hpp:726
Kind
Definition Style.hpp:728
@ Auto
Size to content.
Definition Style.hpp:729
@ Flex
Flexible fraction (fr).
Definition Style.hpp:731
@ Fixed
Explicit length (px, %, vw, vh, calc(...)).
Definition Style.hpp:730
float fr
Used when kind == Kind::Flex.
Definition Style.hpp:736
Value size
Used when kind == Kind::Fixed.
Definition Style.hpp:735
Optional wrapper with value semantics used for all style fields.
Definition Style.hpp:49
Definition Style.hpp:1360
const char * name
camelCase C++ name, e.g. "fontSize".
Definition Style.hpp:1361
const char * defaultExpr
Stringified default expression, e.g. "Value::autoSize()".
Definition Style.hpp:1363
const char * type
Stringified C++ type, e.g. "Value".
Definition Style.hpp:1362
Single compound argument inside a :not(...) pseudo-class.
Definition Style.hpp:643
One :not(a, b, ...) clause; matches when none of items match.
Definition Style.hpp:657
One component of a CSS selector chain.
Definition Style.hpp:632
Kind
Definition Style.hpp:634
@ Any
Universal selector * or implicit base for standalone :not(...) / :hover.
Definition Style.hpp:638
Four-sided Value tuple used for padding, margin and border-width.
Definition Style.hpp:486
Sparse style: every property is Opt<T>, unset by default.
Definition Style.hpp:932
Style & overlay(const Style &o)
Merge o into *this; every set field of o wins.
Definition Style.hpp:943
Reference to a texture asset with optional nine-slice insets.
Definition Style.hpp:604
One entry in the transitions list of a Style.
Definition Style.hpp:525
8-byte tagged length expression:
Definition Unit.hpp:58
CSS z-index with an explicit "auto" state.
Definition Style.hpp:562