mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:27:35 +00:00
WindowServer+LibGUI: Paint exclusive actions as radio buttons in menus
Actions that are checkable and members of a GActionGroup will now be painted with a radio button appearance in menus.
This commit is contained in:
parent
cc8c26c39b
commit
463ed77024
5 changed files with 34 additions and 10 deletions
|
@ -167,6 +167,7 @@ OwnPtr<WindowServer::AddMenuItemResponse> WSClientConnection::handle(const Windo
|
|||
menu_item->set_icon(shared_icon);
|
||||
}
|
||||
menu_item->set_submenu_id(message.submenu_id());
|
||||
menu_item->set_exclusive(message.exclusive());
|
||||
menu.add_item(move(menu_item));
|
||||
return make<WindowServer::AddMenuItemResponse>();
|
||||
}
|
||||
|
|
|
@ -164,13 +164,19 @@ void WSMenu::draw()
|
|||
}
|
||||
Rect text_rect = item.rect().translated(stripe_rect.width() + 6, 0);
|
||||
if (item.is_checkable()) {
|
||||
Rect checkmark_rect { item.rect().x() + 7, 0, s_checked_bitmap_width, s_checked_bitmap_height };
|
||||
checkmark_rect.center_vertically_within(text_rect);
|
||||
Rect checkbox_rect = checkmark_rect.inflated(4, 4);
|
||||
painter.fill_rect(checkbox_rect, palette.base());
|
||||
StylePainter::paint_frame(painter, checkbox_rect, palette, FrameShape::Container, FrameShadow::Sunken, 2);
|
||||
if (item.is_checked()) {
|
||||
painter.draw_bitmap(checkmark_rect.location(), *s_checked_bitmap, palette.button_text());
|
||||
if (item.is_exclusive()) {
|
||||
Rect radio_rect { item.rect().x() + 5, 0, 12, 12 };
|
||||
radio_rect.center_vertically_within(text_rect);
|
||||
StylePainter::paint_radio_button(painter, radio_rect, palette, item.is_checked(), false);
|
||||
} else {
|
||||
Rect checkmark_rect { item.rect().x() + 7, 0, s_checked_bitmap_width, s_checked_bitmap_height };
|
||||
checkmark_rect.center_vertically_within(text_rect);
|
||||
Rect checkbox_rect = checkmark_rect.inflated(4, 4);
|
||||
painter.fill_rect(checkbox_rect, palette.base());
|
||||
StylePainter::paint_frame(painter, checkbox_rect, palette, FrameShape::Container, FrameShadow::Sunken, 2);
|
||||
if (item.is_checked()) {
|
||||
painter.draw_bitmap(checkmark_rect.location(), *s_checked_bitmap, palette.button_text());
|
||||
}
|
||||
}
|
||||
} else if (item.icon()) {
|
||||
Rect icon_rect { item.rect().x() + 3, 0, s_item_icon_width, s_item_icon_width };
|
||||
|
|
|
@ -50,6 +50,9 @@ public:
|
|||
|
||||
WSMenu* submenu();
|
||||
|
||||
bool is_exclusive() const { return m_exclusive; }
|
||||
void set_exclusive(bool exclusive) { m_exclusive = exclusive; }
|
||||
|
||||
private:
|
||||
WSMenu& m_menu;
|
||||
Type m_type { None };
|
||||
|
@ -62,4 +65,5 @@ private:
|
|||
Rect m_rect;
|
||||
RefPtr<GraphicsBitmap> m_icon;
|
||||
int m_submenu_id { -1 };
|
||||
bool m_exclusive { false };
|
||||
};
|
||||
|
|
|
@ -11,7 +11,18 @@ endpoint WindowServer = 2
|
|||
AddMenuToMenubar(i32 menubar_id, i32 menu_id) => ()
|
||||
SetApplicationMenubar(i32 menubar_id) => ()
|
||||
|
||||
AddMenuItem(i32 menu_id, i32 identifier, i32 submenu_id, String text, bool enabled, bool checkable, bool checked, String shortcut, i32 icon_buffer_id) => ()
|
||||
AddMenuItem(
|
||||
i32 menu_id,
|
||||
i32 identifier,
|
||||
i32 submenu_id,
|
||||
String text,
|
||||
bool enabled,
|
||||
bool checkable,
|
||||
bool checked,
|
||||
String shortcut,
|
||||
i32 icon_buffer_id,
|
||||
bool exclusive) => ()
|
||||
|
||||
AddMenuSeparator(i32 menu_id) => ()
|
||||
|
||||
UpdateMenuItem(i32 menu_id, i32 identifier, i32 submenu_id, String text, bool enabled, bool checkable, bool checked, String shortcut) => ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue