guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
tooltip.hpp
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#pragma once
24
25#include <optional>
26#include <string>
27#include <utility>
28
29#include "guillaume/ecs/component.hpp"
30#include "guillaume/ecs/entity.hpp"
31
33{
34
54 class Tooltip: public ecs::Component
55 {
56 public:
63 enum class Variant { Plain, Rich };
64
67 using Viewport = std::pair<float, float>;
68
71 static constexpr float DefaultEnterDelay = 0.5f;
72
75 static constexpr float DefaultLeaveDelay = 1.5f;
76
77 private:
78 Variant _variant { Variant::Plain };
79 std::string _text {};
80 std::string _title {};
81 ecs::Entity::Identifier _titleEntity {
83 };
84
85 ecs::Entity::Identifier _textEntity {
87 };
88
91 };
92
93 float _enterDelay { DefaultEnterDelay };
94 float _leaveDelay { DefaultLeaveDelay };
95 float _hoverTime { 0.0f };
96 float _leaveTime { 0.0f };
97 float _lastProgress { 0.0f };
98 bool _visible { false };
99 std::optional<Viewport> _viewport {};
100
101 public:
106 Tooltip(void) = default;
107
111 ~Tooltip(void) = default;
112
117 Variant getVariant(void) const noexcept;
118
126 Tooltip &setVariant(Variant variant);
127
132 const std::string &getText(void) const noexcept;
133
142 Tooltip &setText(const std::string &text);
143
148 const std::string &getTitle(void) const noexcept;
149
159 Tooltip &setTitle(const std::string &title);
160
166 ecs::Entity::Identifier getTitleEntity(void) const noexcept;
167
176
182 ecs::Entity::Identifier getTextEntity(void) const noexcept;
183
192
198 ecs::Entity::Identifier getAnchor(void) const noexcept;
199
212
218 float getEnterDelay(void) const noexcept;
219
230 Tooltip &setEnterDelay(float seconds);
231
237 float getLeaveDelay(void) const noexcept;
238
249 Tooltip &setLeaveDelay(float seconds);
250
255 float getHoverTime(void) const noexcept;
256
265 Tooltip &setHoverTime(float seconds);
266
273 float getLeaveTime(void) const noexcept;
274
283 Tooltip &setLeaveTime(float seconds);
284
289 float getLastProgress(void) const noexcept;
290
301 Tooltip &setLastProgress(float progress);
302
307 bool isVisible(void) const noexcept;
308
319 Tooltip &setVisible(bool visible);
320
326 const std::optional<Viewport> &getViewport(void) const noexcept;
327
338 Tooltip &setViewport(std::optional<Viewport> viewport);
339 };
340
341} // 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
~Tooltip(void)=default
Default destructor.
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
std::pair< float, float > Viewport
Definition tooltip.hpp:67
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
static constexpr float DefaultLeaveDelay
Definition tooltip.hpp:75
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
static constexpr float DefaultEnterDelay
Definition tooltip.hpp:71
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
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
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
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
Definition entity.hpp:93
State. Every class here is plain data attached to an entity.