mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 10:01:13 +09:00
LibGUI: Share code for text painting in GAbstractButton.
This gives all the GAbstractButton a consistent disabled appearance.
This commit is contained in:
parent
149b7f92a7
commit
c62be7bb2b
Notes:
sideshowbarker
2024-07-19 13:58:01 +09:00
Author: https://github.com/awesomekling
Commit: c62be7bb2b
5 changed files with 31 additions and 30 deletions
|
@ -1,4 +1,5 @@
|
|||
#include <LibGUI/GAbstractButton.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
|
||||
GAbstractButton::GAbstractButton(GWidget* parent)
|
||||
: GWidget(parent)
|
||||
|
@ -106,3 +107,22 @@ void GAbstractButton::keydown_event(GKeyEvent& event)
|
|||
click();
|
||||
GWidget::keydown_event(event);
|
||||
}
|
||||
|
||||
void GAbstractButton::paint_text(GPainter& painter, const Rect& rect, const Font& font, TextAlignment text_alignment)
|
||||
{
|
||||
if (!is_enabled()) {
|
||||
painter.draw_text(rect.translated(1, 1), text(), font, text_alignment, Color::White, TextElision::Right);
|
||||
painter.draw_text(rect, text(), font, text_alignment, Color::from_rgb(0x808080), TextElision::Right);
|
||||
return;
|
||||
}
|
||||
|
||||
if (text().is_empty())
|
||||
return;
|
||||
painter.draw_text(rect, text(), font, text_alignment, foreground_color(), TextElision::Right);
|
||||
if (is_focused()) {
|
||||
Rect focus_rect = { 0, 0, font.width(text()), font.glyph_height() };
|
||||
focus_rect.inflate(6, 4);
|
||||
focus_rect.center_within(rect);
|
||||
painter.draw_rect(focus_rect, Color(140, 140, 140));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue