ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
Text.hpp
Go to the documentation of this file.
1#pragma once
2
11
12#include "Common.hpp"
13#include "Layout.hpp"
14
15namespace ZenitUI::UI
16{
17
21
22 class Tooltip;
23
31 class Text : public TLayout<Text>
32 {
33 public:
35 explicit Text(std::string text);
36
38 void setText(std::string new_text);
39
41 const std::string &getText() const { return text; }
42
45
47 void setWrap(bool w);
48
50 bool getWrap() const { return wrap_; }
51
53 bool isEllipsized() const { return ellipsized_; }
54
56 void setAutoEllipsisTooltip(bool enabled);
57 bool getAutoEllipsisTooltip() const { return autoEllipsisTooltip_; }
58
59 protected:
60 Vec2 computeIntrinsicSize(float availW, float availH) override;
61 void renderContent(float op, const ComputedStyle &style) override;
62 void onLayout() override;
63 void onUpdate(float dt) override;
64
65 private:
66 TextMeasureSpec makeSpec(const ComputedStyle &style) const;
67 void ensureLayout(float wrapW, const ComputedStyle &style);
68 bool computeEllipsized(const ComputedStyle &style);
69
70 std::string text;
71 FontHandle defaultFont{0};
72 bool text_dirty{true};
73 bool wrap_{false};
74 bool ellipsized_{false};
75 bool autoEllipsisTooltip_{true};
76 bool ellipsisHovered_{false};
77 float cachedFs{-1.0f};
78 float cachedSp{-1.0f};
79 float cachedWrapW{-2.0f};
80 uint32_t cachedFontId{0};
81 FontStack cachedFontStack;
83 std::shared_ptr<const TextLayout> layout_;
84 std::shared_ptr<Tooltip> ellipsisTooltip_;
85 };
86
88 inline std::shared_ptr<Text> Label(std::string t) { return Text::create(std::move(t)); }
90} // namespace ZenitUI::UI
Centralized standard library includes used throughout ZenitUI.
The node class: tree structure, layout pass, style resolution, input dispatch, render orchestration,...
TLayout(Args &&...args)
Definition Layout.hpp:1401
static std::shared_ptr< Text > create(Args &&...args)
Definition Layout.hpp:1410
bool getWrap() const
Whether word wrapping is enabled.
Definition Text.hpp:50
Vec2 computeIntrinsicSize(float availW, float availH) override
Compute the intrinsic size, excluding padding and border.
const std::string & getText() const
Current content.
Definition Text.hpp:41
void onUpdate(float dt) override
Called every frame from update, after input dispatch.
void setText(std::string new_text)
Replace the content.
void setAutoEllipsisTooltip(bool enabled)
Automatically show a hover tooltip with the full text when ellipsized (default: true).
void onLayout() override
Called after arrange assigns the node's rect.
void setWrap(bool w)
Enable or disable word wrapping.
void renderContent(float op, const ComputedStyle &style) override
Draw the node's content (text, images, custom geometry).
Text(std::string text)
Construct with initial content.
bool isEllipsized() const
True when the text is currently truncated with an ellipsis.
Definition Text.hpp:53
void setFont(FontHandle f)
Override the font used for measurement and rendering.
A portal-based hover label.
Definition Tooltip.hpp:36
TextDirection
Inline / layout writing direction for Bidi text and RTL layout mirroring (ยง6.2).
Definition UIEnums.hpp:83
@ Auto
Infer paragraph direction from first strong Bidi character (fallback LTR).
Definition UIEnums.hpp:84
std::shared_ptr< Text > Label(std::string t)
Convenience factory: a Text node.
Definition Text.hpp:88
Dense style: every property has a concrete value.
Definition Style.hpp:1036
Opaque handle to a font loaded by TextEngine.
Definition CoreTypes.hpp:135
Typographic parameters governing shaping and measurement.
Definition TextEngine.hpp:51
2D vector with component-wise arithmetic.
Definition CoreTypes.hpp:25