summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2022-02-24 08:48:17 -0500
committerAndreas Kling <kling@serenityos.org>2022-02-24 18:09:22 +0100
commit07910c12e316a20297ce56f9fc333a42755f3005 (patch)
tree12b8e51b5be2580111e53292a94e227429da5b20 /Userland
parent35b06ef1eb1b503f9f4850ba449719f8f8889b38 (diff)
downloadserenity-07910c12e316a20297ce56f9fc333a42755f3005.zip
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'
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp5
1 files 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<int>(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