From b478c5f86c14f27103161a103d905917c0980c6e Mon Sep 17 00:00:00 2001 From: DexesTTP Date: Thu, 7 May 2020 16:42:34 +0200 Subject: [PATCH] LibGUI: Properly draw the background of the selected TreeView line In the TreeView, the background of the selected line (or any background, really) was only drawn until the frame's width. When the text was larger than the frame's width, this caused the end of the text to be displayed without background, making it unreadable if it was white (which is the default text color for selected lines). To compute the background width, we have a choice between : - The inner frame width (the current behaviour which causes the issue) - The total width of all columns (which causes the background to end early if the columns don't cover the full width) The new algorithm uses the biggest of the above values, which gives us exactly what we want in all cases :^) Fixes #2134 --- Libraries/LibGUI/TreeView.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Libraries/LibGUI/TreeView.cpp b/Libraries/LibGUI/TreeView.cpp index fd23ae522e..1af3799c32 100644 --- a/Libraries/LibGUI/TreeView.cpp +++ b/Libraries/LibGUI/TreeView.cpp @@ -224,7 +224,17 @@ void TreeView::paint_event(PaintEvent& event) } } - Gfx::Rect row_rect { 0, rect.y(), frame_inner_rect().width(), rect.height() }; + int row_width = 0; + for (int column_index = 0; column_index < model.column_count(); ++column_index) { + if (is_column_hidden(column_index)) + continue; + row_width += this->column_width(column_index) + horizontal_padding() * 2; + } + if (frame_inner_rect().width() > row_width) { + row_width = frame_inner_rect().width(); + } + + Gfx::Rect row_rect { 0, rect.y(), row_width, rect.height() }; painter.fill_rect(row_rect, background_color); int x_offset = 0;