output: more big refactors

This commit is contained in:
🪞👃🪞 2025-09-07 12:34:30 +03:00
parent 194f2f9874
commit 5e6338fad8
68 changed files with 1604 additions and 1016 deletions

98
output/src/layout.rs Normal file
View file

@ -0,0 +1,98 @@
use crate::*;
pub trait Layout<O: Out> {
fn x (&self, area: O::Area) -> O::Unit {
area.x()
}
fn y (&self, area: O::Area) -> O::Unit {
area.y()
}
fn min_w (&self, _area: O::Area) -> O::Unit {
0.into()
}
fn max_w (&self, area: O::Area) -> O::Unit {
area.w()
}
fn min_h (&self, _area: O::Area) -> O::Unit {
0.into()
}
fn max_h (&self, area: O::Area) -> O::Unit {
area.h()
}
fn layout (&self, area: O::Area) -> O::Area {
O::Area::from([
self.x(area),
self.y(area),
area.w().max(self.min_w(area)).min(self.max_w(area)),
area.h().max(self.min_h(area)).min(self.max_h(area)),
])
}
}
#[macro_export] macro_rules! layout {
// Implement for all [Out] backends.
(|$self:ident:$Struct:ident $(<
$($L:lifetime),* $($T:ident $(:$Trait:path)?),*
>)?, $to:ident|$($method:ident = |$area:ident|$body:expr;)*) => {
impl <$($($L),*)? O: Out, $($($T$(:$Trait)?),*)?> Layout<O>
for $Struct $(<$($L),* $($T),*>)? {
$(fn $method (&$self, $area: O::Area) -> O::Area {
$body
})*
}
};
// Implement for a specific [Out] backend.
($O:ty:|
$self:ident:
$Struct:ident $(<$($($L:lifetime)? $($T:ident)? $(:$Trait:path)?),+>)?,
$to:ident
|$($method:ident = |$area:ident|$body:expr;)*) => {
impl $(<$($($L)? $($T)? $(:$Trait)?),+>)? Layout<$O>
for $Struct $(<$($($L)? $($T)?),+>)? {
$(fn $method (&$self, $area: <$O as Out>::Area) -> <$O as Out>::Area {
$body
})*
}
};
}
impl<O: Out> Layout<O> for () {}
impl<O: Out, L: Layout<O>> Layout<O> for &L { /*FIXME*/ }
impl<O: Out, L: Layout<O>> Layout<O> for RwLock<L> { /*FIXME*/ }
impl<O: Out, L: Layout<O>> Layout<O> for Option<L> { /*FIXME*/ }
//impl<O: Out> Layout<O> for fn(&mut O) {}
impl<O: Out, L: Layout<O>> Layout<O> for Arc<L> {
fn layout (&self, to: O::Area) -> O::Area {
(**self).layout(to)
}
}
impl<'x, O: Out> Layout<O> for &(dyn Draw<O> + 'x) {
fn layout (&self, to: O::Area) -> O::Area {
Fill::xy(self).layout(to)
}
}
mod layout_align; pub use self::layout_align::*;
mod layout_bsp; pub use self::layout_bsp::*;
mod layout_cond; pub use self::layout_cond::*;
mod layout_expand; pub use self::layout_expand::*;
mod layout_fill; pub use self::layout_fill::*;
mod layout_fixed; pub use self::layout_fixed::*;
mod layout_map; pub use self::layout_map::*;
mod layout_margin; pub use self::layout_margin::*;
mod layout_max; pub use self::layout_max::*;
mod layout_min; pub use self::layout_min::*;
mod layout_padding; pub use self::layout_padding::*;
mod layout_pull; pub use self::layout_pull::*;
mod layout_push; pub use self::layout_push::*;
mod layout_shrink; pub use self::layout_shrink::*;
mod layout_stack; pub use self::layout_stack::*;