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 <utility>
26#include <memory>
27#include <string>
28
29#include <utility/graphic/color.hpp>
30#include <utility/graphic/pose.hpp>
31
32#include "guillaume/ecs/component_registry.hpp"
33#include "guillaume/ecs/entity_builder.hpp"
34
35#include "guillaume/components/accessibility.hpp"
36#include "guillaume/components/animation.hpp"
37#include "guillaume/components/elevation.hpp"
38#include "guillaume/components/overlay.hpp"
39#include "guillaume/components/tooltip.hpp"
40
41#include "guillaume/entities/builder_base.hpp"
42#include "guillaume/entities/surface.hpp"
43#include "guillaume/entities/text.hpp"
44
45namespace guillaume::entities
46{
47
105 class Tooltip:
106 public SurfaceBase<components::Overlay, components::Elevation,
107 components::Animation, components::Accessibility,
108 components::Tooltip>
109 {
110 public:
113
118 static constexpr float DefaultEnterDelay =
120
125 static constexpr float DefaultLeaveDelay =
127
132 class Builder: public EntityBuilderBase<Tooltip>
133 {
134 private:
135 SurfaceConfig _config;
136 Variant _variant { Variant::Plain };
137 std::string _text {};
138 std::string _title {};
139
140 public:
148 Builder(ecs::ComponentRegistry &componentRegistry,
149 ecs::EntityRegistry &entityRegistry);
150
156 std::shared_ptr<Tooltip> buildEntity(void) override;
157
162 void reset(void) override;
163
171 Builder &withPose(const utility::graphic::PoseF &pose);
172
178 Builder &withVariant(Variant variant);
179
186 Builder &withText(const std::string &text);
187
194 Builder &withTitle(const std::string &title);
195
202 Builder &withFixedWidth(float width);
203
217 std::shared_ptr<Tooltip>
218 makeTooltip(std::shared_ptr<ecs::Entity> parent,
219 Variant variant, const std::string &text,
220 const std::string &title = "");
221 };
222
223 public:
236 template<typename... Arguments>
237 static std::shared_ptr<Tooltip> create(Arguments &&...arguments)
238 {
239 std::shared_ptr<Tooltip> entity(
240 new Tooltip(std::forward<Arguments>(arguments)...));
241 entity->build();
242 return entity;
243 }
244
248 ~Tooltip(void) override = default;
249
259 Tooltip &setVariant(Variant variant);
260
265 Variant getVariant(void) const;
266
275 Tooltip &setText(const std::string &text);
276
291 Tooltip &setAnchor(std::shared_ptr<ecs::Entity> anchor);
292
301 Tooltip &setEnterDelay(float seconds);
302
311 Tooltip &setLeaveDelay(float seconds);
312
318 float getEnterDelay(void) const;
319
325 float getLeaveDelay(void) const;
326
338 Tooltip &setViewport(float width, float height);
339
349 Tooltip &show(void);
350
356 Tooltip &hide(void);
357
363 bool isVisible(void) const;
364
377 void advance(float deltaTime);
378
389 void place(void);
390
391 private:
398 void buildContent(void);
399
400 private:
411 Tooltip(ecs::ComponentRegistry &registry, const SurfaceConfig &config,
412 Variant variant, const std::string &text,
413 const std::string &title);
414
421 void build(void);
422 };
423
424} // namespace guillaume::entities
static constexpr float DefaultLeaveDelay
Definition tooltip.hpp:75
static constexpr float DefaultEnterDelay
Definition tooltip.hpp:71
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
Owns entities and gives the systems the list of entities to visit.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Builder & withTitle(const std::string &title)
Set the title shown above the text.
Definition tooltip.cpp:86
std::shared_ptr< Tooltip > buildEntity(void) override
Build a tooltip and its children from the current configuration, without registering it or setting it...
Definition tooltip.cpp:44
Builder & withFixedWidth(float width)
Give the tooltip a fixed width.
Definition tooltip.cpp:92
Builder & withVariant(Variant variant)
Set the tooltip variant.
Definition tooltip.cpp:74
std::shared_ptr< Tooltip > makeTooltip(std::shared_ptr< ecs::Entity > parent, Variant variant, const std::string &text, const std::string &title="")
Build a tooltip, register it under parent and reset the builder.
Definition tooltip.cpp:100
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Create a builder set to the defaults of reset().
Definition tooltip.cpp:37
Builder & withText(const std::string &text)
Set the body text.
Definition tooltip.cpp:80
Builder & withPose(const utility::graphic::PoseF &pose)
Set the pose the tooltip is created with.
Definition tooltip.cpp:68
void reset(void) override
Restore the defaults: Plain variant, no text, no title, a default pose and a width that follows the c...
Definition tooltip.cpp:51
~Tooltip(void) override=default
Default destructor.
void place(void)
Move the tooltip next to its anchor.
Definition tooltip.cpp:197
bool isVisible(void) const
Check whether the tooltip is shown.
Definition tooltip.cpp:184
float getEnterDelay(void) const
Get how long the anchor must be hovered before the tooltip shows.
Definition tooltip.cpp:151
Tooltip & setEnterDelay(float seconds)
Set how long the anchor must be hovered before the tooltip shows (Paper enterTouchDelay).
Definition tooltip.cpp:135
Tooltip & setVariant(Variant variant)
Change the tooltip variant.
Definition tooltip.cpp:202
Tooltip & setLeaveDelay(float seconds)
Set how long the tooltip stays shown after the anchor is left (Paper leaveTouchDelay).
Definition tooltip.cpp:143
void advance(float deltaTime)
Advance the hover delays by hand.
Definition tooltip.cpp:191
static constexpr float DefaultEnterDelay
Default time the anchor must be hovered before the tooltip shows: 0.5 second (Paper enterTouchDelay).
Definition tooltip.hpp:118
Tooltip & setViewport(float width, float height)
Set the area the tooltip must stay inside, usually the window.
Definition tooltip.cpp:165
float getLeaveDelay(void) const
Get how long the tooltip stays shown after the anchor is left.
Definition tooltip.cpp:158
Tooltip & setAnchor(std::shared_ptr< ecs::Entity > anchor)
Choose the entity whose hover shows the tooltip.
Definition tooltip.cpp:126
components::Tooltip::Variant Variant
Look of the tooltip: Plain (one text) or Rich (title and text).
Definition tooltip.hpp:112
Variant getVariant(void) const
Get the tooltip variant.
Definition tooltip.cpp:212
Tooltip & setText(const std::string &text)
Change the body text.
Definition tooltip.cpp:219
static constexpr float DefaultLeaveDelay
Default time after the anchor is left before the tooltip hides: 1.5 seconds (Paper leaveTouchDelay).
Definition tooltip.hpp:125
Tooltip & show(void)
Show the tooltip at once, without waiting for the enter delay.
Definition tooltip.cpp:172
Tooltip & hide(void)
Hide the tooltip at once, without waiting for the leave delay. Restyles at once.
Definition tooltip.cpp:178
static std::shared_ptr< Tooltip > create(Arguments &&...arguments)
Create a tooltip and its children, without registering it in an entity registry.
Definition tooltip.hpp:237
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...
Definition surface.hpp:71