diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-26 18:10:07 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-26 18:10:07 +0200 |
commit | d522a6fe4c6dae3d36ca7f77c957be7073b27d9c (patch) | |
tree | 76faed29417d0f2daddec9805989927ca050dc04 /Servers/WindowServer/WSMenu.cpp | |
parent | cef2c0495288df21809d6247e98e7f8612cd9f20 (diff) | |
download | serenity-d522a6fe4c6dae3d36ca7f77c957be7073b27d9c.zip |
WindowServer: Improved look of checkable menu items
Paint a little checkbox frame for checkable items to make it obvious
that they are indeed checkable. This looks quite nice :^)
We also now shift all menu items to the right if we have any checkable
items in the menu.
Diffstat (limited to 'Servers/WindowServer/WSMenu.cpp')
-rw-r--r-- | Servers/WindowServer/WSMenu.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Servers/WindowServer/WSMenu.cpp b/Servers/WindowServer/WSMenu.cpp index a4c15219f7..cc9bb91e19 100644 --- a/Servers/WindowServer/WSMenu.cpp +++ b/Servers/WindowServer/WSMenu.cpp @@ -124,6 +124,10 @@ void WSMenu::draw() if (!s_checked_bitmap) s_checked_bitmap = &CharacterBitmap::create_from_ascii(s_checked_bitmap_data, s_checked_bitmap_width, s_checked_bitmap_height).leak_ref(); + bool has_checkable_items = false; + for (auto& item : m_items) + has_checkable_items = has_checkable_items | item.is_checkable(); + for (auto& item : m_items) { if (item.type() == WSMenuItem::Text) { Color text_color = Color::Black; @@ -135,13 +139,17 @@ void WSMenu::draw() text_color = Color::MidGray; Rect text_rect = item.rect().translated(left_padding(), 0); if (item.is_checkable()) { + Rect checkmark_rect { text_rect.location().x(), 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, Color::White); + StylePainter::paint_frame(painter, checkbox_rect, FrameShape::Container, FrameShadow::Sunken, 2); if (item.is_checked()) { - Rect checkmark_rect { text_rect.location().x(), 0, s_checked_bitmap_width, s_checked_bitmap_height }; - checkmark_rect.center_vertically_within(text_rect); painter.draw_bitmap(checkmark_rect.location(), *s_checked_bitmap, Color::Black); } - text_rect.move_by(s_checked_bitmap_width + s_checked_bitmap_padding, 0); } + if (has_checkable_items) + text_rect.move_by(s_checked_bitmap_width + s_checked_bitmap_padding, 0); painter.draw_text(text_rect, item.text(), TextAlignment::CenterLeft, text_color); if (!item.shortcut_text().is_empty()) { painter.draw_text(item.rect().translated(-right_padding(), 0), item.shortcut_text(), TextAlignment::CenterRight, text_color); |