This commit is contained in:
2025-11-11 13:55:36 -05:00
parent 92db1264a6
commit deaf730901
9 changed files with 87 additions and 3 deletions

View File

@@ -38,7 +38,8 @@ pub struct Padding {
}
impl Padding {
pub fn uniform(amt: f32) -> Self {
pub fn uniform(amt: impl UiNum) -> Self {
let amt = amt.to_f32();
Self {
left: amt,
right: amt,
@@ -54,6 +55,24 @@ impl Padding {
region.bot_right.abs.y -= self.bottom;
region
}
pub fn x(amt: impl UiNum) -> Self {
let amt = amt.to_f32();
Self {
left: amt,
right: amt,
top: 0.0,
bottom: 0.0,
}
}
pub fn y(amt: impl UiNum) -> Self {
let amt = amt.to_f32();
Self {
left: 0.0,
right: 0.0,
top: amt,
bottom: amt,
}
}
}
impl<T: UiNum> From<T> for Padding {

View File

@@ -3,6 +3,7 @@ use crate::prelude::*;
pub struct Span {
pub children: Vec<(WidgetId, SpanLen)>,
pub dir: Dir,
pub spacing: f32,
}
impl Widget for Span {
@@ -36,6 +37,7 @@ impl Widget for Span {
child_region.flip(self.dir.axis);
}
painter.widget_within(child, child_region);
start.abs += self.spacing;
}
}
@@ -45,7 +47,10 @@ impl Widget for Span {
let dir_len = if total.ratio != 0.0 {
UiScalar::rel_max()
} else {
UiScalar::new(total.rel, total.abs)
UiScalar::new(
total.rel,
total.abs + self.spacing * self.children.len().saturating_sub(1) as f32,
)
};
let mut max_ortho = UiScalar::ZERO;
for (child, _) in &self.children {
@@ -68,9 +73,15 @@ impl Span {
Self {
children: Vec::new(),
dir,
spacing: 0.0,
}
}
pub fn spacing(mut self, spacing: impl UiNum) -> Self {
self.spacing = spacing.to_f32();
self
}
fn setup(&mut self, ctx: &mut SizeCtx) -> SpanLenSums {
self.children
.iter_mut()

View File

@@ -78,6 +78,7 @@ impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> CoreWidgetArr<LEN, Wa,
move |ui| Span {
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
dir,
spacing: 0.0,
}
}
fn stack(self) -> StackBuilder<LEN, Wa, Tag> {