mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-02 17:28:48 +00:00
WindowServer+LibGUI: Show action icons in the menus when possible
Any GAction that has an icon assigned will now show up with that icon when added to a menu as well. I made the menu items 2px taller to accomodate the icons. I think this turned out quite nice as well :^)
This commit is contained in:
parent
d522a6fe4c
commit
1e604b7984
Notes:
sideshowbarker
2024-07-19 12:30:28 +09:00
Author: https://github.com/awesomekling
Commit: 1e604b7984
11 changed files with 61 additions and 11 deletions
|
@ -98,6 +98,22 @@ int GMenu::realize_menu()
|
|||
request.menu.identifier = i;
|
||||
request.menu.enabled = action.is_enabled();
|
||||
request.menu.checkable = action.is_checkable();
|
||||
if (action.icon()) {
|
||||
ASSERT(action.icon()->format() == GraphicsBitmap::Format::RGBA32);
|
||||
ASSERT(action.icon()->size() == Size(16, 16));
|
||||
if (action.icon()->shared_buffer_id() == -1) {
|
||||
auto shared_buffer = SharedBuffer::create_with_size(action.icon()->size_in_bytes());
|
||||
ASSERT(shared_buffer);
|
||||
auto shared_icon = GraphicsBitmap::create_with_shared_buffer(GraphicsBitmap::Format::RGBA32, *shared_buffer, action.icon()->size());
|
||||
memcpy(shared_buffer->data(), action.icon()->bits(0), action.icon()->size_in_bytes());
|
||||
shared_buffer->seal();
|
||||
shared_buffer->share_with(GWindowServerConnection::the().server_pid());
|
||||
action.set_icon(shared_icon);
|
||||
}
|
||||
request.menu.icon_buffer_id = action.icon()->shared_buffer_id();
|
||||
} else {
|
||||
request.menu.icon_buffer_id = -1;
|
||||
}
|
||||
if (action.is_checkable())
|
||||
request.menu.checked = action.is_checked();
|
||||
ASSERT(action.text().length() < (ssize_t)sizeof(request.text));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue