sized spans!

This commit is contained in:
iris committed 2025-08-28 18:25:59 -04:00
1 parent d7d67e4ed3
commit a0e6623abe
7 files changed
+52 -10

No files matched your search

+16 -3
View File
@@ -7,7 +7,7 @@ pub struct Span {
impl Widget for Span {
fn draw(&mut self, painter: &mut Painter) {
let total = self.setup(painter);
let total = self.setup(&mut painter.size_ctx());
let mut start = UIScalar::min();
for (child, length) in &self.children {
let mut child_region = UiRegion::full();
@@ -44,6 +44,17 @@ impl Widget for Span {
painter.draw_within(child, child_region);
}
}
fn size(&mut self, ctx: &mut SizeCtx) -> Vec2 {
let total = self.setup(ctx);
let axis = self.dir.axis;
let dir_len = if total.ratio != 0.0 {
ctx.size.axis(axis)
} else {
total.fixed + total.relative * ctx.screen_size.axis(axis)
};
Vec2::from_axis(axis, dir_len, total.max_sized)
}
}
#[derive(Default)]
@@ -51,6 +62,7 @@ pub struct SpanLenSums {
pub fixed: f32,
pub ratio: f32,
pub relative: f32,
pub max_sized: f32,
}
impl Span {
@@ -61,7 +73,7 @@ impl Span {
}
}
fn setup(&mut self, painter: &mut Painter) -> SpanLenSums {
fn setup(&mut self, ctx: &mut SizeCtx) -> SpanLenSums {
self.children
.iter_mut()
.fold(SpanLenSums::default(), |mut s, (id, l)| {
@@ -70,8 +82,9 @@ impl Span {
SpanLen::Ratio(v) => s.ratio += *v,
SpanLen::Relative(v) => s.relative += *v,
SpanLen::Sized(v) => {
let size = painter.size(id);
let size = ctx.size(id);
let len = size.axis(self.dir.axis);
s.max_sized = s.max_sized.max(size.axis(!self.dir.axis));
*v = size;
s.fixed += len;
}