FINALLY FIXED STUPID TEST UI ISSUES (true painter.rs moment) + scrolling

This commit is contained in:
2025-11-21 01:40:13 -05:00
parent e3b1ddc993
commit 172e7157be
7 changed files with 122 additions and 67 deletions

View File

@@ -9,6 +9,7 @@ mod stack;
pub use align::*;
pub use offset::*;
pub use pad::*;
pub use scroll::*;
pub use sized::*;
pub use span::*;
pub use stack::*;

View File

@@ -3,9 +3,10 @@ use crate::prelude::*;
pub struct Scroll {
inner: WidgetId,
axis: Axis,
snap_end: bool,
amt: f32,
draw_len: f32,
snap_end: bool,
container_len: f32,
content_len: f32,
}
impl Widget for Scroll {
@@ -17,10 +18,14 @@ impl Widget for Scroll {
.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);
self.container_len = container_len.to_abs(output_len);
self.content_len = content_len;
if self.snap_end {
self.amt = self.content_len - self.container_len;
}
self.update_amt();
let region = UiRegion::FULL.offset(Vec2::from_axis(self.axis, -self.amt, 0.0));
painter.widget_within(&self.inner, region);
}
fn desired_width(&mut self, _: &mut SizeCtx) -> Len {
@@ -33,7 +38,26 @@ impl Widget for Scroll {
}
impl Scroll {
pub fn new(inner: WidgetId, axis: Axis) -> Self {
Self {
inner,
axis,
amt: 0.0,
snap_end: true,
container_len: 0.0,
content_len: 0.0,
}
}
pub fn update_amt(&mut self) {
self.amt = self.amt.max(0.0);
let len = (self.content_len - self.container_len).max(0.0);
self.amt = self.amt.min(len);
self.snap_end = self.amt == len;
}
pub fn scroll(&mut self, amt: f32) {
self.amt += amt;
self.amt -= amt;
self.update_amt();
}
}