use kas::Collection;
use kas::prelude::*;
#[macro_export]
macro_rules! float {
( $( $ee:expr ),* ) => {
$crate::Float::new( ::kas::collection! [ $( $ee ),* ] )
};
( $( $ee:expr ),+ , ) => {
$crate::Float::new( ::kas::collection! [ $( $ee ),+ ] )
};
}
#[impl_self]
mod Float {
#[derive(Default)]
#[widget]
pub struct Float<C: Collection> {
core: widget_core!(),
#[collection]
widgets: C,
}
impl Self {
#[inline]
pub fn new(widgets: C) -> Self {
Float {
core: Default::default(),
widgets,
}
}
}
impl Layout for Self {
fn size_rules(&mut self, cx: &mut SizeCx, axis: AxisInfo) -> SizeRules {
let mut rules = SizeRules::EMPTY;
for i in 0..self.widgets.len() {
if let Some(child) = self.widgets.get_mut_tile(i) {
rules = rules.max(child.size_rules(cx, axis));
}
}
rules
}
fn set_rect(&mut self, cx: &mut SizeCx, rect: Rect, hints: AlignHints) {
self.core.set_rect(rect);
for i in 0..self.widgets.len() {
if let Some(child) = self.widgets.get_mut_tile(i) {
child.set_rect(cx, rect, hints);
}
}
}
fn draw(&self, mut draw: DrawCx) {
let mut iter = (0..self.widgets.len()).rev();
if let Some(first) = iter.next() {
if let Some(child) = self.widgets.get_tile(first) {
child.draw(draw.re());
}
}
for i in iter {
if let Some(child) = self.widgets.get_tile(i) {
draw.with_pass(|draw| child.draw(draw));
}
}
}
}
impl Tile for Self {
fn role(&self, _: &mut dyn RoleCx) -> Role<'_> {
Role::None
}
}
impl Events for Self {
type Data = C::Data;
fn probe(&self, coord: Coord) -> Id {
for i in 0..self.widgets.len() {
if let Some(child) = self.widgets.get_tile(i) {
if let Some(id) = child.try_probe(coord) {
return id;
}
}
}
self.id()
}
}
}