summaryrefslogtreecommitdiff
path: root/LibGUI/GButton.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-04 15:20:02 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-04 15:20:02 +0200
commit82b02ed82beeac8f0173f3fb4d7d7286c437c381 (patch)
treeec256f5facc0070abc7ee6d80c21236ffe1b7138 /LibGUI/GButton.cpp
parent4533539e8a1bed378527b50f11e0fb197b223466 (diff)
downloadserenity-82b02ed82beeac8f0173f3fb4d7d7286c437c381.zip
LibGUI: Use TextElision::Right for GButton captions.
Diffstat (limited to 'LibGUI/GButton.cpp')
-rw-r--r--LibGUI/GButton.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/LibGUI/GButton.cpp b/LibGUI/GButton.cpp
index 7be6cc824a..af2edfe215 100644
--- a/LibGUI/GButton.cpp
+++ b/LibGUI/GButton.cpp
@@ -1,6 +1,7 @@
#include "GButton.h"
#include <LibGUI/GPainter.h>
#include <SharedGraphics/StylePainter.h>
+#include <AK/StringBuilder.h>
//#define GBUTTON_DEBUG
@@ -36,18 +37,19 @@ void GButton::paint_event(GPaintEvent& event)
StylePainter::paint_button(painter, rect(), m_button_style, m_being_pressed, m_hovered, m_checkable && m_checked);
- if (!caption().is_empty() || m_icon) {
- auto content_rect = rect().shrunken(10, 2);
- auto icon_location = m_icon ? content_rect.center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2)) : Point();
- if (m_being_pressed) {
- content_rect.move_by(1, 1);
- icon_location.move_by(1, 1);
- }
- if (m_icon)
- painter.blit(icon_location, *m_icon, m_icon->rect());
- auto& font = (m_checkable && m_checked) ? Font::default_bold_font() : this->font();
- painter.draw_text(content_rect, caption(), font, text_alignment(), Color::Black);
+ if (m_caption.is_empty() && !m_icon)
+ return;
+
+ auto content_rect = rect().shrunken(10, 2);
+ auto icon_location = m_icon ? content_rect.center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2)) : Point();
+ if (m_being_pressed) {
+ content_rect.move_by(1, 1);
+ icon_location.move_by(1, 1);
}
+ if (m_icon)
+ painter.blit(icon_location, *m_icon, m_icon->rect());
+ auto& font = (m_checkable && m_checked) ? Font::default_bold_font() : this->font();
+ painter.draw_text(content_rect, m_caption, font, text_alignment(), Color::Black, TextElision::Right);
}
void GButton::mousemove_event(GMouseEvent& event)