rename a bit

This commit is contained in:
2025-08-28 22:21:43 -04:00
parent 97f2f67dee
commit 3df76d926c
10 changed files with 34 additions and 31 deletions

View File

@@ -11,7 +11,7 @@ impl Widget for Aligned {
painter.draw_within(&self.inner, region); 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) ctx.size(&self.inner)
} }
} }

View File

@@ -10,7 +10,7 @@ impl Widget for Image {
painter.draw_texture(&self.handle); painter.draw_texture(&self.handle);
} }
fn size(&mut self, _: &mut SizeCtx) -> Vec2 { fn get_size(&mut self, _: &mut SizeCtx) -> Vec2 {
self.handle.size() self.handle.size()
} }
} }

View File

@@ -10,7 +10,7 @@ impl Widget for Sized {
painter.draw(&self.inner); painter.draw(&self.inner);
} }
fn size(&mut self, _: &mut SizeCtx) -> Vec2 { fn get_size(&mut self, _: &mut SizeCtx) -> Vec2 {
self.size self.size
} }
} }

View File

@@ -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 total = self.setup(ctx);
let axis = self.dir.axis; let axis = self.dir.axis;
let dir_len = if total.ratio != 0.0 { let dir_len = if total.ratio != 0.0 {

View File

@@ -9,9 +9,9 @@ pub struct Text {
} }
impl Text { impl Text {
pub fn size(mut self, size: impl UiNum) -> Self { pub fn font_size(mut self, size: impl UiNum) -> Self {
self.attrs.size = size.to_f32(); self.attrs.font_size = size.to_f32();
self.attrs.line_height = self.attrs.size * 1.1; self.attrs.line_height = self.attrs.font_size * 1.1;
self self
} }
pub fn color(mut self, color: UiColor) -> Self { pub fn color(mut self, color: UiColor) -> Self {
@@ -41,7 +41,7 @@ impl Widget for Text {
// reuse TextureHandle // reuse TextureHandle
} }
fn size(&mut self, ctx: &mut SizeCtx) -> Vec2 { fn get_size(&mut self, ctx: &mut SizeCtx) -> Vec2 {
let (handle, offset) = let (handle, offset) =
ctx.text ctx.text
.draw(&mut self.buf, &self.content, &self.attrs, ctx.textures); .draw(&mut self.buf, &self.content, &self.attrs, ctx.textures);
@@ -53,7 +53,7 @@ pub fn text(text: impl Into<String>) -> Text {
let attrs = TextAttrs::default(); let attrs = TextAttrs::default();
Text { Text {
content: text.into(), 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, attrs,
} }
} }

View File

@@ -7,7 +7,7 @@ pub trait CoreWidget<W, Tag> {
fn center(self) -> WidgetFnRet!(Aligned); fn center(self) -> WidgetFnRet!(Aligned);
fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned); fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned);
fn label(self, label: impl Into<String>) -> WidgetIdFnRet!(W); fn label(self, label: impl Into<String>) -> WidgetIdFnRet!(W);
fn sized(self, size: impl Into<Vec2>) -> WidgetFnRet!(Sized); fn size(self, size: impl Into<Vec2>) -> WidgetFnRet!(Sized);
} }
impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W { impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
@@ -44,7 +44,7 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
} }
} }
fn sized(self, size: impl Into<Vec2>) -> WidgetFnRet!(Sized) { fn size(self, size: impl Into<Vec2>) -> WidgetFnRet!(Sized) {
move |ui| Sized { move |ui| Sized {
inner: self.add(ui).erase_type(), inner: self.add(ui).erase_type(),
size: size.into(), size: size.into(),

View File

@@ -153,7 +153,7 @@ impl<'a> Painter<'a> {
pub fn size<W>(&mut self, id: &WidgetId<W>) -> Vec2 { pub fn size<W>(&mut self, id: &WidgetId<W>) -> Vec2 {
self.widgets self.widgets
.get_dyn_dynamic(&id.id) .get_dyn_dynamic(&id.id)
.size(&mut self.size_ctx()) .get_size(&mut self.size_ctx())
} }
pub fn size_ctx(&mut self) -> SizeCtx<'_> { pub fn size_ctx(&mut self) -> SizeCtx<'_> {

View File

@@ -23,7 +23,7 @@ impl Default for TextData {
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct TextAttrs { pub struct TextAttrs {
pub color: UiColor, pub color: UiColor,
pub size: f32, pub font_size: f32,
pub line_height: f32, pub line_height: f32,
pub family: Family<'static>, pub family: Family<'static>,
} }
@@ -35,7 +35,7 @@ impl Default for TextAttrs {
let size = 14.0; let size = 14.0;
Self { Self {
color: UiColor::WHITE, color: UiColor::WHITE,
size, font_size: size,
line_height: size * 1.2, line_height: size * 1.2,
family: Family::SansSerif, family: Family::SansSerif,
} }
@@ -52,7 +52,7 @@ impl TextData {
) -> (TextureHandle, TextOffset) { ) -> (TextureHandle, TextOffset) {
buffer.set_metrics( buffer.set_metrics(
&mut self.font_system, &mut self.font_system,
Metrics::new(attrs.size, attrs.line_height), Metrics::new(attrs.font_size, attrs.line_height),
); );
buffer.set_text( buffer.set_text(
&mut self.font_system, &mut self.font_system,

View File

@@ -4,7 +4,7 @@ use std::{any::Any, marker::PhantomData};
pub trait Widget: Any { pub trait Widget: Any {
fn draw(&mut self, painter: &mut Painter); 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 ctx.size
} }
} }
@@ -18,7 +18,7 @@ pub struct SizeCtx<'a> {
impl SizeCtx<'_> { impl SizeCtx<'_> {
pub fn size<W>(&mut self, id: &WidgetId<W>) -> Vec2 { pub fn size<W>(&mut self, id: &WidgetId<W>) -> Vec2 {
self.widgets.get_dyn_dynamic(&id.id).size(self) self.widgets.get_dyn_dynamic(&id.id).get_size(self)
} }
} }

View File

@@ -39,7 +39,7 @@ impl Client {
( (
rect.color(Color::BLUE), 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)) (rect.color(Color::ORANGE), rect.color(Color::LIME).pad(10.0))
.span(Dir::RIGHT, [1, 1]), .span(Dir::RIGHT, [1, 1]),
rect.color(Color::YELLOW), rect.color(Color::YELLOW),
@@ -86,25 +86,28 @@ impl Client {
.edit_on(HOVER_END, move |r| { .edit_on(HOVER_END, move |r| {
r.color = color; r.color = color;
}); });
(rect, text(label).size(30)).stack() (rect, text(label).font_size(30)).stack()
}; };
let text_test = ui.add_static( let text_test = ui.add_static(
( (
text("this is a").size(30).align(Align::Left), text("this is a").font_size(30).align(Align::Left),
text("teeeeeeeest").size(30).align(Align::Left), text("teeeeeeeest").font_size(30).align(Align::Left),
text("okkk\nokkkkkk!").size(30).align(Align::Left), text("okkk\nokkkkkk!").font_size(30).align(Align::Left),
text("hmm").size(30), text("hmm").font_size(30),
text("a").size(30), text("a").font_size(30),
( (
text("'").size(30).family(Family::Monospace).align(Align::Top), text("'")
text("'").size(30).family(Family::Monospace), .font_size(30)
text(":gamer mode").size(30).family(Family::Monospace), .family(Family::Monospace)
Rect::new(Color::BLUE).sized(100), .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()) .span(Dir::RIGHT, sized())
.center(), .center(),
text("pretty cool right?").size(30), text("pretty cool right?").font_size(30),
) )
.span(Dir::DOWN, sized()), .span(Dir::DOWN, sized()),
); );
@@ -125,7 +128,7 @@ impl Client {
.erase_type(); .erase_type();
ui[span_add].children.push((child, sized())); ui[span_add].children.push((child, sized()));
}) })
.sized(150) .size(150)
.align(Align::BotRight); .align(Align::BotRight);
let del_button = Rect::new(Color::RED) let del_button = Rect::new(Color::RED)
@@ -133,7 +136,7 @@ impl Client {
.on(PRESS_START, move |ui| { .on(PRESS_START, move |ui| {
ui[span_add].children.pop(); ui[span_add].children.pop();
}) })
.sized(150) .size(150)
.align(Align::BotLeft); .align(Align::BotLeft);
let info = ui.add(text("")); let info = ui.add(text(""));