Last active
January 13, 2022 22:14
-
-
Save ratmice/6e956b2b0e8cc7dbd250afded09d0d79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use druid::widget::ListIter; | |
use druid::Data; | |
use druid::im::Vector; | |
#[derive(Data, Clone)] | |
pub struct ListMod<I, T> | |
{ | |
data: I, | |
mod_elems: Vector<T>, | |
} | |
impl<I, T> ListMod<I, T> { | |
pub fn new(data: I, mod_elems: Vector<T>) -> Self { | |
ListMod { data, mod_elems} | |
} | |
} | |
impl<T: Data, S: Data, I: ListIter<S>> ListIter<(S, T)> for ListMod<I, T> { | |
fn for_each(&self, mut cb: impl FnMut(&(S, T), usize)) { | |
let modulus = self.mod_elems.len(); | |
self.data.for_each(|element_s, index| { | |
let element_t = &self.mod_elems[index % modulus]; | |
cb(&(element_s.clone(), element_t.clone()), index); | |
}) | |
} | |
fn for_each_mut(&mut self, mut cb: impl FnMut(&mut (S, T), usize)) { | |
let modulus = self.mod_elems.len(); | |
let mod_elems = &mut self.mod_elems; | |
self.data.for_each_mut(|element_s, index| { | |
let element_t = &mod_elems[index % modulus]; | |
cb(&mut (element_s.clone(), element_t.clone()), index); | |
// ?? | |
}); | |
} | |
fn data_len(&self) -> usize { | |
self.data.data_len() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment