libui: Add default handlers for events in Widget
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
apio 2023-08-29 15:32:33 +02:00
parent 2c7ae3c61b
commit e85dc97e91
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 23 additions and 38 deletions

View File

@ -20,16 +20,6 @@ struct ColorWidget : public ui::Widget
return ui::EventResult::DidHandle; return ui::EventResult::DidHandle;
} }
Result<ui::EventResult> handle_mouse_down(ui::Point, int) override
{
return ui::EventResult::DidNotHandle;
}
Result<ui::EventResult> handle_mouse_up(ui::Point, int) override
{
return ui::EventResult::DidNotHandle;
}
Result<void> draw(ui::Canvas& canvas) override Result<void> draw(ui::Canvas& canvas) override
{ {
canvas.fill(m_color); canvas.fill(m_color);

View File

@ -84,10 +84,6 @@ namespace ui
public: public:
static Result<OwnedPtr<ImageWidget>> load(const os::Path& path); static Result<OwnedPtr<ImageWidget>> load(const os::Path& path);
Result<EventResult> handle_mouse_move(Point position) override;
Result<EventResult> handle_mouse_leave() override;
Result<EventResult> handle_mouse_down(Point position, int buttons) override;
Result<EventResult> handle_mouse_up(Point position, int buttons) override;
Result<void> draw(Canvas& canvas) override; Result<void> draw(Canvas& canvas) override;
private: private:

View File

@ -8,6 +8,7 @@
*/ */
#pragma once #pragma once
#include <luna/Ignore.h>
#include <luna/Result.h> #include <luna/Result.h>
#include <ui/Canvas.h> #include <ui/Canvas.h>
#include <ui/Point.h> #include <ui/Point.h>
@ -26,10 +27,28 @@ namespace ui
class Widget class Widget
{ {
public: public:
virtual Result<EventResult> handle_mouse_move(Point position); virtual Result<EventResult> handle_mouse_move(Point position)
virtual Result<EventResult> handle_mouse_down(Point position, int buttons); {
virtual Result<EventResult> handle_mouse_up(Point position, int buttons); ignore(position);
virtual Result<EventResult> handle_mouse_leave(); return EventResult::DidNotHandle;
}
virtual Result<EventResult> handle_mouse_down(Point position, int buttons)
{
ignore(position, buttons);
return EventResult::DidNotHandle;
}
virtual Result<EventResult> handle_mouse_up(Point position, int buttons)
{
ignore(position, buttons);
return EventResult::DidNotHandle;
}
virtual Result<EventResult> handle_mouse_leave()
{
return EventResult::DidNotHandle;
}
virtual Result<void> draw(Canvas& canvas); virtual Result<void> draw(Canvas& canvas);

View File

@ -40,26 +40,6 @@ namespace ui
return widget; return widget;
} }
Result<EventResult> ImageWidget::handle_mouse_move(Point)
{
return EventResult::DidNotHandle;
}
Result<EventResult> ImageWidget::handle_mouse_leave()
{
return EventResult::DidNotHandle;
}
Result<EventResult> ImageWidget::handle_mouse_up(Point, int)
{
return EventResult::DidNotHandle;
}
Result<EventResult> ImageWidget::handle_mouse_down(Point, int)
{
return EventResult::DidNotHandle;
}
Result<void> ImageWidget::draw(Canvas& canvas) Result<void> ImageWidget::draw(Canvas& canvas)
{ {
canvas.subcanvas({ 0, 0, m_image->width(), m_image->height() }).fill(m_image->pixels(), m_image->width()); canvas.subcanvas({ 0, 0, m_image->width(), m_image->height() }).fill(m_image->pixels(), m_image->width());