1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

GButton: Draw disabled buttons with grayed-out text.

Based on a patch from "pd" (thanks!)
This commit is contained in:
Andreas Kling 2019-05-02 13:57:35 +02:00
parent 13b8c7eab8
commit 4508287cb2
2 changed files with 10 additions and 5 deletions

View file

@ -60,7 +60,12 @@ void GButton::paint_event(GPaintEvent& event)
content_rect.move_by(m_icon->width() + 4, 0);
content_rect.set_width(content_rect.width() - m_icon->width() - 4);
}
if (is_enabled())
painter.draw_text(content_rect, m_caption, font, text_alignment(), foreground_color(), TextElision::Right);
else {
painter.draw_text(content_rect.translated(1, 1), m_caption, font, text_alignment(), Color::White, TextElision::Right);
painter.draw_text(content_rect, m_caption, font, text_alignment(), Color::from_rgb(0x808080), TextElision::Right);
}
}
void GButton::mousemove_event(GMouseEvent& event)

View file

@ -1,19 +1,19 @@
#include <SharedGraphics/StylePainter.h>
#include <LibGUI/GPainter.h>
static void paint_button_new(Painter& painter, const Rect& rect, bool pressed, bool checked, bool hovered)
static void paint_button_new(Painter& painter, const Rect& rect, bool pressed, bool checked, bool hovered, bool enabled)
{
Color button_color = Color::from_rgb(0xc0c0c0);
Color highlight_color2 = Color::from_rgb(0xdfdfdf);
Color shadow_color1 = Color::from_rgb(0x808080);
Color shadow_color2 = Color::from_rgb(0x404040);
if (checked) {
if (checked && enabled) {
if (hovered)
button_color = Color::from_rgb(0xe3dfdb);
else
button_color = Color::from_rgb(0xd6d2ce);
} else if (hovered)
} else if (hovered && enabled)
button_color = Color::from_rgb(0xd4d4d4);
PainterStateSaver saver(painter);
@ -56,7 +56,7 @@ static void paint_button_new(Painter& painter, const Rect& rect, bool pressed, b
void StylePainter::paint_button(Painter& painter, const Rect& rect, ButtonStyle button_style, bool pressed, bool hovered, bool checked, bool enabled)
{
if (button_style == ButtonStyle::Normal)
return paint_button_new(painter, rect, pressed, checked, hovered);
return paint_button_new(painter, rect, pressed, checked, hovered, enabled);
Color button_color = checked ? Color::from_rgb(0xd6d2ce) : Color::LightGray;
Color highlight_color = Color::White;