Compare commits

1 Commits

Author SHA1 Message Date
97b284e81e store size in tex instead of bot_right 2025-11-21 14:38:16 -05:00
5 changed files with 34 additions and 17 deletions

View File

@@ -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<T: UiNum> From<T> for Padding {

View File

@@ -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);

View File

@@ -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)
}
}

View File

@@ -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

View File

@@ -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
}
}