mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
output: finally Map::east, Map::south
This commit is contained in:
parent
b5fbd14f91
commit
649a89443b
2 changed files with 71 additions and 9 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#![feature(step_trait)]
|
#![feature(step_trait)]
|
||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
#![feature(impl_trait_in_assoc_type)]
|
#![feature(impl_trait_in_assoc_type)]
|
||||||
|
//#![feature(impl_trait_in_fn_trait_return)]
|
||||||
|
|
||||||
mod space; pub use self::space::*;
|
mod space; pub use self::space::*;
|
||||||
mod ops; pub use self::ops::*;
|
mod ops; pub use self::ops::*;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ where
|
||||||
{
|
{
|
||||||
__: PhantomData<(E, B)>,
|
__: PhantomData<(E, B)>,
|
||||||
/// Function that returns iterator over stacked components
|
/// Function that returns iterator over stacked components
|
||||||
get_iterator: F,
|
get_iter: F,
|
||||||
/// Function that returns each stacked component
|
/// Function that returns each stacked component
|
||||||
get_item: G,
|
get_item: G,
|
||||||
}
|
}
|
||||||
|
|
@ -40,15 +40,76 @@ impl<'a, E, A, B, I, F, G> Map<E, A, B, I, F, G> where
|
||||||
I: Iterator<Item = A> + Send + Sync + 'a,
|
I: Iterator<Item = A> + Send + Sync + 'a,
|
||||||
F: Fn() -> I + Send + Sync + 'a,
|
F: Fn() -> I + Send + Sync + 'a,
|
||||||
{
|
{
|
||||||
pub const fn new (get_iterator: F, get_item: G) -> Self {
|
pub const fn new (get_iter: F, get_item: G) -> Self {
|
||||||
Self {
|
Self {
|
||||||
__: PhantomData,
|
__: PhantomData,
|
||||||
get_iterator,
|
get_iter,
|
||||||
get_item
|
get_item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, E, A, B, I, F> Map<E, A, Push<E::Unit, Align<Fixed<E::Unit, Fill<B>>>>, I, F, fn(A, usize)->B>
|
||||||
|
where
|
||||||
|
E: Output,
|
||||||
|
B: Render<E>,
|
||||||
|
I: Iterator<Item = A> + Send + Sync + 'a,
|
||||||
|
F: Fn() -> I + Send + Sync + 'a
|
||||||
|
{
|
||||||
|
pub const fn east (
|
||||||
|
size: E::Unit,
|
||||||
|
get_iter: F,
|
||||||
|
get_item: impl Fn(A, usize)->B + Send + Sync
|
||||||
|
) -> Map<
|
||||||
|
E, A,
|
||||||
|
Push<E::Unit, Align<Fixed<E::Unit, Fill<B>>>>,
|
||||||
|
I, F,
|
||||||
|
impl Fn(A, usize)->Push<E::Unit, Align<Fixed<E::Unit, Fill<B>>>> + Send + Sync
|
||||||
|
> {
|
||||||
|
Map {
|
||||||
|
__: PhantomData,
|
||||||
|
get_iter,
|
||||||
|
get_item: move |item: A, index: usize|{
|
||||||
|
// FIXME: multiply
|
||||||
|
let mut push: E::Unit = E::Unit::from(0u16);
|
||||||
|
for i in 0..index {
|
||||||
|
push = push + size;
|
||||||
|
}
|
||||||
|
Push::x(push, Align::w(Fixed::x(size, Fill::y(get_item(item, index)))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn south (
|
||||||
|
size: E::Unit,
|
||||||
|
get_iter: F,
|
||||||
|
get_item: impl Fn(A, usize)->B + Send + Sync
|
||||||
|
) -> Map<
|
||||||
|
E, A,
|
||||||
|
Push<E::Unit, Fixed<E::Unit, Fill<B>>>,
|
||||||
|
I, F,
|
||||||
|
impl Fn(A, usize)->Push<E::Unit, Fixed<E::Unit, Fill<B>>> + Send + Sync
|
||||||
|
> where
|
||||||
|
E: Output,
|
||||||
|
B: Render<E>,
|
||||||
|
I: Iterator<Item = A> + Send + Sync + 'a,
|
||||||
|
F: Fn() -> I + Send + Sync + 'a
|
||||||
|
{
|
||||||
|
Map {
|
||||||
|
__: PhantomData,
|
||||||
|
get_iter,
|
||||||
|
get_item: move |item: A, index: usize|{
|
||||||
|
// FIXME: multiply
|
||||||
|
let mut push: E::Unit = E::Unit::from(0u16);
|
||||||
|
for i in 0..index {
|
||||||
|
push = push + size;
|
||||||
|
}
|
||||||
|
Push::y(push, Fixed::y(size, Fill::x(get_item(item, index))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, E, A, B, I, F, G> Content<E> for Map<E, A, B, I, F, G> where
|
impl<'a, E, A, B, I, F, G> Content<E> for Map<E, A, B, I, F, G> where
|
||||||
E: Output,
|
E: Output,
|
||||||
B: Render<E>,
|
B: Render<E>,
|
||||||
|
|
@ -57,11 +118,11 @@ impl<'a, E, A, B, I, F, G> Content<E> for Map<E, A, B, I, F, G> where
|
||||||
G: Fn(A, usize)->B + Send + Sync
|
G: Fn(A, usize)->B + Send + Sync
|
||||||
{
|
{
|
||||||
fn layout (&self, area: E::Area) -> E::Area {
|
fn layout (&self, area: E::Area) -> E::Area {
|
||||||
let Self { get_iterator, get_item, .. } = self;
|
let Self { get_iter, get_item, .. } = self;
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
let [mut min_x, mut min_y] = area.center();
|
let [mut min_x, mut min_y] = area.center();
|
||||||
let [mut max_x, mut max_y] = area.center();
|
let [mut max_x, mut max_y] = area.center();
|
||||||
for item in get_iterator() {
|
for item in get_iter() {
|
||||||
let [x,y,w,h] = get_item(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_x = min_x.min(x.into());
|
||||||
min_y = min_y.min(y.into());
|
min_y = min_y.min(y.into());
|
||||||
|
|
@ -75,10 +136,10 @@ impl<'a, E, A, B, I, F, G> Content<E> for Map<E, A, B, I, F, G> where
|
||||||
area.center_xy([w.into(), h.into()].into()).into()
|
area.center_xy([w.into(), h.into()].into()).into()
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut E) {
|
fn render (&self, to: &mut E) {
|
||||||
let Self { get_iterator, get_item, .. } = self;
|
let Self { get_iter, get_item, .. } = self;
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
let area = Content::layout(self, to.area());
|
let area = Content::layout(self, to.area());
|
||||||
for item in get_iterator() {
|
for item in get_iter() {
|
||||||
let item = get_item(item, index);
|
let item = get_item(item, index);
|
||||||
//to.place(area.into(), &item);
|
//to.place(area.into(), &item);
|
||||||
to.place(item.layout(area), &item);
|
to.place(item.layout(area), &item);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue