2023-08-15 10:28:47 +00:00
|
|
|
/**
|
|
|
|
* @file Widget.h
|
|
|
|
* @author apio (cloudapio.eu)
|
|
|
|
* @brief Abstract widget class.
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2023, the Luna authors.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2023-08-29 13:32:33 +00:00
|
|
|
#include <luna/Ignore.h>
|
2023-08-15 10:28:47 +00:00
|
|
|
#include <luna/Result.h>
|
|
|
|
#include <ui/Canvas.h>
|
|
|
|
#include <ui/Point.h>
|
|
|
|
#include <ui/Rect.h>
|
|
|
|
|
|
|
|
namespace ui
|
|
|
|
{
|
|
|
|
class Window;
|
|
|
|
|
|
|
|
enum class EventResult
|
|
|
|
{
|
|
|
|
DidHandle,
|
|
|
|
DidNotHandle,
|
|
|
|
};
|
|
|
|
|
|
|
|
class Widget
|
|
|
|
{
|
|
|
|
public:
|
2023-08-29 13:32:33 +00:00
|
|
|
virtual Result<EventResult> handle_mouse_move(Point position)
|
|
|
|
{
|
|
|
|
ignore(position);
|
|
|
|
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;
|
|
|
|
}
|
2023-08-15 10:28:47 +00:00
|
|
|
|
|
|
|
virtual Result<void> draw(Canvas& canvas);
|
|
|
|
|
|
|
|
void set_window(Window* window, Rect rect, Badge<Window>)
|
|
|
|
{
|
|
|
|
m_window = window;
|
|
|
|
m_rect = rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_parent(Widget* parent)
|
|
|
|
{
|
|
|
|
m_parent = parent;
|
|
|
|
m_window = parent->m_window;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget* parent()
|
|
|
|
{
|
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
Window* window()
|
|
|
|
{
|
|
|
|
return m_window;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect& rect()
|
|
|
|
{
|
|
|
|
return m_rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Widget* m_parent { nullptr };
|
|
|
|
Window* m_window;
|
|
|
|
Rect m_rect { 0, 0, 50, 50 };
|
|
|
|
};
|
|
|
|
}
|