diff --git a/DevTools/Profiler/main.cpp b/DevTools/Profiler/main.cpp index fce799e725..d0393c2969 100644 --- a/DevTools/Profiler/main.cpp +++ b/DevTools/Profiler/main.cpp @@ -92,6 +92,7 @@ int main(int argc, char** argv) auto& bottom_splitter = main_widget.add(); auto& tree_view = bottom_splitter.add(); + tree_view.set_should_fill_selected_rows(true); tree_view.set_column_headers_visible(true); tree_view.set_model(profile->model()); diff --git a/Libraries/LibGUI/TreeView.cpp b/Libraries/LibGUI/TreeView.cpp index 7ad0a482cd..3732f9a6b2 100644 --- a/Libraries/LibGUI/TreeView.cpp +++ b/Libraries/LibGUI/TreeView.cpp @@ -264,7 +264,7 @@ void TreeView::paint_event(PaintEvent& event) bool is_selected_row = selection().contains(index); Color text_color = palette().color(foreground_role()); - if (is_selected_row) + if (is_selected_row && should_fill_selected_rows()) text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); Color background_color; @@ -293,7 +293,9 @@ void TreeView::paint_event(PaintEvent& event) } Gfx::IntRect row_rect { 0, rect.y(), row_width, rect.height() }; - painter.fill_rect(row_rect, background_color); + + if (!is_selected_row || should_fill_selected_rows()) + painter.fill_rect(row_rect, background_color); int x_offset = 0; for (int column_index = 0; column_index < model.column_count(); ++column_index) { @@ -325,6 +327,13 @@ void TreeView::paint_event(PaintEvent& event) } else { // It's the tree column! 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() + }; + + painter.fill_rect(text_rect, background_color); + auto icon = index.data(ModelRole::Icon); if (icon.is_icon()) { if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) { @@ -334,11 +343,13 @@ void TreeView::paint_event(PaintEvent& event) painter.blit(icon_rect.location(), *bitmap, bitmap->rect()); } } - Gfx::IntRect text_rect = { - icon_rect.right() + 1 + icon_spacing(), rect.y(), - rect.width() - icon_size() - icon_spacing(), rect.height() - }; draw_item_text(painter, index, is_selected_row, text_rect, index.data().to_string(), font_for_index(index), Gfx::TextAlignment::Center, Gfx::TextElision::None); + + 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 index_at_indent = index; for (int i = indent_level; i > 0; --i) { auto parent_of_index_at_indent = index_at_indent.parent(); diff --git a/Libraries/LibGUI/TreeView.h b/Libraries/LibGUI/TreeView.h index d8e81dc431..2695dacb34 100644 --- a/Libraries/LibGUI/TreeView.h +++ b/Libraries/LibGUI/TreeView.h @@ -48,6 +48,9 @@ public: Function on_toggle; + void set_should_fill_selected_rows(bool fill) { m_should_fill_selected_rows = fill; } + bool should_fill_selected_rows() const { return m_should_fill_selected_rows; } + protected: TreeView(); @@ -84,6 +87,8 @@ private: RefPtr m_expand_bitmap; RefPtr m_collapse_bitmap; + + bool m_should_fill_selected_rows { false }; }; }