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/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(); diff --git a/crates/ui-contract/src/contract/steps/apply.rs b/crates/ui-contract/src/contract/steps/apply.rs index 2d831eb0c..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 { .. }); + // 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, .. } = 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()); } 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"); }