Luna/libui/include/ui/Button.h

38 lines
1011 B
C
Raw Normal View History

2023-08-15 13:33:44 +00:00
/**
* @file Button.h
* @author apio (cloudapio.eu)
* @brief A clickable component that triggers an action when pressed.
*
* @copyright Copyright (c) 2023, the Luna authors.
*
*/
#pragma once
#include <ui/Action.h>
2023-08-15 13:33:44 +00:00
#include <ui/Widget.h>
namespace ui
{
class Button : public Widget
{
public:
Button(Rect rect);
void set_widget(Widget& widget);
void set_action(Action&& action);
2023-08-15 13:33:44 +00:00
Result<EventResult> handle_mouse_move(Point position) override;
Result<EventResult> handle_mouse_leave() override;
2023-08-15 13:33:44 +00:00
Result<EventResult> handle_mouse_down(Point position, int buttons) override;
Result<EventResult> handle_mouse_up(Point position, int buttons) override;
Result<EventResult> handle_key_event(const ui::KeyEventRequest& request) override;
2023-08-15 13:33:44 +00:00
Result<void> draw(Canvas& canvas) override;
private:
bool m_hovered { false };
bool m_clicked { false };
Widget* m_child;
Action m_action;
2023-08-15 13:33:44 +00:00
};
}