span builder

This commit is contained in:
2025-11-13 16:59:31 -05:00
parent 125fca4075
commit e2690fa611
2 changed files with 53 additions and 9 deletions

View File

@@ -1,3 +1,5 @@
use std::marker::PhantomData;
use crate::prelude::*;
pub struct Span {
@@ -15,13 +17,13 @@ impl Widget for Span {
let mut axis = child_region.axis_mut(self.dir.axis);
axis.top_left.set(start);
let len = painter.size(child).axis(self.dir.axis);
start.abs += len.abs;
start.rel += len.rel;
if len.rest > 0.0 {
let offset = UiScalar::new(total.rel, total.abs);
let rel_end = UiScalar::from_anchor(len.rest / total.rest);
start = rel_end.within(start, (UiScalar::rel_max() + start) - offset);
}
start.abs += len.abs;
start.rel += len.rel;
axis.bot_right.set(start);
if self.dir.sign == Sign::Neg {
child_region.flip(self.dir.axis);
@@ -75,3 +77,40 @@ impl Span {
})
}
}
pub struct SpanBuilder<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> {
pub children: Wa,
pub dir: Dir,
pub gap: f32,
_pd: PhantomData<Tag>,
}
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> FnOnce<(&mut Ui,)>
for SpanBuilder<LEN, Wa, Tag>
{
type Output = Span;
extern "rust-call" fn call_once(self, args: (&mut Ui,)) -> Self::Output {
Span {
children: self.children.ui(args.0).arr.to_vec(),
dir: self.dir,
gap: self.gap,
}
}
}
impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> SpanBuilder<LEN, Wa, Tag> {
pub fn new(children: Wa, dir: Dir) -> Self {
Self {
children,
dir,
gap: 0.0,
_pd: PhantomData,
}
}
pub fn gap(mut self, gap: impl UiNum) -> Self {
self.gap = gap.to_f32();
self
}
}