Compare commits
2 Commits
1f0286c9c7
...
b95cfac3ec
Author | SHA1 | Date | |
---|---|---|---|
b95cfac3ec | |||
17a31e5ea9 |
@ -61,6 +61,7 @@ namespace ui
|
|||||||
HashMap<int, OwnedPtr<Window>> m_windows;
|
HashMap<int, OwnedPtr<Window>> m_windows;
|
||||||
bool m_should_close { false };
|
bool m_should_close { false };
|
||||||
os::EventLoop m_loop;
|
os::EventLoop m_loop;
|
||||||
|
Vector<int> m_window_clear_queue;
|
||||||
|
|
||||||
bool process_events();
|
bool process_events();
|
||||||
|
|
||||||
|
@ -80,6 +80,12 @@ namespace ui
|
|||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void on_close(os::Action&& action)
|
||||||
|
{
|
||||||
|
m_on_close_action = move(action);
|
||||||
|
m_has_on_close_action = true;
|
||||||
|
}
|
||||||
|
|
||||||
~Window();
|
~Window();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -93,6 +99,9 @@ namespace ui
|
|||||||
Option<int> m_old_mouse_buttons;
|
Option<int> m_old_mouse_buttons;
|
||||||
bool m_decorated { false };
|
bool m_decorated { false };
|
||||||
|
|
||||||
|
os::Action m_on_close_action;
|
||||||
|
bool m_has_on_close_action { false };
|
||||||
|
|
||||||
struct ShortcutAction
|
struct ShortcutAction
|
||||||
{
|
{
|
||||||
bool intercept;
|
bool intercept;
|
||||||
|
@ -75,7 +75,7 @@ namespace ui
|
|||||||
void App::unregister_window(Window* window, Badge<Window>)
|
void App::unregister_window(Window* window, Badge<Window>)
|
||||||
{
|
{
|
||||||
int id = window->id();
|
int id = window->id();
|
||||||
check(m_windows.try_remove(id));
|
m_window_clear_queue.try_append(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window* App::find_window(int id)
|
Window* App::find_window(int id)
|
||||||
@ -124,6 +124,15 @@ namespace ui
|
|||||||
{
|
{
|
||||||
check(m_main_window);
|
check(m_main_window);
|
||||||
m_client->check_for_messages().release_value();
|
m_client->check_for_messages().release_value();
|
||||||
|
for (int id : m_window_clear_queue)
|
||||||
|
{
|
||||||
|
check(m_windows.try_remove(id));
|
||||||
|
|
||||||
|
ui::CloseWindowRequest request;
|
||||||
|
request.window = id;
|
||||||
|
client().send_async(request);
|
||||||
|
}
|
||||||
|
m_window_clear_queue.clear_data();
|
||||||
return !m_should_close;
|
return !m_should_close;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,8 @@ namespace ui
|
|||||||
Window::~Window()
|
Window::~Window()
|
||||||
{
|
{
|
||||||
if (m_canvas.ptr) munmap(m_canvas.ptr, ((usize)m_canvas.width) * ((usize)m_canvas.height) * 4);
|
if (m_canvas.ptr) munmap(m_canvas.ptr, ((usize)m_canvas.width) * ((usize)m_canvas.height) * 4);
|
||||||
|
|
||||||
|
if (m_has_on_close_action) m_on_close_action();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::set_title(StringView title)
|
void Window::set_title(StringView title)
|
||||||
@ -108,10 +110,6 @@ namespace ui
|
|||||||
{
|
{
|
||||||
App& app = App::the();
|
App& app = App::the();
|
||||||
|
|
||||||
ui::CloseWindowRequest request;
|
|
||||||
request.window = m_id;
|
|
||||||
app.client().send_async(request);
|
|
||||||
|
|
||||||
if (this == app.main_window()) app.set_should_close(true);
|
if (this == app.main_window()) app.set_should_close(true);
|
||||||
|
|
||||||
app.unregister_window(this, {});
|
app.unregister_window(this, {});
|
||||||
|
@ -44,6 +44,15 @@ namespace os
|
|||||||
other.m_action = {};
|
other.m_action = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Action object, copying it from another one.
|
||||||
|
*
|
||||||
|
* @param other The old Action object to copy from.
|
||||||
|
*/
|
||||||
|
Action(Action& other) : m_action(other.m_action)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Action object, copying it from another one.
|
* @brief Construct a new Action object, copying it from another one.
|
||||||
*
|
*
|
||||||
@ -143,7 +152,7 @@ namespace os
|
|||||||
*
|
*
|
||||||
* @param other The old Function object to move from. This object will become invalid.
|
* @param other The old Function object to move from. This object will become invalid.
|
||||||
*/
|
*/
|
||||||
Function(Function&& other) : m_action(other.m_action)
|
Function(Function<Args...>&& other) : m_action(other.m_action)
|
||||||
{
|
{
|
||||||
other.m_action = {};
|
other.m_action = {};
|
||||||
}
|
}
|
||||||
@ -153,7 +162,16 @@ namespace os
|
|||||||
*
|
*
|
||||||
* @param other The old Function object to copy from.
|
* @param other The old Function object to copy from.
|
||||||
*/
|
*/
|
||||||
Function(const Function& other) : m_action(other.m_action)
|
Function(Function<Args...>& other) : m_action(other.m_action)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Function object, copying it from another one.
|
||||||
|
*
|
||||||
|
* @param other The old Function object to copy from.
|
||||||
|
*/
|
||||||
|
Function(const Function<Args...>& other) : m_action(other.m_action)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,24 +212,43 @@ namespace os
|
|||||||
return m_action->call(args...);
|
return m_action->call(args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Call the underlying object.
|
||||||
|
*/
|
||||||
|
void operator()(Args... args) const
|
||||||
|
{
|
||||||
|
expect(m_action, "os::Function called with no underlying callable object");
|
||||||
|
return m_action->call(args...);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class FunctionBase : public Shareable
|
class FunctionBase : public Shareable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void call(Args... args) = 0;
|
virtual void call(Args... args) = 0;
|
||||||
|
virtual void call(Args... args) const = 0;
|
||||||
virtual ~FunctionBase() = default;
|
virtual ~FunctionBase() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> class FunctionImpl final : public FunctionBase
|
template <typename T> class FunctionImpl final : public FunctionBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
FunctionImpl(FunctionImpl<T>&& function) : m_function(move(function.m_function))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
FunctionImpl(T&& function) : m_function(move(function))
|
FunctionImpl(T&& function) : m_function(move(function))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void call(Args... args) override
|
void call(Args... args) override
|
||||||
{
|
{
|
||||||
return m_function(args...);
|
m_function(args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
void call(Args... args) const override
|
||||||
|
{
|
||||||
|
m_function(args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user