A region is a fraction of the output plus an offset and the shader
resolves it against the window every frame, so a resize already moves
the whole drawing without the CPU. Wiping the tree and drawing it again
was throwing that away.
`Painter::output_size` and `px_size` now record that a widget read
pixels, the way reading a child's size records a dependency on it, and a
resize marks only those. In the `text` example that is the two wrapping
paragraphs out of forty-odd widgets; everything else keeps its drawing
and the window uniform puts it in the right place.
Two defects the change surfaced, both of which made a resize land
somewhere a cold start would not:
`redraw` climbed to the highest reader of the changed widget and drew
from there, trusting that draw to reach back down. It does not: an
intermediate whose own box has not changed is reused as it stands and
the draw stops there. Everything between the two is now marked as well,
which is the only thing that stops the reuse. Not resize-specific --
`a_change_two_levels_under_its_reader_still_reaches_it` fails on the
mutation path too.
`mov` cannot stretch a drawing out of a box with no relative extent.
`UiScalar::within` puts a part into such a box as a plain offset from
its start, and `lerp_inv`'s divide-by-zero fallback then returns a
rel of 0 rather than saying it cannot invert, so the remap silently
leaves the drawing its old size. `OnResize::Scale` now only reuses
across a length change when the old box had a relative extent. The
underlying loss belongs to the position chain, which separates the
drawn box from the offered one; until then this is the honest
predicate.
Checked: fmt, clippy and 33 tests. `tabs` (with the image replay),
`view`, `minimal` still byte-identical to `upstream/main`, and `text`
unchanged at 1920x1200 and 900x1200. Driven live under the GPU as well:
started at 1920x1200, resized to 900x1200 and back through sway, and
each screenshot matches a cold start at that size byte for byte.
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.
`SizeDependence::{None, Internal, External}` becomes
`OnResize::{Scale, Translate, Redraw}`, which says what the retained path
may do rather than leaving the reader to work it out from a dependency.
`Redraw` is now the default, and that is the substance of this rather
than the naming. `Translate` was, and nothing opted into it: `SetSize`
reports one size and hands its child the whole box, so its pixels change
with the box and carrying them stretched a 100x100 rect across half the
window. A default that is only right for widgets that happen to qualify
is the same fault as an unchecked reuse flag.
`Translate` still does nothing, and now for the reason rather than the
one I gave before: `mov` translates perfectly well, but `ActiveData`'s
`region` is both the box a widget was given and the box its primitives
occupy, and `mov` remaps out of it. Keeping a drawing at its old size
while the box grows leaves those two disagreeing, and the next move
stretches it. Separating them is what the offset chain does.
Caught by rendering `tabs` against `main` rather than by a test, which is
the argument for keeping that check in the loop.
`desired_width`/`desired_height`, `WidgetAxisFns`, `SizeCtx` and the size
cache are gone. A widget states what it used with `Painter::set_size`
while it draws, and `Painter::widget` hands back a `DrawResult` whose
`size()` both reads the child and records that this widget's size depends
on it. Reading nothing keeps the parent independent of what the child came
to.
`Span` is what the change is for. It takes each child's `size_hint` where
there is one, draws only the children that cannot answer, allocates the
flexible space, then places everything -- which deletes `desired_ortho`,
whose own comment said it "literally copies draw ... which makes this slow
and not cool".
Invalidation follows the dependency edges the draw recorded: a widget that
needs redrawing hands off to the highest ancestor that read its size,
instead of re-running a measurement to find out whether anything changed.
`Widget::size_dependence(axis)` says how much of its box a widget's
drawing depends on -- none of it, its own extent, or the whole box -- so
the retained path can keep a drawing and write a new box into it. Asked
per axis, because wrapped text depends on the width it is offered and not
on the height. `Internal` does not yet buy more than `External`: keeping a
drawing when only the room around it changed is a translation, which waits
for the move chain.
`tests/retained.rs` covers the second frame rather than the first, which
is where the bugs were: a placed child that was not recorded as one got
pruned as departed on the next draw.
`examples/text.rs` is new, since wrapping was the one thing here with no
way to see it on its own.