|
Velvet 0.1a
A beginner-friendly C++ GUI framework built on SFML.
|
Clickable button widget with text label. More...
#include <Button.hpp>
Inheritance diagram for Button:Public Member Functions | |
| void | render (sf::RenderWindow &window) override |
| Render the button. | |
| void | handleEvent (const sf::Event &event, sf::RenderWindow &window) override |
| Process hover/press input events. | |
| Button (float width, float height, std::string label, std::unordered_map< std::string, std::variant< unsigned int, float, std::string > > styling={}, unsigned int borderColor=0x000000FFu, float borderThickness=1.f) | |
| Create a button. | |
| Button (const Button &other) | |
| Copy constructor. | |
| void | setPosition (float x, float y) override |
| Set top-left position of the button. | |
| sf::Vector2< float > | getDimensions () override |
| Get button dimensions. | |
| void | overrideStyling (std::unordered_map< std::string, std::variant< unsigned int, float, std::string > > styling) |
| Apply/override style properties. | |
Public Member Functions inherited from Widget | |
| Widget () | |
| Construct a widget with default font loading. | |
Public Attributes | |
| std::function< void()> | onclick |
| Called when the button is pressed with left mouse button while hovered. | |
Public Attributes inherited from Widget | |
| sf::Font | font |
| Shared font loaded by the base widget. | |
Additional Inherited Members | |
Protected Attributes inherited from Widget | |
| float | x |
| float | y |
Clickable button widget with text label.
Assign a lambda to onclick to react to left-click presses.
Supported style keys (std::unordered_map<std::string, std::variant<unsigned int, float, std::string>>):
fontPath (std::string)fontSize (float)letterSpacing (float)fontColor (unsigned int, RGBA hex like 0xRRGGBBAA)hoverFontColor (unsigned int)outlineColor (unsigned int)outlineThickness (float)backgroundColor (unsigned int)hoverBackgroundColor (unsigned int)width (float)height (float) | Button::Button | ( | float | width, |
| float | height, | ||
| std::string | label, | ||
| std::unordered_map< std::string, std::variant< unsigned int, float, std::string > > | styling = {}, |
||
| unsigned int | borderColor = 0x000000FFu, |
||
| float | borderThickness = 1.f |
||
| ) |
Create a button.
| width | Button width in pixels. |
| height | Button height in pixels. |
| label | Text displayed in the center. |
| styling | Optional style map that overrides default visual properties such as font, colors, and size (see class documentation for supported keys). |
| borderColor | Border color (maps to the outlineColor style key). |
| borderThickness | Border thickness (maps to the outlineThickness style key). |
| Button::Button | ( | const Button & | other | ) |
Copy constructor.
|
overridevirtual |
Get button dimensions.
Implements Widget.
|
overridevirtual |
Process hover/press input events.
Reimplemented from Widget.
| void Button::overrideStyling | ( | std::unordered_map< std::string, std::variant< unsigned int, float, std::string > > | styling | ) |
Apply/override style properties.
Unknown keys are ignored with a warning.
|
overridevirtual |
Render the button.
Reimplemented from Widget.
|
overridevirtual |
Set top-left position of the button.
Implements Widget.
| std::function<void()> Button::onclick |
Called when the button is pressed with left mouse button while hovered.