mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
LibGUI: Add mimic_pressed
to Button to signify being virtually clicked
A button that is "mimic pressed" is drawn like it is being clicked when it isn't necessarily actually being pressed. This lets programs which keyboard based input that mirrors a button to show visual feedback when a key is pressed.
This commit is contained in:
parent
1fd16232d3
commit
e8f6a650ad
2 changed files with 11 additions and 1 deletions
|
@ -55,7 +55,7 @@ void Button::paint_event(PaintEvent& event)
|
||||||
Painter painter(*this);
|
Painter painter(*this);
|
||||||
painter.add_clip_rect(event.rect());
|
painter.add_clip_rect(event.rect());
|
||||||
|
|
||||||
bool paint_pressed = is_being_pressed() || (m_menu && m_menu->is_visible());
|
bool paint_pressed = is_being_pressed() || is_mimic_pressed() || (m_menu && m_menu->is_visible());
|
||||||
|
|
||||||
Gfx::StylePainter::paint_button(painter, rect(), palette(), m_button_style, paint_pressed, is_hovered(), is_checked(), is_enabled(), is_focused(), is_default() && !another_button_has_focus());
|
Gfx::StylePainter::paint_button(painter, rect(), palette(), m_button_style, paint_pressed, is_hovered(), is_checked(), is_enabled(), is_focused(), is_default() && !another_button_has_focus());
|
||||||
|
|
||||||
|
@ -222,4 +222,10 @@ void Button::set_default(bool default_button)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Button::set_mimic_pressed(bool mimic_pressed)
|
||||||
|
{
|
||||||
|
m_mimic_pressed = mimic_pressed;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,9 @@ public:
|
||||||
|
|
||||||
bool another_button_has_focus() const { return m_another_button_has_focus; }
|
bool another_button_has_focus() const { return m_another_button_has_focus; }
|
||||||
|
|
||||||
|
void set_mimic_pressed(bool mimic_pressed);
|
||||||
|
bool is_mimic_pressed() const { return m_mimic_pressed; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Button(String text = {});
|
explicit Button(String text = {});
|
||||||
virtual void mousedown_event(MouseEvent&) override;
|
virtual void mousedown_event(MouseEvent&) override;
|
||||||
|
@ -67,6 +70,7 @@ private:
|
||||||
WeakPtr<Action> m_action;
|
WeakPtr<Action> m_action;
|
||||||
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 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue