41 std::shared_ptr<Component> _target;
51 Event(
const std::string &type, std::shared_ptr<Component> target,
52 const std::any &data = std::any())
53 : _type(type), _target(target), _data(data) {}
61 const std::string &
getType(
void)
const {
return _type; }
67 std::shared_ptr<Component>
getTarget(
void)
const {
return _target; }
74 template <
typename T> T
getData(
void)
const {
75 if (_data.has_value()) {
76 return std::any_cast<T>(_data);
85 bool hasData(
void)
const {
return _data.has_value(); }
Base class for all UI components.
Represents a UI event with type, target, and optional data.
T getData(void) const
Get the event data with type casting.
Event(const std::string &type, std::shared_ptr< Component > target, const std::any &data=std::any())
Construct an event.
const std::string & getType(void) const
Get the event type.
bool hasData(void) const
Check if the event has data.
std::shared_ptr< Component > getTarget(void) const
Get the target component.