From 4abffa4dbe067847335a1fcdcc5d18200e322830 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 10 Apr 2019 01:37:08 +0200 Subject: [PATCH] GSpinBox: Put nice little arrow glyphs on the buttons. --- Base/res/fonts/Katica10.font | Bin 10574 -> 10574 bytes LibGUI/GSpinBox.cpp | 6 +++--- SharedGraphics/Painter.cpp | 36 +++++++++++++++++++---------------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Base/res/fonts/Katica10.font b/Base/res/fonts/Katica10.font index c677abb3d98792a778bc31937a00b19da071c34f..71ca82d7ca7c64be33aee05cd0fa7cc42a8103da 100644 GIT binary patch delta 46 ucmX>XbS`MaF*RNe1_lNh1_lN@1_p-uiHh>P^-vB-kYl2v@Ma-(8zunqSqOOm delta 15 WcmX>XbS`MaF|~;XKAVNqZI}Q%;|3G} diff --git a/LibGUI/GSpinBox.cpp b/LibGUI/GSpinBox.cpp index 1f00d1bbe9..67ef6daf03 100644 --- a/LibGUI/GSpinBox.cpp +++ b/LibGUI/GSpinBox.cpp @@ -15,10 +15,10 @@ GSpinBox::GSpinBox(GWidget* parent) m_editor->set_text(String::format("%d", m_value)); }; m_increment_button = new GButton(this); - m_increment_button->set_caption("+"); + m_increment_button->set_caption("\xf6"); m_increment_button->on_click = [this] (GButton&) { set_value(m_value + 1); }; m_decrement_button = new GButton(this); - m_decrement_button->set_caption("-"); + m_decrement_button->set_caption("\xf7"); m_decrement_button->on_click = [this] (GButton&) { set_value(m_value - 1); }; } @@ -64,7 +64,7 @@ void GSpinBox::set_range(int min, int max) void GSpinBox::resize_event(GResizeEvent& event) { int button_height = event.size().height() / 2; - int button_width = 16; + int button_width = 15; m_increment_button->set_relative_rect(width() - button_width, 0, button_width, button_height); m_decrement_button->set_relative_rect(width() - button_width, button_height, button_width, button_height); m_editor->set_relative_rect(0, 0, width() - button_width, height()); diff --git a/SharedGraphics/Painter.cpp b/SharedGraphics/Painter.cpp index c42c14be30..8e51736c45 100644 --- a/SharedGraphics/Painter.cpp +++ b/SharedGraphics/Painter.cpp @@ -6,6 +6,7 @@ #include #include #include +#include Painter::Painter(GraphicsBitmap& bitmap) : m_target(bitmap) @@ -348,27 +349,30 @@ void Painter::draw_text(const Rect& rect, const char* text, int length, const Fo { String elided_text; if (elision == TextElision::Right) { + int text_width = font.width(text, length); if (font.width(text, length) > rect.width()) { int glyph_spacing = font.glyph_spacing(); int new_length = 0; int new_width = font.width("..."); - for (int i = 0; i < length; ++i) { - int glyph_width = font.glyph_width(text[i]); - // NOTE: Glyph spacing should not be added after the last glyph on the line, - // but since we are here because the last glyph does not actually fit on the line, - // we don't have to worry about spacing. - int width_with_this_glyph_included = new_width + glyph_width + glyph_spacing; - if (width_with_this_glyph_included > rect.width()) - break; - ++new_length; - new_width += glyph_width + glyph_spacing; + if (new_width < text_width) { + for (int i = 0; i < length; ++i) { + int glyph_width = font.glyph_width(text[i]); + // NOTE: Glyph spacing should not be added after the last glyph on the line, + // but since we are here because the last glyph does not actually fit on the line, + // we don't have to worry about spacing. + int width_with_this_glyph_included = new_width + glyph_width + glyph_spacing; + if (width_with_this_glyph_included > rect.width()) + break; + ++new_length; + new_width += glyph_width + glyph_spacing; + } + StringBuilder builder; + builder.append(text, new_length); + builder.append("..."); + elided_text = builder.to_string(); + text = elided_text.characters(); + length = elided_text.length(); } - StringBuilder builder; - builder.append(text, new_length); - builder.append("..."); - elided_text = builder.to_string(); - text = elided_text.characters(); - length = elided_text.length(); } }