From 32b10383d83ac5ac94bf530b683e662420d326c4 Mon Sep 17 00:00:00 2001 From: AIris <4+iris-ai@noreply.localhost> Date: Sun, 13 Sep 2026 20:16:17 -0400 Subject: [PATCH] Rename the Sized widget to SetSize (#14) `Sized` shadowed the marker trait, so a `?Sized` bound in any crate that imports the prelude failed to resolve -- a compile error in someone else's code that nothing here would have caught. It was already biting inside iris: `default/mod.rs`, `widget/ptr.rs` and `widget/text/build.rs` all imported `std::marker::Sized` explicitly to get out from under it, which they no longer need. `SetSize` rather than `FixedSize` because the size it sets need not be fixed -- `width(rest(2))` (a flex weight) and `width(rel(0.5))` (half the parent) build the same widget, and both are more common than `sized((100, 100))`. It also pairs with the `MaxSize` beside it in that module: one sets a length, the other caps it. The builders are unchanged. `tests/prelude_bounds.rs` is a compile-level guard -- it fails to build if the prelude shadows `Sized` again, which I checked by reverting `src/` under it: ``` error[E0404]: expected trait, found struct `Sized` --> tests/prelude_bounds.rs:8:22 | 8 | fn takes_unsized(_: &T) {} | ^^^^^ not a trait ``` The pad tab of the tabs example -- the one built out of `sized` and the flexible widths -- renders pixel-identical to before the rename. --------- Co-authored-by: iris <2+iris@noreply.localhost> Reviewed-on: https://git.arirex.me/iris/iris/pulls/14 Co-authored-by: AIris <4+iris-ai@noreply.localhost> --- src/default/mod.rs | 6 +----- src/widget/position/mod.rs | 4 ++-- src/widget/position/{sized.rs => set_size.rs} | 6 +++--- src/widget/ptr.rs | 2 +- src/widget/text/build.rs | 2 +- src/widget/trait_fns.rs | 12 ++++++------ 6 files changed, 14 insertions(+), 18 deletions(-) rename src/widget/position/{sized.rs => set_size.rs} (92%) diff --git a/src/default/mod.rs b/src/default/mod.rs index ea00eb7..af2c520 100644 --- a/src/default/mod.rs +++ b/src/default/mod.rs @@ -1,10 +1,6 @@ use crate::prelude::*; use arboard::Clipboard; -use std::{ - marker::{PhantomData, Sized}, - sync::Arc, - time::Instant, -}; +use std::{marker::PhantomData, sync::Arc, time::Instant}; use winit::{ event::{Ime, WindowEvent}, event_loop::{ActiveEventLoop, EventLoopProxy}, diff --git a/src/widget/position/mod.rs b/src/widget/position/mod.rs index c389b6c..12d6614 100644 --- a/src/widget/position/mod.rs +++ b/src/widget/position/mod.rs @@ -4,7 +4,7 @@ mod max_size; mod offset; mod pad; mod scroll; -mod sized; +mod set_size; mod span; mod stack; @@ -14,6 +14,6 @@ pub use max_size::*; pub use offset::*; pub use pad::*; pub use scroll::*; -pub use sized::*; +pub use set_size::*; pub use span::*; pub use stack::*; diff --git a/src/widget/position/sized.rs b/src/widget/position/set_size.rs similarity index 92% rename from src/widget/position/sized.rs rename to src/widget/position/set_size.rs index aa1fc58..b39d6e6 100644 --- a/src/widget/position/sized.rs +++ b/src/widget/position/set_size.rs @@ -1,12 +1,12 @@ use crate::prelude::*; -pub struct Sized { +pub struct SetSize { pub inner: StrongWidget, pub x: Option, pub y: Option, } -impl Sized { +impl SetSize { fn apply_to_outer(&self, ctx: &mut SizeCtx) { if let Some(x) = self.x { ctx.outer.x.select_len(x.apply_rest()); @@ -17,7 +17,7 @@ impl Sized { } } -impl Widget for Sized { +impl Widget for SetSize { fn draw(&mut self, painter: &mut Painter) { painter.widget(&self.inner); } diff --git a/src/widget/ptr.rs b/src/widget/ptr.rs index 1e6241b..b3387b2 100644 --- a/src/widget/ptr.rs +++ b/src/widget/ptr.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use std::marker::{Sized, Unsize}; +use std::marker::Unsize; pub struct WidgetPtr { pub inner: Option, diff --git a/src/widget/text/build.rs b/src/widget/text/build.rs index 1619bfe..c20c308 100644 --- a/src/widget/text/build.rs +++ b/src/widget/text/build.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use std::marker::{PhantomData, Sized}; +use std::marker::PhantomData; pub struct TextBuilder = ()> { pub content: String, diff --git a/src/widget/trait_fns.rs b/src/widget/trait_fns.rs index effebc8..f76b9a2 100644 --- a/src/widget/trait_fns.rs +++ b/src/widget/trait_fns.rs @@ -31,9 +31,9 @@ widget_trait! { } } - fn sized(self, size: impl Into) -> impl WidgetFn { + fn sized(self, size: impl Into) -> impl WidgetFn { let size = size.into(); - move |state| Sized { + move |state| SetSize { inner: self.add_strong(state), x: Some(size.x), y: Some(size.y), @@ -58,18 +58,18 @@ widget_trait! { } } - fn width(self, len: impl Into) -> impl WidgetFn { + fn width(self, len: impl Into) -> impl WidgetFn { let len = len.into(); - move |state| Sized { + move |state| SetSize { inner: self.add_strong(state), x: Some(len), y: None, } } - fn height(self, len: impl Into) -> impl WidgetFn { + fn height(self, len: impl Into) -> impl WidgetFn { let len = len.into(); - move |state| Sized { + move |state| SetSize { inner: self.add_strong(state), x: None, y: Some(len),