diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-02 21:36:01 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-02 23:05:04 +0100 |
commit | 8e8e8c801ce97b3f519c4a123e448f2cceb278a2 (patch) | |
tree | 8500af7f4a86a7a7a1ea8fc07c4ca93dcb32d080 | |
parent | 2719d6d502bf64a5d4c8f60256312981630f0487 (diff) | |
download | serenity-8e8e8c801ce97b3f519c4a123e448f2cceb278a2.zip |
LibGUI: Fix broken TreeView rendering with more than two columns
The computation of the tree column x offset was not taking padding into
account. This patch fixes that and collects the logic in a helper.
-rw-r--r-- | Libraries/LibGUI/TreeView.cpp | 30 | ||||
-rw-r--r-- | Libraries/LibGUI/TreeView.h | 1 |
2 files changed, 18 insertions, 13 deletions
diff --git a/Libraries/LibGUI/TreeView.cpp b/Libraries/LibGUI/TreeView.cpp index 9740ea6534..bbc6ef97e5 100644 --- a/Libraries/LibGUI/TreeView.cpp +++ b/Libraries/LibGUI/TreeView.cpp @@ -125,13 +125,7 @@ void TreeView::traverse_in_paint_order(Callback callback) const auto& model = *this->model(); int indent_level = 1; int y_offset = 0; - int tree_column = model.tree_column(); - int tree_column_x_offset = 0; - - for (int i = 0; i < tree_column; ++i) { - if (!is_column_hidden(i)) - tree_column_x_offset += column_width(i); - } + int tree_column_x_offset = this->tree_column_x_offset(); Function<IterationDecision(const ModelIndex&)> traverse_index = [&](const ModelIndex& index) { int row_count_at_index = model.row_count(index); @@ -145,7 +139,7 @@ void TreeView::traverse_in_paint_order(Callback callback) const }; Gfx::Rect toggle_rect; if (row_count_at_index > 0) { - int toggle_x = tree_column_x_offset + horizontal_padding() + indent_width_in_pixels() * indent_level - icon_size() / 2 - 4; + int toggle_x = tree_column_x_offset + horizontal_padding() + (indent_width_in_pixels() * indent_level) - (icon_size() / 2) - 4; toggle_rect = { toggle_x, rect.y(), toggle_size(), toggle_size() }; toggle_rect.center_vertically_within(rect); } @@ -190,11 +184,8 @@ void TreeView::paint_event(PaintEvent& event) auto visible_content_rect = this->visible_content_rect(); int tree_column = model.tree_column(); - int tree_column_x_offset = 0; - for (int i = 0; i < tree_column; ++i) { - if (!is_column_hidden(i)) - tree_column_x_offset += column_width(i); - } + int tree_column_x_offset = this->tree_column_x_offset(); + int y_offset = header_height(); int painted_row_index = 0; @@ -517,4 +508,17 @@ void TreeView::update_column_sizes() column_data.has_initialized_width = true; } +int TreeView::tree_column_x_offset() const +{ + int tree_column = model()->tree_column(); + int offset = 0; + for (int i = 0; i < tree_column; ++i) { + if (!is_column_hidden(i)) { + offset += column_width(i); + offset += horizontal_padding(); + } + } + return offset; +} + } diff --git a/Libraries/LibGUI/TreeView.h b/Libraries/LibGUI/TreeView.h index e5c94edcb9..f5c731cfc6 100644 --- a/Libraries/LibGUI/TreeView.h +++ b/Libraries/LibGUI/TreeView.h @@ -59,6 +59,7 @@ private: int icon_spacing() const { return 2; } int toggle_size() const { return 9; } int text_padding() const { return 2; } + int tree_column_x_offset() const; virtual void toggle_index(const ModelIndex&) override; virtual void update_column_sizes() override; |