From 7617a0522dd0ec161b1d91657566c84f4bc4d351 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 05:10:23 +0000 Subject: [PATCH 1/3] A set writes the bound value as a commit does The apply step counted a write only for Update and Commit, so a Set (cx.set, or a gesture that begins and commits in one pass) changed the bound place without noting the edit: no settled region or hidden page that read the value measured again, and no earlier reader got the edit rerun. A given binding's Set likewise unsettled nothing. Set now carries its value in both tests. The Pages edit trial asserts one measuring run of the hidden page in the edit frame. The popover click trial counts the row's activations: a leaf counts a press in every pass with a press phase, so a click that lands counts more than one. It clicks the new page's row right after the switch frame's idle frame. --- crates/ui-contract/src/contract/steps/apply.rs | 4 ++-- crates/ui-contract/tests/it/contract/pages.rs | 6 +++--- crates/ui-widgets/tests/it/overlay/pages.rs | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/ui-contract/src/contract/steps/apply.rs b/crates/ui-contract/src/contract/steps/apply.rs index 2d831eb0c..7c35c76b2 100644 --- a/crates/ui-contract/src/contract/steps/apply.rs +++ b/crates/ui-contract/src/contract/steps/apply.rs @@ -84,9 +84,9 @@ pub(crate) fn apply_values(comp: &mut C, cx: &mut Cx<'_, C>) -> Va } _ => {} } - let carries = matches!(event, EditEvent::Update { .. } | EditEvent::Commit { .. }); + let carries = matches!(event, EditEvent::Update { .. } | EditEvent::Commit { .. } | EditEvent::Set { .. }); if bind.is_given() - && let EditEvent::Update { value, .. } | EditEvent::Commit { after: value, .. } = event + && let EditEvent::Update { value, .. } | EditEvent::Commit { after: value, .. } | EditEvent::Set { after: value, .. } = event { given |= bind.get() != Some(Mixed::Same(value.clone())); } diff --git a/crates/ui-contract/tests/it/contract/pages.rs b/crates/ui-contract/tests/it/contract/pages.rs index acf6b4394..602463d0e 100644 --- a/crates/ui-contract/tests/it/contract/pages.rs +++ b/crates/ui-contract/tests/it/contract/pages.rs @@ -101,8 +101,8 @@ fn a_settled_hidden_page_runs_no_body() { } } -/// An edit of a value the hidden page read measures that page again in the frame of the edit, and the pages take its -/// new size there. +/// An edit of a value the hidden page read measures that page again in the frame of the edit, once, and the pages take +/// its new size there. The edit is a `set`, as a click on a control makes it. #[trial] fn an_edit_of_a_value_a_hidden_page_read_measures_it_again() { let scene = Scene::new(); @@ -110,7 +110,7 @@ fn an_edit_of_a_value_a_hidden_page_read_measures_it_again() { frames.idle(30, |ui| scene.show(ui)); let before = scene.width.get(); scene.set_to.set(Some(before * 3.0)); - assert!(scene.frame(&mut frames) > 0, "the edit ran the hidden page"); + assert_eq!(scene.frame(&mut frames), 1, "the edit measured the hidden page again, once"); assert!(scene.width.get() > before, "the pages took the hidden page's new width in the frame of the edit"); frames.idle(30, |ui| scene.show(ui)); assert_eq!(scene.frame(&mut frames), 0, "the hidden page settles again"); diff --git a/crates/ui-widgets/tests/it/overlay/pages.rs b/crates/ui-widgets/tests/it/overlay/pages.rs index 72aedf23f..5c4025345 100644 --- a/crates/ui-widgets/tests/it/overlay/pages.rs +++ b/crates/ui-widgets/tests/it/overlay/pages.rs @@ -104,8 +104,8 @@ fn a_content_sized_popover_is_narrower_than_the_room() { assert!(fill.rect.width() + 0.5 >= row.rect.width(), "the filling leaf fills the width the popover settled on"); } -/// A page switch moves and resizes nothing: the tabs stay where they were, and a click on the new page's row in the -/// frame after the switch lands on it. +/// A page switch moves and resizes nothing: the tabs stay where they were, and a click on the new page's row right +/// after the switch lands on it. #[trial] fn a_page_switch_keeps_the_popover_and_the_next_click_lands_on_the_new_page() { let paged = Rc::new(Paged::default()); @@ -113,12 +113,11 @@ fn a_page_switch_keeps_the_popover_and_the_next_click_lands_on_the_new_page() { let tab_b = fixture.by_label("Tab B").expect("the tabs show"); let row_a = fixture.by_label("A row").expect("page 0 shows"); fixture.click(&tab_b); - fixture.frame(Vec::new()); assert_eq!(paged.page.get(), 1, "the tab switched the page"); let tab_after = fixture.by_label("Tab B").expect("the tabs still show"); assert!((tab_after.rect.min - tab_b.rect.min).length() < 0.5, "the switch did not move the tabs"); let row_b = fixture.by_label("B row").expect("page 1 shows"); assert!((row_b.rect.min - row_a.rect.min).length() < 0.5, "the new page starts where the old one did"); fixture.click(&row_b); - assert_eq!(paged.row_b.borrow().presses, 1, "the click right after the switch landed on the new page's row"); + assert_eq!(paged.row_b.borrow().activations, 1, "the click right after the switch landed on the new page's row"); } From ca8e6455678d16a002a7f981161028a6bce7b63b Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 05:12:37 +0000 Subject: [PATCH 2/3] A cancel that restores the value counts as a write The apply step counts every event that changes the bound value: a proposal, commit or set, and a cancel that puts the value from before the gesture back. A given binding unsettles on the same events, compared by the value each lands. EditEvent::apply reports Restored only when the cancel changed the value, so a cancel under a commit-only policy, whose place still holds the value from before, counts as no write. --- crates/behavior/src/value.rs | 7 ++++--- crates/ui-contract/src/contract/steps/apply.rs | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/behavior/src/value.rs b/crates/behavior/src/value.rs index b87d41c25..42391e6f6 100644 --- a/crates/behavior/src/value.rs +++ b/crates/behavior/src/value.rs @@ -119,7 +119,7 @@ pub enum Applied { Changed, /// The value was already the event's. Unchanged, - /// A cancel put the value from before the gesture back. + /// A cancel put the value from before the gesture back: the value differed from it. Restored, } @@ -332,7 +332,7 @@ impl EditEvent { Applied::Changed } } - EditEvent::Cancel { before: Some(Mixed::Same(before)), .. } => { + EditEvent::Cancel { before: Some(Mixed::Same(before)), .. } if *v != *before => { *v = before.clone(); Applied::Restored } @@ -343,10 +343,11 @@ impl EditEvent { /// Applies the event to a value that may be mixed: the written value is a concrete one. pub fn apply_mixed(&self, v: &mut Mixed) -> Applied { match (self, self.value()) { - (EditEvent::Cancel { before: Some(before), .. }, _) => { + (EditEvent::Cancel { before: Some(before), .. }, _) if *v != *before => { *v = before.clone(); Applied::Restored } + (EditEvent::Cancel { .. }, _) => Applied::Unchanged, (_, Some(new)) if !matches!(v, Mixed::Same(held) if held == new) => { *v = Mixed::Same(new.clone()); Applied::Changed diff --git a/crates/ui-contract/src/contract/steps/apply.rs b/crates/ui-contract/src/contract/steps/apply.rs index 7c35c76b2..7b12affc4 100644 --- a/crates/ui-contract/src/contract/steps/apply.rs +++ b/crates/ui-contract/src/contract/steps/apply.rs @@ -84,13 +84,13 @@ pub(crate) fn apply_values(comp: &mut C, cx: &mut Cx<'_, C>) -> Va } _ => {} } - let carries = matches!(event, EditEvent::Update { .. } | EditEvent::Commit { .. } | EditEvent::Set { .. }); + // Every event that changes the value counts: a proposal, commit or set, and a cancel that restores. if bind.is_given() - && let EditEvent::Update { value, .. } | EditEvent::Commit { after: value, .. } | EditEvent::Set { after: value, .. } = event + && let Some(value) = event.landed() { given |= bind.get() != Some(Mixed::Same(value.clone())); } - written |= bind.apply(event) != Applied::Unchanged && carries; + written |= bind.apply(event) != Applied::Unchanged; if let Some(value) = event.landed() { landing = Some(value.clone()); } From 4f53e27dba6553764f920b53f9996b81c80f8d2b Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 05:13:49 +0000 Subject: [PATCH 3/3] Pages: page children take their scope id from the framework's id derivation Each page's child Ui, measured or shown, is scoped by its page id (memory::sub of the set's base), as a lazy child is, not salted by hand. --- crates/ui-contract/src/contract/pages.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-contract/src/contract/pages.rs b/crates/ui-contract/src/contract/pages.rs index 6ca6fee43..ade77d7c7 100644 --- a/crates/ui-contract/src/contract/pages.rs +++ b/crates/ui-contract/src/contract/pages.rs @@ -66,7 +66,7 @@ impl<'a, K: Hash + PartialEq> Pages<'a, K> { // not show it, so nothing there checks it. layout_memory::boundary(&ctx, true, || { let room = Rect::from_min_size(region.min, Vec2::new(region.width(), f32::INFINITY)); - let mut child = alloc::child(ui, UiBuilder::new().max_rect(room).layout(layout).id_salt(id).sizing_pass().invisible()); + let mut child = alloc::child(ui, UiBuilder::new().max_rect(room).layout(layout).scope_id(id).sizing_pass().invisible()); page(&mut child, key); child.min_rect().size() }) @@ -78,7 +78,7 @@ impl<'a, K: Hash + PartialEq> Pages<'a, K> { largest.max(size) }); let id = sub(base, hash(self.current)); - let mut child = alloc::child(ui, UiBuilder::new().max_rect(region).layout(layout).id_salt(id)); + let mut child = alloc::child(ui, UiBuilder::new().max_rect(region).layout(layout).scope_id(id)); child.set_min_size(hidden.min(region.size())); let out = page(&mut child, self.current); let rect = child.min_rect();