|
Zappy GUI
C++ graphic client: renderer, camera, network
|
A configurable, stateful clickable button. More...
#include <ButtonWidget.hpp>
Inheritance diagram for ButtonWidget:
Collaboration diagram for ButtonWidget:Public Types | |
| enum class | Anchor { TopLeft , TopCenter , TopRight , MiddleLeft , Center , MiddleRight , BottomLeft , BottomCenter , BottomRight , None } |
| Positioning modes for automatic layout. More... | |
Public Member Functions | |
| ButtonWidget ()=default | |
| ~ButtonWidget () override=default | |
| ButtonWidget & | setLabel (const std::string &label) |
| ButtonWidget & | setPosition (float x, float y) |
| Sets the button position directly (requires Anchor::None). | |
| ButtonWidget & | setSize (float width, float height) |
| ButtonWidget & | setAnchor (Anchor anchor, float margin=10.0f) |
| Sets anchor: button is auto-positioned relative to screen edges. | |
| ButtonWidget & | setNormalColor (Color color) |
| ButtonWidget & | setHoverColor (Color color) |
| ButtonWidget & | setTextColor (Color color) |
| ButtonWidget & | setBorderColor (Color color) |
| ButtonWidget & | setBorderThickness (float thickness) |
| ButtonWidget & | setRoundness (float roundness) |
| ButtonWidget & | setOnClick (std::function< void()> callback) |
| Registers a callback invoked when the button is clicked. | |
| void | draw (int scaledFontSize) const override |
| Draws the widget. | |
| bool | handleInput () override |
| bool | wasClicked () |
| Returns true once per click, then resets. | |
| Rectangle | getBounds () const |
| Returns the bounding rectangle (after anchor resolution). | |
Public Member Functions inherited from IWidget | |
| virtual | ~IWidget ()=default |
Private Member Functions | |
| Rectangle | _resolvedBounds () const |
Private Attributes | |
| std::string | _label |
| float | _x = 0.0f |
| float | _y = 0.0f |
| float | _width = 120.0f |
| float | _height = 36.0f |
| Anchor | _anchor = Anchor::None |
| float | _margin = 10.0f |
| Color | _normalColor = {60, 70, 90, 220} |
| Color | _hoverColor = {100, 120, 160, 240} |
| Color | _textColor = {210, 220, 240, 255} |
| Color | _borderColor = {60, 70, 90, 200} |
| float | _borderThickness = 2.0f |
| float | _roundness = 0.3f |
| bool | _hovered = false |
| bool | _clicked = false |
| std::function< void()> | _onClick |
A configurable, stateful clickable button.
Supports custom label, position, size, colors, corner roundness, and an optional on-click callback. Hover state is tracked internally each frame. Use wasClicked() to poll the result, or setOnClick() for a callback.
Definition at line 17 of file ButtonWidget.hpp.
|
strong |
Positioning modes for automatic layout.
| Enumerator | |
|---|---|
| TopLeft | |
| TopCenter | |
| TopRight | |
| MiddleLeft | |
| Center | |
| MiddleRight | |
| BottomLeft | |
| BottomCenter | |
| BottomRight | |
| None | No anchor: position set directly via setPosition(). |
Definition at line 20 of file ButtonWidget.hpp.
|
default |
|
overridedefault |
|
private |
Definition at line 77 of file ButtonWidget.cpp.
References _anchor, _height, _margin, _width, _x, _y, BottomCenter, BottomLeft, BottomRight, Center, MiddleLeft, MiddleRight, None, TopCenter, TopLeft, and TopRight.
Referenced by draw(), getBounds(), and handleInput().
Here is the caller graph for this function:
|
overridevirtual |
Draws the widget.
| scaledFontSize | Base font size for UI scaling. |
Implements IWidget.
Definition at line 153 of file ButtonWidget.cpp.
References _borderColor, _borderThickness, _hoverColor, _hovered, _label, _normalColor, _resolvedBounds(), _roundness, _textColor, TextRenderer::draw(), and TextRenderer::measure().
Referenced by EntityTooltipWidget::draw(), and WinScreen::draw().
Here is the call graph for this function:
Here is the caller graph for this function:| Rectangle ButtonWidget::getBounds | ( | ) | const |
Returns the bounding rectangle (after anchor resolution).
Definition at line 130 of file ButtonWidget.cpp.
References _resolvedBounds().
Referenced by EntityTooltipWidget::handleInput().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Implements IWidget.
Definition at line 132 of file ButtonWidget.cpp.
References _clicked, _hovered, _onClick, and _resolvedBounds().
Referenced by EntityTooltipWidget::handleInput(), and WinScreen::handleInput().
Here is the call graph for this function:
Here is the caller graph for this function:| ButtonWidget & ButtonWidget::setAnchor | ( | Anchor | anchor, |
| float | margin = 10.0f |
||
| ) |
Sets anchor: button is auto-positioned relative to screen edges.
| margin | Pixel offset from the anchored edge. |
Definition at line 28 of file ButtonWidget.cpp.
References _anchor, and _margin.
Referenced by WinScreen::WinScreen().
Here is the caller graph for this function:| ButtonWidget & ButtonWidget::setBorderColor | ( | Color | color | ) |
Definition at line 53 of file ButtonWidget.cpp.
References _borderColor.
Referenced by EntityTooltipWidget::EntityTooltipWidget(), and WinScreen::WinScreen().
Here is the caller graph for this function:| ButtonWidget & ButtonWidget::setBorderThickness | ( | float | thickness | ) |
Definition at line 59 of file ButtonWidget.cpp.
References _borderThickness.
Referenced by EntityTooltipWidget::EntityTooltipWidget(), PlayerPanel::handleInput(), and WinScreen::WinScreen().
Here is the caller graph for this function:| ButtonWidget & ButtonWidget::setHoverColor | ( | Color | color | ) |
Definition at line 41 of file ButtonWidget.cpp.
References _hoverColor.
| ButtonWidget & ButtonWidget::setLabel | ( | const std::string & | label | ) |
Definition at line 7 of file ButtonWidget.cpp.
References _label.
Referenced by WinScreen::draw(), EntityTooltipWidget::handleInput(), and PlayerPanel::handleInput().
Here is the caller graph for this function:| ButtonWidget & ButtonWidget::setNormalColor | ( | Color | color | ) |
Definition at line 35 of file ButtonWidget.cpp.
References _normalColor.
Referenced by EntityTooltipWidget::handleInput().
Here is the caller graph for this function:| ButtonWidget & ButtonWidget::setOnClick | ( | std::function< void()> | callback | ) |
Registers a callback invoked when the button is clicked.
Definition at line 71 of file ButtonWidget.cpp.
References _onClick.
Referenced by PlayerPanel::handleInput().
Here is the caller graph for this function:| ButtonWidget & ButtonWidget::setPosition | ( | float | x, |
| float | y | ||
| ) |
Sets the button position directly (requires Anchor::None).
Definition at line 13 of file ButtonWidget.cpp.
References _anchor, _x, _y, and None.
Referenced by EntityTooltipWidget::_positionButton(), WinScreen::draw(), and PlayerPanel::handleInput().
Here is the caller graph for this function:| ButtonWidget & ButtonWidget::setRoundness | ( | float | roundness | ) |
Definition at line 65 of file ButtonWidget.cpp.
References _roundness.
Referenced by EntityTooltipWidget::EntityTooltipWidget(), PlayerPanel::handleInput(), and WinScreen::WinScreen().
Here is the caller graph for this function:| ButtonWidget & ButtonWidget::setSize | ( | float | width, |
| float | height | ||
| ) |
Definition at line 21 of file ButtonWidget.cpp.
References _height, and _width.
Referenced by EntityTooltipWidget::_positionButton(), WinScreen::draw(), EntityTooltipWidget::EntityTooltipWidget(), PlayerPanel::handleInput(), and WinScreen::WinScreen().
Here is the caller graph for this function:| ButtonWidget & ButtonWidget::setTextColor | ( | Color | color | ) |
Definition at line 47 of file ButtonWidget.cpp.
References _textColor.
Referenced by EntityTooltipWidget::EntityTooltipWidget().
Here is the caller graph for this function:| bool ButtonWidget::wasClicked | ( | ) |
Returns true once per click, then resets.
Definition at line 146 of file ButtonWidget.cpp.
References _clicked.
Referenced by EntityTooltipWidget::handleInput(), and WinScreen::handleInput().
Here is the caller graph for this function:
|
private |
Definition at line 80 of file ButtonWidget.hpp.
Referenced by _resolvedBounds(), setAnchor(), and setPosition().
|
private |
Definition at line 86 of file ButtonWidget.hpp.
Referenced by draw(), and setBorderColor().
|
private |
Definition at line 87 of file ButtonWidget.hpp.
Referenced by draw(), and setBorderThickness().
|
private |
Definition at line 91 of file ButtonWidget.hpp.
Referenced by handleInput(), and wasClicked().
|
private |
Definition at line 78 of file ButtonWidget.hpp.
Referenced by _resolvedBounds(), and setSize().
|
private |
Definition at line 84 of file ButtonWidget.hpp.
Referenced by draw(), and setHoverColor().
|
private |
Definition at line 90 of file ButtonWidget.hpp.
Referenced by draw(), and handleInput().
|
private |
Definition at line 73 of file ButtonWidget.hpp.
Referenced by draw(), and setLabel().
|
private |
Definition at line 81 of file ButtonWidget.hpp.
Referenced by _resolvedBounds(), and setAnchor().
|
private |
Definition at line 83 of file ButtonWidget.hpp.
Referenced by draw(), and setNormalColor().
|
private |
Definition at line 93 of file ButtonWidget.hpp.
Referenced by handleInput(), and setOnClick().
|
private |
Definition at line 88 of file ButtonWidget.hpp.
Referenced by draw(), and setRoundness().
|
private |
Definition at line 85 of file ButtonWidget.hpp.
Referenced by draw(), and setTextColor().
|
private |
Definition at line 77 of file ButtonWidget.hpp.
Referenced by _resolvedBounds(), and setSize().
|
private |
Definition at line 75 of file ButtonWidget.hpp.
Referenced by _resolvedBounds(), and setPosition().
|
private |
Definition at line 76 of file ButtonWidget.hpp.
Referenced by _resolvedBounds(), and setPosition().