ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
Tooltip.hpp
Go to the documentation of this file.
1#pragma once
2
14
15#include "Common.hpp"
16#include "Layout.hpp"
17#include "Layouts.hpp"
18
19namespace ZenitUI::UI
20{
24
25 class Text;
26
35 class Tooltip : public TLayout<Tooltip, Panel>
36 {
37 public:
43 explicit Tooltip(std::string text);
44
54 static std::shared_ptr<Tooltip> attach(std::shared_ptr<Layout> owner,
55 std::string text,
56 float showDelay = 0.4f);
57
58 void setText(std::string text);
59 const std::string &getText() const { return text_; }
60
62 void setAnchor(std::weak_ptr<Layout> a) { anchor_ = std::move(a); }
64 void setShowDelay(float s) { showDelay_ = s; }
65
67 void show();
69 void hide();
70
72 void arrange(Rect) override {}
73
74 protected:
75 void onBuild() override;
76 void onUpdate(float dt) override;
77
78 private:
79 std::string text_;
80 std::weak_ptr<Text> label_;
81 std::weak_ptr<Layout> anchor_;
82 float showDelay_{0.4f};
83 float timer_{0.0f};
84 bool hovering_{false};
85 bool visible_{false};
86
87 void setTargetOpacity(float op);
88 };
89
90} // namespace ZenitUI::UI
Centralized standard library includes used throughout ZenitUI.
The node class: tree structure, layout pass, style resolution, input dispatch, render orchestration,...
Basic layout containers: VStack, HStack, Panel.
TLayout(Args &&...args)
Definition Layout.hpp:1401
A read-only text node.
Definition Text.hpp:32
void arrange(Rect) override
No-op: the tooltip owns its rect via onUpdate.
Definition Tooltip.hpp:72
void onBuild() override
Hook: called once after create() finishes constructing the object.
static std::shared_ptr< Tooltip > attach(std::shared_ptr< Layout > owner, std::string text, float showDelay=0.4f)
Attach a tooltip to owner.
void hide()
Hide immediately and cancel any pending countdown.
void setShowDelay(float s)
Change the delay in seconds before the tooltip appears.
Definition Tooltip.hpp:64
Tooltip(std::string text)
Construct a tooltip with the given text.
void show()
Begin the countdown to show.
void setAnchor(std::weak_ptr< Layout > a)
Change the anchor (advanced).
Definition Tooltip.hpp:62
Axis-aligned rectangle in screen coordinates.
Definition CoreTypes.hpp:46