mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:17:46 +00:00
LibGUI: Add ability to assign a menu to a GUI::Button
When a button has a menu, it opens the menu on mousedown and the menu gains input focus immediately. While the menu is open, the button is painted in a pressed state.
This commit is contained in:
parent
9b740f218b
commit
15349a3712
2 changed files with 36 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -63,12 +63,16 @@ public:
|
|||
int icon_spacing() const { return m_icon_spacing; }
|
||||
void set_icon_spacing(int spacing) { m_icon_spacing = spacing; }
|
||||
|
||||
void set_menu(RefPtr<GUI::Menu>);
|
||||
|
||||
protected:
|
||||
explicit Button(String text = {});
|
||||
virtual void mousedown_event(MouseEvent&) override;
|
||||
virtual void paint_event(PaintEvent&) override;
|
||||
|
||||
private:
|
||||
RefPtr<Gfx::Bitmap> m_icon;
|
||||
RefPtr<GUI::Menu> m_menu;
|
||||
Gfx::ButtonStyle m_button_style { Gfx::ButtonStyle::Normal };
|
||||
Gfx::TextAlignment m_text_alignment { Gfx::TextAlignment::Center };
|
||||
WeakPtr<Action> m_action;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue