`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: ?Sized>(_: &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: iris/iris#14
Co-authored-by: AIris <4+iris-ai@noreply.localhost>
58 lines
1.2 KiB
Rust
58 lines
1.2 KiB
Rust
use crate::prelude::*;
|
|
use std::marker::Unsize;
|
|
|
|
pub struct WidgetPtr {
|
|
pub inner: Option<StrongWidget>,
|
|
}
|
|
|
|
impl Widget for WidgetPtr {
|
|
fn draw(&mut self, painter: &mut Painter) {
|
|
if let Some(id) = &self.inner {
|
|
painter.widget(id);
|
|
}
|
|
}
|
|
|
|
fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len {
|
|
if let Some(id) = &self.inner {
|
|
ctx.width(id)
|
|
} else {
|
|
Len::ZERO
|
|
}
|
|
}
|
|
|
|
fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len {
|
|
if let Some(id) = &self.inner {
|
|
ctx.height(id)
|
|
} else {
|
|
Len::ZERO
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WidgetPtr {
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
pub fn empty() -> Self {
|
|
Self {
|
|
inner: Default::default(),
|
|
}
|
|
}
|
|
pub fn set<W: ?Sized + Unsize<dyn Widget>>(&mut self, to: StrongWidget<W>) {
|
|
self.inner = Some(to)
|
|
}
|
|
|
|
pub fn replace<W: ?Sized + Unsize<dyn Widget>>(
|
|
&mut self,
|
|
to: StrongWidget<W>,
|
|
) -> Option<StrongWidget> {
|
|
self.inner.replace(to)
|
|
}
|
|
}
|
|
|
|
impl Default for WidgetPtr {
|
|
fn default() -> Self {
|
|
Self::empty()
|
|
}
|
|
}
|