use ribir_core::prelude::*;
#[derive(MultiChild, Query, Declare)]
pub struct Stack {
#[declare(default)]
fit: StackFit,
}
#[derive(Default)]
pub enum StackFit {
#[default]
Loose,
Expand,
Passthrough,
}
impl Render for Stack {
fn perform_layout(&self, clamp: BoxClamp, ctx: &mut LayoutCtx) -> Size {
let clamp = match self.fit {
StackFit::Loose => clamp.loose(),
StackFit::Expand => BoxClamp { min: clamp.max, max: clamp.max },
StackFit::Passthrough => clamp,
};
let mut size = ZERO_SIZE;
let mut layouter = ctx.first_child_layouter();
while let Some(mut l) = layouter {
let child_size = l.perform_widget_layout(clamp);
size = size.max(child_size);
layouter = l.into_next_sibling();
}
size
}
fn paint(&self, _: &mut PaintingCtx) {
}
}
#[cfg(test)]
mod tests {
use ribir_core::test_helper::*;
use ribir_dev_helper::*;
use super::*;
use crate::prelude::*;
const FIVE: Size = Size::new(5., 5.);
fn smoke() -> impl WidgetBuilder {
let one = Size::new(1., 1.);
let five = Size::new(5., 5.);
fn_widget! {
@Stack {
@SizedBox { size: one}
@SizedBox { size: five}
}
}
}
widget_layout_test!(smoke, size == FIVE,);
}