1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 00:37:35 +00:00

Browser+LibGUI+WindowServer: Open Button menus uniformly

Instead of letting buttons determine the relative position
of their menus, a workaround only used by Statusbar segments,
open them all uniformly for a nice, consistent UI.

Passing a rect to popup() now routes to open_button_menu(), an
analog to open_menubar_menu(), which adjusts the menu's popup
position in the same way. Fixes button menus obscuring the buttons
which spawn them and jutting out at odd corners depending on screen
position.
This commit is contained in:
thankyouverycool 2022-09-04 19:48:37 -04:00 committed by Linus Groh
parent 0fc1925cd7
commit 35e557c657
12 changed files with 34 additions and 31 deletions

View file

@ -145,7 +145,7 @@ void ConnectionFromClient::add_menu_item(i32 menu_id, i32 identifier, i32 submen
menu.add_item(move(menu_item));
}
void ConnectionFromClient::popup_menu(i32 menu_id, Gfx::IntPoint const& screen_position)
void ConnectionFromClient::popup_menu(i32 menu_id, Gfx::IntPoint const& screen_position, Gfx::IntRect const& button_rect)
{
auto position = screen_position;
auto it = m_menus.find(menu_id);
@ -154,7 +154,10 @@ void ConnectionFromClient::popup_menu(i32 menu_id, Gfx::IntPoint const& screen_p
return;
}
auto& menu = *(*it).value;
menu.popup(position);
if (!button_rect.is_null())
menu.open_button_menu(position, button_rect);
else
menu.popup(position);
}
void ConnectionFromClient::dismiss_menu(i32 menu_id)

View file

@ -138,7 +138,7 @@ private:
virtual void show_screen_numbers(bool) override;
virtual void set_window_cursor(i32, i32) override;
virtual void set_window_custom_cursor(i32, Gfx::ShareableBitmap const&) override;
virtual void popup_menu(i32, Gfx::IntPoint const&) override;
virtual void popup_menu(i32, Gfx::IntPoint const&, Gfx::IntRect const&) override;
virtual void dismiss_menu(i32) override;
virtual void set_window_icon_bitmap(i32, Gfx::ShareableBitmap const&) override;
virtual Messages::WindowServer::StartDragResponse start_drag(String const&, HashMap<String, ByteBuffer> const&, Gfx::ShareableBitmap const&) override;

View file

@ -597,6 +597,27 @@ void Menu::redraw_if_theme_changed()
redraw();
}
void Menu::open_button_menu(Gfx::IntPoint const& position, Gfx::IntRect const& button_rect)
{
if (is_empty())
return;
auto& screen = Screen::closest_to_location(position);
auto& window = ensure_menu_window(position);
Gfx::IntPoint adjusted_pos = position;
if (window.rect().right() > screen.width())
adjusted_pos = adjusted_pos.translated(-(window.rect().right() - screen.width()) - 1, 0);
if (window.rect().bottom() > screen.height())
adjusted_pos = adjusted_pos.translated(0, -window.rect().height() - button_rect.height() + 1);
window.set_rect(adjusted_pos.x(), adjusted_pos.y(), window.rect().width(), window.rect().height());
window.move_to(adjusted_pos);
MenuManager::the().open_menu(*this, true);
WindowManager::the().did_popup_a_menu({});
}
void Menu::popup(Gfx::IntPoint const& position)
{
do_popup(position, true);

View file

@ -115,6 +115,7 @@ public:
void popup(Gfx::IntPoint const&);
void do_popup(Gfx::IntPoint const&, bool make_input, bool as_submenu = false);
void open_button_menu(Gfx::IntPoint const& position, Gfx::IntRect const& button_rect);
bool is_menu_ancestor_of(Menu const&) const;

View file

@ -100,7 +100,7 @@ endpoint WindowServer
set_fullscreen(i32 window_id, bool fullscreen) =|
set_frameless(i32 window_id, bool frameless) =|
set_forced_shadow(i32 window_id, bool shadow) =|
popup_menu(i32 menu_id, Gfx::IntPoint screen_position) =|
popup_menu(i32 menu_id, Gfx::IntPoint screen_position, Gfx::IntRect button_rect) =|
dismiss_menu(i32 menu_id) =|
set_wallpaper(Gfx::ShareableBitmap wallpaper_bitmap) => (bool success)