A widget reports a fraction of the box it was given. Span added that
fraction straight into a cursor that counts fractions of the row, and Pad
summed its padding onto it, both right only while the offer had the
parent's whole extent -- which a span's does not after a relative child.
DrawResult::size and known_len now compose the answer through the offer's
length, so a container reads lengths of its own box.
That exposed placed_box scaling a fractional answer against a box the
parent had already chosen from it, halving a nested span twice. The
near-edge alignment override becomes per-axis `decided` flags: a box the
parent chose from the answer is the answer, and is not placed again.
Span decides the row axis; Scroll and Stack's sizing child decide both.
Alignment is always the widget's own property now.
The window is no longer a move entry. Chains bottom out in MoveIdx::NONE
and the window is applied where a fraction becomes pixels, in to_px on the
CPU and by the uniform in the shader, which now snaps the summed coordinate
since a floor does not distribute over a sum. A resize rewrites no entry.
Verified: view, minimal, random, tabs and text render byte-identical at
1920x1200 against 5f16617, a live resize to 1280x800 is identical to a
cold render, and the 100-seed oracle, all fifteen shrinker cases at 400
seeds of depth 5, and 1000 seeds of depth 6 pass.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
89 lines
2.7 KiB
Rust
89 lines
2.7 KiB
Rust
use std::marker::PhantomData;
|
|
|
|
use crate::prelude::*;
|
|
|
|
pub struct Stack {
|
|
pub children: Vec<StrongWidget>,
|
|
pub size: StackSize,
|
|
}
|
|
|
|
impl Widget for Stack {
|
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
|
let sizing = match self.size {
|
|
StackSize::Default => None,
|
|
StackSize::Child(i) => Some(i),
|
|
};
|
|
// Whichever child sizes the stack decides the box every child gets.
|
|
// The stack reports that size, so a child given a longer box would
|
|
// draw outside what the stack says it occupies.
|
|
let size = match sizing.and_then(|i| self.children.get(i).map(|c| (i, c))) {
|
|
// On the layer that child ends up on, so the ask below is a reuse
|
|
// rather than a second drawing of it somewhere else: a retained
|
|
// drawing belongs to the layer it was made on.
|
|
Some((i, child)) => {
|
|
painter.child_layer_at(i);
|
|
painter.widget(child).size()
|
|
}
|
|
None => Size::LEFTOVER,
|
|
};
|
|
let region = painter.box_of(size);
|
|
for (i, child) in self.children.iter().enumerate() {
|
|
painter.child_layer_at(i);
|
|
// The sizing child placed its own content in the box its answer
|
|
// decided, and this box was derived from that answer, so applying
|
|
// its alignment again here would place it twice. Every other
|
|
// child is handed a box that owes nothing to its own answer, and
|
|
// where it sits in one bigger than itself is its own business.
|
|
match sizing == Some(i) {
|
|
true => painter.widget_decided(child, region, [true; 2]),
|
|
false => painter.widget_within(child, region),
|
|
};
|
|
}
|
|
size
|
|
}
|
|
}
|
|
|
|
#[derive(Default, Debug)]
|
|
pub enum StackSize {
|
|
#[default]
|
|
Default,
|
|
Child(usize),
|
|
}
|
|
|
|
pub struct StackBuilder<State, const LEN: usize, Wa: WidgetArrLike<State, LEN, Tag>, Tag> {
|
|
pub children: Wa,
|
|
pub size: StackSize,
|
|
_pd: PhantomData<(State, Tag)>,
|
|
}
|
|
|
|
impl<Rsc, const LEN: usize, Wa: WidgetArrLike<Rsc, LEN, Tag>, Tag> WidgetFnTrait<Rsc>
|
|
for StackBuilder<Rsc, LEN, Wa, Tag>
|
|
{
|
|
type Widget = Stack;
|
|
|
|
#[track_caller]
|
|
fn run(self, rsc: &mut Rsc) -> Self::Widget {
|
|
Stack {
|
|
children: self.children.add(rsc).arr.into_iter().collect(),
|
|
size: self.size,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<State, const LEN: usize, Wa: WidgetArrLike<State, LEN, Tag>, Tag>
|
|
StackBuilder<State, LEN, Wa, Tag>
|
|
{
|
|
pub fn new(children: Wa) -> Self {
|
|
Self {
|
|
children,
|
|
size: StackSize::default(),
|
|
_pd: PhantomData,
|
|
}
|
|
}
|
|
|
|
pub fn size(mut self, size: StackSize) -> Self {
|
|
self.size = size;
|
|
self
|
|
}
|
|
}
|