guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
tooltip.cpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#include "guillaume/components/tooltip.hpp"
24
25#include <stdexcept>
26
28{
30 {
31 return _variant;
32 }
33
35 {
36 if (_variant != variant) {
37 _variant = variant;
38 setHasChanged(true);
39 }
40 return *this;
41 }
42
43 const std::string &Tooltip::getText(void) const noexcept
44 {
45 return _text;
46 }
47
48 Tooltip &Tooltip::setText(const std::string &text)
49 {
50 if (_text != text) {
51 _text = text;
52 setHasChanged(true);
53 }
54 return *this;
55 }
56
57 const std::string &Tooltip::getTitle(void) const noexcept
58 {
59 return _title;
60 }
61
62 Tooltip &Tooltip::setTitle(const std::string &title)
63 {
64 if (_title != title) {
65 _title = title;
66 setHasChanged(true);
67 }
68 return *this;
69 }
70
72 {
73 return _titleEntity;
74 }
75
77 {
78 if (_titleEntity != identifier) {
79 _titleEntity = identifier;
80 setHasChanged(true);
81 }
82 return *this;
83 }
84
86 {
87 return _textEntity;
88 }
89
91 {
92 if (_textEntity != identifier) {
93 _textEntity = identifier;
94 setHasChanged(true);
95 }
96 return *this;
97 }
98
100 {
101 return _anchor;
102 }
103
105 {
106 if (_anchor != identifier) {
107 _anchor = identifier;
108 setHasChanged(true);
109 }
110 return *this;
111 }
112
113 float Tooltip::getEnterDelay(void) const noexcept
114 {
115 return _enterDelay;
116 }
117
119 {
120 if (seconds < 0.0f) {
121 throw std::invalid_argument("Tooltip delay must be >= 0");
122 }
123 if (_enterDelay != seconds) {
124 _enterDelay = seconds;
125 setHasChanged(true);
126 }
127 return *this;
128 }
129
130 float Tooltip::getLeaveDelay(void) const noexcept
131 {
132 return _leaveDelay;
133 }
134
136 {
137 if (seconds < 0.0f) {
138 throw std::invalid_argument("Tooltip delay must be >= 0");
139 }
140 if (_leaveDelay != seconds) {
141 _leaveDelay = seconds;
142 setHasChanged(true);
143 }
144 return *this;
145 }
146
147 float Tooltip::getHoverTime(void) const noexcept
148 {
149 return _hoverTime;
150 }
151
153 {
154 if (_hoverTime != seconds) {
155 _hoverTime = seconds;
156 setHasChanged(true);
157 }
158 return *this;
159 }
160
161 float Tooltip::getLeaveTime(void) const noexcept
162 {
163 return _leaveTime;
164 }
165
167 {
168 if (_leaveTime != seconds) {
169 _leaveTime = seconds;
170 setHasChanged(true);
171 }
172 return *this;
173 }
174
175 float Tooltip::getLastProgress(void) const noexcept
176 {
177 return _lastProgress;
178 }
179
181 {
182 if (_lastProgress != progress) {
183 _lastProgress = progress;
184 setHasChanged(true);
185 }
186 return *this;
187 }
188
189 bool Tooltip::isVisible(void) const noexcept
190 {
191 return _visible;
192 }
193
195 {
196 if (_visible != visible) {
197 _visible = visible;
198 setHasChanged(true);
199 }
200 return *this;
201 }
202
203 const std::optional<Tooltip::Viewport> &
204 Tooltip::getViewport(void) const noexcept
205 {
206 return _viewport;
207 }
208
209 Tooltip &Tooltip::setViewport(std::optional<Viewport> viewport)
210 {
211 if (_viewport != viewport) {
212 _viewport = viewport;
213 setHasChanged(true);
214 }
215 return *this;
216 }
217} // namespace guillaume::components
Tooltip & setTitle(const std::string &title)
Set the title of a rich tooltip.
Definition tooltip.cpp:62
const std::optional< Viewport > & getViewport(void) const noexcept
Get the area the tooltip must stay inside.
Definition tooltip.cpp:204
Tooltip & setLeaveTime(float seconds)
Store how long ago the pointer left the anchor.
Definition tooltip.cpp:166
ecs::Entity::Identifier getTextEntity(void) const noexcept
Get the child that draws the body text.
Definition tooltip.cpp:85
Tooltip & setHoverTime(float seconds)
Store how long the anchor has been hovered.
Definition tooltip.cpp:152
bool isVisible(void) const noexcept
Tell whether the tooltip is shown.
Definition tooltip.cpp:189
Tooltip & setText(const std::string &text)
Set the body text.
Definition tooltip.cpp:48
const std::string & getTitle(void) const noexcept
Get the title of a rich tooltip.
Definition tooltip.cpp:57
Tooltip & setEnterDelay(float seconds)
Set how long the anchor must be hovered before the tooltip shows.
Definition tooltip.cpp:118
Tooltip & setTitleEntity(ecs::Entity::Identifier identifier)
Record the child that draws the title.
Definition tooltip.cpp:76
Tooltip(void)=default
Create the configuration of a hidden, empty plain tooltip with no anchor and the default delays.
Variant getVariant(void) const noexcept
Get the kind of tooltip.
Definition tooltip.cpp:29
float getLastProgress(void) const noexcept
Get the progress the timer animation reported last.
Definition tooltip.cpp:175
Tooltip & setTextEntity(ecs::Entity::Identifier identifier)
Record the child that draws the body text.
Definition tooltip.cpp:90
Tooltip & setAnchor(ecs::Entity::Identifier identifier)
Record the entity whose hover shows the tooltip.
Definition tooltip.cpp:104
ecs::Entity::Identifier getTitleEntity(void) const noexcept
Get the child that draws the title.
Definition tooltip.cpp:71
const std::string & getText(void) const noexcept
Get the body text.
Definition tooltip.cpp:43
Tooltip & setLastProgress(float progress)
Store the progress the timer animation reported last.
Definition tooltip.cpp:180
float getLeaveTime(void) const noexcept
Get how long ago the pointer left the anchor while the tooltip was shown.
Definition tooltip.cpp:161
float getLeaveDelay(void) const noexcept
Get how long the tooltip stays after the pointer leaves the anchor.
Definition tooltip.cpp:130
Tooltip & setVariant(Variant variant)
Set the kind of tooltip.
Definition tooltip.cpp:34
Tooltip & setVisible(bool visible)
Record whether the tooltip is shown.
Definition tooltip.cpp:194
Tooltip & setLeaveDelay(float seconds)
Set how long the tooltip stays after the pointer leaves the anchor.
Definition tooltip.cpp:135
Tooltip & setViewport(std::optional< Viewport > viewport)
Set the area the tooltip must stay inside.
Definition tooltip.cpp:209
ecs::Entity::Identifier getAnchor(void) const noexcept
Get the entity whose hover shows the tooltip.
Definition tooltip.cpp:99
float getEnterDelay(void) const noexcept
Get how long the anchor must be hovered before the tooltip shows.
Definition tooltip.cpp:113
float getHoverTime(void) const noexcept
Get how long the anchor has been hovered without a break.
Definition tooltip.cpp:147
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
State. Every class here is plain data attached to an entity.