Luna/libui/include/ui/Window.h

70 lines
1.5 KiB
C
Raw Normal View History

/**
* @file Window.h
* @author apio (cloudapio.eu)
* @brief UI windows.
*
* @copyright Copyright (c) 2023, the Luna authors.
*
*/
#pragma once
#include <luna/OwnedPtr.h>
#include <luna/StringView.h>
#include <ui/Canvas.h>
2023-08-15 13:10:13 +00:00
#include <ui/Mouse.h>
#include <ui/Rect.h>
#include <ui/Widget.h>
#include <ui/ipc/Server.h>
namespace ui
{
class Window
{
public:
static Result<Window*> create(Rect rect, WindowType type = WindowType::Normal);
void set_title(StringView title);
void set_background(Color color)
{
m_background = color;
}
void set_main_widget(Widget& widget)
{
check(!m_main_widget);
widget.set_window(this, m_canvas.rect(), {});
m_main_widget = &widget;
}
Canvas& canvas()
{
return m_canvas;
}
void update();
void close();
Result<void> draw();
Result<ui::EventResult> handle_mouse_leave();
Result<ui::EventResult> handle_mouse_move(ui::Point position);
Result<ui::EventResult> handle_mouse_buttons(ui::Point position, int buttons);
Result<ui::EventResult> handle_key_event(const ui::KeyEventRequest& request);
int id() const
{
return m_id;
}
~Window();
private:
int m_id;
Canvas m_canvas;
Widget* m_main_widget { nullptr };
Option<Color> m_background {};
2023-08-15 13:10:13 +00:00
Option<int> m_old_mouse_buttons;
};
}