Read a child's report as a fraction of the containing widget
`rel(0.5)` is half the span whatever else is in it and wherever the child sits among them (Bryan, 2026-09-17). It was half of what the span had left at the point it asked, because a report came back composed through the box it was offered and a span offers each child the room from its cursor -- so a nested span taking half of what it was given took a quarter of a row whose first half was already spoken for, where the same half written as a rule on the child took half the row. The offer stays the remainder: a text has to wrap at the width actually there, and `a_text_in_a_span_wraps_at_the_room_left_rather_than_the_whole_row` pins that. What separates from it is the base a report's fractions are of, which the ask now carries. It is the box the child was given wherever that box is the child's whole area -- a pad's inset, a stack child, a scroll's content -- and a span passes its own extent along the row. `widget_decided` becomes `widget_at`, which says both things about an ask rather than one of them; `widget_within` is still the sugar for neither. Two spans asking for half each now take the whole row between them and a third overflows, which the rewritten `a_span_reads_a_child_report_as_a_fraction_of_the_row` states outright. The five reference renders are byte-identical at 1920x1200 and `random` live-resized still matches a cold render, so nothing that exists reports a fraction to a span today.
This commit is contained in:
1 parent
0e0d4af326
commit
ffd79f32d3
6 files changed
+102
-46
No files matched your search
+32
-28
@@ -139,29 +139,30 @@ impl<'a> Painter<'a> {
|
||||
id: &'s StrongWidget<W>,
|
||||
region: UiRegion,
|
||||
) -> DrawResult<'s, 'a, W> {
|
||||
self.widget_at(id, region, [false; 2])
|
||||
self.widget_at(id, region, region.size(), [false; 2])
|
||||
}
|
||||
|
||||
/// Draws a widget in a box this widget chose from the widget's own
|
||||
/// answer along the `decided` axes. On those the answer is not placed
|
||||
/// inside the box again: it already is the box, and a fraction the
|
||||
/// widget reported of its offer, taken of this box a second time, would
|
||||
/// shrink it twice. A container uses this where it hands back exactly
|
||||
/// Draws a widget in `region`, saying what the answer means.
|
||||
///
|
||||
/// `reports_of` is what a fraction the child reports is a fraction of, as
|
||||
/// lengths of this widget's own box. It is the box the child was given
|
||||
/// wherever that box is the child's whole area -- a pad's inset, a stack
|
||||
/// child, a scroll's content -- and a span passes its own extent along
|
||||
/// the row instead: it offers each child the room left from its cursor,
|
||||
/// because a text has to wrap at the width actually there, while
|
||||
/// `rel(0.5)` still means half the span wherever the child sits in it.
|
||||
///
|
||||
/// A `decided` axis is one where this box was chosen from the widget's
|
||||
/// own answer. On those the answer is not placed inside the box again: it
|
||||
/// already is the box, and a fraction taken of it a second time would
|
||||
/// shrink it twice. A container uses that where it hands back exactly
|
||||
/// what a child asked for -- a span placing a child at the length it
|
||||
/// reported, a scroll giving its content the content's own length.
|
||||
pub fn widget_decided<'s, W: ?Sized>(
|
||||
&'s mut self,
|
||||
id: &'s StrongWidget<W>,
|
||||
region: UiRegion,
|
||||
decided: [bool; 2],
|
||||
) -> DrawResult<'s, 'a, W> {
|
||||
self.widget_at(id, region, decided)
|
||||
}
|
||||
|
||||
fn widget_at<'s, W: ?Sized>(
|
||||
pub fn widget_at<'s, W: ?Sized>(
|
||||
&'s mut self,
|
||||
id: &'s StrongWidget<W>,
|
||||
region: UiRegion,
|
||||
reports_of: UiVec2,
|
||||
decided: [bool; 2],
|
||||
) -> DrawResult<'s, 'a, W> {
|
||||
let region_node = self.rsc.widgets().is_region_node(id.id());
|
||||
@@ -234,7 +235,7 @@ impl<'a> Painter<'a> {
|
||||
DrawResult {
|
||||
child: id,
|
||||
painter: self,
|
||||
size: in_parent_frame(size, local, declared),
|
||||
size: in_parent_frame(size, reports_of, declared),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,12 +269,14 @@ impl<'a> Painter<'a> {
|
||||
|
||||
/// A child's length in the box it is about to be offered, if it can be
|
||||
/// had without drawing it: from its hint, or from a drawing it already
|
||||
/// has that holds for that box.
|
||||
/// has that holds for that box. `reports_of` is what a fraction in the
|
||||
/// answer is a fraction of, as it is for [`Self::widget_at`].
|
||||
pub fn known_len<W: ?Sized>(
|
||||
&mut self,
|
||||
child: &StrongWidget<W>,
|
||||
axis: Axis,
|
||||
region: UiRegion,
|
||||
reports_of: UiVec2,
|
||||
) -> Option<LayoutLen> {
|
||||
let declared = self.declared_lens(child);
|
||||
let align = self.rsc.widgets().alignment(child.id());
|
||||
@@ -299,7 +302,7 @@ impl<'a> Painter<'a> {
|
||||
for (axis, under) in AXES.into_iter().zip(self.under.iter_mut()) {
|
||||
*under = under.and(holds[axis as usize].through(local.axis(axis).len()));
|
||||
}
|
||||
Some(in_parent_frame(size, local, declared).axis(axis))
|
||||
Some(in_parent_frame(size, reports_of, declared).axis(axis))
|
||||
}
|
||||
|
||||
/// Whether this is the first box a child is asked about in during a draw
|
||||
@@ -518,18 +521,19 @@ impl PrimitiveLike for &TextureHandle {
|
||||
}
|
||||
}
|
||||
|
||||
/// A child's answer as lengths of the box it was asked from. A widget reports
|
||||
/// a fraction of the box it was given, and the widget that gave it wants the
|
||||
/// same length as a fraction of its own: one composition apart wherever the
|
||||
/// offer was not the whole of the parent's extent, as a span's is after a
|
||||
/// relative child. A declared axis is already the parent's: it resolved the
|
||||
/// rule in its own box, and the rule is what the report says.
|
||||
fn in_parent_frame(size: Size, local: UiRegion, declared: [Option<LayoutLen>; 2]) -> Size {
|
||||
/// A child's answer as lengths of the parent's own box. A widget reports a
|
||||
/// fraction, and `reports_of` is the length that fraction is of: the box the
|
||||
/// child was given wherever that is the child's whole area, and the parent's
|
||||
/// own extent wherever the box is a positional remainder, as a span's is
|
||||
/// after an earlier child. Pixels come through untouched either way, being
|
||||
/// that many pixels wherever they end up. A declared axis is already the
|
||||
/// parent's: it resolved the rule in its own box, and the rule is what the
|
||||
/// report says.
|
||||
fn in_parent_frame(size: Size, reports_of: UiVec2, declared: [Option<LayoutLen>; 2]) -> Size {
|
||||
let mut size = size;
|
||||
for (axis, declared) in AXES.into_iter().zip(declared) {
|
||||
if declared.is_none() {
|
||||
let len = local.axis(axis).len();
|
||||
*size.axis_mut(axis) = size.axis(axis).within_len(len);
|
||||
*size.axis_mut(axis) = size.axis(axis).within_len(reports_of.axis(axis));
|
||||
}
|
||||
}
|
||||
size
|
||||
|
||||
Reference in new issue
Block a user