38namespace ZenitUI::Debug
46 inline const char *unitName(Unit u)
73 inline std::string valueToString(
const Value &v)
77 if (v.getOp() != ValueOp::None)
79 auto opName = [](ValueOp op) ->
const char *
83 case ValueOp::Add:
return "add";
84 case ValueOp::Sub:
return "sub";
85 case ValueOp::Mul:
return "mul";
86 case ValueOp::Div:
return "div";
87 case ValueOp::Min:
return "min";
88 case ValueOp::Max:
return "max";
89 case ValueOp::Clamp:
return "clamp";
90 case ValueOp::Round:
return "round";
91 case ValueOp::Floor:
return "floor";
92 case ValueOp::Ceil:
return "ceil";
93 case ValueOp::Mod:
return "mod";
94 default:
return "calc";
97 std::ostringstream os;
98 os << opName(v.getOp()) <<
"(";
99 if (
const auto *args = v.astArgs())
101 for (
size_t i = 0; i < args->size(); ++i)
105 os << valueToString((*args)[i]);
111 std::ostringstream os;
112 const size_t n = v.termCount();
113 for (
size_t i = 0; i < n; ++i)
115 const auto t = v.termAt(i);
120 os << std::abs(t.coeff) << unitName(t.unit);
124 os << (t.coeff < 0.0f ?
" - " :
" + ");
125 os << std::abs(t.coeff) << unitName(t.unit);
131 inline std::string toString(
float v)
133 std::ostringstream os;
137 inline std::string toString(
const std::string &s) {
return s.empty() ?
"\"\"" : s; }
138 inline std::string toString(
const Value &v) {
return valueToString(v); }
140 inline std::string toString(
const Color &c)
142 std::ostringstream os;
143 os <<
"#" << std::hex << std::setfill(
'0')
144 << std::setw(2) << (int)c.r
145 << std::setw(2) << (int)c.g
146 << std::setw(2) << (int)c.b
147 << std::setw(2) << (int)c.a
152 inline std::string toString(
const Spacing &s)
154 return "[" + valueToString(s.top) +
" " + valueToString(s.right) +
" " + valueToString(s.bottom) +
" " + valueToString(s.left) +
"]";
157 inline std::string toString(
const FontStack &stack)
161 std::string out =
"[";
162 for (
size_t i = 0; i < stack.size(); ++i)
172 inline std::string toString(
Align a)
190 inline std::string toString(
Justify j)
201 return "space-between";
206 inline std::string toString(
Position p)
210 case Position::Static:
212 case Position::Relative:
214 case Position::Absolute:
220 inline std::string toString(Direction d)
224 case Direction::Auto:
228 case Direction::Column:
257 return "nesw-resize";
259 return "nwse-resize";
261 return "not-allowed";
284 inline std::string toString(
Overflow o)
288 case Overflow::Visible:
290 case Overflow::Hidden:
292 case Overflow::Scroll:
304 case WhiteSpace::Normal:
306 case WhiteSpace::Nowrap:
316 case TextOverflow::Visible:
318 case TextOverflow::Ellipsis:
328 case TransitionFunction::Linear:
330 case TransitionFunction::EaseInQuad:
331 return "ease-in-quad";
332 case TransitionFunction::EaseOutQuad:
333 return "ease-out-quad";
334 case TransitionFunction::EaseInOutQuad:
335 return "ease-in-out-quad";
336 case TransitionFunction::EaseInCubic:
337 return "ease-in-cubic";
338 case TransitionFunction::EaseOutCubic:
339 return "ease-out-cubic";
340 case TransitionFunction::EaseInOutCubic:
341 return "ease-in-out-cubic";
342 case TransitionFunction::EaseInBack:
343 return "ease-in-back";
344 case TransitionFunction::EaseOutBack:
345 return "ease-out-back";
346 case TransitionFunction::EaseOutElastic:
347 return "ease-out-elastic";
348 case TransitionFunction::EaseOutBounce:
349 return "ease-out-bounce";
354 inline std::string toString(
const ZIndex &z)
356 return z.isAuto ?
"auto" : std::to_string(z.value);
359 inline std::string toString(
const TextureRef &t)
361 std::ostringstream os;
364 os <<
" " << t.left <<
" " << t.top <<
" " << t.right <<
" " << t.bottom;
368 inline std::string toString(
const FilterRef &f)
372 std::string s = f.name +
"(";
373 for (
size_t i = 0; i < f.args.size(); ++i)
383 inline std::string toString(
const SharedVector<FilterRef> &fs)
385 return toString(fs.asVector());
388 inline std::string toString(
const BoxShadow &b)
392 std::ostringstream os;
393 os << valueToString(b.x) <<
" " << valueToString(b.y)
394 <<
" " << valueToString(b.blur) <<
" " << toString(b.color);
398 inline std::string toString(
const GridTrack &t)
405 return toString(t.size);
407 return toString(t.fr) +
"fr";
412 inline std::string toString(
const SharedVector<GridTrack> &ts)
414 return toString(ts.asVector());
417 inline std::string toString(
const GridPlacement &p)
420 return (p.span <= 1) ?
"auto" : (
"span " + std::to_string(p.span));
422 return std::to_string(p.start);
423 return std::to_string(p.start) +
" / span " + std::to_string(p.span);
429 inline std::string styleToString(
const Style &s)
431 std::ostringstream os;
434 {
if (!first) os <<
", "; first =
false; };
436#define X(T, name, def) \
440 os << #name "=" << toString(s.name.value); \
442 BUBBLE_STYLE_PROPS(X)
445 if (s.transitions.is_set)
448 os <<
"transitions(" << s.transitions.value.size() <<
")";
450 if (s.animations.is_set)
453 os <<
"animations(" << s.animations.value.size() <<
")";
461 inline std::string computedStyleToString(
const ComputedStyle &cs)
463 std::ostringstream os;
464 os <<
"size=" << valueToString(cs.width) <<
"x" << valueToString(cs.height);
465 os <<
" bg=" << toString(cs.background);
466 os <<
" color=" << toString(cs.color);
467 if (!cs.font.empty())
468 os <<
" font=" << cs.font;
469 os <<
" fs=" << valueToString(cs.fontSize);
470 os <<
" padding=" << toString(cs.padding);
471 os <<
" margin=" << toString(cs.margin);
472 os <<
" radius=" << valueToString(cs.radius);
473 if (cs.borderWidth != Spacing())
475 os <<
" borderW=" << toString(cs.borderWidth);
476 os <<
" borderC=" << toString(cs.borderColor);
478 if (cs.opacity != 1.0f)
479 os <<
" opacity=" << cs.opacity;
480 if (cs.position != Position::Static)
481 os <<
" pos=" << toString(cs.position);
482 if (!cs.zIndex.isAuto)
483 os <<
" zIndex=" << cs.zIndex.value;
484 if (cs.overflowX != Overflow::Visible)
485 os <<
" overflow-x=" << toString(cs.overflowX);
486 if (cs.overflowY != Overflow::Visible)
487 os <<
" overflow-y=" << toString(cs.overflowY);
488 if (!cs.left.isAuto())
489 os <<
" left=" << valueToString(cs.left);
490 if (!cs.top.isAuto())
491 os <<
" top=" << valueToString(cs.top);
492 if (!cs.right.isAuto())
493 os <<
" right=" << valueToString(cs.right);
494 if (!cs.bottom.isAuto())
495 os <<
" bottom=" << valueToString(cs.bottom);
496 if (!cs.translateX.isAuto() || !cs.translateY.isAuto())
497 os <<
" translate=(" << valueToString(cs.translateX) <<
"," << valueToString(cs.translateY) <<
")";
498 if (cs.scale != 1.0f)
499 os <<
" scale=" << cs.scale;
500 if (cs.rotation != 0.0f)
501 os <<
" rotation=" << cs.rotation;
502 if (!cs.customProps.empty())
506 for (
const auto &[k, v] : cs.customProps)
519 inline std::string selectorToString(
const ThemeRule &r)
521 std::ostringstream os;
522 for (
size_t i = 0; i < r.chain.size(); ++i)
526 const auto &ss = r.chain[i];
529 const std::string &name)
531 if (kind == SimpleSelector::Kind::Class)
533 else if (kind == SimpleSelector::Kind::Id)
538 printComponent(ss.kind, ss.name);
539 for (
const auto &[kind, name] : ss.extras)
540 printComponent(kind, name);
544 if (ss.requirePressed)
548 if (ss.requireDisabled)
550 if (ss.requireChecked)
554 os <<
"::" << r.part;
559 inline std::string stateFlagsToString(
const Layout &node)
562 if (node.isHoveredState())
564 if (node.isPressedState())
566 if (node.isFocusedState())
568 if (node.isCheckedState())
570 if (node.isDisabledState())
572 return s.empty() ?
"-" : s;
578 inline void dumpStyle(
const Layout &node, std::ostream &os = std::cerr)
580 os <<
"=== Node ===\n";
581 os <<
" tag : " << node.getStyleTag() <<
"\n";
582 if (!node.nodeId.empty())
583 os <<
" id : #" << node.nodeId <<
"\n";
584 if (!node.ref.empty())
585 os <<
" ref : @" << node.ref <<
"\n";
586 if (!node.getStyleClasses().empty())
589 for (
const auto &c : node.getStyleClasses())
593 os <<
" state : " << stateFlagsToString(node) <<
"\n";
594 const auto &r = node.getRect();
595 os <<
" rect : (" << r.x <<
", " << r.y <<
" " << r.width <<
"x" << r.height <<
")\n";
596 os <<
" style : " << computedStyleToString(node.getStyle()) <<
"\n";
598 auto matches = node.getMatchingRules();
599 os <<
" matches : " << matches.size() <<
" rule(s)\n";
600 for (
const auto *rule : matches)
602 os <<
"spec=" << rule->specificity.ids <<
"."
603 << rule->specificity.classes <<
"."
604 << rule->specificity.tags <<
"] "
605 << selectorToString(*rule) <<
"\n";
606 os <<
" -> { " << styleToString(rule->style) <<
" }\n";
614 inline void dumpTree(
const Layout &node, std::ostream &os = std::cerr,
615 int maxDepth = -1,
int depth = 0)
617 std::string indent(depth * 2,
' ');
618 os << indent <<
"- ";
619 if (!node.nodeId.empty())
620 os <<
"#" << node.nodeId <<
" ";
621 if (!node.ref.empty())
622 os <<
"@" << node.ref <<
" ";
623 os << node.getStyleTag();
624 for (
const auto &c : node.getStyleClasses())
627 const auto &r = node.getRect();
628 os <<
" [" << r.width <<
"x" << r.height <<
" @ " << r.x <<
"," << r.y <<
"]";
630 std::string st = stateFlagsToString(node);
632 os <<
" {" << st <<
"}";
635 if (maxDepth >= 0 && depth >= maxDepth)
637 for (
const auto &c : node.children)
638 dumpTree(*c, os, maxDepth, depth + 1);
645 inline void dumpTheme(
const Theme &theme, std::ostream &os = std::cerr)
647 os <<
"=== Theme ===\n";
648 os <<
"Rules : " << theme.rules.size() <<
"\n";
649 os <<
"Keyframes: " << theme.keyframes.size() <<
"\n";
651 if (!theme.keyframes.empty())
653 os <<
"\n--- Keyframes ---\n";
654 for (
const auto &[name, kf] : theme.keyframes)
656 os <<
" " << name <<
" (" << kf.keyframes.size() <<
" frames)\n";
660 os <<
"\n--- Rules ---\n";
661 for (
size_t i = 0; i < theme.rules.size(); ++i)
663 const auto &r = theme.rules[i];
664 os <<
" [" << std::setw(3) << i <<
"] spec=" << std::setw(6) << r.specificity.ids <<
"."
665 << r.specificity.classes <<
"."
666 << r.specificity.tags <<
" "
667 << selectorToString(r) <<
"\n";
668 os <<
" { " << styleToString(r.style) <<
" }\n";
676 inline void dumpParts(
const Layout &node, std::ostream &os = std::cerr)
678 static const char *candidates[] = {
679 "track",
"fill",
"knob",
"box",
"mark",
"cursor"};
680 os <<
"=== Parts of " << node.getStyleTag() <<
" ===\n";
681 const auto &theme = node.theme();
682 for (
auto *name : candidates)
685 for (
const auto &r : theme.rules)
694 os <<
" ::" << name <<
" (" << matchCount <<
" matching rule(s))\n";
702 inline std::string renderStatsToString(
const RenderStats &s)
704 std::ostringstream os;
705 os <<
"targets[created=" << s.targetsCreated
706 <<
" destroyed=" << s.targetsDestroyed
707 <<
" live=" << s.liveTargets
708 <<
"] pushTarget=" << s.pushTargetCalls
709 <<
" passes=" << s.filterPasses;
716 inline void dumpRenderStats(
const RenderStats &s, std::ostream &os = std::cerr)
718 os <<
"[RenderStats] " << renderStatsToString(s) <<
"\n";
724 inline void dumpRenderStats(
const UIContext &ctx, std::ostream &os = std::cerr)
726 dumpRenderStats(ctx.renderStats, os);
735namespace ZenitUI::Debug
739 inline void dumpStyle(
const Layout &, std::ostream & = std::cerr) {}
740 inline void dumpTree(
const Layout &, std::ostream & = std::cerr,
int = -1,
int = 0) {}
741 inline void dumpTheme(
const Theme &, std::ostream & = std::cerr) {}
742 inline void dumpParts(
const Layout &, std::ostream & = std::cerr) {}
743 inline std::string renderStatsToString(
const RenderStats &) {
return {}; }
744 inline void dumpRenderStats(
const RenderStats &, std::ostream & = std::cerr) {}
745 inline void dumpRenderStats(
const UIContext &, std::ostream & = std::cerr) {}
Small value types shared by the layout, rendering and input layers.
The node class: tree structure, layout pass, style resolution, input dispatch, render orchestration,...
Global stylesheet storage and rule matching.
Length units and the compact 8-byte tagged Value expression representation.
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
bool ruleMatches(const ThemeRule &r, const Layout *node, Vec2 viewport)
true if node matches the full rule selector chain ( , >, +, ~, :not()).
Definition Layout.hpp:1615
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
@ Center
Center the whole set.
Definition CoreTypes.hpp:464
@ End
Pack at the trailing edge.
Definition CoreTypes.hpp:465
@ Start
Pack at the leading edge.
Definition CoreTypes.hpp:463
@ SpaceBetween
Distribute leftover space between items.
Definition CoreTypes.hpp:466
@ Auto
Defer to the parent's alignItems.
Definition CoreTypes.hpp:453
@ Center
Center within the available space.
Definition CoreTypes.hpp:455
@ End
Pack at the trailing edge.
Definition CoreTypes.hpp:456
@ Start
Pack at the leading edge.
Definition CoreTypes.hpp:454
@ Stretch
Stretch to fill the cross axis.
Definition CoreTypes.hpp:457
@ Auto
Infer paragraph direction from first strong Bidi character (fallback LTR).
Definition UIEnums.hpp:84
@ LTR
Explicit left-to-right direction.
Definition UIEnums.hpp:85
@ RTL
Explicit right-to-left direction.
Definition UIEnums.hpp:86
@ Auto
Inherit or fall back to Default.
Definition UIEnums.hpp:62
@ Crosshair
Precision crosshair (crosshair).
Definition UIEnums.hpp:74
@ Wait
Busy / loading indicator (wait, progress).
Definition UIEnums.hpp:75
@ ResizeEW
Horizontal resize (ew-resize, col-resize).
Definition UIEnums.hpp:69
@ ResizeNS
Vertical resize (ns-resize, row-resize).
Definition UIEnums.hpp:70
@ Pointer
Pointing hand (buttons, links, interactive controls).
Definition UIEnums.hpp:64
@ ResizeNESW
Diagonal NE-SW resize (nesw-resize).
Definition UIEnums.hpp:71
@ Move
Four-way move cursor.
Definition UIEnums.hpp:66
@ Grabbing
Closed hand (active drag).
Definition UIEnums.hpp:68
@ Default
Standard arrow cursor.
Definition UIEnums.hpp:63
@ ResizeNWSE
Diagonal NW-SE resize (nwse-resize).
Definition UIEnums.hpp:72
@ Text
I-beam (editable text fields).
Definition UIEnums.hpp:65
@ Grab
Open hand (draggable item).
Definition UIEnums.hpp:67
@ NotAllowed
Forbidden / disabled action (not-allowed).
Definition UIEnums.hpp:73
TextOverflow
CSS text-overflow modes supported by the text renderer.
Definition Style.hpp:595
Overflow
CSS overflow modes for one axis.
Definition Style.hpp:579
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
@ 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
Kind
Definition Style.hpp:634