mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
0.2.0: constrain map
This commit is contained in:
parent
1774419d93
commit
10a2d17b48
2 changed files with 60 additions and 12 deletions
|
|
@ -23,22 +23,70 @@ use crate::*;
|
|||
Push::x(item_offset, Align::w(Fixed::x(item_width, Fill::y(item))))
|
||||
}
|
||||
|
||||
pub struct Map<'a, A, B, I, F, G>(pub PhantomData<&'a()>, pub F, pub G) where
|
||||
pub struct Map<
|
||||
'a,
|
||||
E,
|
||||
A,
|
||||
B,
|
||||
I: Iterator<Item = A> + Send + Sync,
|
||||
F: Fn() -> I + Send + Sync + 'a,
|
||||
G: Fn(A, usize)->B + Send + Sync;
|
||||
G,
|
||||
> {
|
||||
__: PhantomData<&'a (E, B)>,
|
||||
/// Function that returns iterator over stacked components
|
||||
get_iterator: F,
|
||||
/// Function that returns each stacked component
|
||||
get_item: G,
|
||||
}
|
||||
|
||||
impl<'a, A, B, I, F, G> Map<'a, A, B, I, F, G> where
|
||||
impl<'a, E, A, B, I, F, G> Map<'a, E, A, B, I, F, G> where
|
||||
I: Iterator<Item = A> + Send + Sync,
|
||||
F: Fn() -> I + Send + Sync + 'a,
|
||||
G: Fn(A, usize)->B + Send + Sync
|
||||
{
|
||||
pub fn new (f: F, g: G) -> Self {
|
||||
Self(Default::default(), f, g)
|
||||
pub fn new (get_iterator: F, get_item: G) -> Self {
|
||||
Self {
|
||||
__: Default::default(),
|
||||
get_iterator,
|
||||
get_item
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E, A, B, I, F, G> Content<E> for Map<'a, A, B, I, F, G> where
|
||||
//impl<'a, E, A, B, I, F> Map<'a, E, A, B, I, F, ()> where
|
||||
//E: Output,
|
||||
//B: Content<E>,
|
||||
//I: Iterator<Item = A> + Send + Sync,
|
||||
//F: Fn() -> I + Send + Sync + 'a,
|
||||
//{
|
||||
//pub fn south <G> (
|
||||
//get_iterator: F,
|
||||
//get_content: impl Fn(A, usize)->B + Send + Sync,
|
||||
//) -> Map<'a, E, A, B, I, F, G> where
|
||||
//G: Fn(A, usize)->Push<E::Unit, Align<Fixed<E::Unit, Fill<B>>>> + Send + Sync
|
||||
//{
|
||||
//let mut offset = 0;
|
||||
//Map::new(get_iterator, move|item, index|map_south(
|
||||
//0.into(),
|
||||
//0.into(),
|
||||
//get_content(item, index)
|
||||
//))
|
||||
//}
|
||||
//pub fn east <G> (
|
||||
//get_iterator: F,
|
||||
//get_content: impl Fn(A, usize)->B + Send + Sync,
|
||||
//) -> Map<'a, E, A, B, I, F, G> where
|
||||
//G: Fn(A, usize)->Push<E::Unit, Align<Fixed<E::Unit, Fill<B>>>> + Send + Sync
|
||||
//{
|
||||
//let mut offset = 0;
|
||||
//Map::new(get_iterator, move|item, index|map_east(
|
||||
//0.into(),
|
||||
//0.into(),
|
||||
//get_content(item, index)
|
||||
//))
|
||||
//}
|
||||
//}
|
||||
|
||||
impl<'a, E, A, B, I, F, G> Content<E> for Map<'a, E, A, B, I, F, G> where
|
||||
E: Output,
|
||||
B: Render<E>,
|
||||
I: Iterator<Item = A> + Send + Sync,
|
||||
|
|
@ -46,12 +94,12 @@ impl<'a, E, A, B, I, F, G> Content<E> for Map<'a, A, B, I, F, G> where
|
|||
G: Fn(A, usize)->B + Send + Sync
|
||||
{
|
||||
fn layout (&self, area: E::Area) -> E::Area {
|
||||
let Self(_, get_iterator, callback) = self;
|
||||
let Self { get_iterator, get_item, .. } = self;
|
||||
let mut index = 0;
|
||||
let [mut min_x, mut min_y] = area.center();
|
||||
let [mut max_x, mut max_y] = area.center();
|
||||
for item in get_iterator() {
|
||||
let [x,y,w,h] = callback(item, index).layout(area).xywh();
|
||||
let [x,y,w,h] = get_item(item, index).layout(area).xywh();
|
||||
min_x = min_x.min(x.into());
|
||||
min_y = min_y.min(y.into());
|
||||
max_x = max_x.max((x + w).into());
|
||||
|
|
@ -64,11 +112,11 @@ impl<'a, E, A, B, I, F, G> Content<E> for Map<'a, A, B, I, F, G> where
|
|||
area.center_xy([w.into(), h.into()].into()).into()
|
||||
}
|
||||
fn render (&self, to: &mut E) {
|
||||
let Self(_, get_iterator, callback) = self;
|
||||
let Self { get_iterator, get_item, .. } = self;
|
||||
let mut index = 0;
|
||||
let area = Content::layout(self, to.area());
|
||||
for item in get_iterator() {
|
||||
let item = callback(item, index);
|
||||
let item = get_item(item, index);
|
||||
//to.place(area.into(), &item);
|
||||
to.place(item.layout(area), &item);
|
||||
index += 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue