diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2021-08-07 23:31:29 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-08 01:41:23 +0200 |
commit | ba768eb872b151f8edd436bfc463fb4a6e781822 (patch) | |
tree | ba5fc03fde7f4f3113b66c1a1ee9e6fa53641a91 /Userland/Libraries/LibGUI/TreeView.cpp | |
parent | beda2161d4c9c58982ede679bfe9da1d7391e1df (diff) | |
download | serenity-ba768eb872b151f8edd436bfc463fb4a6e781822.zip |
LibGUI: TreeView tree column text painting adjustments
The text was painted with the assumption that no other column would be
present after the tree column, which won't always be true. Additionally,
some alignment and focus rect-related issues have been fixed.
Diffstat (limited to 'Userland/Libraries/LibGUI/TreeView.cpp')
-rw-r--r-- | Userland/Libraries/LibGUI/TreeView.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGUI/TreeView.cpp b/Userland/Libraries/LibGUI/TreeView.cpp index 8219467f11..dd0c433fe0 100644 --- a/Userland/Libraries/LibGUI/TreeView.cpp +++ b/Userland/Libraries/LibGUI/TreeView.cpp @@ -309,10 +309,12 @@ void TreeView::paint_event(PaintEvent& event) } } else { // It's the tree column! + int indent_width = indent_width_in_pixels() * indent_level; + Gfx::IntRect icon_rect = { rect.x(), rect.y(), icon_size(), icon_size() }; Gfx::IntRect text_rect = { icon_rect.right() + 1 + icon_spacing(), rect.y(), - rect.width() - icon_size() - icon_spacing(), rect.height() + column_width - indent_width - icon_size() - 1 - icon_spacing() + horizontal_padding(), rect.height() }; painter.fill_rect(text_rect, background_color); @@ -328,11 +330,15 @@ void TreeView::paint_event(PaintEvent& event) } } } - draw_item_text(painter, index, is_selected_row, text_rect, index.data().to_string(), font_for_index(index), Gfx::TextAlignment::Center, Gfx::TextElision::None); + draw_item_text(painter, index, is_selected_row, text_rect, index.data().to_string(), font_for_index(index), Gfx::TextAlignment::CenterLeft, Gfx::TextElision::Right); if (is_focused() && index == cursor_index()) { - painter.draw_rect(text_rect, palette().color(background_role())); - painter.draw_focus_rect(text_rect, palette().focus_outline()); + auto focus_rect = text_rect; + focus_rect.set_left(focus_rect.left() - 2); + focus_rect.set_width(focus_rect.width() + 2); + + painter.draw_rect(focus_rect, palette().color(background_role())); + painter.draw_focus_rect(focus_rect, palette().focus_outline()); } auto index_at_indent = index; |