mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
ui-widgets: an equal link the host turned off again before the pass that sees it turn on sets no field to the first one's value
This commit is contained in:
@@ -317,7 +317,8 @@ impl<const N: usize> Component for LinkedFields<'_, N> {
|
||||
memo.base = Some(shown_of(shown.as_ref()));
|
||||
}
|
||||
let was = std::mem::replace(&mut memo.before, memo.seen);
|
||||
let turned_on = memo.seen == Some(true) && was == Some(false);
|
||||
// The link showed on in the last pass and not before it; a host that has turned it off again since keeps its values.
|
||||
let turned_on = memo.seen == Some(true) && was == Some(false) && self.link.value() != Some(&false);
|
||||
if let (true, LinkMode::Equal, Some(values)) = (turned_on, self.mode, shown)
|
||||
&& let Mixed::Same(Some(first)) = values[0]
|
||||
&& values.iter().any(|value| *value != Mixed::Same(Some(first)))
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use craft_behavior::Mixed;
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use craft_ui::text::LinkedFields;
|
||||
use craft_ui::text::{LinkMode, LinkedFields};
|
||||
use egui::{Key, Modifiers};
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
@@ -40,3 +40,24 @@ fn typing_into_a_linked_field_keeps_the_starting_ratio() {
|
||||
fixture.idle(2);
|
||||
assert_eq!(values.get(), same(100.0, 80.0));
|
||||
}
|
||||
|
||||
/// Values and a link the host sets between frames apply as set: a link the host turned on and off again before the
|
||||
/// pass that sees it turn on sets no field to the first one's value.
|
||||
#[trial]
|
||||
fn an_equal_link_turned_off_again_leaves_the_values_alone() {
|
||||
let values: Values = Rc::new(Cell::new(same(20.0, 20.0)));
|
||||
let link = Rc::new(Cell::new(false));
|
||||
let (shown, linked) = (values.clone(), link.clone());
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let mut current = shown.get();
|
||||
LinkedFields::new("Scale", Bind::bound(&mut current), Bind::given(linked.get())).mode(LinkMode::Equal).show(ui);
|
||||
shown.set(current);
|
||||
});
|
||||
fixture.settle();
|
||||
link.set(true);
|
||||
fixture.idle(1);
|
||||
values.set(same(20.0, 60.0));
|
||||
link.set(false);
|
||||
fixture.idle(2);
|
||||
assert_eq!(values.get(), same(20.0, 60.0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user