mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
wip: fixing Map, centering
This commit is contained in:
parent
059ff2ca79
commit
d17d20e7db
10 changed files with 104 additions and 78 deletions
|
|
@ -21,13 +21,14 @@ pub trait Layout<E: Engine> {
|
|||
{
|
||||
Opt(option, cb, Default::default())
|
||||
}
|
||||
fn map <T, I, R, F>(iterator: I, callback: F) -> Map<E, T, I, R, F> where
|
||||
fn map <T, I, J, R, F>(iterator: J, callback: F) -> Map<E, T, I, J, R, F> where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
J: Fn() -> I + Send + Sync,
|
||||
R: Content<E>,
|
||||
F: Fn(T, usize)->R + Send + Sync
|
||||
{
|
||||
Map(Default::default(), RwLock::new(iterator), callback)
|
||||
Map(Default::default(), iterator, callback)
|
||||
}
|
||||
//pub fn reduce <E, T, I, R, F>(iterator: I, callback: F) -> Reduce<E, T, I, R, F> where
|
||||
//E: Engine,
|
||||
|
|
@ -77,21 +78,39 @@ impl<E: Engine, A: Content<E>, B: Content<E>> Content<E> for Either<E, A, B> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Map<E, T, I, R, F>(PhantomData<E>, RwLock<I>, F) where
|
||||
pub struct Map<E, T, I, J, R, F>(PhantomData<E>, J, F) where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
J: Fn()->I + Send + Sync,
|
||||
R: Content<E>,
|
||||
F: Fn(T, usize)->R + Send + Sync;
|
||||
|
||||
impl<E, T, I, R, F> Content<E> for Map<E, T, I, R, F> where
|
||||
impl<E, T, I, J, R, F> Content<E> for Map<E, T, I, J, R, F> where
|
||||
E: Engine,
|
||||
I: Iterator<Item = T> + Send + Sync,
|
||||
J: Fn()->I + Send + Sync,
|
||||
R: Content<E>,
|
||||
F: Fn(T, usize)->R + Send + Sync
|
||||
{
|
||||
fn layout (&self, area: E::Area) -> E::Area {
|
||||
let mut index = 0;
|
||||
let mut max_w = 0;
|
||||
let mut max_h = 0;
|
||||
for item in (self.1)() {
|
||||
let [x, y, w, h] = (self.2)(item, index).layout(area).xywh();
|
||||
max_w = max_w.max((x + w).into());
|
||||
max_h = max_h.max((y + h).into());
|
||||
index += 1;
|
||||
}
|
||||
align_areas(
|
||||
Alignment::Center,
|
||||
area.xywh(),
|
||||
[0.into(), 0.into(), max_w.into(), max_h.into()]
|
||||
).into()
|
||||
}
|
||||
fn render (&self, to: &mut E::Output) {
|
||||
let mut index = 0;
|
||||
for item in &mut*self.1.write().unwrap() {
|
||||
for item in (self.1)() {
|
||||
(self.2)(item, index).render(to);
|
||||
index += 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue