mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 14:47:34 +00:00
LibGUI: Let Buttons set their menu popup position
The previous ButtonStyle::Tray conditional was a hack for Statusbars.
This commit is contained in:
parent
1084eaea0b
commit
58955d37cc
3 changed files with 27 additions and 3 deletions
|
@ -215,10 +215,22 @@ void Button::set_menu(RefPtr<GUI::Menu> menu)
|
||||||
void Button::mousedown_event(MouseEvent& event)
|
void Button::mousedown_event(MouseEvent& event)
|
||||||
{
|
{
|
||||||
if (m_menu) {
|
if (m_menu) {
|
||||||
if (button_style() == Gfx::ButtonStyle::Tray)
|
switch (m_menu_position) {
|
||||||
m_menu->popup(screen_relative_rect().top_right());
|
case TopLeft:
|
||||||
else
|
|
||||||
m_menu->popup(screen_relative_rect().top_left());
|
m_menu->popup(screen_relative_rect().top_left());
|
||||||
|
break;
|
||||||
|
case TopRight:
|
||||||
|
m_menu->popup(screen_relative_rect().top_right());
|
||||||
|
break;
|
||||||
|
case BottomLeft:
|
||||||
|
m_menu->popup(screen_relative_rect().bottom_left());
|
||||||
|
break;
|
||||||
|
case BottomRight:
|
||||||
|
m_menu->popup(screen_relative_rect().bottom_right());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
update();
|
update();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,13 @@ class Button : public AbstractButton {
|
||||||
C_OBJECT(Button);
|
C_OBJECT(Button);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum MenuPosition {
|
||||||
|
TopLeft,
|
||||||
|
TopRight,
|
||||||
|
BottomLeft,
|
||||||
|
BottomRight
|
||||||
|
};
|
||||||
|
|
||||||
virtual ~Button() override;
|
virtual ~Button() override;
|
||||||
|
|
||||||
void set_icon(RefPtr<Gfx::Bitmap>);
|
void set_icon(RefPtr<Gfx::Bitmap>);
|
||||||
|
@ -59,6 +66,9 @@ public:
|
||||||
void set_mimic_pressed(bool mimic_pressed);
|
void set_mimic_pressed(bool mimic_pressed);
|
||||||
bool is_mimic_pressed() const { return m_mimic_pressed; };
|
bool is_mimic_pressed() const { return m_mimic_pressed; };
|
||||||
|
|
||||||
|
MenuPosition menu_position() const { return m_menu_position; }
|
||||||
|
void set_menu_position(MenuPosition position) { m_menu_position = position; }
|
||||||
|
|
||||||
virtual Optional<UISize> calculated_min_size() const override;
|
virtual Optional<UISize> calculated_min_size() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -78,6 +88,7 @@ private:
|
||||||
int m_icon_spacing { 4 };
|
int m_icon_spacing { 4 };
|
||||||
bool m_another_button_has_focus { false };
|
bool m_another_button_has_focus { false };
|
||||||
bool m_mimic_pressed { false };
|
bool m_mimic_pressed { false };
|
||||||
|
MenuPosition m_menu_position { MenuPosition::TopLeft };
|
||||||
};
|
};
|
||||||
|
|
||||||
class DialogButton final : public Button {
|
class DialogButton final : public Button {
|
||||||
|
|
|
@ -133,6 +133,7 @@ Statusbar::Segment::Segment()
|
||||||
set_focus_policy(GUI::FocusPolicy::NoFocus);
|
set_focus_policy(GUI::FocusPolicy::NoFocus);
|
||||||
set_button_style(Gfx::ButtonStyle::Tray);
|
set_button_style(Gfx::ButtonStyle::Tray);
|
||||||
set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||||
|
set_menu_position(GUI::Button::MenuPosition::TopRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Statusbar::Segment::paint_event(PaintEvent& event)
|
void Statusbar::Segment::paint_event(PaintEvent& event)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue