mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:48:10 +00:00
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'
This commit is contained in:
parent
35b06ef1eb
commit
07910c12e3
1 changed files with 3 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue