mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 18:04:48 +00:00
Merge branch 'fw/popover' into fw/mac1
This commit is contained in:
@@ -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<T: Value> EditEvent<T> {
|
||||
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<T: Value> EditEvent<T> {
|
||||
/// 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<T>) -> 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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -84,13 +84,13 @@ pub(crate) fn apply_values<C: Component>(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());
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user