2021-05-21 15:52:05 +03:00
|
|
|
use crate::{filetreeitems::FileTreeItems, item::FileTreeItem};
|
|
|
|
|
|
|
|
pub struct TreeItemsIterator<'a> {
|
2021-08-17 15:24:25 +03:00
|
|
|
tree: &'a FileTreeItems,
|
|
|
|
index: usize,
|
|
|
|
increments: Option<usize>,
|
|
|
|
max_amount: usize,
|
2021-05-21 15:52:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> TreeItemsIterator<'a> {
|
2021-08-17 15:24:25 +03:00
|
|
|
pub const fn new(
|
|
|
|
tree: &'a FileTreeItems,
|
|
|
|
start: usize,
|
|
|
|
max_amount: usize,
|
|
|
|
) -> Self {
|
|
|
|
TreeItemsIterator {
|
|
|
|
max_amount,
|
|
|
|
increments: None,
|
|
|
|
index: start,
|
|
|
|
tree,
|
|
|
|
}
|
|
|
|
}
|
2021-05-21 15:52:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Iterator for TreeItemsIterator<'a> {
|
2021-08-17 15:24:25 +03:00
|
|
|
type Item = (usize, &'a FileTreeItem);
|
2021-05-21 15:52:05 +03:00
|
|
|
|
2021-08-17 15:24:25 +03:00
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
if self.increments.unwrap_or_default() < self.max_amount {
|
|
|
|
let items = &self.tree.tree_items;
|
2021-05-21 15:52:05 +03:00
|
|
|
|
2021-08-17 15:24:25 +03:00
|
|
|
let mut init = self.increments.is_none();
|
2021-05-21 15:52:05 +03:00
|
|
|
|
2021-08-17 15:24:25 +03:00
|
|
|
if let Some(i) = self.increments.as_mut() {
|
|
|
|
*i += 1;
|
|
|
|
} else {
|
|
|
|
self.increments = Some(0);
|
|
|
|
};
|
2021-05-21 15:52:05 +03:00
|
|
|
|
2021-08-17 15:24:25 +03:00
|
|
|
loop {
|
|
|
|
if !init {
|
|
|
|
self.index += 1;
|
|
|
|
}
|
|
|
|
init = false;
|
2021-05-21 15:52:05 +03:00
|
|
|
|
2021-08-17 15:24:25 +03:00
|
|
|
if self.index >= self.tree.len() {
|
|
|
|
break;
|
|
|
|
}
|
2021-05-21 15:52:05 +03:00
|
|
|
|
2021-08-17 15:24:25 +03:00
|
|
|
let elem = &items[self.index];
|
2021-05-21 15:52:05 +03:00
|
|
|
|
2021-08-17 15:24:25 +03:00
|
|
|
if elem.info().is_visible() {
|
|
|
|
return Some((self.index, &items[self.index]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-21 15:52:05 +03:00
|
|
|
|
2021-08-17 15:24:25 +03:00
|
|
|
None
|
|
|
|
}
|
2021-05-21 15:52:05 +03:00
|
|
|
}
|