I love control flow

This commit is contained in:
2025-11-20 22:48:08 -05:00
parent f6f9ebbe51
commit dff72d2c43
19 changed files with 126 additions and 63 deletions

View File

@@ -1,6 +1,7 @@
mod align;
mod offset;
mod pad;
mod scroll;
mod sized;
mod span;
mod stack;

View File

@@ -0,0 +1,39 @@
use crate::prelude::*;
pub struct Scroll {
inner: WidgetId,
axis: Axis,
snap_end: bool,
amt: f32,
draw_len: f32,
}
impl Widget for Scroll {
fn draw(&mut self, painter: &mut Painter) {
let output_len = painter.output_size().axis(self.axis);
let container_len = painter.region().axis(self.axis).len();
let content_len = painter
.len_axis(&self.inner, self.axis)
.apply_rest()
.within_len(container_len)
.to_abs(output_len);
let container_len = container_len.to_abs(output_len);
self.draw_len = content_len;
// let region = UiRegion::FULL.offset(self.amt);
// painter.widget_within(&self.inner, region);
}
fn desired_width(&mut self, _: &mut SizeCtx) -> Len {
Len::default()
}
fn desired_height(&mut self, _: &mut SizeCtx) -> Len {
Len::default()
}
}
impl Scroll {
pub fn scroll(&mut self, amt: f32) {
self.amt += amt;
}
}

View File

@@ -11,6 +11,9 @@ impl Widget for Span {
fn draw(&mut self, painter: &mut Painter) {
let total = self.len_sum(&mut painter.size_ctx());
let mut start = UiScalar::rel_min();
if painter.label() == "fricker" {
println!("redraw");
}
for child in &self.children {
let mut span = UiSpan::FULL;
span.start = start;
@@ -88,7 +91,10 @@ impl Span {
}
fn desired_ortho(&mut self, ctx: &mut SizeCtx) -> Len {
// this is an awful hack to get text wrapping to work properly when in a downward span
// this is a weird hack to get text wrapping to work properly when in a downward span
// the correct solution here is to add a function to widget that lets them
// request that ctx.outer has an axis "resolved" before checking the other,
// and panicking or warning if two request opposite axis (unsolvable in that case)
let outer = ctx.outer.axis(self.dir.axis);
if self.dir.axis == Axis::X {
// so....... this literally copies draw so that the lengths are correctly set in the