summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorForLoveOfCats <floc@unpromptedtirade.com>2022-02-06 13:40:07 -0500
committerLinus Groh <mail@linusgroh.de>2022-03-03 22:06:14 +0100
commite8f6a650ad77fdbdbcebfd6e6d8935ba49eb7b09 (patch)
treeab3c5c5793e15b06c0877fdbf55ccd1bd8ab8631 /Userland
parent1fd16232d30dcd6852d54808ec3fbe7070d46281 (diff)
downloadserenity-e8f6a650ad77fdbdbcebfd6e6d8935ba49eb7b09.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/Button.cpp8
-rw-r--r--Userland/Libraries/LibGUI/Button.h4
2 files changed, 11 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/Button.cpp b/Userland/Libraries/LibGUI/Button.cpp
index 0eb7ac9042..e75b041364 100644
--- a/Userland/Libraries/LibGUI/Button.cpp
+++ b/Userland/Libraries/LibGUI/Button.cpp
@@ -55,7 +55,7 @@ void Button::paint_event(PaintEvent& event)
Painter painter(*this);
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());
@@ -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();
+}
+
}
diff --git a/Userland/Libraries/LibGUI/Button.h b/Userland/Libraries/LibGUI/Button.h
index 20472c90b4..5cb06ef25d 100644
--- a/Userland/Libraries/LibGUI/Button.h
+++ b/Userland/Libraries/LibGUI/Button.h
@@ -53,6 +53,9 @@ public:
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:
explicit Button(String text = {});
virtual void mousedown_event(MouseEvent&) override;
@@ -67,6 +70,7 @@ private:
WeakPtr<Action> m_action;
int m_icon_spacing { 4 };
bool m_another_button_has_focus { false };
+ bool m_mimic_pressed { false };
};
}