Velvet 0.1a
A beginner-friendly C++ GUI framework built on SFML.
Loading...
Searching...
No Matches
Label.hpp
Go to the documentation of this file.
1#pragma once
2#include <SFML/Graphics/RectangleShape.hpp>
3#include <SFML/System/Vector2.hpp>
4#include <unordered_map>
5#include <variant>
7#include <SFML/Graphics/Color.hpp>
8
23class Label : public Widget {
24private:
25 sf::Text LText;
26 sf::Font font;
27 sf::RectangleShape backgroundShape;
28
29 std::unordered_map<std::string, std::variant<unsigned int, float, std::string>> styles = {
30 {"fontPath", "src/assets/AdwaitaSans-Regular.ttf"},
31 {"fontSize", 20.f},
32 {"lineSpacing", 1.f},
33 {"letterSpacing", 1.f},
34 {"fillColor", 0x000000FFu},
35 {"outlineColor", 0xFFFFFFFFu},
36 {"outlineThickness", 0.f},
37 {"fontStyle", "regular"},
38 {"backgroundColor", 0x00000000u}
39 };
40
41 void draw(sf::RenderWindow &window) override;
42 void update(sf::RenderWindow &window) override;
43
44public:
46 void render(sf::RenderWindow &window) override;
47
49 void setPosition(float x, float y) override;
50
52 sf::Vector2f getDimensions() override;
53
57 Label(std::string text, std::unordered_map<std::string, std::variant<unsigned int, float, std::string>> styling = {});
58
62 void setText(const std::string txt);
63
69 void overrideStyling(std::unordered_map<std::string, std::variant<unsigned int, float, std::string>> styling);
70};
Text display widget with simple style map support.
Definition Label.hpp:23
void setPosition(float x, float y) override
Set top-left position of label text/background.
void setText(const std::string txt)
Replace displayed string.
void render(sf::RenderWindow &window) override
Render the label.
void overrideStyling(std::unordered_map< std::string, std::variant< unsigned int, float, std::string > > styling)
Apply/override style properties.
sf::Vector2f getDimensions() override
Get current text bounds.
Label(std::string text, std::unordered_map< std::string, std::variant< unsigned int, float, std::string > > styling={})
Create label with text and optional style overrides.
Base class for all Velvet UI elements.
Definition Widget.hpp:16
float y
Definition Widget.hpp:31
float x
Definition Widget.hpp:31