LibGUI: Window Creation takes attributes as an argument

This reduces windows showing/moving once they are opened and setting
their attributes.
This commit is contained in:
2024-11-14 20:57:34 +02:00
parent 04eee2ea75
commit a859558840
6 changed files with 21 additions and 19 deletions

View File

@@ -178,10 +178,20 @@ namespace LibGUI
namespace WindowPacket
{
struct Attributes
{
bool title_bar;
bool movable;
bool focusable;
bool rounded_corners;
bool alpha_channel;
};
DEFINE_PACKET(
WindowCreate,
uint32_t, width,
uint32_t, height,
Attributes, attributes,
BAN::String, title
);
@@ -199,15 +209,8 @@ namespace LibGUI
int32_t, y
);
DEFINE_PACKET_EXTRA(
DEFINE_PACKET(
WindowSetAttributes,
struct Attributes {
bool title_bar;
bool movable;
bool focusable;
bool rounded_corners;
bool alpha_channel;
},
Attributes, attributes
);

View File

@@ -14,7 +14,7 @@ namespace LibGUI
class Window
{
public:
using Attributes = WindowPacket::WindowSetAttributes::Attributes;
using Attributes = WindowPacket::Attributes;
static constexpr Attributes default_attributes = {
.title_bar = true,
@@ -27,7 +27,7 @@ namespace LibGUI
public:
~Window();
static BAN::ErrorOr<BAN::UniqPtr<Window>> create(uint32_t width, uint32_t height, BAN::StringView title);
static BAN::ErrorOr<BAN::UniqPtr<Window>> create(uint32_t width, uint32_t height, BAN::StringView title, Attributes attributes = default_attributes);
void set_pixel(uint32_t x, uint32_t y, uint32_t color)
{
@@ -87,8 +87,9 @@ namespace LibGUI
int server_fd() const { return m_server_fd; }
private:
Window(int server_fd)
Window(int server_fd, Attributes attributes)
: m_server_fd(server_fd)
, m_attributes(attributes)
{ }
bool clamp_to_framebuffer(int32_t& x, int32_t& y, uint32_t& width, uint32_t& height) const;