Compare commits
1 Commits
c428de8fd5
...
97b284e81e
| Author | SHA1 | Date | |
|---|---|---|---|
| 97b284e81e |
@@ -74,6 +74,26 @@ impl Padding {
|
|||||||
bottom: amt,
|
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 {
|
impl<T: UiNum> From<T> for Padding {
|
||||||
|
|||||||
@@ -20,10 +20,12 @@ impl Widget for Scroll {
|
|||||||
.to_abs(output_len);
|
.to_abs(output_len);
|
||||||
self.container_len = container_len.to_abs(output_len);
|
self.container_len = container_len.to_abs(output_len);
|
||||||
self.content_len = content_len;
|
self.content_len = content_len;
|
||||||
|
|
||||||
if self.snap_end {
|
if self.snap_end {
|
||||||
self.amt = self.content_len - self.container_len;
|
self.amt = self.content_len - self.container_len;
|
||||||
}
|
}
|
||||||
self.update_amt();
|
self.update_amt();
|
||||||
|
|
||||||
let mut region = UiRegion::FULL.offset(Vec2::from_axis(self.axis, -self.amt, 0.0));
|
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);
|
region.axis_mut(self.axis).end = region.axis(self.axis).start.offset(self.content_len);
|
||||||
painter.widget_within(&self.inner, region);
|
painter.widget_within(&self.inner, region);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub struct TextEdit {
|
|||||||
impl TextEdit {
|
impl TextEdit {
|
||||||
pub fn region(&self) -> UiRegion {
|
pub fn region(&self) -> UiRegion {
|
||||||
self.tex()
|
self.tex()
|
||||||
.map(|t| t.size())
|
.map(|t| t.size)
|
||||||
.unwrap_or(Vec2::ZERO)
|
.unwrap_or(Vec2::ZERO)
|
||||||
.align(self.align)
|
.align(self.align)
|
||||||
}
|
}
|
||||||
@@ -49,11 +49,11 @@ impl Widget for TextEdit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len {
|
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 {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,19 +92,19 @@ impl Widget for Text {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len {
|
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 {
|
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 {
|
pub fn text_region(tex: &TextTexture, align: RegionAlign) -> UiRegion {
|
||||||
let tex_dims = tex.handle.size();
|
let tex_dims = tex.handle.size();
|
||||||
let mut region = tex.size().align(align);
|
let mut region = tex.size.align(align);
|
||||||
region.x.start.abs += tex.top_left.x;
|
region.x.start.abs += tex.top_left_offset.x;
|
||||||
region.y.start.abs += tex.top_left.y;
|
region.y.start.abs += tex.top_left_offset.y;
|
||||||
region.x.end.abs = region.x.start.abs + tex_dims.x;
|
region.x.end.abs = region.x.start.abs + tex_dims.x;
|
||||||
region.y.end.abs = region.y.start.abs + tex_dims.y;
|
region.y.end.abs = region.y.start.abs + tex_dims.y;
|
||||||
region
|
region
|
||||||
|
|||||||
@@ -157,8 +157,8 @@ impl TextData {
|
|||||||
}
|
}
|
||||||
TextTexture {
|
TextTexture {
|
||||||
handle: textures.add(image),
|
handle: textures.add(image),
|
||||||
top_left: Vec2::new(min_x as f32, min_y as f32),
|
top_left_offset: 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),
|
size: Vec2::new(max_width, height),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,12 +166,7 @@ impl TextData {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TextTexture {
|
pub struct TextTexture {
|
||||||
pub handle: TextureHandle,
|
pub handle: TextureHandle,
|
||||||
pub top_left: Vec2,
|
pub top_left_offset: Vec2,
|
||||||
pub bot_right: Vec2,
|
pub size: Vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TextTexture {
|
|
||||||
pub fn size(&self) -> Vec2 {
|
|
||||||
self.handle.size() - self.top_left + self.bot_right
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user