diff options
author | networkException <git@nwex.de> | 2022-01-28 17:18:58 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-29 11:22:02 +0100 |
commit | b67d4ab52fb5511685c8fc8dbb7592567b8690b0 (patch) | |
tree | d12f93bac30a287e3b2d7576024b702d2d4453ba /Userland/Libraries | |
parent | e2df145e14e82b14a41c9c13ededb52713bf3f05 (diff) | |
download | serenity-b67d4ab52fb5511685c8fc8dbb7592567b8690b0.zip |
LibGUI: Allow falling back to default paint behavior in delegate
This patch adds a method that can optionally be implemented to allow
a TableCellPaintingDelegate to fall back to the default painting in a
View.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGUI/AbstractTableView.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/TableView.cpp | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/TreeView.cpp | 3 |
3 files changed, 6 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/AbstractTableView.h b/Userland/Libraries/LibGUI/AbstractTableView.h index 916ecf05c2..996f33487b 100644 --- a/Userland/Libraries/LibGUI/AbstractTableView.h +++ b/Userland/Libraries/LibGUI/AbstractTableView.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2022, Jakob-Niklas See <git@nwex.de> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,6 +15,7 @@ class TableCellPaintingDelegate { public: virtual ~TableCellPaintingDelegate() { } + virtual bool should_paint(ModelIndex const&) { return true; } virtual void paint(Painter&, const Gfx::IntRect&, const Gfx::Palette&, const ModelIndex&) = 0; }; diff --git a/Userland/Libraries/LibGUI/TableView.cpp b/Userland/Libraries/LibGUI/TableView.cpp index 1ce93d194a..a7c6568988 100644 --- a/Userland/Libraries/LibGUI/TableView.cpp +++ b/Userland/Libraries/LibGUI/TableView.cpp @@ -98,7 +98,8 @@ void TableView::paint_event(PaintEvent& event) painter.fill_rect(cell_rect_for_fill, key_column_background_color); auto cell_index = model()->index(row_index, column_index); - if (auto* delegate = column_painting_delegate(column_index)) { + auto* delegate = column_painting_delegate(column_index); + if (delegate && delegate->should_paint(cell_index)) { delegate->paint(painter, cell_rect, palette(), cell_index); } else { auto data = cell_index.data(); diff --git a/Userland/Libraries/LibGUI/TreeView.cpp b/Userland/Libraries/LibGUI/TreeView.cpp index da44bbfeea..c7f6d0f390 100644 --- a/Userland/Libraries/LibGUI/TreeView.cpp +++ b/Userland/Libraries/LibGUI/TreeView.cpp @@ -291,7 +291,8 @@ void TreeView::paint_event(PaintEvent& event) Gfx::IntRect cell_rect(horizontal_padding() + x_offset, rect.y(), column_width, row_height()); auto cell_index = model.index(index.row(), column_index, index.parent()); - if (auto* delegate = column_painting_delegate(column_index)) { + auto* delegate = column_painting_delegate(column_index); + if (delegate && delegate->should_paint(cell_index)) { delegate->paint(painter, cell_rect, palette(), cell_index); } else { auto data = cell_index.data(); |