LibGUI: Tighten paint invalidation rects in item views :^)

AbstractView now has a paint_invalidation_rect(index) function that
subclasses can override to provide a tighter invalidation rect for
an index.
This commit is contained in:
Andreas Kling 2021-07-10 17:11:04 +02:00
parent 148e72bfa0
commit df96380121
Notes: sideshowbarker 2024-07-18 09:25:01 +09:00
9 changed files with 48 additions and 1 deletions

View file

@ -293,6 +293,13 @@ void AbstractTableView::context_menu_event(ContextMenuEvent& event)
on_context_menu_request(index, event);
}
Gfx::IntRect AbstractTableView::paint_invalidation_rect(ModelIndex const& index) const
{
if (!index.is_valid())
return {};
return row_rect(index.row());
}
Gfx::IntRect AbstractTableView::content_rect(int row, int column) const
{
auto row_rect = this->row_rect(row);

View file

@ -51,6 +51,8 @@ public:
Gfx::IntRect content_rect(int row, int column) const;
Gfx::IntRect row_rect(int item_index) const;
virtual Gfx::IntRect paint_invalidation_rect(ModelIndex const& index) const override;
virtual void scroll_into_view(const ModelIndex&, bool scroll_horizontally = true, bool scroll_vertically = true) override;
void scroll_into_view(const ModelIndex& index, Orientation orientation)
{

View file

@ -90,6 +90,7 @@ public:
virtual Gfx::IntRect content_rect(const ModelIndex&) const { return {}; }
virtual Gfx::IntRect editing_rect(ModelIndex const& index) const { return content_rect(index); }
virtual Gfx::IntRect paint_invalidation_rect(ModelIndex const& index) const { return content_rect(index); }
virtual ModelIndex index_at_event_position(const Gfx::IntPoint&) const { return {}; }
void begin_editing(const ModelIndex&);

View file

@ -323,4 +323,12 @@ Gfx::IntRect ColumnsView::content_rect(const ModelIndex& index) const
return {};
}
Gfx::IntRect ColumnsView::paint_invalidation_rect(ModelIndex const& index) const
{
auto rect = content_rect(index);
rect.translate_by(-icon_size(), 0);
rect.set_width(rect.width() + icon_size());
return rect;
}
}

View file

@ -19,6 +19,7 @@ public:
virtual ModelIndex index_at_event_position(const Gfx::IntPoint&) const override;
virtual Gfx::IntRect content_rect(const ModelIndex&) const override;
virtual Gfx::IntRect paint_invalidation_rect(ModelIndex const&) const override;
private:
ColumnsView();

View file

@ -388,7 +388,15 @@ void IconView::update_item_rects(int item_index, ItemData& item_data) const
item_data.text_rect.set_top(item_rect.y() + item_data.text_offset_y);
}
Gfx::IntRect IconView::content_rect(const ModelIndex& index) const
Gfx::IntRect IconView::content_rect(ModelIndex const& index) const
{
if (!index.is_valid())
return {};
auto& item_data = get_item_data(index.row());
return item_data.rect();
}
Gfx::IntRect IconView::editing_rect(ModelIndex const& index) const
{
if (!index.is_valid())
return {};

View file

@ -40,6 +40,7 @@ public:
virtual ModelIndex index_at_event_position(const Gfx::IntPoint&) const override;
virtual Gfx::IntRect content_rect(const ModelIndex&) const override;
virtual Gfx::IntRect editing_rect(ModelIndex const&) const override;
virtual void select_all() override;

View file

@ -717,4 +717,20 @@ int TreeView::tree_column_x_offset() const
return offset;
}
Gfx::IntRect TreeView::content_rect(ModelIndex const& index) const
{
if (!index.is_valid())
return {};
Gfx::IntRect found_rect;
traverse_in_paint_order([&](ModelIndex const& current_index, Gfx::IntRect const& rect, Gfx::IntRect const&, int) {
if (index == current_index) {
found_rect = rect;
return IterationDecision::Break;
}
return IterationDecision::Continue;
});
return found_rect;
}
}

View file

@ -33,6 +33,9 @@ public:
virtual int vertical_padding() const override { return m_vertical_padding; }
virtual Gfx::IntRect content_rect(ModelIndex const&) const override;
virtual Gfx::IntRect paint_invalidation_rect(ModelIndex const& index) const override { return content_rect(index); }
protected:
TreeView();