1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 17:55:08 +00:00

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.
This commit is contained in:
Andreas Kling 2020-10-25 15:22:21 +01:00
parent 3ba6dceee3
commit 8b12d200ba

View file

@ -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())