moly_kit/utils/makepad/
portal_list.rs1use makepad_widgets::*;
4use std::ops::RangeBounds;
5
6pub struct ItemsRangeIter<R: RangeBounds<usize>> {
8 list: PortalListRef,
9 range: R,
10 current: usize,
11}
12
13impl<R: RangeBounds<usize>> ItemsRangeIter<R> {
14 pub fn new(list: PortalListRef, range: R) -> Self {
15 let start = match range.start_bound() {
16 std::ops::Bound::Included(&start) => start,
17 std::ops::Bound::Excluded(&start) => start + 1,
18 std::ops::Bound::Unbounded => 0,
19 };
20
21 Self {
22 list,
23 range,
24 current: start,
25 }
26 }
27}
28
29impl<R: RangeBounds<usize>> Iterator for ItemsRangeIter<R> {
30 type Item = (usize, WidgetRef);
31
32 fn next(&mut self) -> Option<Self::Item> {
33 if !self.range.contains(&self.current) {
34 return None;
35 }
36
37 let Some((_, item)) = self.list.get_item(self.current) else {
41 return None;
42 };
43
44 self.current += 1;
45 Some((self.current - 1, item))
46 }
47}