From 07910c12e316a20297ce56f9fc333a42755f3005 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Thu, 24 Feb 2022 08:48:17 -0500 Subject: [PATCH] LibGUI: Ensure ruler grows properly when using proportional fonts Ruler needs to take into account spacing between glyphs for proportional fonts as line count increases. This also replaces the less accurate 'x' width estimate for widest character with a '4' --- Userland/Libraries/LibGUI/TextEditor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index a8e2f7aeee..240b0833ee 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -334,8 +334,9 @@ int TextEditor::ruler_width() const if (!m_ruler_visible) return 0; int line_count_digits = static_cast(log10(line_count())) + 1; - constexpr size_t padding = 5; - return line_count() < 10 ? (line_count_digits + 1) * font().glyph_width('x') + padding : line_count_digits * font().glyph_width('x') + padding; + auto padding = 5 + (font().is_fixed_width() ? 1 : (line_count_digits - (line_count() < 10 ? -1 : 0))); + auto widest_numeral = font().bold_variant().glyph_width('4'); + return line_count() < 10 ? (line_count_digits + 1) * widest_numeral + padding : line_count_digits * widest_numeral + padding; } int TextEditor::gutter_width() const