mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 01:44:25 +00:00
tfix4-f6: HostedAdjustDialog::edited is the dialog's edit signal (editor, Reset, field sets, value_mut); seed replaces the value without one
This commit is contained in:
@@ -91,6 +91,9 @@ pub struct HostedAdjustDialog<V, E = ()> {
|
||||
title: Label,
|
||||
open: bool,
|
||||
value: V,
|
||||
/// Whether the value was edited since the dialog opened: by the editor, Reset, a field set or
|
||||
/// [`value_mut`](HostedAdjustDialog::value_mut). A [`seed`](HostedAdjustDialog::seed) is not an edit.
|
||||
edited: bool,
|
||||
preview: bool,
|
||||
comparing: bool,
|
||||
context: AdjustContext,
|
||||
@@ -129,6 +132,7 @@ impl<V: Value + Default + Serialize + DeserializeOwned, E: Send + 'static> Hoste
|
||||
title: title.into(),
|
||||
open: true,
|
||||
value,
|
||||
edited: false,
|
||||
preview: true,
|
||||
comparing: false,
|
||||
context: AdjustContext::dialog(true),
|
||||
@@ -246,11 +250,26 @@ impl<V: Value + Default + Serialize + DeserializeOwned, E: Send + 'static> Hoste
|
||||
&self.value
|
||||
}
|
||||
|
||||
/// The value, for the app's answers to the editor's asks (Auto's levels).
|
||||
/// The value, for the app's edits of it (Auto's levels, a picked colour, an automation set): the dialog counts
|
||||
/// as [`edited`](HostedAdjustDialog::edited) from then on.
|
||||
pub fn value_mut(&mut self) -> &mut V {
|
||||
self.edited = true;
|
||||
&mut self.value
|
||||
}
|
||||
|
||||
/// Replaces the value with the one the dialog opens at (the app seeds it after opening, or again once its target
|
||||
/// resolves or changes), without counting as an edit.
|
||||
pub fn seed(&mut self, value: V) {
|
||||
self.value = value;
|
||||
}
|
||||
|
||||
/// Whether the value was edited since the dialog opened: by the editor, Reset, a field set or
|
||||
/// [`value_mut`](HostedAdjustDialog::value_mut). Preview, the picker, the channel and the clipping display are not
|
||||
/// the value; seeds are not edits.
|
||||
pub fn edited(&self) -> bool {
|
||||
self.edited
|
||||
}
|
||||
|
||||
/// Whether the Preview box is ticked.
|
||||
pub fn is_previewing(&self) -> bool {
|
||||
self.preview
|
||||
@@ -279,6 +298,7 @@ impl<V: Value + Default + Serialize + DeserializeOwned, E: Send + 'static> Stack
|
||||
title,
|
||||
open,
|
||||
value,
|
||||
edited,
|
||||
preview,
|
||||
comparing,
|
||||
context,
|
||||
@@ -302,6 +322,8 @@ impl<V: Value + Default + Serialize + DeserializeOwned, E: Send + 'static> Stack
|
||||
// The request to select a point is this pass's alone: a rerun of the pass in the frame finds none.
|
||||
let (canvas, select_point) = (*canvas, select_point.take());
|
||||
let (context, resizable, remember) = (*context, *resizable, remember.clone());
|
||||
// What the editor, Reset and the form's undo change in this pass is the dialog's edit.
|
||||
let before = value.clone();
|
||||
let form = FormDialog::new(title.clone(), Bind::bound(value))
|
||||
.opened(Bind::bound(open))
|
||||
.preview(Some(Bind::bound(&mut *preview)))
|
||||
@@ -334,6 +356,7 @@ impl<V: Value + Default + Serialize + DeserializeOwned, E: Send + 'static> Stack
|
||||
true
|
||||
});
|
||||
*comparing = shown.comparing;
|
||||
*edited |= *value != before;
|
||||
if held.refusal().is_some_and(|(_, refused)| refused != value) {
|
||||
held.clear_refusal();
|
||||
}
|
||||
@@ -403,7 +426,10 @@ impl<V: Value + Default + Serialize + DeserializeOwned, E: Send + 'static> Stack
|
||||
let clip = clipping_from_json(&value).ok_or_else(|| rejected(&value))?;
|
||||
self.set_clipping(clip);
|
||||
}
|
||||
_ => return set_serde_field(&mut self.value, field, value),
|
||||
_ => {
|
||||
set_serde_field(&mut self.value, field, value)?;
|
||||
self.edited = true;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -100,6 +100,36 @@ fn a_hosted_adjustment_dialog_previews_and_answers_with_its_value() {
|
||||
assert_eq!(host.borrow_mut().take::<Adjust>(), Some(DialogResult::Cancel), "Escape cancels a reopened dialog");
|
||||
}
|
||||
|
||||
// The dialog's own edited signal: false at open, after a preview toggle and after a seed; true after an editor change,
|
||||
// and after a field set of the value.
|
||||
#[trial]
|
||||
fn an_adjustment_dialog_counts_editor_changes_and_sets_as_edits_but_not_seeds_or_preview() {
|
||||
let host = Rc::new(RefCell::new(DialogHost::new()));
|
||||
let mut fixture = fixture(&host);
|
||||
let id = host.borrow_mut().open(brightness_contrast());
|
||||
fixture.idle(10);
|
||||
let edited = |host: &Rc<RefCell<DialogHost>>| host.borrow().get::<Adjust>().map(Adjust::edited);
|
||||
assert_eq!(edited(&host), Some(false), "a dialog opens unedited");
|
||||
let preview = fixture.by_label("Preview").expect("the Preview box");
|
||||
fixture.click(&preview).idle(4);
|
||||
if let Some(dialog) = host.borrow_mut().get_mut::<Adjust>() {
|
||||
dialog.seed(BrightnessContrast { brightness: 0.0, contrast: 0.0, legacy: false });
|
||||
}
|
||||
fixture.idle(4);
|
||||
assert_eq!(edited(&host), Some(false), "a preview toggle and a seed are not edits");
|
||||
let slider = fixture.by_role(craft_ui::contract::Role::SLIDER).first().cloned().expect("the Brightness slider");
|
||||
fixture.drag(&slider, Vec2::new(slider.rect.width() / 4.0, 0.0)).settle();
|
||||
assert_eq!(edited(&host), Some(true), "an editor change is an edit");
|
||||
|
||||
let host = Rc::new(RefCell::new(DialogHost::new()));
|
||||
let mut again = self::fixture(&host);
|
||||
host.borrow_mut().open(brightness_contrast());
|
||||
again.idle(10);
|
||||
let ctx = again.ctx().clone();
|
||||
assert_eq!(host.borrow_mut().set_json_field(&ctx, id, "contrast", serde_json::json!(0.0)), Ok(()));
|
||||
assert_eq!(edited(&host), Some(true), "a field set of the value is an edit");
|
||||
}
|
||||
|
||||
/// Why the app refuses the held OK.
|
||||
const REFUSED: &str = "The layer is locked.";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user