Rename the Sized widget to SetSize
It 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. Three files inside iris already imported `std::marker::Sized` to get out from under it; they no longer need to. `SetSize` rather than `FixedSize` because the size it sets need not be fixed: `width(rest(2))` and `width(rel(0.5))` build the same widget. It pairs with the `MaxSize` beside it -- one sets a length, the other caps it. `tests/prelude_bounds.rs` is a compile-level guard: it fails to build if the prelude shadows `Sized` again. The pad tab of the tabs example, which is what uses `sized` and the flexible widths, renders pixel-identical. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
00d2230b84
commit
f312db60c2
7 files changed
+27
-18
No files matched your search
+1
-5
@@ -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},
|
||||
|
||||
@@ -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::*;
|
||||
@@ -1,12 +1,12 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
pub struct Sized {
|
||||
pub struct SetSize {
|
||||
pub inner: StrongWidget,
|
||||
pub x: Option<Len>,
|
||||
pub y: Option<Len>,
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
use std::marker::{Sized, Unsize};
|
||||
use std::marker::Unsize;
|
||||
|
||||
pub struct WidgetPtr {
|
||||
pub inner: Option<StrongWidget>,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
use std::marker::{PhantomData, Sized};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct TextBuilder<State, O = TextOutput, H: WidgetOption<State> = ()> {
|
||||
pub content: String,
|
||||
|
||||
@@ -31,9 +31,9 @@ widget_trait! {
|
||||
}
|
||||
}
|
||||
|
||||
fn sized(self, size: impl Into<Size>) -> impl WidgetFn<Rsc, Sized> {
|
||||
fn sized(self, size: impl Into<Size>) -> impl WidgetFn<Rsc, SetSize> {
|
||||
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<Len>) -> impl WidgetFn<Rsc, Sized> {
|
||||
fn width(self, len: impl Into<Len>) -> impl WidgetFn<Rsc, SetSize> {
|
||||
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<Len>) -> impl WidgetFn<Rsc, Sized> {
|
||||
fn height(self, len: impl Into<Len>) -> impl WidgetFn<Rsc, SetSize> {
|
||||
let len = len.into();
|
||||
move |state| Sized {
|
||||
move |state| SetSize {
|
||||
inner: self.add_strong(state),
|
||||
x: None,
|
||||
y: Some(len),
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//! The prelude must not shadow names from the standard prelude. A widget
|
||||
//! called `Sized` meant every `?Sized` bound in a crate using iris resolved
|
||||
//! to the widget and failed to compile, which is an error in someone else's
|
||||
//! code that nothing here would have noticed.
|
||||
|
||||
use iris::prelude::*;
|
||||
|
||||
fn takes_unsized<T: ?Sized>(_: &T) {}
|
||||
|
||||
#[test]
|
||||
fn the_prelude_leaves_sized_alone() {
|
||||
takes_unsized("a `?Sized` bound resolves to the marker trait");
|
||||
}
|
||||
Reference in new issue
Block a user