WIP: a widget's region stays put and its placement moves in it
The protocol split: `region` is the box a parent gives a widget -- what a fraction it declares or reports is a fraction of, and the coordinates every region it writes composes within -- and it is the same box on the ask that measures and the ask that places. `placement` is what of that region the drawing takes, chosen by the parent per axis or by the widget's own answer and alignment. That is what stops a fraction being resolved twice: the placing ask no longer hands the widget its own answer as its box, so nothing under it re-resolves against a box that came from its own report. `reports_of` and `decided` are gone, folded into the two regions; `box_of` is gone; `declared_box` becomes `ask_box`, which gives a rule the region's length and takes the position from the placement. 84 of 92 suite tests pass. Five text and region-node cases still diverge warm against cold, and three count a second widget draw where a span's measuring ask and its placing ask give different placements.
This commit is contained in:
1 parent
e44dea34b4
commit
5fcace1bfa
11 files changed
+346
-206
No files matched your search
+36
-34
@@ -10,25 +10,36 @@ pub struct Span {
|
||||
impl Widget for Span {
|
||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||
let axis = self.dir.axis;
|
||||
// The row: this span's own box, as a span of the region it was given.
|
||||
// Its children are laid out along it, and what they declare or report
|
||||
// is a fraction of the region -- the area this span was told it has,
|
||||
// which it passes on unchanged.
|
||||
let own = painter.placement();
|
||||
let row = *own.axis(axis);
|
||||
// Across itself the span's own box is the child's region: a span is
|
||||
// what contains its children there, and nothing divides that axis.
|
||||
// Along it the whole region is, so a fraction means the same thing
|
||||
// for every child however much of the row is left when it is asked.
|
||||
let region = UiRegion::from_axis(axis, UiSpan::FULL, *own.axis(!axis));
|
||||
let along = |from: Len, to: Len| match self.dir.sign {
|
||||
Sign::Pos => UiSpan::new(row.start + from, row.start + to),
|
||||
Sign::Neg => UiSpan::new(row.end - to, row.end - from),
|
||||
};
|
||||
let far = row.len();
|
||||
// A length for every child before their final boxes are chosen: from
|
||||
// a hint where one exists, and from drawing otherwise.
|
||||
let mut cursor = Len::rel_min();
|
||||
let mut lens = Vec::with_capacity(self.children.len());
|
||||
for child in &self.children {
|
||||
let mut span = UiSpan::new(cursor, Len::rel_max());
|
||||
if self.dir.sign == Sign::Neg {
|
||||
span.flip();
|
||||
}
|
||||
let region = UiRegion::from_axis(axis, span, UiSpan::FULL);
|
||||
// Offered the room left from the cursor, because a text has to
|
||||
// wrap at the width actually there, but reporting a fraction of
|
||||
// the whole row: `rel(0.5)` is half the span whatever else is in
|
||||
// it and wherever this child sits among them.
|
||||
let len = match painter.known_len(child, axis, region, UiVec2::FULL_SIZE) {
|
||||
// The whole region is the child's, so `rel(0.5)` is half the area
|
||||
// this span was given whatever else is in it and wherever this
|
||||
// child sits among them. What it is placed in is the room left
|
||||
// from the cursor, because a text has to wrap at the width
|
||||
// actually there.
|
||||
let room = axis.pair(Some(along(cursor, far)), None);
|
||||
let len = match painter.known_len(child, axis, region) {
|
||||
Some(len) => len,
|
||||
None => painter
|
||||
.widget_at(child, region, UiVec2::FULL_SIZE, [false; 2])
|
||||
.len(axis),
|
||||
None => painter.widget_at(child, region, room).len(axis),
|
||||
};
|
||||
cursor.px += len.px + self.gap;
|
||||
cursor.rel += len.rel;
|
||||
@@ -46,9 +57,9 @@ impl Widget for Span {
|
||||
|sum, len| sum + *len,
|
||||
);
|
||||
|
||||
// What is left for the shares to divide: the box less everything
|
||||
// fixed, as a length of the box rather than a number of pixels.
|
||||
let room = Len::rel_max() - Len::from_parts(total.rel, total.px);
|
||||
// What is left for the shares to divide: the row less everything
|
||||
// fixed, as a length of the region rather than a number of pixels.
|
||||
let room = far - Len::from_parts(total.rel, total.px);
|
||||
// Whether anything is left over is a question in pixels: `rel(0.5)`
|
||||
// beside 300 px is full at 600 and overfull at 400. Asked of `room`
|
||||
// itself, and answered back through the same expression, so the
|
||||
@@ -60,12 +71,12 @@ impl Widget for Span {
|
||||
// exist at all turns on this.
|
||||
let mut shares = false;
|
||||
if total.leftover > Weight::ZERO {
|
||||
shares = room.to_px(painter.px_len(axis)) > Px::ZERO;
|
||||
shares = room.to_px(painter.region_px_len(axis)) > Px::ZERO;
|
||||
let holds = match shares {
|
||||
true => Holds::from(Px::STEP..=Px::MAX),
|
||||
false => Holds::from(Px::MIN..=Px::ZERO),
|
||||
};
|
||||
painter.holds(axis, holds.through(room));
|
||||
painter.region_holds(axis, holds.through(room));
|
||||
}
|
||||
|
||||
// Across itself a span is as long as its longest child -- unless a
|
||||
@@ -94,28 +105,19 @@ impl Widget for Span {
|
||||
fixed.px += self.gap;
|
||||
continue;
|
||||
}
|
||||
let mut span = UiSpan::FULL;
|
||||
span.start = start;
|
||||
let from = start;
|
||||
if len.leftover > Weight::ZERO && shares {
|
||||
taken += len.leftover;
|
||||
}
|
||||
fixed.px += len.px;
|
||||
fixed.rel += len.rel;
|
||||
start = shared(fixed, taken, total.leftover, room);
|
||||
span.end = start;
|
||||
let mut region = UiRegion::from_axis(axis, span, UiSpan::FULL);
|
||||
if self.dir.sign == Sign::Neg {
|
||||
region.flip(axis);
|
||||
}
|
||||
// Along the row this box is the child's own answer, so the answer
|
||||
// is not placed in it again; across it the child sits where its
|
||||
// alignment says.
|
||||
let placed = painter.widget_at(
|
||||
child,
|
||||
region,
|
||||
UiVec2::FULL_SIZE,
|
||||
[axis == Axis::X, axis == Axis::Y],
|
||||
);
|
||||
// Along the row the span says where the child goes; across it the
|
||||
// child sits where its own alignment says. Its region is the
|
||||
// whole of what this span was given either way, which is what its
|
||||
// fractions are of.
|
||||
let placed =
|
||||
painter.widget_at(child, region, axis.pair(Some(along(from, start)), None));
|
||||
if shrinks {
|
||||
let used = placed.len(!axis);
|
||||
// Choosing between a fixed and a relative length from the
|
||||
|
||||
Reference in new issue
Block a user