mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
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.
This commit is contained in:
parent
2719d6d502
commit
8e8e8c801c
2 changed files with 18 additions and 13 deletions
|
@ -125,13 +125,7 @@ void TreeView::traverse_in_paint_order(Callback callback) const
|
||||||
auto& model = *this->model();
|
auto& model = *this->model();
|
||||||
int indent_level = 1;
|
int indent_level = 1;
|
||||||
int y_offset = 0;
|
int y_offset = 0;
|
||||||
int tree_column = model.tree_column();
|
int tree_column_x_offset = this->tree_column_x_offset();
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
Function<IterationDecision(const ModelIndex&)> traverse_index = [&](const ModelIndex& index) {
|
Function<IterationDecision(const ModelIndex&)> traverse_index = [&](const ModelIndex& index) {
|
||||||
int row_count_at_index = model.row_count(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;
|
Gfx::Rect toggle_rect;
|
||||||
if (row_count_at_index > 0) {
|
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 = { toggle_x, rect.y(), toggle_size(), toggle_size() };
|
||||||
toggle_rect.center_vertically_within(rect);
|
toggle_rect.center_vertically_within(rect);
|
||||||
}
|
}
|
||||||
|
@ -190,11 +184,8 @@ void TreeView::paint_event(PaintEvent& event)
|
||||||
|
|
||||||
auto visible_content_rect = this->visible_content_rect();
|
auto visible_content_rect = this->visible_content_rect();
|
||||||
int tree_column = model.tree_column();
|
int tree_column = model.tree_column();
|
||||||
int tree_column_x_offset = 0;
|
int tree_column_x_offset = this->tree_column_x_offset();
|
||||||
for (int i = 0; i < tree_column; ++i) {
|
|
||||||
if (!is_column_hidden(i))
|
|
||||||
tree_column_x_offset += column_width(i);
|
|
||||||
}
|
|
||||||
int y_offset = header_height();
|
int y_offset = header_height();
|
||||||
|
|
||||||
int painted_row_index = 0;
|
int painted_row_index = 0;
|
||||||
|
@ -517,4 +508,17 @@ void TreeView::update_column_sizes()
|
||||||
column_data.has_initialized_width = true;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ private:
|
||||||
int icon_spacing() const { return 2; }
|
int icon_spacing() const { return 2; }
|
||||||
int toggle_size() const { return 9; }
|
int toggle_size() const { return 9; }
|
||||||
int text_padding() const { return 2; }
|
int text_padding() const { return 2; }
|
||||||
|
int tree_column_x_offset() const;
|
||||||
virtual void toggle_index(const ModelIndex&) override;
|
virtual void toggle_index(const ModelIndex&) override;
|
||||||
virtual void update_column_sizes() override;
|
virtual void update_column_sizes() override;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue