diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2020-08-15 10:27:54 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-16 19:39:46 +0200 |
commit | a5fefbf8408597752f5ecb513f07a8e537e1bb33 (patch) | |
tree | c451bd7483c9f446f13044c8169f5cd013e6b025 /Libraries/LibGUI | |
parent | 15cb4207fc5797f7a9027d788bf962411a1200bd (diff) | |
download | serenity-a5fefbf8408597752f5ecb513f07a8e537e1bb33.zip |
LibGUI: Resize TextEditor ruler based on needed space
Ruler width is now calculated according to the number of digits
in the line count.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r-- | Libraries/LibGUI/TextEditor.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index 31c6c60e8f..fd63e29815 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -42,6 +42,7 @@ #include <LibGfx/Palette.h> #include <ctype.h> #include <fcntl.h> +#include <math.h> #include <stdio.h> #include <unistd.h> @@ -328,8 +329,8 @@ int TextEditor::ruler_width() const { if (!m_ruler_visible) return 0; - // FIXME: Resize based on needed space. - return 5 * font().glyph_width('x') + 4; + int line_count_digits = static_cast<int>(log10(line_count())) + 1; + return line_count() < 10 ? (line_count_digits + 1) * font().glyph_width('x') + 4 : line_count_digits * font().glyph_width('x') + 4; } Gfx::IntRect TextEditor::ruler_content_rect(size_t line_index) const |