Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
TooltipWidget Class Reference

A configurable, stateful tooltip panel. More...

#include <TooltipWidget.hpp>

+ Inheritance diagram for TooltipWidget:
+ Collaboration diagram for TooltipWidget:

Classes

struct  Line
 

Public Types

enum class  Anchor {
  None , TopLeft , TopCenter , TopRight ,
  MiddleLeft , Center , MiddleRight , BottomLeft ,
  BottomCenter , BottomRight
}
 
enum class  TextAlign { Left , Center }
 

Public Member Functions

 TooltipWidget ()=default
 
 ~TooltipWidget () override=default
 
TooltipWidgetaddLine (const std::string &text, Color color=WHITE)
 Adds a single-color text line.
 
TooltipWidgetaddColoredLine (const std::vector< std::string > &segments, const std::vector< Color > &colors)
 Adds a line with multiple colored segments (inline spans).
 
TooltipWidgetclearLines ()
 Removes all lines.
 
TooltipWidgetsetPosition (float x, float y)
 Absolute position. Sets anchor to None.
 
TooltipWidgetsetAnchor (Anchor anchor, float margin=10.0f)
 Auto-positioning relative to screen edges.
 
TooltipWidgetsetMinWidth (float minWidth)
 Override minimum panel width (0 = fit to content).
 
TooltipWidgetsetExtraBottomPadding (float px)
 Adds extra blank space at the bottom of the box (e.g. to reserve room for a button).
 
TooltipWidgetsetTextAlign (TextAlign align)
 
TooltipWidgetsetBackgroundColor (Color color)
 
TooltipWidgetsetBackgroundAlpha (unsigned char alpha)
 
TooltipWidgetsetBorderColor (Color color)
 
TooltipWidgetsetBorderThickness (int thickness)
 
TooltipWidgetsetPadding (int padding)
 
void draw (int scaledFontSize) const override
 Draws the widget.
 
bool handleInput () override
 Always returns false — tooltip panels are display-only.
 
Rectangle getLastBounds () const
 Returns the bounding rectangle for the last drawn frame. Useful for positioning sibling widgets (e.g. a button below the panel).
 
- Public Member Functions inherited from IWidget
virtual ~IWidget ()=default
 

Private Member Functions

Vector2 _resolvePosition (float boxWidth, float boxHeight) const
 

Private Attributes

std::vector< Line_lines
 
float _x = 0.0f
 
float _y = 0.0f
 
Anchor _anchor = Anchor::None
 
float _margin = 10.0f
 
float _minWidth = 0.0f
 
float _extraBottomPadding = 0.0f
 
Color _bgColor = {20, 25, 35, 220}
 
unsigned char _bgAlpha = 220
 
Color _borderColor = {60, 70, 90, 200}
 
int _borderThickness = 2
 
int _padding = 12
 
TextAlign _textAlign = TextAlign::Left
 
Rectangle _lastBounds = {}
 

Detailed Description

A configurable, stateful tooltip panel.

Wraps TooltipRenderer::Builder to provide an IWidget-compatible component. Content is built once via the fluent API and drawn each frame until changed. Never handles input (handleInput always returns false) — it is display-only.

Positioning modes:

  • Anchor::None + setPosition(): absolute screen coordinates.
  • Any other Anchor: auto-positioned relative to screen edges with a margin.
  • setScreenCenter(): centers the panel on screen each frame.

Definition at line 22 of file TooltipWidget.hpp.

Member Enumeration Documentation

◆ Anchor

enum class TooltipWidget::Anchor
strong
Enumerator
None 
TopLeft 
TopCenter 
TopRight 
MiddleLeft 
Center 
MiddleRight 
BottomLeft 
BottomCenter 
BottomRight 

Definition at line 24 of file TooltipWidget.hpp.

◆ TextAlign

enum class TooltipWidget::TextAlign
strong
Enumerator
Left 
Center 

Definition at line 66 of file TooltipWidget.hpp.

Constructor & Destructor Documentation

◆ TooltipWidget()

TooltipWidget::TooltipWidget ( )
default

◆ ~TooltipWidget()

TooltipWidget::~TooltipWidget ( )
overridedefault

Member Function Documentation

◆ _resolvePosition()

Vector2 TooltipWidget::_resolvePosition ( float  boxWidth,
float  boxHeight 
) const
private

Definition at line 94 of file TooltipWidget.cpp.

References _anchor, _margin, _x, _y, BottomCenter, BottomLeft, BottomRight, Center, MiddleLeft, MiddleRight, None, TopCenter, TopLeft, and TopRight.

Referenced by draw().

+ Here is the caller graph for this function:

◆ addColoredLine()

TooltipWidget & TooltipWidget::addColoredLine ( const std::vector< std::string > &  segments,
const std::vector< Color > &  colors 
)

Adds a line with multiple colored segments (inline spans).

Definition at line 16 of file TooltipWidget.cpp.

References _lines.

Referenced by EntityTooltipWidget::_rebuild(), and WinScreen::_rebuildPanel().

+ Here is the caller graph for this function:

◆ addLine()

TooltipWidget & TooltipWidget::addLine ( const std::string &  text,
Color  color = WHITE 
)

Adds a single-color text line.

Definition at line 10 of file TooltipWidget.cpp.

References _lines.

Referenced by EntityTooltipWidget::_rebuild(), WinScreen::_rebuildPanel(), and PlayerPanel::handleInput().

+ Here is the caller graph for this function:

◆ clearLines()

TooltipWidget & TooltipWidget::clearLines ( )

Removes all lines.

Definition at line 25 of file TooltipWidget.cpp.

References _lines.

Referenced by EntityTooltipWidget::_rebuild(), WinScreen::_rebuildPanel(), and PlayerPanel::handleInput().

+ Here is the caller graph for this function:

◆ draw()

void TooltipWidget::draw ( int  scaledFontSize) const
overridevirtual

Draws the widget.

Parameters
scaledFontSizeBase font size for UI scaling.

Implements IWidget.

Definition at line 125 of file TooltipWidget.cpp.

References _bgAlpha, _bgColor, _borderColor, _borderThickness, _extraBottomPadding, _lastBounds, _lines, _minWidth, _padding, _resolvePosition(), _textAlign, Center, TextRenderer::draw(), and TextRenderer::measure().

Referenced by EntityTooltipWidget::draw(), PlayerPanel::draw(), and WinScreen::draw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastBounds()

Rectangle TooltipWidget::getLastBounds ( ) const
inline

Returns the bounding rectangle for the last drawn frame. Useful for positioning sibling widgets (e.g. a button below the panel).

Definition at line 83 of file TooltipWidget.hpp.

References _lastBounds.

Referenced by EntityTooltipWidget::_positionButton(), WinScreen::draw(), and PlayerPanel::handleInput().

+ Here is the caller graph for this function:

◆ handleInput()

bool TooltipWidget::handleInput ( )
inlineoverridevirtual

Always returns false — tooltip panels are display-only.

Implements IWidget.

Definition at line 79 of file TooltipWidget.hpp.

◆ setAnchor()

TooltipWidget & TooltipWidget::setAnchor ( Anchor  anchor,
float  margin = 10.0f 
)

Auto-positioning relative to screen edges.

Parameters
marginPixel gap from the anchored edge.

Definition at line 39 of file TooltipWidget.cpp.

References _anchor, and _margin.

Referenced by EntityTooltipWidget::EntityTooltipWidget(), PlayerPanel::handleInput(), and WinScreen::WinScreen().

+ Here is the caller graph for this function:

◆ setBackgroundAlpha()

TooltipWidget & TooltipWidget::setBackgroundAlpha ( unsigned char  alpha)

Definition at line 70 of file TooltipWidget.cpp.

References _bgAlpha.

Referenced by EntityTooltipWidget::EntityTooltipWidget().

+ Here is the caller graph for this function:

◆ setBackgroundColor()

TooltipWidget & TooltipWidget::setBackgroundColor ( Color  color)

Definition at line 64 of file TooltipWidget.cpp.

References _bgColor.

Referenced by EntityTooltipWidget::EntityTooltipWidget(), and WinScreen::WinScreen().

+ Here is the caller graph for this function:

◆ setBorderColor()

TooltipWidget & TooltipWidget::setBorderColor ( Color  color)

Definition at line 76 of file TooltipWidget.cpp.

References _borderColor.

Referenced by EntityTooltipWidget::EntityTooltipWidget(), and WinScreen::WinScreen().

+ Here is the caller graph for this function:

◆ setBorderThickness()

TooltipWidget & TooltipWidget::setBorderThickness ( int  thickness)

Definition at line 82 of file TooltipWidget.cpp.

References _borderThickness.

Referenced by EntityTooltipWidget::EntityTooltipWidget(), and WinScreen::WinScreen().

+ Here is the caller graph for this function:

◆ setExtraBottomPadding()

TooltipWidget & TooltipWidget::setExtraBottomPadding ( float  px)

Adds extra blank space at the bottom of the box (e.g. to reserve room for a button).

Definition at line 52 of file TooltipWidget.cpp.

References _extraBottomPadding.

Referenced by EntityTooltipWidget::_rebuild(), PlayerPanel::handleInput(), and WinScreen::WinScreen().

+ Here is the caller graph for this function:

◆ setMinWidth()

TooltipWidget & TooltipWidget::setMinWidth ( float  minWidth)

Override minimum panel width (0 = fit to content).

Definition at line 46 of file TooltipWidget.cpp.

References _minWidth.

Referenced by EntityTooltipWidget::_rebuild(), PlayerPanel::handleInput(), and WinScreen::WinScreen().

+ Here is the caller graph for this function:

◆ setPadding()

TooltipWidget & TooltipWidget::setPadding ( int  padding)

Definition at line 88 of file TooltipWidget.cpp.

References _padding.

Referenced by EntityTooltipWidget::EntityTooltipWidget(), and WinScreen::WinScreen().

+ Here is the caller graph for this function:

◆ setPosition()

TooltipWidget & TooltipWidget::setPosition ( float  x,
float  y 
)

Absolute position. Sets anchor to None.

Definition at line 31 of file TooltipWidget.cpp.

References _anchor, _x, _y, and None.

◆ setTextAlign()

TooltipWidget & TooltipWidget::setTextAlign ( TextAlign  align)

Definition at line 58 of file TooltipWidget.cpp.

References _textAlign.

Referenced by PlayerPanel::handleInput(), and WinScreen::WinScreen().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _anchor

Anchor TooltipWidget::_anchor = Anchor::None
private

Definition at line 95 of file TooltipWidget.hpp.

Referenced by _resolvePosition(), setAnchor(), and setPosition().

◆ _bgAlpha

unsigned char TooltipWidget::_bgAlpha = 220
private

Definition at line 101 of file TooltipWidget.hpp.

Referenced by draw(), and setBackgroundAlpha().

◆ _bgColor

Color TooltipWidget::_bgColor = {20, 25, 35, 220}
private

Definition at line 100 of file TooltipWidget.hpp.

Referenced by draw(), and setBackgroundColor().

◆ _borderColor

Color TooltipWidget::_borderColor = {60, 70, 90, 200}
private

Definition at line 102 of file TooltipWidget.hpp.

Referenced by draw(), and setBorderColor().

◆ _borderThickness

int TooltipWidget::_borderThickness = 2
private

Definition at line 103 of file TooltipWidget.hpp.

Referenced by draw(), and setBorderThickness().

◆ _extraBottomPadding

float TooltipWidget::_extraBottomPadding = 0.0f
private

Definition at line 98 of file TooltipWidget.hpp.

Referenced by draw(), and setExtraBottomPadding().

◆ _lastBounds

Rectangle TooltipWidget::_lastBounds = {}
mutableprivate

Definition at line 107 of file TooltipWidget.hpp.

Referenced by draw(), and getLastBounds().

◆ _lines

std::vector<Line> TooltipWidget::_lines
private

Definition at line 91 of file TooltipWidget.hpp.

Referenced by addColoredLine(), addLine(), clearLines(), and draw().

◆ _margin

float TooltipWidget::_margin = 10.0f
private

Definition at line 96 of file TooltipWidget.hpp.

Referenced by _resolvePosition(), and setAnchor().

◆ _minWidth

float TooltipWidget::_minWidth = 0.0f
private

Definition at line 97 of file TooltipWidget.hpp.

Referenced by draw(), and setMinWidth().

◆ _padding

int TooltipWidget::_padding = 12
private

Definition at line 104 of file TooltipWidget.hpp.

Referenced by draw(), and setPadding().

◆ _textAlign

TextAlign TooltipWidget::_textAlign = TextAlign::Left
private

Definition at line 105 of file TooltipWidget.hpp.

Referenced by draw(), and setTextAlign().

◆ _x

float TooltipWidget::_x = 0.0f
private

Definition at line 93 of file TooltipWidget.hpp.

Referenced by _resolvePosition(), and setPosition().

◆ _y

float TooltipWidget::_y = 0.0f
private

Definition at line 94 of file TooltipWidget.hpp.

Referenced by _resolvePosition(), and setPosition().


The documentation for this class was generated from the following files: