mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 21:05:07 +00:00
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:
parent
148e72bfa0
commit
df96380121
9 changed files with 48 additions and 1 deletions
|
@ -293,6 +293,13 @@ void AbstractTableView::context_menu_event(ContextMenuEvent& event)
|
||||||
on_context_menu_request(index, 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
|
Gfx::IntRect AbstractTableView::content_rect(int row, int column) const
|
||||||
{
|
{
|
||||||
auto row_rect = this->row_rect(row);
|
auto row_rect = this->row_rect(row);
|
||||||
|
|
|
@ -51,6 +51,8 @@ public:
|
||||||
Gfx::IntRect content_rect(int row, int column) const;
|
Gfx::IntRect content_rect(int row, int column) const;
|
||||||
Gfx::IntRect row_rect(int item_index) 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;
|
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)
|
void scroll_into_view(const ModelIndex& index, Orientation orientation)
|
||||||
{
|
{
|
||||||
|
|
|
@ -90,6 +90,7 @@ public:
|
||||||
|
|
||||||
virtual Gfx::IntRect content_rect(const ModelIndex&) const { return {}; }
|
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 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 {}; }
|
virtual ModelIndex index_at_event_position(const Gfx::IntPoint&) const { return {}; }
|
||||||
void begin_editing(const ModelIndex&);
|
void begin_editing(const ModelIndex&);
|
||||||
|
|
|
@ -323,4 +323,12 @@ Gfx::IntRect ColumnsView::content_rect(const ModelIndex& index) const
|
||||||
return {};
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ public:
|
||||||
|
|
||||||
virtual ModelIndex index_at_event_position(const Gfx::IntPoint&) const override;
|
virtual ModelIndex index_at_event_position(const Gfx::IntPoint&) const override;
|
||||||
virtual Gfx::IntRect content_rect(const ModelIndex&) const override;
|
virtual Gfx::IntRect content_rect(const ModelIndex&) const override;
|
||||||
|
virtual Gfx::IntRect paint_invalidation_rect(ModelIndex const&) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ColumnsView();
|
ColumnsView();
|
||||||
|
|
|
@ -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);
|
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())
|
if (!index.is_valid())
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
|
|
||||||
virtual ModelIndex index_at_event_position(const Gfx::IntPoint&) const override;
|
virtual ModelIndex index_at_event_position(const Gfx::IntPoint&) const override;
|
||||||
virtual Gfx::IntRect content_rect(const ModelIndex&) 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;
|
virtual void select_all() override;
|
||||||
|
|
||||||
|
|
|
@ -717,4 +717,20 @@ int TreeView::tree_column_x_offset() const
|
||||||
return offset;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,9 @@ public:
|
||||||
|
|
||||||
virtual int vertical_padding() const override { return m_vertical_padding; }
|
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:
|
protected:
|
||||||
TreeView();
|
TreeView();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue