FifeGUI 0.2.0
A C++ GUI library designed for games.
tooltip.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
3
4#ifndef FIFEGUI_TOOLTIP_H
5#define FIFEGUI_TOOLTIP_H
6
7#include <functional>
8#include <string>
9
10// Platform config include (for FIFEGUI_API)
11#include "fifechan/platform.hpp"
12#include "fifechan/widgets/container.hpp"
13
14namespace fcn
15{
16
20 enum class TooltipTrigger : uint8_t
21 {
22 Hover
23 };
24
28 enum class TooltipPlacement : uint8_t
29 {
30 Cursor,
31 Right,
32 Bottom
33 };
34
39 {
43 bool enabled = false;
44
48 int modifier = 0x100; // KMOD_ALT from SDL
49
54 std::function<std::string(int widgetId)> modifiedContent;
55 };
56
61 {
65 std::function<std::string(int widgetId)> content;
66
70 int delayMs = 300;
71
75 TooltipTrigger trigger = TooltipTrigger::Hover;
76
80 TooltipPlacement placement = TooltipPlacement::Cursor;
81
86 };
87
100 class FIFEGUI_API Tooltip : public Container
101 {
102 public:
106 Tooltip();
107
111 ~Tooltip() override = default;
112
116 void setSpec(TooltipSpec const & spec);
117
121 TooltipSpec const & getSpec() const;
122
126 void setWidgetId(int id);
127
131 int getWidgetId() const;
132
136 void startHover();
137
141 void endHover();
142
146 bool isHovering() const;
147
154 void update(int deltaMs, int modifierState);
155
159 void generateContent();
160
164 std::string const & getCurrentContent() const;
165
169 bool isExtendedView() const;
170
174 void draw(Graphics* graphics) override;
175
179 Rectangle getChildrenArea() override;
180
181 private:
182 void generateNormalContent();
183 void generateExtendedContent();
184
185 TooltipSpec mSpec;
186 int mWidgetId{0};
187 bool mIsHovering{false};
188 int mHoverTimer{0};
189 int mModifierState{0};
190
191 std::string mCurrentContent;
192 bool mIsExtended{false};
193 };
194
195} // namespace fcn
196
197#endif // FIFEGUI_TOOLTIP_H
Container()
Constructor.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:22
Rectangle getChildrenArea() override
Compute the children area for layout.
Definition tooltip.cpp:168
int getWidgetId() const
Get the widget id this tooltip is attached to.
Definition tooltip.cpp:40
void setSpec(TooltipSpec const &spec)
Set the tooltip specification describing content and behavior.
Definition tooltip.cpp:25
Tooltip()
Constructor.
Definition tooltip.cpp:17
void update(int deltaMs, int modifierState)
Periodic update to advance timers and compute modifier state.
Definition tooltip.cpp:63
void draw(Graphics *graphics) override
Draw the tooltip.
Definition tooltip.cpp:139
void setWidgetId(int id)
Attach this tooltip to a widget id.
Definition tooltip.cpp:35
std::string const & getCurrentContent() const
Get the currently generated content string.
Definition tooltip.cpp:93
TooltipSpec const & getSpec() const
Get the current tooltip specification.
Definition tooltip.cpp:30
void endHover()
End hover tracking for the attached widget.
Definition tooltip.cpp:51
void generateContent()
Generate tooltip content based on mSpec and widget id.
Definition tooltip.cpp:78
void startHover()
Begin hover tracking for the attached widget.
Definition tooltip.cpp:45
bool isHovering() const
Query whether the tooltip is currently hovering.
Definition tooltip.cpp:58
bool isExtendedView() const
True if the tooltip is showing extended (modifier) content.
Definition tooltip.cpp:98
~Tooltip() override=default
Destructor.
Used replacement tokens by configure_file():
TooltipPlacement
Tooltip placement relative to cursor.
Definition tooltip.hpp:29
TooltipTrigger
Tooltip trigger type.
Definition tooltip.hpp:21
Tooltip modifier behavior (for an ALT-key extended view).
Definition tooltip.hpp:39
int modifier
Modifier key mask used to trigger extended content (SDL mask value).
Definition tooltip.hpp:48
std::function< std::string(int widgetId)> modifiedContent
Function that returns modified content when the modifier is active.
Definition tooltip.hpp:54
bool enabled
True if modifier-based extended content is enabled.
Definition tooltip.hpp:43
Tooltip specification (data + behavior).
Definition tooltip.hpp:61
std::function< std::string(int widgetId)> content
Function that generates tooltip content for a widget id.
Definition tooltip.hpp:65
int delayMs
Delay in milliseconds before showing the tooltip.
Definition tooltip.hpp:70
TooltipPlacement placement
Preferred placement for the tooltip relative to cursor/widget.
Definition tooltip.hpp:80
TooltipModifierBehavior modifierBehavior
Behavior configuration for modifier-extended content.
Definition tooltip.hpp:85
TooltipTrigger trigger
Trigger mechanism for the tooltip (e.g., hover).
Definition tooltip.hpp:75