Review response. `Painter::set_size` is gone: `Widget::draw` returns the `Size` instead, so a widget that does not say what it used cannot compile rather than panicking at the widget that forgot. That also settles setting it twice -- a branch that learns something late just returns a different value. `Painter::place` and `UiRenderState::place` are gone too. `draw_inner` already tried to reuse an active widget's drawing before redrawing it, so `place` was `widget_within` with its own bookkeeping bolted on; drawing a child a second time now *is* how a parent puts it where it belongs, and a child is deduplicated in `children` because listing one twice would move it twice. The unification also drops `place`'s use of `ActiveData::layer`, which is the layer a widget's own `child_layer()` left the painter on rather than the layer it was drawn into. What `place` did unconditionally and `widget_within` did not is record the size dependency, so `Painter::size_hint` now records one: reading a child's length to lay out around it is reading its size, whether it came from a draw or from a hint. `tests/retained.rs` has a parent that only ever reads the hint, which is the case no existing widget exercises. `()` sizes itself `Size::default()` -- rest -- rather than zero, so it is a gap that takes an even share of a span; `WidgetPtr` with nothing in it does the same, since it is the same situation. `Widget::on_resize`'s default body said `Translate` while the enum's `#[default]` said `Redraw`; it now defers to the enum. `was` is `old` throughout, the `OnResize` variant comments are gone, and so are two empty `impl` blocks. Checked: fmt, clippy and 27 tests across the workspace; `tabs` on each of its five tabs, and `tabs` with a replay that adds two images, all byte-identical to `upstream/main`; `view` and `minimal` likewise; and the `text` example rendered at 1920x1200 and 900x1200 to see the paragraph reflow and its container follow.
43 lines
880 B
Rust
43 lines
880 B
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) -> Size {
|
|
match &self.inner {
|
|
Some(id) => painter.widget(id).size(),
|
|
None => Size::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
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()
|
|
}
|
|
}
|