25#include "component.hpp"
26#include "primitives/rectangle.hpp"
27#include "primitives/text.hpp"
41 std::function<void()> _onClick;
50 :
Component(), _label(label), _onClick(nullptr) {
62 :
Component(properties), _label(label), _onClick(nullptr) {
78 void setOnClick(std::function<
void()> callback) { _onClick = callback; }
85 const std::string &
getLabel(
void)
const {
return _label; }
102 std::shared_ptr<Component>
render(
void)
override {
105 _label =
_state.
get<std::string>(
"label");
113 auto rectPrimitive = std::make_shared<Rectangle>(
Point(50.0f, 15.0f, 0.0f), 100.0f, 30.0f,
Point(0.0f, 0.0f, 0.0f));
117 auto textPrimitive = std::make_shared<Text>(_label,
Point(10, 15, 0));
120 return shared_from_this();
131 if (event.
getType() ==
"click" && _onClick) {
Base class for all UI components.
std::vector< std::shared_ptr< Primitive > > _primitives
Vector of primitives for rendering.
State _state
The component's state.
Represents a UI event with type, target, and optional data.
const std::string & getType(void) const
Get the event type.
Represents a point in 3D space.
Manages immutable component properties.
const std::map< std::string, std::any > & getData(void) const
Get the entire state data map.
void set(const std::string &key, const T &value)
Set a state value by key.
T get(const std::string &key) const
Get a state value by key with type casting.