wind+libui: Rename SetTitlebarRect to SetTitlebarHeight

We only need the height to be customizable.
This commit is contained in:
apio 2024-02-04 13:13:21 +01:00
parent b8470f753b
commit b9ccda132a
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 13 additions and 14 deletions

View File

@ -24,7 +24,7 @@ namespace ui
INVALIDATE_ID,
CLOSE_WINDOW_ID,
GET_SCREEN_RECT_ID,
SET_TITLEBAR_RECT_ID,
SET_TITLEBAR_HEIGHT_ID,
};
enum class WindowType : u8
@ -80,11 +80,11 @@ namespace ui
int _shadow; // Unused.
};
struct SetTitlebarRectRequest
struct SetTitlebarHeightRequest
{
static constexpr u8 ID = SET_TITLEBAR_RECT_ID;
static constexpr u8 ID = SET_TITLEBAR_HEIGHT_ID;
int window;
ui::Rect titlebar_rect;
int height;
};
}

View File

@ -59,8 +59,8 @@ namespace ui
window->m_titlebar_canvas = canvas.subcanvas(ui::Rect { 0, 0, canvas.width, height });
window->m_window_canvas = canvas.subcanvas(ui::Rect { 0, height, canvas.width, canvas.height - height });
ui::SetTitlebarRectRequest titlebar_request;
titlebar_request.titlebar_rect = window->m_titlebar_canvas.rect();
ui::SetTitlebarHeightRequest titlebar_request;
titlebar_request.height = height;
titlebar_request.window = response.window;
App::the().client().send_async(titlebar_request);
}

View File

@ -139,25 +139,24 @@ static Result<void> handle_get_screen_rect_message(Client& client)
return {};
}
static Result<void> handle_set_titlebar_rect_message(Client& client)
static Result<void> handle_set_titlebar_height_message(Client& client)
{
ui::SetTitlebarRectRequest request;
ui::SetTitlebarHeightRequest request;
if (!TRY(client.conn->read_message(request))) return {};
request.titlebar_rect = request.titlebar_rect.normalized();
if (request.height < 0) request.height = 0;
CHECK_WINDOW_ID(request);
auto* window = client.windows[request.window];
ui::Rect titlebar_rect = window->surface.absolute(request.titlebar_rect);
if (!window->surface.contains(titlebar_rect))
if (request.height > window->surface.height)
{
os::eprintln("wind: SetTitlebarRect: titlebar rect outside window!");
os::eprintln("wind: SetTitlebarHeight: titlebar height bigger than window!");
return {};
}
window->titlebar = request.titlebar_rect;
window->titlebar = ui::Rect { 0, 0, window->surface.width, request.height };
return {};
}
@ -174,7 +173,7 @@ namespace wind
case ui::INVALIDATE_ID: handle_invalidate_message(client); break;
case ui::CLOSE_WINDOW_ID: handle_close_window_message(client); break;
case ui::GET_SCREEN_RECT_ID: handle_get_screen_rect_message(client); break;
case ui::SET_TITLEBAR_RECT_ID: handle_set_titlebar_rect_message(client); break;
case ui::SET_TITLEBAR_HEIGHT_ID: handle_set_titlebar_height_message(client); break;
default: os::eprintln("wind: Invalid IPC message from client!"); return;
}
}