mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +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
Notes:
sideshowbarker
2024-07-19 08:55:26 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8e8e8c801ce
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();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue