unleash the sizes

This commit is contained in:
2025-09-25 21:30:26 -04:00
parent 06cfeaac6b
commit 5f2dffc189
5 changed files with 24 additions and 24 deletions

View File

@@ -70,7 +70,7 @@ impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> StackBuilder<LEN, Wa, T
} }
} }
pub fn stack_size(mut self, size: StackSize) -> Self { pub fn size(mut self, size: StackSize) -> Self {
self.size = size; self.size = size;
self self
} }

View File

@@ -12,7 +12,7 @@ pub struct Text {
} }
impl Text { impl Text {
pub fn font_size(mut self, size: impl UiNum) -> Self { pub fn size(mut self, size: impl UiNum) -> Self {
self.attrs.font_size = size.to_f32(); self.attrs.font_size = size.to_f32();
self.attrs.line_height = self.attrs.font_size * 1.1; self.attrs.line_height = self.attrs.font_size * 1.1;
self self
@@ -97,7 +97,7 @@ pub struct TextBuilder {
} }
impl TextBuilder { impl TextBuilder {
pub fn font_size(mut self, size: impl UiNum) -> Self { pub fn size(mut self, size: impl UiNum) -> Self {
self.attrs.font_size = size.to_f32(); self.attrs.font_size = size.to_f32();
self.attrs.line_height = self.attrs.font_size * 1.1; self.attrs.line_height = self.attrs.font_size * 1.1;
self self

View File

@@ -92,7 +92,7 @@ pub struct TextEditBuilder {
} }
impl TextEditBuilder { impl TextEditBuilder {
pub fn font_size(mut self, size: impl UiNum) -> Self { pub fn size(mut self, size: impl UiNum) -> Self {
self.attrs.font_size = size.to_f32(); self.attrs.font_size = size.to_f32();
self.attrs.line_height = self.attrs.font_size * 1.1; self.attrs.line_height = self.attrs.font_size * 1.1;
self self

View File

@@ -6,7 +6,7 @@ pub trait CoreWidget<W, Tag> {
fn align(self, align: Align) -> impl WidgetFn<Aligned>; fn align(self, align: Align) -> impl WidgetFn<Aligned>;
fn center(self) -> impl WidgetFn<Aligned>; fn center(self) -> impl WidgetFn<Aligned>;
fn label(self, label: impl Into<String>) -> impl WidgetIdFn<W>; fn label(self, label: impl Into<String>) -> impl WidgetIdFn<W>;
fn size(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized>; fn sized(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized>;
} }
impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W { impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
@@ -36,7 +36,7 @@ impl<W: WidgetLike<Tag>, Tag> CoreWidget<W::Widget, Tag> for W {
} }
} }
fn size(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized> { fn sized(self, size: impl Into<Vec2>) -> impl WidgetFn<Sized> {
move |ui| Sized { move |ui| Sized {
inner: self.add(ui).any(), inner: self.add(ui).any(),
size: size.into(), size: size.into(),

View File

@@ -40,7 +40,7 @@ impl Client {
let pad_test = ( let pad_test = (
rrect.color(Color::BLUE), rrect.color(Color::BLUE),
( (
rrect.color(Color::RED).size(100).center(), rrect.color(Color::RED).sized(100).center(),
( (
rrect.color(Color::ORANGE), rrect.color(Color::ORANGE),
rrect.color(Color::LIME).pad(10.0), rrect.color(Color::LIME).pad(10.0),
@@ -86,7 +86,7 @@ impl Client {
.any(); .any();
ctx.ui[span_add].children.push((child, sized())); ctx.ui[span_add].children.push((child, sized()));
}) })
.size(150) .sized(150)
.align(Align::BotRight); .align(Align::BotRight);
let del_button = rect(Color::RED) let del_button = rect(Color::RED)
@@ -94,7 +94,7 @@ impl Client {
.on(Sense::click(), move |ctx: &mut Client, _| { .on(Sense::click(), move |ctx: &mut Client, _| {
ctx.ui[span_add].children.pop(); ctx.ui[span_add].children.pop();
}) })
.size(150) .sized(150)
.align(Align::BotLeft); .align(Align::BotLeft);
let span_add_test = (span_add, add_button, del_button) let span_add_test = (span_add, add_button, del_button)
@@ -103,7 +103,7 @@ impl Client {
let main = pad_test.pad(10).add_static(&mut ui); let main = pad_test.pad(10).add_static(&mut ui);
let btext = |content| text(content).font_size(30); let btext = |content| text(content).size(30);
let text_test = ( let text_test = (
btext("this is a").align(Align::Left), btext("this is a").align(Align::Left),
@@ -115,13 +115,13 @@ impl Client {
btext("'").family(Family::Monospace).align(Align::Top), btext("'").family(Family::Monospace).align(Align::Top),
btext("'").family(Family::Monospace), btext("'").family(Family::Monospace),
btext(":gamer mode").family(Family::Monospace), btext(":gamer mode").family(Family::Monospace),
rect(Color::CYAN).size(10).center(), rect(Color::CYAN).sized(10).center(),
rect(Color::RED).size(100).center(), rect(Color::RED).sized(100).center(),
rect(Color::PURPLE).size(50).align(Align::Top), rect(Color::PURPLE).sized(50).align(Align::Top),
) )
.span(Dir::RIGHT, sized()) .span(Dir::RIGHT, sized())
.center(), .center(),
text("pretty cool right?").font_size(50), text("pretty cool right?").size(50),
) )
.span(Dir::DOWN, sized()) .span(Dir::DOWN, sized())
.add_static(&mut ui); .add_static(&mut ui);
@@ -129,23 +129,23 @@ impl Client {
let texts = Span::empty(Dir::DOWN).add_static(&mut ui); let texts = Span::empty(Dir::DOWN).add_static(&mut ui);
let add_text = text_edit("add") let add_text = text_edit("add")
.text_align(Align::Left) .text_align(Align::Left)
.font_size(30) .size(30)
.id_on(Sense::click(), |id, client: &mut Client, ctx| { .id_on(Sense::click(), |id, client: &mut Client, ctx| {
client.ui.text(id).select(ctx.cursor, ctx.size); client.ui.text(id).select(ctx.cursor, ctx.size);
client.focus = Some(id.clone()); client.focus = Some(id.clone());
}) })
.id_on(Submit, move |id, client: &mut Client, _| { .id_on(Submit, move |id, client: &mut Client, _| {
let content = client.ui.text(id).take(); let content = client.ui.text(id).take();
let text = text_edit(content) let text = text_edit(content).size(30).text_align(Align::Left).id_on(
.font_size(30) Sense::click(),
.text_align(Align::Left) |id, client: &mut Client, ctx| {
.id_on(Sense::click(), |id, client: &mut Client, ctx| {
client.ui.text(id).select(ctx.cursor, ctx.size); client.ui.text(id).select(ctx.cursor, ctx.size);
client.focus = Some(id.clone()); client.focus = Some(id.clone());
}); },
);
let msg_box = (rect(Color::WHITE.darker(0.5)), text) let msg_box = (rect(Color::WHITE.darker(0.5)), text)
.stack() .stack()
.stack_size(StackSize::Child(1)) .size(StackSize::Child(1))
.add(&mut client.ui); .add(&mut client.ui);
client.ui[texts].children.push((msg_box.any(), sized())); client.ui[texts].children.push((msg_box.any(), sized()));
}) })
@@ -160,13 +160,13 @@ impl Client {
.on(Sense::click(), move |client: &mut Client, _| { .on(Sense::click(), move |client: &mut Client, _| {
client.run_event(&add_text, Submit, ()); client.run_event(&add_text, Submit, ());
}) })
.size(40), .sized(40),
) )
.span(Dir::RIGHT, [ratio(1), sized()]) .span(Dir::RIGHT, [ratio(1), sized()])
.pad(10), .pad(10),
) )
.stack() .stack()
.stack_size(StackSize::Child(1)) .size(StackSize::Child(1))
.offset_layer(1) .offset_layer(1)
.align(Align::Bot), .align(Align::Bot),
) )
@@ -185,7 +185,7 @@ impl Client {
.edit_on(Sense::HoverEnd, move |r, _| { .edit_on(Sense::HoverEnd, move |r, _| {
r.color = color; r.color = color;
}); });
(rect, text(label).font_size(30)).stack() (rect, text(label).size(30)).stack()
}; };
let tabs = ( let tabs = (