mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:47:34 +00:00
WindowServer: Rework and simplify Menu event handling
The menu manager will now send events directly to the current menu. Previously if a menu was opened it would always be set as the current menu. Now when opening a menu you can optionally say that you do not want to have it as the current menu. One scenerio when this happens is when a menu is popped up as part of a preview, for example, when hovering over a menu item that is a submenu. Sending the event to the current menu simplifies things and solves a few inconsistencies in bevhaviour (such as hovering over a submenu, but key events not being sent to the submenu).
This commit is contained in:
parent
b1c83e5a64
commit
d5c40899cb
4 changed files with 80 additions and 77 deletions
|
@ -104,13 +104,20 @@ public:
|
|||
void redraw();
|
||||
|
||||
MenuItem* hovered_item() const;
|
||||
|
||||
void set_hovered_item(int index)
|
||||
{
|
||||
m_hovered_item_index = index;
|
||||
update_for_new_hovered_item();
|
||||
}
|
||||
|
||||
void clear_hovered_item();
|
||||
|
||||
Function<void(MenuItem&)> on_item_activation;
|
||||
|
||||
void close();
|
||||
|
||||
void popup(const Gfx::Point&, bool is_submenu = false);
|
||||
void popup(const Gfx::Point&);
|
||||
|
||||
bool is_menu_ancestor_of(const Menu&) const;
|
||||
|
||||
|
@ -119,6 +126,9 @@ public:
|
|||
bool is_scrollable() const { return m_scrollable; }
|
||||
int scroll_offset() const { return m_scroll_offset; }
|
||||
|
||||
void descend_into_submenu_at_hovered_item();
|
||||
void open_hovered_item();
|
||||
|
||||
private:
|
||||
virtual void event(Core::Event&) override;
|
||||
|
||||
|
@ -130,9 +140,7 @@ private:
|
|||
int item_index_at(const Gfx::Point&);
|
||||
int padding_between_text_and_shortcut() const { return 50; }
|
||||
void did_activate(MenuItem&);
|
||||
void open_hovered_item();
|
||||
void update_for_new_hovered_item();
|
||||
void descend_into_submenu_at_hovered_item();
|
||||
|
||||
ClientConnection* m_client { nullptr };
|
||||
int m_menu_id { 0 };
|
||||
|
@ -148,7 +156,6 @@ private:
|
|||
Gfx::Point m_last_position_in_hover;
|
||||
int m_theme_index_at_last_paint { -1 };
|
||||
int m_hovered_item_index { -1 };
|
||||
bool m_in_submenu { false };
|
||||
|
||||
bool m_scrollable { false };
|
||||
int m_scroll_offset { 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue