#[allow(unused)] use crate::event::ConfigCx;
use crate::geom::{Rect, Size};
use crate::layout::{AlignHints, AxisInfo, SizeRules};
use crate::theme::SizeCx;
use crate::{Layout, Widget};
use kas_macros::{autoimpl, impl_self};
#[impl_self]
mod MapAny {
#[autoimpl(Deref, DerefMut using self.inner)]
#[autoimpl(Clone, Default where W: trait)]
#[derive_widget]
pub struct MapAny<A, W: Widget<Data = ()>> {
_a: std::marker::PhantomData<A>,
#[widget = &()]
pub inner: W,
}
impl Widget for Self {
type Data = A;
}
impl Self {
pub fn new(inner: W) -> Self {
MapAny {
_a: std::marker::PhantomData,
inner,
}
}
}
}
#[impl_self]
mod Align {
#[autoimpl(Deref, DerefMut using self.inner)]
#[autoimpl(Clone where W: trait)]
#[autoimpl(Viewport using self.inner where W: trait)]
#[derive_widget]
pub struct Align<W: Widget> {
#[widget]
pub inner: W,
pub hints: AlignHints,
}
impl Self {
#[inline]
pub fn new(inner: W, hints: AlignHints) -> Self {
Align { inner, hints }
}
}
impl Layout for Self {
fn set_rect(&mut self, cx: &mut SizeCx, rect: Rect, hints: AlignHints) {
self.inner.set_rect(cx, rect, self.hints.combine(hints));
}
}
}
#[impl_self]
mod Pack {
#[autoimpl(Deref, DerefMut using self.inner)]
#[autoimpl(Clone where W: trait)]
#[autoimpl(Viewport using self.inner where W: trait)]
#[derive_widget]
pub struct Pack<W: Widget> {
#[widget]
pub inner: W,
pub hints: AlignHints,
size: Size,
}
impl Self {
#[inline]
pub fn new(inner: W, hints: AlignHints) -> Self {
Pack {
inner,
hints,
size: Size::ZERO,
}
}
}
impl Layout for Self {
fn size_rules(&mut self, cx: &mut SizeCx, axis: AxisInfo) -> SizeRules {
let rules = self.inner.size_rules(cx, axis);
self.size.set_component(axis, rules.ideal_size());
rules
}
fn set_rect(&mut self, cx: &mut SizeCx, rect: Rect, hints: AlignHints) {
let align = self.hints.combine(hints).complete_default();
let rect = align.aligned_rect(self.size, rect);
self.inner.set_rect(cx, rect, hints);
}
}
}