diff --git a/src/core/align.rs b/src/core/align.rs index de1ecd0..9e642d4 100644 --- a/src/core/align.rs +++ b/src/core/align.rs @@ -11,7 +11,7 @@ impl Widget for Aligned { painter.draw_within(&self.inner, region); } - fn size(&mut self, ctx: &mut SizeCtx) -> Vec2 { + fn get_size(&mut self, ctx: &mut SizeCtx) -> Vec2 { ctx.size(&self.inner) } } diff --git a/src/core/image.rs b/src/core/image.rs index 1e313d4..124d04e 100644 --- a/src/core/image.rs +++ b/src/core/image.rs @@ -10,7 +10,7 @@ impl Widget for Image { painter.draw_texture(&self.handle); } - fn size(&mut self, _: &mut SizeCtx) -> Vec2 { + fn get_size(&mut self, _: &mut SizeCtx) -> Vec2 { self.handle.size() } } diff --git a/src/core/sized.rs b/src/core/sized.rs index 2663285..d5af1d2 100644 --- a/src/core/sized.rs +++ b/src/core/sized.rs @@ -10,7 +10,7 @@ impl Widget for Sized { painter.draw(&self.inner); } - fn size(&mut self, _: &mut SizeCtx) -> Vec2 { + fn get_size(&mut self, _: &mut SizeCtx) -> Vec2 { self.size } } diff --git a/src/core/span.rs b/src/core/span.rs index 159b0d9..90126f7 100644 --- a/src/core/span.rs +++ b/src/core/span.rs @@ -43,7 +43,7 @@ impl Widget for Span { } } - fn size(&mut self, ctx: &mut SizeCtx) -> Vec2 { + fn get_size(&mut self, ctx: &mut SizeCtx) -> Vec2 { let total = self.setup(ctx); let axis = self.dir.axis; let dir_len = if total.ratio != 0.0 { diff --git a/src/core/text.rs b/src/core/text.rs index b119376..cadd31a 100644 --- a/src/core/text.rs +++ b/src/core/text.rs @@ -9,9 +9,9 @@ pub struct Text { } impl Text { - pub fn size(mut self, size: impl UiNum) -> Self { - self.attrs.size = size.to_f32(); - self.attrs.line_height = self.attrs.size * 1.1; + pub fn font_size(mut self, size: impl UiNum) -> Self { + self.attrs.font_size = size.to_f32(); + self.attrs.line_height = self.attrs.font_size * 1.1; self } pub fn color(mut self, color: UiColor) -> Self { @@ -41,7 +41,7 @@ impl Widget for Text { // reuse TextureHandle } - fn size(&mut self, ctx: &mut SizeCtx) -> Vec2 { + fn get_size(&mut self, ctx: &mut SizeCtx) -> Vec2 { let (handle, offset) = ctx.text .draw(&mut self.buf, &self.content, &self.attrs, ctx.textures); @@ -53,7 +53,7 @@ pub fn text(text: impl Into) -> Text { let attrs = TextAttrs::default(); Text { content: text.into(), - buf: TextBuffer::new_empty(Metrics::new(attrs.size, attrs.line_height)), + buf: TextBuffer::new_empty(Metrics::new(attrs.font_size, attrs.line_height)), attrs, } } diff --git a/src/core/trait_fns.rs b/src/core/trait_fns.rs index a17126d..b7786ac 100644 --- a/src/core/trait_fns.rs +++ b/src/core/trait_fns.rs @@ -7,7 +7,7 @@ pub trait CoreWidget { fn center(self) -> WidgetFnRet!(Aligned); fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned); fn label(self, label: impl Into) -> WidgetIdFnRet!(W); - fn sized(self, size: impl Into) -> WidgetFnRet!(Sized); + fn size(self, size: impl Into) -> WidgetFnRet!(Sized); } impl, Tag> CoreWidget for W { @@ -44,7 +44,7 @@ impl, Tag> CoreWidget for W { } } - fn sized(self, size: impl Into) -> WidgetFnRet!(Sized) { + fn size(self, size: impl Into) -> WidgetFnRet!(Sized) { move |ui| Sized { inner: self.add(ui).erase_type(), size: size.into(), diff --git a/src/layout/painter.rs b/src/layout/painter.rs index 608cc06..1f6e1d2 100644 --- a/src/layout/painter.rs +++ b/src/layout/painter.rs @@ -153,7 +153,7 @@ impl<'a> Painter<'a> { pub fn size(&mut self, id: &WidgetId) -> Vec2 { self.widgets .get_dyn_dynamic(&id.id) - .size(&mut self.size_ctx()) + .get_size(&mut self.size_ctx()) } pub fn size_ctx(&mut self) -> SizeCtx<'_> { diff --git a/src/layout/text.rs b/src/layout/text.rs index 8936cce..f14db96 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -23,7 +23,7 @@ impl Default for TextData { #[derive(Clone, Copy)] pub struct TextAttrs { pub color: UiColor, - pub size: f32, + pub font_size: f32, pub line_height: f32, pub family: Family<'static>, } @@ -35,7 +35,7 @@ impl Default for TextAttrs { let size = 14.0; Self { color: UiColor::WHITE, - size, + font_size: size, line_height: size * 1.2, family: Family::SansSerif, } @@ -52,7 +52,7 @@ impl TextData { ) -> (TextureHandle, TextOffset) { buffer.set_metrics( &mut self.font_system, - Metrics::new(attrs.size, attrs.line_height), + Metrics::new(attrs.font_size, attrs.line_height), ); buffer.set_text( &mut self.font_system, diff --git a/src/layout/widget.rs b/src/layout/widget.rs index dae2963..a4ef104 100644 --- a/src/layout/widget.rs +++ b/src/layout/widget.rs @@ -4,7 +4,7 @@ use std::{any::Any, marker::PhantomData}; pub trait Widget: Any { fn draw(&mut self, painter: &mut Painter); - fn size(&mut self, ctx: &mut SizeCtx) -> Vec2 { + fn get_size(&mut self, ctx: &mut SizeCtx) -> Vec2 { ctx.size } } @@ -18,7 +18,7 @@ pub struct SizeCtx<'a> { impl SizeCtx<'_> { pub fn size(&mut self, id: &WidgetId) -> Vec2 { - self.widgets.get_dyn_dynamic(&id.id).size(self) + self.widgets.get_dyn_dynamic(&id.id).get_size(self) } } diff --git a/src/testing/mod.rs b/src/testing/mod.rs index b82525a..2b512c0 100644 --- a/src/testing/mod.rs +++ b/src/testing/mod.rs @@ -39,7 +39,7 @@ impl Client { ( rect.color(Color::BLUE), ( - rect.color(Color::RED).sized((100.0, 100.0)), + rect.color(Color::RED).size(100).center(), (rect.color(Color::ORANGE), rect.color(Color::LIME).pad(10.0)) .span(Dir::RIGHT, [1, 1]), rect.color(Color::YELLOW), @@ -86,25 +86,28 @@ impl Client { .edit_on(HOVER_END, move |r| { r.color = color; }); - (rect, text(label).size(30)).stack() + (rect, text(label).font_size(30)).stack() }; let text_test = ui.add_static( ( - text("this is a").size(30).align(Align::Left), - text("teeeeeeeest").size(30).align(Align::Left), - text("okkk\nokkkkkk!").size(30).align(Align::Left), - text("hmm").size(30), - text("a").size(30), + text("this is a").font_size(30).align(Align::Left), + text("teeeeeeeest").font_size(30).align(Align::Left), + text("okkk\nokkkkkk!").font_size(30).align(Align::Left), + text("hmm").font_size(30), + text("a").font_size(30), ( - text("'").size(30).family(Family::Monospace).align(Align::Top), - text("'").size(30).family(Family::Monospace), - text(":gamer mode").size(30).family(Family::Monospace), - Rect::new(Color::BLUE).sized(100), + text("'") + .font_size(30) + .family(Family::Monospace) + .align(Align::Top), + text("'").font_size(30).family(Family::Monospace), + text(":gamer mode").font_size(30).family(Family::Monospace), + Rect::new(Color::BLUE).size(100), ) .span(Dir::RIGHT, sized()) .center(), - text("pretty cool right?").size(30), + text("pretty cool right?").font_size(30), ) .span(Dir::DOWN, sized()), ); @@ -125,7 +128,7 @@ impl Client { .erase_type(); ui[span_add].children.push((child, sized())); }) - .sized(150) + .size(150) .align(Align::BotRight); let del_button = Rect::new(Color::RED) @@ -133,7 +136,7 @@ impl Client { .on(PRESS_START, move |ui| { ui[span_add].children.pop(); }) - .sized(150) + .size(150) .align(Align::BotLeft); let info = ui.add(text(""));