From 8b12d200ba9104ab0e788b27c6a50fdde8798a23 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 25 Oct 2020 15:22:21 +0100 Subject: [PATCH] LibGUI: Raise toolbar button icons slightly when hovered :^) This make buttons look extra clickable when hovered by lifting up their icons (-1,-1) and painting a little icon-shaped shadow under them. Partially inspired by the Office XP toolbars, although we don't go all the way with the faux-hyperlink stuff that was all the rage back then. --- Libraries/LibGUI/Button.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Libraries/LibGUI/Button.cpp b/Libraries/LibGUI/Button.cpp index 38ae156937..1ff8f18194 100644 --- a/Libraries/LibGUI/Button.cpp +++ b/Libraries/LibGUI/Button.cpp @@ -60,8 +60,17 @@ void Button::paint_event(PaintEvent& event) auto icon_location = m_icon ? content_rect.center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2)) : Gfx::IntPoint(); if (m_icon && !text().is_empty()) icon_location.set_x(content_rect.x()); + if (is_being_pressed() || is_checked()) painter.translate(1, 1); + else if (m_icon && is_enabled() && is_hovered() && button_style() == Gfx::ButtonStyle::CoolBar) { + auto shadow_color = palette().threed_shadow1(); + painter.blit_filtered(icon_location, *m_icon, m_icon->rect(), [&shadow_color](auto) { + return shadow_color; + }); + icon_location.move_by(-1, -1); + } + if (m_icon) { if (is_enabled()) { if (is_hovered())