diff --git a/src/core/position/pad.rs b/src/core/position/pad.rs index 1b921fd..9bd9343 100644 --- a/src/core/position/pad.rs +++ b/src/core/position/pad.rs @@ -74,6 +74,26 @@ impl Padding { bottom: amt, } } + + pub fn with_top(mut self, amt: impl UiNum) -> Self { + self.top = amt.to_f32(); + self + } + + pub fn with_bottom(mut self, amt: impl UiNum) -> Self { + self.bottom = amt.to_f32(); + self + } + + pub fn with_left(mut self, amt: impl UiNum) -> Self { + self.left = amt.to_f32(); + self + } + + pub fn with_right(mut self, amt: impl UiNum) -> Self { + self.right = amt.to_f32(); + self + } } impl From for Padding { diff --git a/src/core/position/scroll.rs b/src/core/position/scroll.rs index dfbdea6..dd13783 100644 --- a/src/core/position/scroll.rs +++ b/src/core/position/scroll.rs @@ -20,10 +20,12 @@ impl Widget for Scroll { .to_abs(output_len); 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 mut region = UiRegion::FULL.offset(Vec2::from_axis(self.axis, -self.amt, 0.0)); region.axis_mut(self.axis).end = region.axis(self.axis).start.offset(self.content_len); painter.widget_within(&self.inner, region); diff --git a/src/core/text/edit.rs b/src/core/text/edit.rs index 4ed9ed5..3f014cf 100644 --- a/src/core/text/edit.rs +++ b/src/core/text/edit.rs @@ -16,7 +16,7 @@ pub struct TextEdit { impl TextEdit { pub fn region(&self) -> UiRegion { self.tex() - .map(|t| t.size()) + .map(|t| t.size) .unwrap_or(Vec2::ZERO) .align(self.align) } @@ -49,11 +49,11 @@ impl Widget for TextEdit { } fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len { - Len::abs(self.view.draw(ctx).size().x) + Len::abs(self.view.draw(ctx).size.x) } fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len { - Len::abs(self.view.draw(ctx).size().y) + Len::abs(self.view.draw(ctx).size.y) } } diff --git a/src/core/text/mod.rs b/src/core/text/mod.rs index 168fcc8..e2601f7 100644 --- a/src/core/text/mod.rs +++ b/src/core/text/mod.rs @@ -92,19 +92,19 @@ impl Widget for Text { } fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len { - Len::abs(self.update_buf(ctx).size().x) + Len::abs(self.update_buf(ctx).size.x) } fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len { - Len::abs(self.update_buf(ctx).size().y) + Len::abs(self.update_buf(ctx).size.y) } } pub fn text_region(tex: &TextTexture, align: RegionAlign) -> UiRegion { let tex_dims = tex.handle.size(); - let mut region = tex.size().align(align); - region.x.start.abs += tex.top_left.x; - region.y.start.abs += tex.top_left.y; + let mut region = tex.size.align(align); + region.x.start.abs += tex.top_left_offset.x; + region.y.start.abs += tex.top_left_offset.y; region.x.end.abs = region.x.start.abs + tex_dims.x; region.y.end.abs = region.y.start.abs + tex_dims.y; region diff --git a/src/layout/text.rs b/src/layout/text.rs index c0c9ff5..c2b4295 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -157,8 +157,8 @@ impl TextData { } TextTexture { handle: textures.add(image), - top_left: Vec2::new(min_x as f32, min_y as f32), - bot_right: Vec2::new(max_width - max_x as f32, height - max_y as f32), + top_left_offset: Vec2::new(min_x as f32, min_y as f32), + size: Vec2::new(max_width, height), } } } @@ -166,12 +166,7 @@ impl TextData { #[derive(Clone)] pub struct TextTexture { pub handle: TextureHandle, - pub top_left: Vec2, - pub bot_right: Vec2, + pub top_left_offset: Vec2, + pub size: Vec2, } -impl TextTexture { - pub fn size(&self) -> Vec2 { - self.handle.size() - self.top_left + self.bot_right - } -}