summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2022-01-24 14:22:02 -0500
committerAndreas Kling <kling@serenityos.org>2022-01-26 23:19:54 +0100
commitf77ac3a73cfc07fc6fda5f9493f4a1ac41426449 (patch)
treebc9e0f766d43d7515828d68a1b5a963070573df5 /Userland/Libraries/LibGfx
parentaefe3ef539dbdddcbe5d3a74ffb7c2b53b469027 (diff)
downloadserenity-f77ac3a73cfc07fc6fda5f9493f4a1ac41426449.zip
LibGUI: Allow Buttons to set themselves as default
Several apps were implementing this behavior ad hoc. This provides a standard API as well as a comfy visual cue for default return key behavior.
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r--Userland/Libraries/LibGfx/ClassicStylePainter.cpp8
-rw-r--r--Userland/Libraries/LibGfx/ClassicStylePainter.h2
-rw-r--r--Userland/Libraries/LibGfx/StylePainter.cpp4
-rw-r--r--Userland/Libraries/LibGfx/StylePainter.h4
4 files changed, 9 insertions, 9 deletions
diff --git a/Userland/Libraries/LibGfx/ClassicStylePainter.cpp b/Userland/Libraries/LibGfx/ClassicStylePainter.cpp
index 28a03ee78d..557e784acc 100644
--- a/Userland/Libraries/LibGfx/ClassicStylePainter.cpp
+++ b/Userland/Libraries/LibGfx/ClassicStylePainter.cpp
@@ -93,7 +93,7 @@ void ClassicStylePainter::paint_tab_button(Painter& painter, IntRect const& rect
}
}
-static void paint_button_new(Painter& painter, IntRect const& a_rect, Palette const& palette, ButtonStyle style, bool pressed, bool checked, bool hovered, bool enabled, bool focused)
+static void paint_button_new(Painter& painter, IntRect const& a_rect, Palette const& palette, ButtonStyle style, bool pressed, bool checked, bool hovered, bool enabled, bool focused, bool default_button)
{
Color button_color = palette.button();
Color highlight_color = palette.threed_highlight();
@@ -111,7 +111,7 @@ static void paint_button_new(Painter& painter, IntRect const& a_rect, Palette co
PainterStateSaver saver(painter);
auto rect = a_rect;
- if (focused) {
+ if (focused || default_button) {
painter.draw_rect(a_rect, palette.threed_shadow2());
rect.shrink(2, 2);
}
@@ -165,10 +165,10 @@ static void paint_button_new(Painter& painter, IntRect const& a_rect, Palette co
}
}
-void ClassicStylePainter::paint_button(Painter& painter, IntRect const& rect, Palette const& palette, ButtonStyle button_style, bool pressed, bool hovered, bool checked, bool enabled, bool focused)
+void ClassicStylePainter::paint_button(Painter& painter, IntRect const& rect, Palette const& palette, ButtonStyle button_style, bool pressed, bool hovered, bool checked, bool enabled, bool focused, bool default_button)
{
if (button_style == ButtonStyle::Normal || button_style == ButtonStyle::ThickCap)
- return paint_button_new(painter, rect, palette, button_style, pressed, checked, hovered, enabled, focused);
+ return paint_button_new(painter, rect, palette, button_style, pressed, checked, hovered, enabled, focused, default_button);
if (button_style == ButtonStyle::Coolbar && !enabled)
return;
diff --git a/Userland/Libraries/LibGfx/ClassicStylePainter.h b/Userland/Libraries/LibGfx/ClassicStylePainter.h
index d8ce836370..669f73b5da 100644
--- a/Userland/Libraries/LibGfx/ClassicStylePainter.h
+++ b/Userland/Libraries/LibGfx/ClassicStylePainter.h
@@ -15,7 +15,7 @@ namespace Gfx {
class ClassicStylePainter : public BaseStylePainter {
public:
- virtual void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false) override;
+ virtual void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false, bool default_button = false) override;
virtual void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, bool top, bool in_active_window) override;
virtual void paint_frame(Painter&, IntRect const&, Palette const&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false) override;
virtual void paint_window_frame(Painter&, IntRect const&, Palette const&) override;
diff --git a/Userland/Libraries/LibGfx/StylePainter.cpp b/Userland/Libraries/LibGfx/StylePainter.cpp
index affe70540b..286fc03684 100644
--- a/Userland/Libraries/LibGfx/StylePainter.cpp
+++ b/Userland/Libraries/LibGfx/StylePainter.cpp
@@ -23,9 +23,9 @@ void StylePainter::paint_tab_button(Painter& painter, const IntRect& rect, const
current().paint_tab_button(painter, rect, palette, active, hovered, enabled, top, in_active_window);
}
-void StylePainter::paint_button(Painter& painter, const IntRect& rect, const Palette& palette, ButtonStyle button_style, bool pressed, bool hovered, bool checked, bool enabled, bool focused)
+void StylePainter::paint_button(Painter& painter, const IntRect& rect, const Palette& palette, ButtonStyle button_style, bool pressed, bool hovered, bool checked, bool enabled, bool focused, bool default_button)
{
- current().paint_button(painter, rect, palette, button_style, pressed, hovered, checked, enabled, focused);
+ current().paint_button(painter, rect, palette, button_style, pressed, hovered, checked, enabled, focused, default_button);
}
void StylePainter::paint_frame(Painter& painter, const IntRect& rect, const Palette& palette, FrameShape shape, FrameShadow shadow, int thickness, bool skip_vertical_lines)
diff --git a/Userland/Libraries/LibGfx/StylePainter.h b/Userland/Libraries/LibGfx/StylePainter.h
index c3d3d34ad8..a386e63587 100644
--- a/Userland/Libraries/LibGfx/StylePainter.h
+++ b/Userland/Libraries/LibGfx/StylePainter.h
@@ -37,7 +37,7 @@ class BaseStylePainter {
public:
virtual ~BaseStylePainter() { }
- virtual void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false) = 0;
+ virtual void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false, bool default_button = false) = 0;
virtual void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, bool top, bool in_active_window) = 0;
virtual void paint_frame(Painter&, IntRect const&, Palette const&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false) = 0;
virtual void paint_window_frame(Painter&, IntRect const&, Palette const&) = 0;
@@ -56,7 +56,7 @@ public:
static BaseStylePainter& current();
// FIXME: These are here for API compatibility, we should probably remove them and move BaseStylePainter into here
- static void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false);
+ static void paint_button(Painter&, IntRect const&, Palette const&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false, bool default_button = false);
static void paint_tab_button(Painter&, IntRect const&, Palette const&, bool active, bool hovered, bool enabled, bool top, bool in_active_window);
static void paint_frame(Painter&, IntRect const&, Palette const&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false);
static void paint_window_frame(Painter&, IntRect const&, Palette const&);