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>
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()
|
|
}
|
|
}
|