mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:57:45 +00:00
Let's use the existing Rect and Color types in the GUI API.
Any type that doesn't depend on indirect data can probably be used here.
This commit is contained in:
parent
b2d86b7597
commit
f7261d7b26
4 changed files with 68 additions and 23 deletions
|
@ -1,13 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
// GUI system call API types.
|
||||
#include <Widgets/Color.h>
|
||||
#include <Widgets/Rect.h>
|
||||
|
||||
struct GUI_Rect {
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
// GUI system call API types.
|
||||
|
||||
struct GUI_WindowFlags { enum {
|
||||
Visible = 1 << 0,
|
||||
|
@ -16,9 +12,9 @@ struct GUI_WindowFlags { enum {
|
|||
typedef unsigned GUI_Color;
|
||||
|
||||
struct GUI_CreateWindowParameters {
|
||||
GUI_Rect rect;
|
||||
GUI_Color background_color;
|
||||
unsigned flags;
|
||||
Rect rect;
|
||||
Color background_color;
|
||||
unsigned flags { 0 };
|
||||
char title[128];
|
||||
};
|
||||
|
||||
|
@ -29,9 +25,9 @@ enum class GUI_WidgetType : unsigned {
|
|||
|
||||
struct GUI_CreateWidgetParameters {
|
||||
GUI_WidgetType type;
|
||||
GUI_Rect rect;
|
||||
GUI_Color background_color;
|
||||
bool opaque;
|
||||
unsigned flags;
|
||||
Rect rect;
|
||||
Color background_color;
|
||||
bool opaque { true };
|
||||
unsigned flags { 0 };
|
||||
char text[256];
|
||||
};
|
||||
|
|
|
@ -37,9 +37,8 @@ int Process::gui$create_window(const GUI_CreateWindowParameters* user_params)
|
|||
return -EFAULT;
|
||||
|
||||
auto params = *user_params;
|
||||
Rect rect { params.rect.x, params.rect.y, params.rect.width, params.rect.height };
|
||||
|
||||
if (rect.is_empty())
|
||||
if (params.rect.is_empty())
|
||||
return -EINVAL;
|
||||
|
||||
ProcessPagingScope scope(EventLoop::main().server_process());
|
||||
|
@ -52,14 +51,14 @@ int Process::gui$create_window(const GUI_CreateWindowParameters* user_params)
|
|||
m_windows.append(window->makeWeakPtr());
|
||||
|
||||
window->setTitle(params.title);
|
||||
window->setRect(rect);
|
||||
window->setRect(params.rect);
|
||||
|
||||
auto* main_widget = new Widget;
|
||||
window->setMainWidget(main_widget);
|
||||
main_widget->setWindowRelativeRect({ 0, 0, rect.width(), rect.height() });
|
||||
main_widget->setWindowRelativeRect({ 0, 0, params.rect.width(), params.rect.height() });
|
||||
main_widget->setBackgroundColor(params.background_color);
|
||||
main_widget->setFillWithBackgroundColor(true);
|
||||
dbgprintf("%s<%u> gui$create_window: %d with rect {%d,%d %dx%d}\n", name().characters(), pid(), window_id, rect.x(), rect.y(), rect.width(), rect.height());
|
||||
dbgprintf("%s<%u> gui$create_window: %d with rect {%d,%d %dx%d}\n", name().characters(), pid(), window_id, params.rect.x(), params.rect.y(), params.rect.width(), params.rect.height());
|
||||
|
||||
return window_id;
|
||||
}
|
||||
|
@ -92,9 +91,8 @@ int Process::gui$create_widget(int window_id, const GUI_CreateWidgetParameters*
|
|||
auto& window = *m_windows[window_id];
|
||||
|
||||
auto params = *user_params;
|
||||
Rect rect { params.rect.x, params.rect.y, params.rect.width, params.rect.height };
|
||||
|
||||
if (rect.is_empty())
|
||||
if (params.rect.is_empty())
|
||||
return -EINVAL;
|
||||
|
||||
Widget* widget = nullptr;
|
||||
|
@ -112,10 +110,10 @@ int Process::gui$create_widget(int window_id, const GUI_CreateWidgetParameters*
|
|||
int widget_id = m_widgets.size();
|
||||
m_widgets.append(widget->makeWeakPtr());
|
||||
|
||||
widget->setWindowRelativeRect(rect);
|
||||
widget->setWindowRelativeRect(params.rect);
|
||||
widget->setBackgroundColor(params.background_color);
|
||||
widget->setFillWithBackgroundColor(params.opaque);
|
||||
dbgprintf("%s<%u> gui$create_widget: %d with rect {%d,%d %dx%d}\n", name().characters(), pid(), widget_id, rect.x(), rect.y(), rect.width(), rect.height());
|
||||
dbgprintf("%s<%u> gui$create_widget: %d with rect {%d,%d %dx%d}\n", name().characters(), pid(), widget_id, params.rect.x(), params.rect.y(), params.rect.width(), params.rect.height());
|
||||
|
||||
return window_id;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue