mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-02-21 18:49:04 +01:00
uuugh
This commit is contained in:
parent
ca862b9802
commit
90fc869e14
42 changed files with 645 additions and 1158 deletions
|
|
@ -1,98 +1,10 @@
|
|||
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::*;
|
||||
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_map; pub use self::layout_map::*;
|
||||
mod layout_pad; pub use self::layout_pad::*;
|
||||
mod layout_move; pub use self::layout_move::*;
|
||||
mod layout_size; pub use self::layout_size::*;
|
||||
mod layout_stack; //pub use self::layout_stack::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue