mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 10:15:07 +00:00
LibGUI: Move some large IconView internal helpers to the .cpp file
Stuff that's only used internally by the class is nice to keep out of the header when possible.
This commit is contained in:
parent
815d39886f
commit
0117c57418
2 changed files with 40 additions and 34 deletions
|
@ -735,4 +735,42 @@ void IconView::move_cursor(CursorMovement movement, SelectionUpdate selection_up
|
|||
set_cursor(new_index, selection_update);
|
||||
}
|
||||
|
||||
template<typename Function>
|
||||
inline IterationDecision IconView::for_each_item_intersecting_rect(const Gfx::IntRect& rect, Function f) const
|
||||
{
|
||||
ASSERT(model());
|
||||
if (rect.is_empty())
|
||||
return IterationDecision::Continue;
|
||||
int begin_row, begin_column;
|
||||
column_row_from_content_position(rect.top_left(), begin_row, begin_column);
|
||||
int end_row, end_column;
|
||||
column_row_from_content_position(rect.bottom_right(), end_row, end_column);
|
||||
int items_per_column = end_column - begin_column + 1;
|
||||
int item_index = max(0, begin_row * m_visual_column_count + begin_column);
|
||||
int last_index = min(item_count(), end_row * m_visual_column_count + end_column + 1);
|
||||
while (item_index < last_index) {
|
||||
for (int i = item_index; i < min(item_index + items_per_column, last_index); i++) {
|
||||
auto& item_data = get_item_data(i);
|
||||
if (item_data.is_intersecting(rect)) {
|
||||
auto decision = f(item_data);
|
||||
if (decision != IterationDecision::Continue)
|
||||
return decision;
|
||||
}
|
||||
}
|
||||
item_index += m_visual_column_count;
|
||||
};
|
||||
return IterationDecision::Continue;
|
||||
}
|
||||
|
||||
template<typename Function>
|
||||
inline IterationDecision IconView::for_each_item_intersecting_rects(const Vector<Gfx::IntRect>& rects, Function f) const
|
||||
{
|
||||
for (auto& rect : rects) {
|
||||
auto decision = for_each_item_intersecting_rect(rect, f);
|
||||
if (decision != IterationDecision::Continue)
|
||||
return decision;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue