Keep valid layout guarantees when a redraw widens their range
This commit is contained in:
1 parent
f860f716e6
commit
0e107f0e89
3 files changed
+46
-1
No files matched your search
@@ -34,6 +34,17 @@ impl LayoutHolds {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn covers(self, other: Self) -> bool {
|
||||
self.placement
|
||||
.is_none_or(|placement| other.placement == Some(placement))
|
||||
&& [0, 1].into_iter().all(|n| {
|
||||
self.frame[n].lo <= other.frame[n].lo
|
||||
&& self.frame[n].hi >= other.frame[n].hi
|
||||
&& self.extent[n].lo <= other.extent[n].lo
|
||||
&& self.extent[n].hi >= other.extent[n].hi
|
||||
})
|
||||
}
|
||||
|
||||
pub fn contains(self, px: PxVec2, placement: UiRegion) -> bool {
|
||||
self.placement.is_none_or(|old| old == placement)
|
||||
&& [Axis::X, Axis::Y].into_iter().all(|axis| {
|
||||
|
||||
@@ -1163,7 +1163,19 @@ impl UiRenderState {
|
||||
if info.placement != offered.placement {
|
||||
self.draw_inner(id, given, info, None, false, rsc);
|
||||
}
|
||||
if Some((answer.0, answer.1)) != was_answer || self.active[&id].holds != was_holds {
|
||||
let active = self.active.get_mut(&id).unwrap();
|
||||
// A wider contract does not invalidate the guarantee the parent kept.
|
||||
// Retain that guarantee so widening and narrowing back do not churn it.
|
||||
if let Some((size, holds)) = was_answer
|
||||
&& answer.0 == size
|
||||
&& answer.1.covers(holds)
|
||||
{
|
||||
active.answer = was_answer;
|
||||
}
|
||||
if active.holds.covers(was_holds) && was_holds.contains(given_px, active.placement) {
|
||||
active.holds = was_holds;
|
||||
}
|
||||
if active.answer != was_answer || active.holds != was_holds {
|
||||
// The parent retains both the answer and the drawing's validity;
|
||||
// even an unchanged size can narrow the range safe for a resize.
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
|
||||
Reference in new issue
Block a user