Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62a16b5608 | ||
|
|
34cafb6edc | ||
|
|
3bf22935ce | ||
|
|
e6ba570d07 |
No files matched your search
@@ -54,10 +54,13 @@ pub(crate) enum Counter {
|
||||
TextShapes,
|
||||
TextBreaks,
|
||||
GlyphPlacements,
|
||||
OutsidePlacement,
|
||||
OutsideFrame,
|
||||
OutsideExtent,
|
||||
}
|
||||
|
||||
impl Counter {
|
||||
const COUNT: usize = Self::GlyphPlacements as usize + 1;
|
||||
const COUNT: usize = Self::OutsideExtent as usize + 1;
|
||||
|
||||
const NAMES: [&'static str; Self::COUNT] = [
|
||||
"updates",
|
||||
@@ -89,6 +92,9 @@ impl Counter {
|
||||
"text shapes",
|
||||
"text line breaks",
|
||||
"glyph placements",
|
||||
"reuse outside: the placement it was pinned to",
|
||||
"reuse outside: a frame length",
|
||||
"reuse outside: an extent length",
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+27
-1
@@ -18,6 +18,9 @@ pub struct ActiveData {
|
||||
/// The original frame in its parent widget's coordinates. Recomposition
|
||||
/// and pixel-length evaluation both follow this chain.
|
||||
pub given_region: UiRegion,
|
||||
/// The frame it was first asked in, in the same coordinates: the offer's
|
||||
/// frame, which its parent's placing draw may since have narrowed.
|
||||
pub offer_region: UiRegion,
|
||||
/// The lengths of the box its parent first asked about it in, as
|
||||
/// lengths of the box the parent was itself offered. Any later box it
|
||||
/// was given was decided knowing its answer, so this is the question
|
||||
@@ -41,7 +44,11 @@ pub struct ActiveData {
|
||||
pub textures: Vec<TextureHandle>,
|
||||
pub primitives: Vec<RetainedPrimitive>,
|
||||
pub mask_region: Option<DrawRegion>,
|
||||
pub inherited_children: Vec<WidgetId>,
|
||||
/// The children whose box is a part of this widget's extent rather than
|
||||
/// of its frame, and which part each was given. Moving the extent
|
||||
/// re-places them through that part, so the drawing need not depend on
|
||||
/// where it sits.
|
||||
pub(crate) extent_children: Vec<(WidgetId, ExtentPlacement)>,
|
||||
pub children: Vec<WidgetId>,
|
||||
/// The children whose size this widget read while drawing.
|
||||
pub size_deps: Vec<WidgetId>,
|
||||
@@ -87,3 +94,22 @@ impl ActiveData {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// What of a container's extent a child was given: the whole of it, for a
|
||||
/// wrapper whose box is its child's, or a part of it.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub(crate) enum ExtentPlacement {
|
||||
Inherit,
|
||||
Within(UiRegion),
|
||||
}
|
||||
|
||||
impl ExtentPlacement {
|
||||
/// The child's frame in the container's frame coordinates, and the slot
|
||||
/// the container chose within it.
|
||||
pub fn resolve(self, extent: UiRegion) -> (UiRegion, [Option<crate::UiSpan>; 2]) {
|
||||
match self {
|
||||
Self::Inherit => (UiRegion::FULL, [Some(extent.x), Some(extent.y)]),
|
||||
Self::Within(part) => (part.within(&extent), [None; 2]),
|
||||
}
|
||||
}
|
||||
}
|
||||
+80
-22
@@ -1,9 +1,9 @@
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
use crate::layout_diagnostics::{self as diag, Counter};
|
||||
use crate::{
|
||||
Axis, DrawRegion, Holds, LayoutHolds, LayoutLen, Len, Px, PxVec2, RegionAlign, RenderedText,
|
||||
RetainedPrimitive, Size, StrongWidget, TextAttrs, TextBuffer, TextData, TextureHandle,
|
||||
UiRegion, UiRenderState, UiRsc, UiSpan, UiVec2, Weight, WidgetId, Widgets,
|
||||
Axis, DrawRegion, ExtentPlacement, Holds, LayoutHolds, LayoutLen, Len, Px, PxVec2, RegionAlign,
|
||||
RenderedText, RetainedPrimitive, Size, StrongWidget, TextAttrs, TextBuffer, TextData,
|
||||
TextureHandle, UiRegion, UiRenderState, UiRsc, UiSpan, UiVec2, Weight, WidgetId, Widgets,
|
||||
render::{
|
||||
GlyphPrimitive, Mask, MaskIdx, MoveIdx, Primitive, PrimitiveInst, PrimitiveKind,
|
||||
TexturePrimitive,
|
||||
@@ -40,7 +40,7 @@ pub struct Painter<'a> {
|
||||
pub(super) textures: Vec<TextureHandle>,
|
||||
pub(super) primitives: Vec<RetainedPrimitive>,
|
||||
pub(super) mask_region: Option<DrawRegion>,
|
||||
pub(super) inherited_children: Vec<WidgetId>,
|
||||
pub(super) extent_children: Vec<(WidgetId, ExtentPlacement)>,
|
||||
pub(super) extent_own: [Holds; 2],
|
||||
/// Only children whose answers were read constrain this widget's answer.
|
||||
pub(super) answer_under: LayoutHolds,
|
||||
@@ -155,7 +155,13 @@ impl<'a> Painter<'a> {
|
||||
/// around one child wants, since its box is the child's.
|
||||
pub fn widget<'s, W: ?Sized>(&'s mut self, id: &'s StrongWidget<W>) -> DrawResult<'s, 'a, W> {
|
||||
let own = self.placement;
|
||||
self.widget_at_inner(id, UiRegion::FULL, [Some(own.x), Some(own.y)], true, false)
|
||||
self.widget_at_inner(
|
||||
id,
|
||||
UiRegion::FULL,
|
||||
[Some(own.x), Some(own.y)],
|
||||
Some(ExtentPlacement::Inherit),
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
/// What a widget's rules declare its lengths to be, which whoever draws
|
||||
@@ -171,19 +177,36 @@ impl<'a> Painter<'a> {
|
||||
/// this frame; what it answered is still something this widget asked.
|
||||
pub fn undraw<W: ?Sized>(&mut self, id: &StrongWidget<W>) {
|
||||
self.children.retain(|child| *child != id.id());
|
||||
self.inherited_children.retain(|child| *child != id.id());
|
||||
self.extent_children.retain(|(child, _)| *child != id.id());
|
||||
self.state.undraw_rec(id.id(), self.rsc);
|
||||
}
|
||||
|
||||
/// Draws a child in `region`, relative to this widget's frame. The child
|
||||
/// resolves declared lengths and reports against that frame, then places
|
||||
/// its drawing by its own alignment.
|
||||
///
|
||||
/// `DrawRegion::Extent` gives a part of where this widget's drawing sits
|
||||
/// instead, for a container whose children belong inside that rather than
|
||||
/// inside the box it was offered. The part is what is kept, so moving the
|
||||
/// extent re-places the child rather than drawing this widget again.
|
||||
pub fn widget_within<'s, W: ?Sized>(
|
||||
&'s mut self,
|
||||
id: &'s StrongWidget<W>,
|
||||
region: UiRegion,
|
||||
region: impl Into<DrawRegion>,
|
||||
) -> DrawResult<'s, 'a, W> {
|
||||
self.widget_at(id, region, [None; 2])
|
||||
match region.into() {
|
||||
DrawRegion::Frame(region) => self.widget_at(id, region, [None; 2]),
|
||||
DrawRegion::Extent(part) => {
|
||||
let within = part.within(&self.placement);
|
||||
self.widget_at_inner(
|
||||
id,
|
||||
within,
|
||||
[None; 2],
|
||||
Some(ExtentPlacement::Within(part)),
|
||||
false,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws a widget in `region`, saying where in it the drawing goes.
|
||||
@@ -206,7 +229,7 @@ impl<'a> Painter<'a> {
|
||||
region: UiRegion,
|
||||
placement: [Option<UiSpan>; 2],
|
||||
) -> DrawResult<'s, 'a, W> {
|
||||
self.widget_at_inner(id, region, placement, false, false)
|
||||
self.widget_at_inner(id, region, placement, None, false)
|
||||
}
|
||||
|
||||
fn widget_at_inner<'s, W: ?Sized>(
|
||||
@@ -214,15 +237,12 @@ impl<'a> Painter<'a> {
|
||||
id: &'s StrongWidget<W>,
|
||||
region: UiRegion,
|
||||
placement: [Option<UiSpan>; 2],
|
||||
inherited: bool,
|
||||
extent: Option<ExtentPlacement>,
|
||||
measuring: bool,
|
||||
) -> DrawResult<'s, 'a, W> {
|
||||
if inherited {
|
||||
if !self.inherited_children.contains(&id.id()) {
|
||||
self.inherited_children.push(id.id());
|
||||
}
|
||||
} else {
|
||||
self.inherited_children.retain(|child| *child != id.id());
|
||||
self.extent_children.retain(|(child, _)| *child != id.id());
|
||||
if let Some(extent) = extent {
|
||||
self.extent_children.push((id.id(), extent));
|
||||
}
|
||||
let region_node = self.rsc.widgets().is_region_node(id.id());
|
||||
let declared = self.declared_lens(id);
|
||||
@@ -251,6 +271,14 @@ impl<'a> Painter<'a> {
|
||||
.get(&id.id())
|
||||
.map_or(given_len, |a| a.offer_len),
|
||||
};
|
||||
let offer_region = match first_ask {
|
||||
true => local,
|
||||
false => self
|
||||
.state
|
||||
.active
|
||||
.get(&id.id())
|
||||
.map_or(local, |a| a.offer_region),
|
||||
};
|
||||
let offer_placement = if first_ask {
|
||||
placement
|
||||
} else {
|
||||
@@ -275,6 +303,7 @@ impl<'a> Painter<'a> {
|
||||
region_node,
|
||||
mask: self.mask,
|
||||
given_region: local,
|
||||
offer_region,
|
||||
offer_len,
|
||||
offer_placement,
|
||||
px,
|
||||
@@ -289,25 +318,53 @@ impl<'a> Painter<'a> {
|
||||
let mut result = LayoutHolds::ANY;
|
||||
for axis in AXES {
|
||||
let n = axis as usize;
|
||||
let chosen = placement[n].unwrap_or(UiSpan::FULL).len();
|
||||
match extent {
|
||||
// Its box is this widget's own, so what its drawing holds
|
||||
// for is what this widget's extent holds for.
|
||||
Some(ExtentPlacement::Inherit) if declared[n].is_none() => {
|
||||
result.frame[n] = holds.frame[n].through(local.axis(axis).len());
|
||||
if inherited && declared[n].is_none() {
|
||||
result.extent[n] = holds.extent[n];
|
||||
if holds.placement.is_some() {
|
||||
result.placement = Some(self.placement);
|
||||
}
|
||||
} else {
|
||||
let chosen = placement[n].unwrap_or(UiSpan::FULL).len();
|
||||
result.frame[n] = result.frame[n].and(
|
||||
}
|
||||
// Its box is a part of this widget's extent, so what it
|
||||
// holds for is a range on that extent and none of it a
|
||||
// range on the frame. Only the part's length reaches it,
|
||||
// which is what lets the extent move without a redraw.
|
||||
Some(ExtentPlacement::Within(part)) if declared[n].is_none() => {
|
||||
result.extent[n] = holds.frame[n]
|
||||
.and(holds.extent[n].through(chosen))
|
||||
.through(part.axis(axis).len());
|
||||
}
|
||||
// Its box is a length of this widget's frame: an
|
||||
// ordinary ask, or a declared length, which is that
|
||||
// length wherever the box it sits in came from.
|
||||
_ => {
|
||||
result.frame[n] = holds.frame[n].through(local.axis(axis).len()).and(
|
||||
holds.extent[n]
|
||||
.through(chosen)
|
||||
.through(local.axis(axis).len()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
result
|
||||
};
|
||||
self.under = self.under.and(in_parent(holds));
|
||||
let answer_holds = in_parent(answer_holds);
|
||||
let mut answer_holds = in_parent(answer_holds);
|
||||
// What it reports is a fraction of the box it was given, which is a
|
||||
// part of this widget's extent -- so the same fraction is a different
|
||||
// length once that extent is, and pixels are not. The answer only:
|
||||
// the drawing this holds is re-placed rather than made again.
|
||||
if matches!(extent, Some(ExtentPlacement::Within(_)))
|
||||
&& AXES.into_iter().any(|axis| {
|
||||
declared[axis as usize].is_none() && size.axis(axis).rel != crate::Rel::ZERO
|
||||
})
|
||||
{
|
||||
answer_holds.placement = Some(self.placement);
|
||||
}
|
||||
DrawResult {
|
||||
child: id,
|
||||
painter: self,
|
||||
@@ -369,7 +426,7 @@ impl<'a> Painter<'a> {
|
||||
.retained_size(child.id(), px, placement, self.move_idx, self.rsc.widgets());
|
||||
let Some((size, holds)) = retained else {
|
||||
return self
|
||||
.widget_at_inner(child, region, offered, false, true)
|
||||
.widget_at_inner(child, region, offered, None, true)
|
||||
.len(axis);
|
||||
};
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
@@ -379,6 +436,7 @@ impl<'a> Painter<'a> {
|
||||
self.offered.push(child.id());
|
||||
let active = self.state.active.get_mut(&child.id()).unwrap();
|
||||
active.offer_len = local.size();
|
||||
active.offer_region = local;
|
||||
active.offer_placement = placement;
|
||||
}
|
||||
let placement = UiRegion {
|
||||
|
||||
+108
-40
@@ -24,6 +24,8 @@ pub(super) struct DrawInfo {
|
||||
pub given_region: UiRegion,
|
||||
/// The original offer's lengths relative to the parent's own offer.
|
||||
pub offer_len: UiVec2,
|
||||
/// The offer's frame in the parent widget's coordinates.
|
||||
pub offer_region: UiRegion,
|
||||
pub offer_placement: [Option<UiSpan>; 2],
|
||||
/// This ask's box in pixels, and the offer's: one multiply from the
|
||||
/// parent's own, which is where every pixel length in layout comes from.
|
||||
@@ -69,6 +71,9 @@ pub struct UiRenderState {
|
||||
/// Widgets waiting for an ancestor to draw them, so the walk down the
|
||||
/// depths does not pick one up again at its own depth.
|
||||
deferred: crate::util::HashSet<WidgetId>,
|
||||
/// What the walk has left to settle, deepest last. Ordered rather than
|
||||
/// searched for, so finding the next one is not a pass over the marks.
|
||||
pending: std::collections::BTreeSet<(usize, WidgetId)>,
|
||||
pub moves: Moves,
|
||||
}
|
||||
|
||||
@@ -81,6 +86,7 @@ impl UiRenderState {
|
||||
old_root: None,
|
||||
slots: Default::default(),
|
||||
deferred: Default::default(),
|
||||
pending: Default::default(),
|
||||
moves: Default::default(),
|
||||
resized: false,
|
||||
}
|
||||
@@ -130,6 +136,7 @@ impl UiRenderState {
|
||||
region_node: false,
|
||||
mask: MaskIdx::NONE,
|
||||
given_region: region,
|
||||
offer_region: region,
|
||||
offer_len: UiVec2::FULL_SIZE,
|
||||
offer_placement: [None; 2],
|
||||
px,
|
||||
@@ -270,6 +277,7 @@ impl UiRenderState {
|
||||
// same question again from these.
|
||||
active.region = region;
|
||||
active.given_region = info.given_region;
|
||||
active.offer_region = info.offer_region;
|
||||
active.offer_len = info.offer_len;
|
||||
if info.placement == info.offer_placement && info.px == info.offered_px {
|
||||
active.answer = Some(answer);
|
||||
@@ -288,7 +296,7 @@ impl UiRenderState {
|
||||
&& let Some(old_parent) = self.active.get_mut(&old_parent)
|
||||
{
|
||||
old_parent.children.retain(|child| *child != id);
|
||||
old_parent.inherited_children.retain(|child| *child != id);
|
||||
old_parent.extent_children.retain(|(child, _)| *child != id);
|
||||
}
|
||||
(answer.0, answer.1, settled.1)
|
||||
}
|
||||
@@ -361,7 +369,7 @@ impl UiRenderState {
|
||||
textures: Vec::new(),
|
||||
primitives: Vec::new(),
|
||||
mask_region: None,
|
||||
inherited_children: Vec::new(),
|
||||
extent_children: Vec::new(),
|
||||
children: Vec::new(),
|
||||
offered: Vec::new(),
|
||||
offered_px: info.offered_px,
|
||||
@@ -398,7 +406,7 @@ impl UiRenderState {
|
||||
textures,
|
||||
primitives,
|
||||
mask_region,
|
||||
inherited_children,
|
||||
extent_children,
|
||||
extent_own,
|
||||
answer_under,
|
||||
children,
|
||||
@@ -474,6 +482,7 @@ impl UiRenderState {
|
||||
region_node: false,
|
||||
mask,
|
||||
given_region: UiRegion::FULL,
|
||||
offer_region: UiRegion::FULL,
|
||||
offer_len: UiVec2::FULL_SIZE,
|
||||
offer_placement: [None; 2],
|
||||
px,
|
||||
@@ -491,6 +500,7 @@ impl UiRenderState {
|
||||
region,
|
||||
placement,
|
||||
given_region: info.given_region,
|
||||
offer_region: info.offer_region,
|
||||
offer_len: info.offer_len,
|
||||
offer_placement: info.offer_placement,
|
||||
// Whoever asked writes the answer, if this was the asking.
|
||||
@@ -503,7 +513,7 @@ impl UiRenderState {
|
||||
textures,
|
||||
primitives,
|
||||
mask_region,
|
||||
inherited_children,
|
||||
extent_children,
|
||||
children,
|
||||
size_deps,
|
||||
declared: declared_lens(rsc.widgets(), id),
|
||||
@@ -680,6 +690,24 @@ impl UiRenderState {
|
||||
if !active.holds.contains(info.px, placement) {
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
{
|
||||
// Which of the three said no, so a frame that redraws more
|
||||
// than it should says where to look. They overlap: a drawing
|
||||
// can be outside two of them at once.
|
||||
let holds = active.holds;
|
||||
if holds.placement.is_some_and(|pinned| pinned != placement) {
|
||||
diag::bump(Counter::OutsidePlacement);
|
||||
}
|
||||
for axis in AXES {
|
||||
let n = axis as usize;
|
||||
if !holds.frame[n].contains(info.px.axis(axis)) {
|
||||
diag::bump(Counter::OutsideFrame);
|
||||
}
|
||||
if !holds.extent[n]
|
||||
.contains(placement.axis(axis).len().to_px(info.px.axis(axis)))
|
||||
{
|
||||
diag::bump(Counter::OutsideExtent);
|
||||
}
|
||||
}
|
||||
diag::bump(Counter::ReuseOutside);
|
||||
diag::reuse(id, ReuseOutcome::Outside);
|
||||
}
|
||||
@@ -702,6 +730,7 @@ impl UiRenderState {
|
||||
let active = self.active.get_mut(&id).unwrap();
|
||||
active.region = region;
|
||||
active.given_region = info.given_region;
|
||||
active.offer_region = info.offer_region;
|
||||
active.offer_len = info.offer_len;
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
{
|
||||
@@ -752,19 +781,18 @@ impl UiRenderState {
|
||||
}
|
||||
let parent_move = active.move_idx;
|
||||
let mask = active.mask;
|
||||
let children = active.inherited_children.len();
|
||||
let children = active.extent_children.len();
|
||||
for index in 0..children {
|
||||
let child = self.active[&id].inherited_children[index];
|
||||
let (child, extent) = self.active[&id].extent_children[index];
|
||||
let (part, slot) = extent.resolve(placement);
|
||||
let active = &self.active[&child];
|
||||
let (child_local, chosen) = ask_box(
|
||||
UiRegion::FULL,
|
||||
active.declared,
|
||||
active.own_align,
|
||||
[Some(placement.x), Some(placement.y)],
|
||||
);
|
||||
let (child_local, chosen) = ask_box(part, active.declared, active.own_align, slot);
|
||||
// What it took of that box is its own answer, which this move did
|
||||
// not ask again: keep the placement it has on any axis this
|
||||
// widget is not the one choosing.
|
||||
let child_placement = UiRegion {
|
||||
x: chosen[0].unwrap_or(UiSpan::FULL),
|
||||
y: chosen[1].unwrap_or(UiSpan::FULL),
|
||||
x: chosen[0].unwrap_or(active.placement.x),
|
||||
y: chosen[1].unwrap_or(active.placement.y),
|
||||
};
|
||||
let child_info = DrawInfo {
|
||||
layer: active.layer,
|
||||
@@ -774,6 +802,7 @@ impl UiRenderState {
|
||||
region_node: active.move_idx != active.parent_move,
|
||||
mask,
|
||||
given_region: child_local,
|
||||
offer_region: active.offer_region,
|
||||
offer_len: active.offer_len,
|
||||
offer_placement: active.offer_placement,
|
||||
px: child_local.size().to_px(info.px),
|
||||
@@ -913,6 +942,7 @@ impl UiRenderState {
|
||||
region: UiRegion::FULL,
|
||||
placement: UiRegion::FULL,
|
||||
given_region: UiRegion::FULL,
|
||||
offer_region: UiRegion::FULL,
|
||||
offer_len: UiVec2::FULL_SIZE,
|
||||
offer_placement: [None; 2],
|
||||
answer: None,
|
||||
@@ -924,7 +954,7 @@ impl UiRenderState {
|
||||
textures: Vec::new(),
|
||||
primitives: Vec::new(),
|
||||
mask_region: None,
|
||||
inherited_children: Vec::new(),
|
||||
extent_children: Vec::new(),
|
||||
children: Vec::new(),
|
||||
size_deps: Vec::new(),
|
||||
move_idx: info.parent_move,
|
||||
@@ -977,24 +1007,52 @@ impl UiRenderState {
|
||||
// something below is about to change it -- which is the whole class
|
||||
// of defect where a widget settles inside its parent's draw, clears
|
||||
// its mark there, and tells nobody its answer moved.
|
||||
// The queue is that set, ordered: a mark made while the walk runs
|
||||
// queues itself through `mark`. What ends the walk is still the set
|
||||
// being spent, not the queue, so a mark that reached it another way
|
||||
// cannot be left for the next frame.
|
||||
loop {
|
||||
let next = rsc
|
||||
.widgets()
|
||||
.needs_redraw
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|id| !self.deferred.contains(id))
|
||||
.max_by_key(|&id| self.depth(id));
|
||||
let Some(id) = next else { break };
|
||||
for &id in rsc.widgets().needs_redraw.iter() {
|
||||
if !self.deferred.contains(&id) {
|
||||
let depth = self.depth(id);
|
||||
self.pending.insert((depth, id));
|
||||
}
|
||||
}
|
||||
if self.pending.is_empty() {
|
||||
break;
|
||||
}
|
||||
while let Some((depth, id)) = self.pending.pop_last() {
|
||||
// Settled inside an ancestor's draw, or deferred to one,
|
||||
// since the mark that queued it.
|
||||
if self.deferred.contains(&id) || !rsc.widgets().needs_redraw.contains(&id) {
|
||||
continue;
|
||||
}
|
||||
// A subtree that changed hands takes its descendants' depths
|
||||
// with it, so an entry queued before that move names the
|
||||
// depth it had under the parent it left.
|
||||
let now = self.depth(id);
|
||||
if now != depth {
|
||||
self.pending.insert((now, id));
|
||||
continue;
|
||||
}
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
diag::bump(Counter::QueuePops);
|
||||
if !self.redraw(id, rsc) {
|
||||
self.deferred.insert(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.deferred.clear();
|
||||
}
|
||||
|
||||
/// Marks a widget for the walk to settle, and queues it at its depth.
|
||||
fn mark(&mut self, id: WidgetId, widgets: &mut Widgets) {
|
||||
if widgets.needs_redraw.insert(id) && !self.deferred.contains(&id) {
|
||||
let depth = self.depth(id);
|
||||
self.pending.insert((depth, id));
|
||||
}
|
||||
}
|
||||
|
||||
fn depth(&self, id: WidgetId) -> usize {
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
diag::bump(Counter::DepthReads);
|
||||
@@ -1098,8 +1156,8 @@ impl UiRenderState {
|
||||
// Both stay marked: the parent because it has this to draw, and
|
||||
// this because the parent must draw it rather than keep what it
|
||||
// has. The mark comes off in `draw_at`, where the parent draws.
|
||||
rsc.widgets_mut().needs_redraw.insert(id);
|
||||
rsc.widgets_mut().needs_redraw.insert(parent);
|
||||
self.mark(id, rsc.widgets_mut());
|
||||
self.mark(parent, rsc.widgets_mut());
|
||||
return false;
|
||||
}
|
||||
if !active.drawn {
|
||||
@@ -1121,16 +1179,6 @@ impl UiRenderState {
|
||||
return true;
|
||||
};
|
||||
let (given_px, offered_px) = self.asked_px(id);
|
||||
// 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 offer. 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.
|
||||
if given_px != offered_px {
|
||||
rsc.widgets_mut().needs_redraw.insert(id);
|
||||
rsc.widgets_mut().needs_redraw.insert(parent);
|
||||
return false;
|
||||
}
|
||||
let info = DrawInfo {
|
||||
layer: active.layer,
|
||||
parent: active.parent,
|
||||
@@ -1139,6 +1187,7 @@ impl UiRenderState {
|
||||
region_node: rsc.widgets().is_region_node(id),
|
||||
mask: active.parent_mask,
|
||||
given_region: active.given_region,
|
||||
offer_region: active.offer_region,
|
||||
offer_len: active.offer_len,
|
||||
offer_placement: active.offer_placement,
|
||||
px: given_px,
|
||||
@@ -1153,14 +1202,33 @@ impl UiRenderState {
|
||||
diag::bump(Counter::LocalRedraws);
|
||||
|
||||
let old = self.remove(id, false, rsc);
|
||||
// Refresh the original measurement before restoring the assigned slot.
|
||||
// Its lengths may differ even though the fraction reference is unchanged.
|
||||
// Asked again where its parent asked: the offer's frame, composed
|
||||
// where the given one is, at the offer's lengths and placement. That
|
||||
// is the question its answer came from, whatever box the parent then
|
||||
// chose from the answer -- which is often a different frame, since a
|
||||
// span hands its children its own placement across itself. The
|
||||
// parent draws in its own frame, or in `FULL` where it is a region
|
||||
// node.
|
||||
let parent_frame = match self.active.get(&parent) {
|
||||
Some(p) if p.move_idx == p.parent_move => p.region,
|
||||
_ => UiRegion::FULL,
|
||||
};
|
||||
let offer_frame = match info.offer_region == UiRegion::FULL {
|
||||
true => parent_frame,
|
||||
false => info.offer_region.within(&parent_frame),
|
||||
};
|
||||
let offered = DrawInfo {
|
||||
placement: info.offer_placement,
|
||||
given_region: info.offer_region,
|
||||
px: offered_px,
|
||||
..info
|
||||
};
|
||||
let answer = self.draw_inner(id, given, offered, old, false, rsc);
|
||||
if info.placement != offered.placement {
|
||||
// Where the given differs from the offer, the first draw is only the
|
||||
// measurement and the second puts the drawing where the parent did.
|
||||
let placed_apart =
|
||||
info.placement != offered.placement || info.px != offered.px || given != offer_frame;
|
||||
let answer = self.draw_inner(id, offer_frame, offered, old, placed_apart, rsc);
|
||||
if placed_apart {
|
||||
self.draw_inner(id, given, info, None, false, rsc);
|
||||
}
|
||||
let active = self.active.get_mut(&id).unwrap();
|
||||
@@ -1183,7 +1251,7 @@ impl UiRenderState {
|
||||
diag::bump(Counter::SizeChanges);
|
||||
diag::bump(Counter::ReaderEdges);
|
||||
}
|
||||
rsc.widgets_mut().needs_redraw.insert(parent);
|
||||
self.mark(parent, rsc.widgets_mut());
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct SlotId {
|
||||
idx: u32,
|
||||
genr: u32,
|
||||
|
||||
@@ -13,7 +13,7 @@ impl Widget for Pad {
|
||||
// it; where the box is bigger -- a share of a row, a rule over this
|
||||
// widget -- the slack is the inner's to sit in, and forcing the near
|
||||
// edge pinned it to a corner it had not asked for.
|
||||
let inside = self.padding.region_of(painter.placement());
|
||||
let inside = DrawRegion::Extent(self.padding.region());
|
||||
let inner = painter.widget_within(&self.inner, inside).size();
|
||||
Size {
|
||||
x: LayoutLen {
|
||||
|
||||
@@ -13,7 +13,6 @@ impl Widget for Stack {
|
||||
StackSize::Default => None,
|
||||
StackSize::Child(i) => Some(i),
|
||||
};
|
||||
let placement = painter.placement();
|
||||
// Whichever child sizes the stack keeps the stack's whole region as
|
||||
// its own -- the stack is the length that child asked for, so taking
|
||||
// the fraction of the stack's box again would take it twice -- and is
|
||||
@@ -24,13 +23,7 @@ impl Widget for Stack {
|
||||
// drawing belongs to the layer it was made on.
|
||||
Some((i, child)) => {
|
||||
painter.child_layer_at(i);
|
||||
painter
|
||||
.widget_at(
|
||||
child,
|
||||
UiRegion::FULL,
|
||||
[Some(placement.x), Some(placement.y)],
|
||||
)
|
||||
.size()
|
||||
painter.widget(child).size()
|
||||
}
|
||||
None => Size::LEFTOVER,
|
||||
};
|
||||
@@ -42,7 +35,7 @@ impl Widget for Stack {
|
||||
// Every other child has the stack's own box for its region, since
|
||||
// the stack is what contains it, and where it sits in one bigger
|
||||
// than itself is its own business.
|
||||
painter.widget_within(child, placement);
|
||||
painter.widget_within(child, DrawRegion::Extent(UiRegion::FULL));
|
||||
}
|
||||
size
|
||||
}
|
||||
|
||||
@@ -1127,3 +1127,211 @@ fn widening_and_restoring_a_contract_does_not_invalidate_its_reader() {
|
||||
h.frame();
|
||||
assert_eq!(leaf_draws.get(), settled + 1);
|
||||
}
|
||||
#[test]
|
||||
fn padding_and_stack_frames_follow_the_extent_without_drawing_again() {
|
||||
struct Observed<W> {
|
||||
widget: W,
|
||||
draws: Rc<Cell<usize>>,
|
||||
}
|
||||
impl<W: Widget> Widget for Observed<W> {
|
||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||
self.draws.set(self.draws.get() + 1);
|
||||
self.widget.draw(painter)
|
||||
}
|
||||
}
|
||||
struct Frame {
|
||||
child: StrongWidget,
|
||||
extent: UiRegion,
|
||||
}
|
||||
impl Widget for Frame {
|
||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||
painter.widget_at(
|
||||
&self.child,
|
||||
UiRegion::FULL,
|
||||
[Some(self.extent.x), Some(self.extent.y)],
|
||||
);
|
||||
Size::LEFTOVER
|
||||
}
|
||||
}
|
||||
for node in [false, true] {
|
||||
let plant = |h: &mut Harness, extent| {
|
||||
let draws = Rc::new(Cell::new(0));
|
||||
let leaf = rect(Color::BLUE).masked().add(&mut h.rsc);
|
||||
h.rsc.widgets_mut().set_region_node(leaf, node);
|
||||
let fixed = rect(Color::RED).width(31).height(19).add(&mut h.rsc);
|
||||
let stack = Observed {
|
||||
widget: Stack {
|
||||
children: vec![leaf.add_strong(&mut h.rsc), fixed.add_strong(&mut h.rsc)],
|
||||
size: StackSize::Default,
|
||||
},
|
||||
draws: draws.clone(),
|
||||
}
|
||||
.add_strong(&mut h.rsc);
|
||||
let pad = Observed {
|
||||
widget: Pad {
|
||||
inner: stack,
|
||||
padding: Padding::uniform(7).with_left(13),
|
||||
},
|
||||
draws: draws.clone(),
|
||||
}
|
||||
.add_strong(&mut h.rsc);
|
||||
let root = Frame { child: pad, extent }.add(&mut h.rsc);
|
||||
h.set_root(root);
|
||||
(root, leaf, fixed, draws)
|
||||
};
|
||||
let mut warm = Harness::new((403, 211));
|
||||
let (root, leaf, fixed, draws) = plant(&mut warm, UiRegion::FULL);
|
||||
for (start, end) in [(0.13, 0.83), (-0.17, 1.23), (0.31, 0.67)] {
|
||||
let extent = UiRegion::new(
|
||||
UiSpan::new(Len::rel(start) + Len::px(3.125), Len::rel(end)),
|
||||
UiSpan::new(Len::px(11.25), Len::rel(end)),
|
||||
);
|
||||
let before = draws.get();
|
||||
warm.rsc[root].extent = extent;
|
||||
warm.frame();
|
||||
assert_eq!(draws.get(), before);
|
||||
let mut cold = Harness::new((403, 211));
|
||||
let (_, other, other_fixed, _) = plant(&mut cold, extent);
|
||||
for (a, b) in [(leaf.id(), other.id()), (fixed.id(), other_fixed.id())] {
|
||||
assert_eq!(warm.region(&a), cold.region(&b));
|
||||
assert_eq!(primitive_bounds(&warm, a), primitive_bounds(&cold, b));
|
||||
}
|
||||
let mask = |h: &Harness, id: WidgetId| {
|
||||
let active = &h.render.active[&id];
|
||||
let mask = &h.rsc.ui().masks[active.mask.idx()];
|
||||
h.render
|
||||
.moves
|
||||
.resolve(mask.move_idx, mask.region)
|
||||
.to_px(h.render.output_size())
|
||||
};
|
||||
assert_eq!(mask(&warm, leaf.id()), mask(&cold, other.id()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moving_an_extent_child_preserves_the_slot_chosen_from_its_measurement() {
|
||||
struct Measured;
|
||||
impl Widget for Measured {
|
||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||
let width = painter.px_len(Axis::X);
|
||||
painter.primitive(RectPrimitive::color(Color::BLUE));
|
||||
Size::from((80, if width > Px::from_int(100) { 40 } else { 60 }))
|
||||
}
|
||||
}
|
||||
struct Frame {
|
||||
child: StrongWidget,
|
||||
start: f32,
|
||||
}
|
||||
impl Widget for Frame {
|
||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||
painter.widget_at(
|
||||
&self.child,
|
||||
UiRegion::FULL,
|
||||
[
|
||||
Some(UiSpan::new(
|
||||
Len::px(self.start),
|
||||
Len::px(self.start + 200.0),
|
||||
)),
|
||||
Some(UiSpan::FULL),
|
||||
],
|
||||
);
|
||||
Size::LEFTOVER
|
||||
}
|
||||
}
|
||||
let mut h = Harness::new((400, 200));
|
||||
let leaf = Measured.add(&mut h.rsc);
|
||||
let stack = (leaf,).stack().add_strong(&mut h.rsc);
|
||||
let root = Frame {
|
||||
child: stack,
|
||||
start: 0.0,
|
||||
}
|
||||
.add(&mut h.rsc);
|
||||
h.set_root(root);
|
||||
assert_corners!(h, leaf, (60, 80), (140, 120));
|
||||
h.rsc[root].start = 30.0;
|
||||
h.frame();
|
||||
assert_corners!(h, leaf, (90, 80), (170, 120));
|
||||
assert_eq!(
|
||||
primitive_bounds(&h, leaf.id()),
|
||||
vec![h.region(&leaf).unwrap()]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extent_frames_keep_fractional_reports_and_numeric_dependencies_valid() {
|
||||
struct Container {
|
||||
child: StrongWidget,
|
||||
region: UiRegion,
|
||||
}
|
||||
impl Widget for Container {
|
||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||
painter
|
||||
.widget_within(&self.child, DrawRegion::Extent(self.region))
|
||||
.size()
|
||||
}
|
||||
}
|
||||
struct Frame {
|
||||
child: StrongWidget,
|
||||
extent: UiRegion,
|
||||
answer: Rc<Cell<Size>>,
|
||||
}
|
||||
impl Widget for Frame {
|
||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||
self.answer.set(
|
||||
painter
|
||||
.widget_at(
|
||||
&self.child,
|
||||
UiRegion::FULL,
|
||||
[Some(self.extent.x), Some(self.extent.y)],
|
||||
)
|
||||
.size(),
|
||||
);
|
||||
Size::LEFTOVER
|
||||
}
|
||||
}
|
||||
for fractional in [false, true] {
|
||||
for region in [
|
||||
UiRegion::FULL,
|
||||
UiRegion::new(UiSpan::new(Len::rel(0.13), Len::rel(0.79)), UiSpan::FULL),
|
||||
] {
|
||||
let plant = |h: &mut Harness, extent| {
|
||||
let size = if fractional {
|
||||
Size {
|
||||
x: rel(0.5),
|
||||
y: LayoutLen::px(27),
|
||||
}
|
||||
} else {
|
||||
Size::from((80, 27))
|
||||
};
|
||||
let (leaf, _) = counted(h, size, !fractional);
|
||||
let child = Container {
|
||||
child: leaf.add_strong(&mut h.rsc),
|
||||
region,
|
||||
}
|
||||
.add_strong(&mut h.rsc);
|
||||
let answer = Rc::new(Cell::new(Size::ZERO));
|
||||
let root = Frame {
|
||||
child,
|
||||
extent,
|
||||
answer: answer.clone(),
|
||||
}
|
||||
.add(&mut h.rsc);
|
||||
h.set_root(root);
|
||||
(root, leaf, answer)
|
||||
};
|
||||
let mut warm = Harness::new((403, 211));
|
||||
let (root, leaf, answer) = plant(&mut warm, UiRegion::FULL);
|
||||
for width in [191.125, 297.25, 83.75] {
|
||||
let extent =
|
||||
UiRegion::new(UiSpan::new(Len::px(13.125), Len::px(width)), UiSpan::FULL);
|
||||
warm.rsc[root].extent = extent;
|
||||
warm.frame();
|
||||
let mut cold = Harness::new((403, 211));
|
||||
let (_, other, other_answer) = plant(&mut cold, extent);
|
||||
assert_eq!(answer.get(), other_answer.get());
|
||||
assert_eq!(warm.region(&leaf), cold.region(&other));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user