Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aaba7dbfee |
No files matched your search
+58
-4
@@ -32,6 +32,10 @@ pub struct Painter<'a> {
|
|||||||
/// drawing one that holds for that length alone -- the way reading a
|
/// drawing one that holds for that length alone -- the way reading a
|
||||||
/// length in pixels makes it hold for that number of pixels.
|
/// length in pixels makes it hold for that number of pixels.
|
||||||
pub(super) extent_len: [Option<Len>; 2],
|
pub(super) extent_len: [Option<Len>; 2],
|
||||||
|
/// Symbolic box lengths read only to compute the answer. A container can
|
||||||
|
/// replace the provisional drawings used for that answer with drawings
|
||||||
|
/// in decided boxes, so this contract is independent of the final one.
|
||||||
|
pub(super) answer_extent_len: [Option<Len>; 2],
|
||||||
/// The frame in pixels, which its children's frames are a length of:
|
/// The frame in pixels, which its children's frames are a length of:
|
||||||
/// threaded down rather than composed back up the chain, so every length
|
/// threaded down rather than composed back up the chain, so every length
|
||||||
/// in layout is one multiply from its parent's and [`Holds::through`]
|
/// in layout is one multiply from its parent's and [`Holds::through`]
|
||||||
@@ -58,8 +62,12 @@ pub struct Painter<'a> {
|
|||||||
pub(super) frame_own: [Holds; 2],
|
pub(super) frame_own: [Holds; 2],
|
||||||
/// The same for its own box.
|
/// The same for its own box.
|
||||||
pub(super) extent_own: [Holds; 2],
|
pub(super) extent_own: [Holds; 2],
|
||||||
/// Dependencies of every child drawing, including unmeasured overlays.
|
/// Pixel-box dependencies used only to compute the answer. These do not
|
||||||
pub(super) under: LayoutHolds,
|
/// constrain a retained drawing placed inside that answer.
|
||||||
|
pub(super) answer_extent_own: [Holds; 2],
|
||||||
|
/// The final drawing kept for each child. Asking one child again replaces
|
||||||
|
/// its provisional drawing and therefore replaces this contract too.
|
||||||
|
pub(super) under: Vec<(WidgetId, LayoutHolds)>,
|
||||||
/// The movable region this widget's primitives are positioned through:
|
/// The movable region this widget's primitives are positioned through:
|
||||||
/// its own when opted in, otherwise the nearest ancestor's.
|
/// its own when opted in, otherwise the nearest ancestor's.
|
||||||
pub(super) move_idx: MoveIdx,
|
pub(super) move_idx: MoveIdx,
|
||||||
@@ -228,7 +236,11 @@ impl<'a> Painter<'a> {
|
|||||||
self.rsc,
|
self.rsc,
|
||||||
);
|
);
|
||||||
let compose = |holds| in_parent(holds, local, extent, place, declared);
|
let compose = |holds| in_parent(holds, local, extent, place, declared);
|
||||||
self.under = self.under.and(compose(holds));
|
let holds = compose(holds);
|
||||||
|
match self.under.iter_mut().find(|(child, _)| *child == id.id()) {
|
||||||
|
Some((_, kept)) => *kept = holds,
|
||||||
|
None => self.under.push((id.id(), holds)),
|
||||||
|
}
|
||||||
DrawResult {
|
DrawResult {
|
||||||
child: id,
|
child: id,
|
||||||
painter: self,
|
painter: self,
|
||||||
@@ -242,6 +254,7 @@ impl<'a> Painter<'a> {
|
|||||||
/// this frame; what it answered is still something this widget asked.
|
/// this frame; what it answered is still something this widget asked.
|
||||||
pub fn undraw<W: ?Sized>(&mut self, id: &StrongWidget<W>) {
|
pub fn undraw<W: ?Sized>(&mut self, id: &StrongWidget<W>) {
|
||||||
self.children.retain(|child| *child != id.id());
|
self.children.retain(|child| *child != id.id());
|
||||||
|
self.under.retain(|(child, _)| *child != id.id());
|
||||||
self.state.undraw_rec(id.id(), self.rsc);
|
self.state.undraw_rec(id.id(), self.rsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,9 +369,31 @@ impl<'a> Painter<'a> {
|
|||||||
pub fn extent_len(&mut self, axis: Axis) -> Len {
|
pub fn extent_len(&mut self, axis: Axis) -> Len {
|
||||||
let len = self.extent.axis(axis).len();
|
let len = self.extent.axis(axis).len();
|
||||||
self.extent_len[axis as usize] = Some(len);
|
self.extent_len[axis as usize] = Some(len);
|
||||||
|
self.answer_extent_len[axis as usize] = Some(len);
|
||||||
len
|
len
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The symbolic length used to compute this widget's answer, where the
|
||||||
|
/// final drawing itself is rebuilt without depending on that length.
|
||||||
|
pub fn answer_extent_len(&mut self, axis: Axis) -> Len {
|
||||||
|
let len = self.extent.axis(axis).len();
|
||||||
|
self.answer_extent_len[axis as usize] = Some(len);
|
||||||
|
len
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Says that the final drawing uses a symbolic length already read for
|
||||||
|
/// the answer.
|
||||||
|
pub fn drawing_uses_extent_len(&mut self, axis: Axis, len: Len) {
|
||||||
|
debug_assert_eq!(self.extent.axis(axis).len(), len);
|
||||||
|
self.extent_len[axis as usize] = Some(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A part of this widget's box, expressed in its frame coordinates so it
|
||||||
|
/// can be used as a child frame decided here.
|
||||||
|
pub fn extent_part(&self, axis: Axis, part: Part) -> UiSpan {
|
||||||
|
part.of(*self.extent.axis(axis))
|
||||||
|
}
|
||||||
|
|
||||||
/// Where this widget sits in a box longer than the length it takes. A
|
/// Where this widget sits in a box longer than the length it takes. A
|
||||||
/// widget that positions its own content reads it to place that content
|
/// widget that positions its own content reads it to place that content
|
||||||
/// the way the box around it would have placed the widget.
|
/// the way the box around it would have placed the widget.
|
||||||
@@ -390,6 +425,14 @@ impl<'a> Painter<'a> {
|
|||||||
PxVec2::new(self.px_len(Axis::X), self.px_len(Axis::Y))
|
PxVec2::new(self.px_len(Axis::X), self.px_len(Axis::Y))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This widget's own box in pixels, used only to compute its answer.
|
||||||
|
pub fn answer_px_size(&mut self) -> PxVec2 {
|
||||||
|
PxVec2::new(
|
||||||
|
self.answer_px_len(Axis::X),
|
||||||
|
self.answer_px_len(Axis::Y),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// One axis of this widget's own box in pixels. Prefer this to
|
/// One axis of this widget's own box in pixels. Prefer this to
|
||||||
/// [`Self::px_size`] when the other axis cannot affect the drawing.
|
/// [`Self::px_size`] when the other axis cannot affect the drawing.
|
||||||
pub fn px_len(&mut self, axis: Axis) -> Px {
|
pub fn px_len(&mut self, axis: Axis) -> Px {
|
||||||
@@ -402,6 +445,17 @@ impl<'a> Painter<'a> {
|
|||||||
len
|
len
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// One pixel length used only to compute this widget's answer. The final
|
||||||
|
/// drawing may be retained when that answer is placed in another box.
|
||||||
|
pub fn answer_px_len(&mut self, axis: Axis) -> Px {
|
||||||
|
let len = self.extent.axis(axis).len().to_px(self.px.axis(axis));
|
||||||
|
let own = &mut self.answer_extent_own[axis as usize];
|
||||||
|
if *own == Holds::ANY {
|
||||||
|
*own = Holds::at(len);
|
||||||
|
}
|
||||||
|
len
|
||||||
|
}
|
||||||
|
|
||||||
/// The lengths of this widget's own box on `axis` that what it is drawing
|
/// The lengths of this widget's own box on `axis` that what it is drawing
|
||||||
/// holds for -- the same primitives, in the same fractions and offsets
|
/// holds for -- the same primitives, in the same fractions and offsets
|
||||||
/// of the box, and the same reported size. A widget that read its length
|
/// of the box, and the same reported size. A widget that read its length
|
||||||
@@ -555,7 +609,7 @@ pub(crate) fn in_parent(
|
|||||||
// own box, which is what lets that box move without a redraw. A
|
// own box, which is what lets that box move without a redraw. A
|
||||||
// length it pinned is this widget's length wherever the part is
|
// length it pinned is this widget's length wherever the part is
|
||||||
// the whole of it, and pins the same way.
|
// the whole of it, and pins the same way.
|
||||||
(Part::All, None) => {
|
(Part::All, None) if *frame.axis(axis) == UiSpan::FULL => {
|
||||||
result.extent[n] = holds.extent[n];
|
result.extent[n] = holds.extent[n];
|
||||||
result.extent_len[n] = holds.extent_len[n];
|
result.extent_len[n] = holds.extent_len[n];
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-75
@@ -251,7 +251,7 @@ impl UiRenderState {
|
|||||||
true => None,
|
true => None,
|
||||||
false => self
|
false => self
|
||||||
.retained_answer(id, part, info)
|
.retained_answer(id, part, info)
|
||||||
.or_else(|| self.try_reuse(id, frame, part, info, rsc)),
|
.and_then(|answer| self.try_reuse(id, frame, part, info, rsc).map(|_| answer)),
|
||||||
};
|
};
|
||||||
let answer = retained.unwrap_or_else(|| {
|
let answer = retained.unwrap_or_else(|| {
|
||||||
if old.is_none() {
|
if old.is_none() {
|
||||||
@@ -265,49 +265,25 @@ impl UiRenderState {
|
|||||||
// axis the parent left open. The frame itself does not change, so
|
// axis the parent left open. The frame itself does not change, so
|
||||||
// nothing under it resolves a fraction a second time.
|
// nothing under it resolves a fraction a second time.
|
||||||
//
|
//
|
||||||
// From the answer it gave when its parent measured it, and not from
|
|
||||||
// what a placing evaluation reported: placing a drawing by what it
|
|
||||||
// said in the box its own answer chose would move the box out from
|
|
||||||
// under it.
|
|
||||||
let measured = match info.offer() {
|
|
||||||
true => answer.0,
|
|
||||||
false => self.active[&id].measured().unwrap_or(answer.0),
|
|
||||||
};
|
|
||||||
let extent = placed_extent(
|
let extent = placed_extent(
|
||||||
part,
|
part,
|
||||||
measured,
|
answer.0,
|
||||||
declared_lens(rsc.widgets(), id),
|
declared_lens(rsc.widgets(), id),
|
||||||
info.fill(),
|
info.fill(),
|
||||||
align,
|
align,
|
||||||
);
|
);
|
||||||
self.place(id, extent, info, rsc);
|
self.place(id, extent, info, rsc);
|
||||||
|
|
||||||
// On axes the parent filled, measurement and drawing share an extent.
|
|
||||||
// Otherwise the answer fixes the final extent as a function of the
|
|
||||||
// frame, so pull that drawing's validity back through it.
|
|
||||||
let drawing_holds = self.active[&id].holds;
|
let drawing_holds = self.active[&id].holds;
|
||||||
let mut settled = answer;
|
|
||||||
for axis in AXES {
|
|
||||||
let n = axis as usize;
|
|
||||||
settled.1.frame[n] = settled.1.frame[n].and(drawing_holds.frame[n]);
|
|
||||||
if info.fill()[n] {
|
|
||||||
settled.1.extent[n] = settled.1.extent[n].and(drawing_holds.extent[n]);
|
|
||||||
} else {
|
|
||||||
settled.1.frame[n] = settled.1.frame[n]
|
|
||||||
.and(drawing_holds.extent[n].through(extent.axis(axis).len()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let active = self.active.get_mut(&id).unwrap();
|
let active = self.active.get_mut(&id).unwrap();
|
||||||
// Whoever asked owns how the boxes were reached: the frame it stated,
|
// Whoever asked owns how the boxes were reached: the frame it stated,
|
||||||
// and what of its own box it gave the drawing. A local redraw asks
|
// and what of its own box it gave the drawing. A local redraw asks
|
||||||
// the same question again from these.
|
// the same question again from these.
|
||||||
active.frame_abs = frame;
|
active.frame_abs = frame;
|
||||||
active.frame = info.frame;
|
active.frame = info.frame;
|
||||||
if info.offer() {
|
active.answer = Some(answer);
|
||||||
active.answer = Some(answer);
|
active.offer_place = info.offer_place;
|
||||||
active.offer_place = info.offer_place;
|
active.offer_part = part;
|
||||||
active.offer_part = part;
|
|
||||||
}
|
|
||||||
active.place = info.place;
|
active.place = info.place;
|
||||||
active.own_align = align;
|
active.own_align = align;
|
||||||
// A subtree can be reused whole under a different parent -- same box,
|
// A subtree can be reused whole under a different parent -- same box,
|
||||||
@@ -322,7 +298,7 @@ impl UiRenderState {
|
|||||||
{
|
{
|
||||||
old_parent.children.retain(|child| *child != id);
|
old_parent.children.retain(|child| *child != id);
|
||||||
}
|
}
|
||||||
(answer.0, answer.1, settled.1)
|
(answer.0, answer.1, drawing_holds)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recompose retained geometry when the evaluation still holds at this extent.
|
/// Recompose retained geometry when the evaluation still holds at this extent.
|
||||||
@@ -333,6 +309,15 @@ impl UiRenderState {
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
assert_eq!(
|
||||||
|
extent,
|
||||||
|
info.part,
|
||||||
|
"'{}' ({id:?}) does not hold for the box its answer chose: part {:?}, wanted {extent:?}, retained {:?} with {:?}",
|
||||||
|
rsc.widgets().label(id),
|
||||||
|
info.part,
|
||||||
|
self.active.get(&id).map(|active| active.extent),
|
||||||
|
self.active.get(&id).map(|active| active.holds),
|
||||||
|
);
|
||||||
#[cfg(feature = "layout-diagnostics")]
|
#[cfg(feature = "layout-diagnostics")]
|
||||||
diag::bump(Counter::PlaceRedraws);
|
diag::bump(Counter::PlaceRedraws);
|
||||||
let old = self.remove(id, false, rsc);
|
let old = self.remove(id, false, rsc);
|
||||||
@@ -376,6 +361,7 @@ impl UiRenderState {
|
|||||||
frame: local,
|
frame: local,
|
||||||
extent,
|
extent,
|
||||||
extent_len: [None; 2],
|
extent_len: [None; 2],
|
||||||
|
answer_extent_len: [None; 2],
|
||||||
px,
|
px,
|
||||||
mask: info.mask,
|
mask: info.mask,
|
||||||
layer: info.layer,
|
layer: info.layer,
|
||||||
@@ -389,8 +375,9 @@ impl UiRenderState {
|
|||||||
at_offer,
|
at_offer,
|
||||||
size_deps: Vec::new(),
|
size_deps: Vec::new(),
|
||||||
frame_own: [Holds::ANY; 2],
|
frame_own: [Holds::ANY; 2],
|
||||||
under: LayoutHolds::ANY,
|
under: Vec::new(),
|
||||||
extent_own: [Holds::ANY; 2],
|
extent_own: [Holds::ANY; 2],
|
||||||
|
answer_extent_own: [Holds::ANY; 2],
|
||||||
answer_under: LayoutHolds::ANY,
|
answer_under: LayoutHolds::ANY,
|
||||||
depth: info.depth,
|
depth: info.depth,
|
||||||
move_idx,
|
move_idx,
|
||||||
@@ -419,7 +406,9 @@ impl UiRenderState {
|
|||||||
primitives,
|
primitives,
|
||||||
mask_region,
|
mask_region,
|
||||||
extent_own,
|
extent_own,
|
||||||
|
answer_extent_own,
|
||||||
extent_len,
|
extent_len,
|
||||||
|
answer_extent_len,
|
||||||
answer_under,
|
answer_under,
|
||||||
children,
|
children,
|
||||||
offered: _,
|
offered: _,
|
||||||
@@ -465,13 +454,23 @@ impl UiRenderState {
|
|||||||
if let Some(idx) = retired_move {
|
if let Some(idx) = retired_move {
|
||||||
self.moves.remove(idx);
|
self.moves.remove(idx);
|
||||||
}
|
}
|
||||||
let own_holds = LayoutHolds {
|
let drawing_own = LayoutHolds {
|
||||||
frame: frame_own,
|
frame: frame_own,
|
||||||
extent: extent_own,
|
extent: extent_own,
|
||||||
extent_len,
|
extent_len,
|
||||||
};
|
};
|
||||||
let answer_holds = own_holds.and(answer_under);
|
let answer_own = LayoutHolds {
|
||||||
let holds = answer_holds.and(under);
|
extent: [
|
||||||
|
drawing_own.extent[0].and(answer_extent_own[0]),
|
||||||
|
drawing_own.extent[1].and(answer_extent_own[1]),
|
||||||
|
],
|
||||||
|
extent_len: answer_extent_len,
|
||||||
|
..drawing_own
|
||||||
|
};
|
||||||
|
let answer_holds = answer_own.and(answer_under);
|
||||||
|
let holds = under
|
||||||
|
.into_iter()
|
||||||
|
.fold(drawing_own, |holds, (_, child)| holds.and(child));
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
holds.contains(px, extent),
|
holds.contains(px, extent),
|
||||||
"'{}' ({id:?}) drew in {px:?}, outside the ranges it reported: {holds:?}",
|
"'{}' ({id:?}) drew in {px:?}, outside the ranges it reported: {holds:?}",
|
||||||
@@ -1179,10 +1178,10 @@ impl UiRenderState {
|
|||||||
};
|
};
|
||||||
let px = self.asked_px(id);
|
let px = self.asked_px(id);
|
||||||
let (was_answer, was_holds) = (active.answer, active.holds);
|
let (was_answer, was_holds) = (active.answer, active.holds);
|
||||||
// The boxes its parent gave it, then and now: its frame is the same
|
let needs_replacement = active.place != active.offer_place;
|
||||||
// on every ask, so the question its parent asked is the one this
|
// Re-ask the question its answer came from, not a later placement of
|
||||||
// asks again -- there is no box here that could be its parent's to
|
// that answer. A parent may move the retained drawing into a box the
|
||||||
// choose instead.
|
// answer chose without making that box a new question.
|
||||||
let parent_extent = self.active[&parent].extent;
|
let parent_extent = self.active[&parent].extent;
|
||||||
let info = DrawInfo {
|
let info = DrawInfo {
|
||||||
layer: active.layer,
|
layer: active.layer,
|
||||||
@@ -1193,49 +1192,16 @@ impl UiRenderState {
|
|||||||
mask: active.parent_mask,
|
mask: active.parent_mask,
|
||||||
frame: active.frame,
|
frame: active.frame,
|
||||||
frame_abs: active.frame_abs,
|
frame_abs: active.frame_abs,
|
||||||
part: Self::re_ask(active, parent_extent, active.place).1,
|
part: Self::re_ask(active, parent_extent, active.offer_place).1,
|
||||||
place: active.place,
|
place: active.offer_place,
|
||||||
offer_place: active.offer_place,
|
offer_place: active.offer_place,
|
||||||
px,
|
px,
|
||||||
};
|
};
|
||||||
// The ask that measured it, asked again: the box it was measured in
|
|
||||||
// as its parent left it, rather than where that ask's place resolves
|
|
||||||
// to now -- a parent drawn again in the box its own answer chose
|
|
||||||
// gives its children boxes it never measured anything in.
|
|
||||||
let offered = DrawInfo {
|
|
||||||
place: info.offer_place,
|
|
||||||
part: active.offer_part,
|
|
||||||
..info
|
|
||||||
};
|
|
||||||
#[cfg(feature = "layout-diagnostics")]
|
#[cfg(feature = "layout-diagnostics")]
|
||||||
diag::bump(Counter::LocalRedraws);
|
diag::bump(Counter::LocalRedraws);
|
||||||
|
|
||||||
// Asked again in the box its parent gave it, which is the question
|
|
||||||
// its parent asked only while that box is as long as the one it was
|
|
||||||
// measured in. Any other box is a different question, so the parent
|
|
||||||
// asks it, with the mark left on. Lengths and not whole boxes: what
|
|
||||||
// a drawing depends on is its lengths, so the same lengths elsewhere
|
|
||||||
// is one question.
|
|
||||||
//
|
|
||||||
// The frame is the same on every ask now, so this is about the box
|
|
||||||
// the drawing goes in alone. Removing it -- asking the measuring
|
|
||||||
// question here and placing the answer afterwards -- is what the
|
|
||||||
// transparent-frames plan asks for next, and it does not hold yet:
|
|
||||||
// seeds 104 (`align`) and 210 (`reorder`) at depth 5 settle
|
|
||||||
// differently warm and cold without it.
|
|
||||||
if info.part.size() != offered.part.size() {
|
|
||||||
self.mark(id, rsc.widgets_mut());
|
|
||||||
self.mark(parent, rsc.widgets_mut());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
let old = self.remove(id, false, rsc);
|
let old = self.remove(id, false, rsc);
|
||||||
// The original measurement is refreshed before the assigned slot is
|
let answer = self.draw_inner(id, info, old, rsc);
|
||||||
// restored: its lengths may differ even though the frame is
|
|
||||||
// unchanged.
|
|
||||||
let answer = self.draw_inner(id, offered, old, rsc);
|
|
||||||
if info.place != info.offer_place || info.part != offered.part {
|
|
||||||
self.draw_inner(id, info, None, rsc);
|
|
||||||
}
|
|
||||||
let active = self.active.get_mut(&id).unwrap();
|
let active = self.active.get_mut(&id).unwrap();
|
||||||
// A wider contract does not invalidate the guarantee the parent kept.
|
// A wider contract does not invalidate the guarantee the parent kept.
|
||||||
// Retain that guarantee so widening and narrowing back do not churn it.
|
// Retain that guarantee so widening and narrowing back do not churn it.
|
||||||
@@ -1248,7 +1214,7 @@ impl UiRenderState {
|
|||||||
if active.holds.covers(was_holds) && was_holds.contains(px, active.extent) {
|
if active.holds.covers(was_holds) && was_holds.contains(px, active.extent) {
|
||||||
active.holds = was_holds;
|
active.holds = was_holds;
|
||||||
}
|
}
|
||||||
if active.answer != was_answer || active.holds != was_holds {
|
if needs_replacement || active.answer != was_answer || active.holds != was_holds {
|
||||||
// The parent retains both the answer and the drawing's validity;
|
// The parent retains both the answer and the drawing's validity;
|
||||||
// even an unchanged size can narrow the range safe for a resize.
|
// even an unchanged size can narrow the range safe for a resize.
|
||||||
#[cfg(feature = "layout-diagnostics")]
|
#[cfg(feature = "layout-diagnostics")]
|
||||||
|
|||||||
+1
-1
@@ -124,7 +124,7 @@ impl Widget for Branch {
|
|||||||
.len(Axis::X);
|
.len(Axis::X);
|
||||||
let px = measured.apply_leftover().to_px(painter.px_len(Axis::X));
|
let px = measured.apply_leftover().to_px(painter.px_len(Axis::X));
|
||||||
|
|
||||||
let below = Place::Within(Part::From(UiSpan::new(cut, painter.extent_len(Axis::Y))));
|
let below = Place::Within(Part::Of(UiSpan::new(cut, Len::FULL)));
|
||||||
let place = [Place::Within(Part::All), below];
|
let place = [Place::Within(Part::All), below];
|
||||||
match px > Px::from_f32(self.threshold) {
|
match px > Px::from_f32(self.threshold) {
|
||||||
true => painter.widget_at(&self.wide, UiRegion::FULL, place),
|
true => painter.widget_at(&self.wide, UiRegion::FULL, place),
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ impl Widget for Span {
|
|||||||
// The row: this span's own box, as a length of the frame its children
|
// The row: this span's own box, as a length of the frame its children
|
||||||
// are laid out against. Its start is nothing's business -- a slot is
|
// are laid out against. Its start is nothing's business -- a slot is
|
||||||
// a length from it -- so what this reads is the length alone.
|
// a length from it -- so what this reads is the length alone.
|
||||||
let far = painter.extent_len(axis);
|
let far = painter.answer_extent_len(axis);
|
||||||
let along = |from: Len, to: Len| match self.dir.sign {
|
let measure_along = |from: Len, to: Len| match self.dir.sign {
|
||||||
Sign::Pos => UiSpan::new(from, to),
|
Sign::Pos => UiSpan::new(from, to),
|
||||||
Sign::Neg => UiSpan::new(far - to, far - from),
|
Sign::Neg => UiSpan::new(far - to, far - from),
|
||||||
};
|
};
|
||||||
@@ -30,7 +30,7 @@ impl Widget for Span {
|
|||||||
let mut cursor = Len::rel_min();
|
let mut cursor = Len::rel_min();
|
||||||
let mut lens = Vec::with_capacity(self.children.len());
|
let mut lens = Vec::with_capacity(self.children.len());
|
||||||
for child in &self.children {
|
for child in &self.children {
|
||||||
let room = Place::Within(Part::From(along(cursor, far)));
|
let room = Place::Fill(Part::From(measure_along(cursor, far)));
|
||||||
let len = painter
|
let len = painter
|
||||||
.widget_at(child, UiRegion::FULL, axis.pair(room, across))
|
.widget_at(child, UiRegion::FULL, axis.pair(room, across))
|
||||||
.len(axis);
|
.len(axis);
|
||||||
@@ -50,9 +50,10 @@ impl Widget for Span {
|
|||||||
|sum, len| sum + *len,
|
|sum, len| sum + *len,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let fixed_total = Len::from_parts(total.rel, total.px);
|
||||||
// What is left for the shares to divide: the row less everything
|
// What is left for the shares to divide: the row less everything
|
||||||
// fixed, as a length of the frame rather than a number of pixels.
|
// fixed, as a length of the frame rather than a number of pixels.
|
||||||
let room = far - Len::from_parts(total.rel, total.px);
|
let room = far - fixed_total;
|
||||||
// Whether anything is left over is a question in pixels: `rel(0.5)`
|
// 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`
|
// beside 300 px is full at 600 and overfull at 400. Asked of `room`
|
||||||
// itself, and answered back through the same expression, so the
|
// itself, and answered back through the same expression, so the
|
||||||
@@ -72,6 +73,18 @@ impl Widget for Span {
|
|||||||
painter.frame_holds(axis, holds.through(room));
|
painter.frame_holds(axis, holds.through(room));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if shares {
|
||||||
|
painter.drawing_uses_extent_len(axis, far);
|
||||||
|
}
|
||||||
|
let drawing_far = match shares {
|
||||||
|
true => far,
|
||||||
|
false => fixed_total,
|
||||||
|
};
|
||||||
|
let along = |from: Len, to: Len| match self.dir.sign {
|
||||||
|
Sign::Pos => UiSpan::new(from, to),
|
||||||
|
Sign::Neg => UiSpan::new(drawing_far - to, drawing_far - from),
|
||||||
|
};
|
||||||
|
|
||||||
// Across itself a span is as long as its longest child -- unless a
|
// Across itself a span is as long as its longest child -- unless a
|
||||||
// rule beside it gives that length outright, and then reading them
|
// rule beside it gives that length outright, and then reading them
|
||||||
// answers nothing and makes its size depend on theirs for it. A rule
|
// answers nothing and makes its size depend on theirs for it. A rule
|
||||||
@@ -108,8 +121,19 @@ impl Widget for Span {
|
|||||||
// Along the row the span says where the child goes, and that slot
|
// Along the row the span says where the child goes, and that slot
|
||||||
// is the drawing's box outright rather than something to place an
|
// is the drawing's box outright rather than something to place an
|
||||||
// answer inside again.
|
// answer inside again.
|
||||||
let slot = Place::Fill(Part::From(along(from, start)));
|
let span = along(from, start);
|
||||||
let placed = painter.widget_at(child, UiRegion::FULL, axis.pair(slot, across));
|
let (frame, slot) = match len.leftover > Weight::ZERO && shares {
|
||||||
|
true => (
|
||||||
|
UiRegion::from_axis(
|
||||||
|
axis,
|
||||||
|
painter.extent_part(axis, Part::From(span)),
|
||||||
|
UiSpan::FULL,
|
||||||
|
),
|
||||||
|
Place::Fill(Part::All),
|
||||||
|
),
|
||||||
|
false => (UiRegion::FULL, Place::Fill(Part::From(span))),
|
||||||
|
};
|
||||||
|
let placed = painter.widget_at(child, frame, axis.pair(slot, across));
|
||||||
if shrinks {
|
if shrinks {
|
||||||
let used = placed.len(!axis);
|
let used = placed.len(!axis);
|
||||||
// Choosing between a fixed and a relative length from the
|
// Choosing between a fixed and a relative length from the
|
||||||
|
|||||||
@@ -33,9 +33,15 @@ impl Widget for Stack {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
painter.child_layer_at(i);
|
painter.child_layer_at(i);
|
||||||
// Every other child is drawn in the stack's own box, and where it
|
let place = [Axis::X, Axis::Y].map(|axis| {
|
||||||
// sits in one bigger than itself is its own business.
|
let len = size.axis(axis);
|
||||||
painter.widget(child);
|
let part = match len.leftover > Weight::ZERO {
|
||||||
|
true => Part::All,
|
||||||
|
false => Part::From(UiSpan::new(Len::ZERO, Len::from_parts(len.rel, len.px))),
|
||||||
|
};
|
||||||
|
Place::Within(part)
|
||||||
|
});
|
||||||
|
painter.widget_at(child, UiRegion::FULL, place);
|
||||||
}
|
}
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-17
@@ -12,6 +12,7 @@ struct Counted {
|
|||||||
draws: Rc<Cell<usize>>,
|
draws: Rc<Cell<usize>>,
|
||||||
size: Size,
|
size: Size,
|
||||||
reads_box: bool,
|
reads_box: bool,
|
||||||
|
reads_answer_box: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for Counted {
|
impl Widget for Counted {
|
||||||
@@ -19,6 +20,8 @@ impl Widget for Counted {
|
|||||||
self.draws.set(self.draws.get() + 1);
|
self.draws.set(self.draws.get() + 1);
|
||||||
if self.reads_box {
|
if self.reads_box {
|
||||||
painter.px_size();
|
painter.px_size();
|
||||||
|
} else if self.reads_answer_box {
|
||||||
|
painter.answer_px_size();
|
||||||
}
|
}
|
||||||
self.size
|
self.size
|
||||||
}
|
}
|
||||||
@@ -38,11 +41,18 @@ fn counted(h: &mut Harness, size: Size, reads_box: bool) -> (WeakWidget<Counted>
|
|||||||
draws: draws.clone(),
|
draws: draws.clone(),
|
||||||
size,
|
size,
|
||||||
reads_box,
|
reads_box,
|
||||||
|
reads_answer_box: false,
|
||||||
}
|
}
|
||||||
.add(&mut h.rsc);
|
.add(&mut h.rsc);
|
||||||
(id, Counts(draws))
|
(id, Counts(draws))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn answer_counted(h: &mut Harness, size: Size) -> (WeakWidget<Counted>, Counts) {
|
||||||
|
let (id, draws) = counted(h, size, false);
|
||||||
|
h.rsc[id].reads_answer_box = true;
|
||||||
|
(id, draws)
|
||||||
|
}
|
||||||
|
|
||||||
struct Layered {
|
struct Layered {
|
||||||
children: [StrongWidget<Rect>; 2],
|
children: [StrongWidget<Rect>; 2],
|
||||||
_revision: usize,
|
_revision: usize,
|
||||||
@@ -156,8 +166,8 @@ fn a_span_child_that_declares_its_length_is_drawn_once() {
|
|||||||
h.set_root((hinted, asked).span(Dir::RIGHT));
|
h.set_root((hinted, asked).span(Dir::RIGHT));
|
||||||
|
|
||||||
assert_eq!(told_draws.get(), 1);
|
assert_eq!(told_draws.get(), 1);
|
||||||
// Only the available length changes: positioning the final slot does
|
// Its final slot is a parent decision, so it is evaluated there after
|
||||||
// not invalidate a numeric size read.
|
// the provisional ask established its length.
|
||||||
assert_eq!(asked_draws.get(), 2);
|
assert_eq!(asked_draws.get(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +250,7 @@ fn a_parent_that_only_read_a_hint_relays_out_when_the_hint_changes() {
|
|||||||
assert_corners!(h, inner, (0, 0), (400, 120));
|
assert_corners!(h, inner, (0, 0), (400, 120));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads its box's size, which nothing but its own draw can put right.
|
/// Reads its box's size to compute its answer.
|
||||||
struct ReadsBox {
|
struct ReadsBox {
|
||||||
draws: Rc<Cell<usize>>,
|
draws: Rc<Cell<usize>>,
|
||||||
}
|
}
|
||||||
@@ -248,26 +258,36 @@ struct ReadsBox {
|
|||||||
impl Widget for ReadsBox {
|
impl Widget for ReadsBox {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
self.draws.set(self.draws.get() + 1);
|
self.draws.set(self.draws.get() + 1);
|
||||||
Size::from_px(painter.px_size().div_int(4))
|
Size::from_px(painter.answer_px_size().div_int(4))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads its box across one axis only, so its drawing holds for a taller
|
/// Reads its box across one axis only, so its drawing holds for a taller
|
||||||
/// box on its own and only a wider one is worth a draw.
|
/// box on its own and only a wider one is worth a draw.
|
||||||
///
|
///
|
||||||
/// Both of these report a quarter of what they read, without saying that the
|
/// Both report a quarter of what they read. Their empty drawings are
|
||||||
/// drawing holds there too, so each length they are asked at costs two draws:
|
/// independent of that read, so a changed question costs one draw.
|
||||||
/// one to answer, and one in the quarter-sized box that answer places them
|
|
||||||
/// in. The counts below are in those pairs.
|
|
||||||
struct ReadsWidth {
|
struct ReadsWidth {
|
||||||
draws: Rc<Cell<usize>>,
|
draws: Rc<Cell<usize>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ReadsDrawingWidth {
|
||||||
|
draws: Rc<Cell<usize>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Widget for ReadsDrawingWidth {
|
||||||
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
|
self.draws.set(self.draws.get() + 1);
|
||||||
|
painter.px_len(Axis::X);
|
||||||
|
Size::LEFTOVER
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Widget for ReadsWidth {
|
impl Widget for ReadsWidth {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
self.draws.set(self.draws.get() + 1);
|
self.draws.set(self.draws.get() + 1);
|
||||||
Size::from_px(PxVec2::new(
|
Size::from_px(PxVec2::new(
|
||||||
painter.px_len(Axis::X).div_int(4),
|
painter.answer_px_len(Axis::X).div_int(4),
|
||||||
Px::from_int(20),
|
Px::from_int(20),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -323,6 +343,7 @@ fn a_row_moves_what_follows_a_child_that_grew_rather_than_drawing_it() {
|
|||||||
draws: ruled.clone(),
|
draws: ruled.clone(),
|
||||||
size: Size::LEFTOVER,
|
size: Size::LEFTOVER,
|
||||||
reads_box: false,
|
reads_box: false,
|
||||||
|
reads_answer_box: false,
|
||||||
};
|
};
|
||||||
let second = match declared {
|
let second = match declared {
|
||||||
true => second.width(rel(0.25)).add(&mut h.rsc),
|
true => second.width(rel(0.25)).add(&mut h.rsc),
|
||||||
@@ -384,7 +405,7 @@ fn a_resize_redraws_what_read_its_box() {
|
|||||||
h.resize((800, 100));
|
h.resize((800, 100));
|
||||||
h.frame();
|
h.frame();
|
||||||
|
|
||||||
assert_eq!(draws.get(), settled + 2);
|
assert_eq!(draws.get(), settled + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -404,7 +425,7 @@ fn a_resize_only_redraws_read_axes() {
|
|||||||
|
|
||||||
h.resize((800, 300));
|
h.resize((800, 300));
|
||||||
h.frame();
|
h.frame();
|
||||||
assert_eq!(draws.get(), settled + 2, "width changes its answer");
|
assert_eq!(draws.get(), settled + 1, "width changes its answer");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A window is measured onto the grid like everything else, so a resize too
|
/// A window is measured onto the grid like everything else, so a resize too
|
||||||
@@ -431,7 +452,7 @@ fn a_resize_within_one_step_is_not_a_resize() {
|
|||||||
|
|
||||||
h.resize((400.0 + step, 200.0));
|
h.resize((400.0 + step, 200.0));
|
||||||
h.frame();
|
h.frame();
|
||||||
assert_eq!(draws.get(), settled + 2);
|
assert_eq!(draws.get(), settled + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The same for a box that changes because a sibling did: what is compared
|
/// The same for a box that changes because a sibling did: what is compared
|
||||||
@@ -500,7 +521,7 @@ fn a_change_two_levels_under_its_reader_still_reaches_it() {
|
|||||||
// Every wrapper up to the outer pad read the size below it, so the outer
|
// Every wrapper up to the outer pad read the size below it, so the outer
|
||||||
// pad is what draws again -- and the span it hands the box to is the same
|
// pad is what draws again -- and the span it hands the box to is the same
|
||||||
// size as before, which is what lets a draw reuse its way past the leaf.
|
// size as before, which is what lets a draw reuse its way past the leaf.
|
||||||
let (leaf, _) = counted(&mut h, Size::px((100, 100).into()), true);
|
let (leaf, _) = counted(&mut h, Size::px((100, 100).into()), false);
|
||||||
let padded = leaf.pad(10).add(&mut h.rsc);
|
let padded = leaf.pad(10).add(&mut h.rsc);
|
||||||
let below = rect(Color::RED).add(&mut h.rsc);
|
let below = rect(Color::RED).add(&mut h.rsc);
|
||||||
h.set_root((padded, below).span(Dir::DOWN).pad(12));
|
h.set_root((padded, below).span(Dir::DOWN).pad(12));
|
||||||
@@ -1066,7 +1087,7 @@ fn a_declared_size_change_stops_at_an_independent_parent() {
|
|||||||
fn an_unmeasured_child_still_invalidates_its_parents_drawing_on_resize() {
|
fn an_unmeasured_child_still_invalidates_its_parents_drawing_on_resize() {
|
||||||
let mut h = Harness::new((400, 200));
|
let mut h = Harness::new((400, 200));
|
||||||
let draws = Rc::new(Cell::new(0));
|
let draws = Rc::new(Cell::new(0));
|
||||||
let leaf = ReadsWidth {
|
let leaf = ReadsDrawingWidth {
|
||||||
draws: draws.clone(),
|
draws: draws.clone(),
|
||||||
}
|
}
|
||||||
.add(&mut h.rsc);
|
.add(&mut h.rsc);
|
||||||
@@ -1077,7 +1098,7 @@ fn an_unmeasured_child_still_invalidates_its_parents_drawing_on_resize() {
|
|||||||
h.frame();
|
h.frame();
|
||||||
|
|
||||||
assert!(draws.get() > settled);
|
assert!(draws.get() > settled);
|
||||||
assert_corners!(h, leaf, (300, 90), (500, 110));
|
assert_corners!(h, leaf, (0, 0), (800, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1212,7 +1233,7 @@ fn moving_an_extent_child_preserves_the_slot_chosen_from_its_measurement() {
|
|||||||
struct Measured;
|
struct Measured;
|
||||||
impl Widget for Measured {
|
impl Widget for Measured {
|
||||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||||
let width = painter.px_len(Axis::X);
|
let width = painter.answer_px_len(Axis::X);
|
||||||
painter.primitive(RectPrimitive::color(Color::BLUE));
|
painter.primitive(RectPrimitive::color(Color::BLUE));
|
||||||
Size::from((80, if width > Px::from_int(100) { 40 } else { 60 }))
|
Size::from((80, if width > Px::from_int(100) { 40 } else { 60 }))
|
||||||
}
|
}
|
||||||
@@ -1312,7 +1333,10 @@ fn extent_frames_keep_fractional_reports_and_numeric_dependencies_valid() {
|
|||||||
} else {
|
} else {
|
||||||
Size::from((80, 27))
|
Size::from((80, 27))
|
||||||
};
|
};
|
||||||
let (leaf, _) = counted(h, size, !fractional);
|
let (leaf, _) = match fractional {
|
||||||
|
true => counted(h, size, false),
|
||||||
|
false => answer_counted(h, size),
|
||||||
|
};
|
||||||
let child = Container {
|
let child = Container {
|
||||||
child: leaf.add_strong(&mut h.rsc),
|
child: leaf.add_strong(&mut h.rsc),
|
||||||
region,
|
region,
|
||||||
|
|||||||
Reference in new issue
Block a user