apio
140910763e
All checks were successful
Build and test / build (push) Successful in 1m56s
Why are command-line utilities stored in "apps"? And why are apps like "editor" or "terminal" top-level directories? Command-line utilities now go in "utils". GUI stuff now goes in "gui". This includes: libui -> gui/libui, wind -> gui/wind, GUI apps -> gui/apps, editor&terminal -> gui/apps... System services go in "system".
107 lines
2.4 KiB
C++
107 lines
2.4 KiB
C++
/**
|
|
* @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/String.h>
|
|
#include <luna/StringView.h>
|
|
#include <ui/Canvas.h>
|
|
#include <ui/Mouse.h>
|
|
#include <ui/Rect.h>
|
|
#include <ui/Widget.h>
|
|
#include <ui/ipc/Server.h>
|
|
|
|
namespace ui
|
|
{
|
|
enum class WindowType : u8
|
|
{
|
|
Normal,
|
|
NotDecorated,
|
|
System,
|
|
};
|
|
|
|
struct [[gnu::packed]] Shortcut
|
|
{
|
|
moon::KeyCode key;
|
|
int modifiers;
|
|
|
|
bool operator==(const Shortcut& other) const
|
|
{
|
|
return key == other.key && modifiers == other.modifiers;
|
|
}
|
|
};
|
|
|
|
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_window_canvas.rect(), {});
|
|
m_main_widget = &widget;
|
|
}
|
|
|
|
Canvas& canvas()
|
|
{
|
|
return m_window_canvas;
|
|
}
|
|
|
|
void update();
|
|
|
|
void close();
|
|
|
|
void set_special_attributes(WindowAttributes attributes);
|
|
|
|
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);
|
|
|
|
Result<void> add_keyboard_shortcut(ui::Shortcut shortcut, bool intercept, os::Function<ui::Shortcut>&& action);
|
|
|
|
int id() const
|
|
{
|
|
return m_id;
|
|
}
|
|
|
|
~Window();
|
|
|
|
private:
|
|
int m_id;
|
|
Canvas m_canvas;
|
|
Canvas m_titlebar_canvas;
|
|
Canvas m_window_canvas;
|
|
String m_name;
|
|
Widget* m_main_widget { nullptr };
|
|
Option<Color> m_background {};
|
|
Option<int> m_old_mouse_buttons;
|
|
bool m_decorated { false };
|
|
|
|
struct ShortcutAction
|
|
{
|
|
bool intercept;
|
|
os::Function<Shortcut> action;
|
|
};
|
|
|
|
HashMap<Shortcut, ShortcutAction> m_shortcuts;
|
|
|
|
Result<void> draw_titlebar();
|
|
};
|
|
}
|