mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 10:18:15 +09:00
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.
This commit is contained in:
parent
e2df145e14
commit
b67d4ab52f
Notes:
sideshowbarker
2024-07-17 20:03:26 +09:00
Author: https://github.com/networkException
Commit: b67d4ab52f
Pull-request: https://github.com/SerenityOS/serenity/pull/12183
3 changed files with 6 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||||
|
* Copyright (c) 2022, Jakob-Niklas See <git@nwex.de>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -14,6 +15,7 @@ class TableCellPaintingDelegate {
|
||||||
public:
|
public:
|
||||||
virtual ~TableCellPaintingDelegate() { }
|
virtual ~TableCellPaintingDelegate() { }
|
||||||
|
|
||||||
|
virtual bool should_paint(ModelIndex const&) { return true; }
|
||||||
virtual void paint(Painter&, const Gfx::IntRect&, const Gfx::Palette&, const ModelIndex&) = 0;
|
virtual void paint(Painter&, const Gfx::IntRect&, const Gfx::Palette&, const ModelIndex&) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,8 @@ void TableView::paint_event(PaintEvent& event)
|
||||||
painter.fill_rect(cell_rect_for_fill, key_column_background_color);
|
painter.fill_rect(cell_rect_for_fill, key_column_background_color);
|
||||||
auto cell_index = model()->index(row_index, column_index);
|
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);
|
delegate->paint(painter, cell_rect, palette(), cell_index);
|
||||||
} else {
|
} else {
|
||||||
auto data = cell_index.data();
|
auto data = cell_index.data();
|
||||||
|
|
|
@ -291,7 +291,8 @@ void TreeView::paint_event(PaintEvent& event)
|
||||||
Gfx::IntRect cell_rect(horizontal_padding() + x_offset, rect.y(), column_width, row_height());
|
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());
|
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);
|
delegate->paint(painter, cell_rect, palette(), cell_index);
|
||||||
} else {
|
} else {
|
||||||
auto data = cell_index.data();
|
auto data = cell_index.data();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue