diff --git a/crates/imaging/src/ui/adjust/hosted.rs b/crates/imaging/src/ui/adjust/hosted.rs index c83319102..c2ea746d5 100644 --- a/crates/imaging/src/ui/adjust/hosted.rs +++ b/crates/imaging/src/ui/adjust/hosted.rs @@ -370,7 +370,7 @@ impl Stack } }); let form = match reset_with.as_deref() { - Some(target) => form.reset_with(|current, opened, _| target(current, opened)), // P3(forms-w1): ex.P11 + Some(target) => form.reset_with(|current, opened, _| target(current, opened)), None => form, }; let shown = form.show(ui, |ui, form, value| { diff --git a/crates/ui-panels/src/dialog/trials.rs b/crates/ui-panels/src/dialog/trials.rs index 869fe1b83..7a7cced78 100644 --- a/crates/ui-panels/src/dialog/trials.rs +++ b/crates/ui-panels/src/dialog/trials.rs @@ -327,3 +327,153 @@ fn body_buttons_stand_in_the_slot_the_body_keeps_and_keep_their_keys() { let (escaped, _) = run(Some(Key::Escape)).1; assert_eq!(escaped, Some(CloseReason::Escape), "Escape cancels"); } + +/// A fixture that shows a dialog "Options" while `open` is set, with `body` inside it. +fn dialog_fixture( + open: &std::rc::Rc>, + make: impl Fn(Dialog<'_>) -> Dialog<'_> + 'static, + body: impl Fn(&mut Ui) + 'static, +) -> Fixture { + let shown = std::rc::Rc::clone(open); + Fixture::new(move |ui| { + let mut now = shown.get(); + if now { + make(Dialog::new("Options").opened(Bind::bound(&mut now))).show(ui, |ui, _| body(ui)); + } + shown.set(now); + }) +} + +/// Closes the dialog of `fixture` for a pass and opens it again. +fn reopen(fixture: &mut Fixture, open: &std::rc::Rc>) { + open.set(false); + fixture.idle(3); + open.set(true); + fixture.settle(); +} + +#[trial] +fn a_reopened_dialog_focuses_its_first_enabled_field_again() { + let open = std::rc::Rc::new(Cell::new(true)); + let mut fixture = dialog_fixture(&open, |dialog| dialog, |ui| { + let (mut first, mut second) = (String::new(), String::new()); + TextField::new("First", Bind::bound(&mut first)).enabled(false).show(ui); + TextField::new("Second", Bind::bound(&mut second)).show(ui); + }); + fixture.settle(); + let on_second = |fixture: &Fixture| { + let second = fixture.by_label("Second").expect("the second field is shown"); + crate::testing::access::focused_key(fixture.tree()) == second.node + }; + assert!(on_second(&fixture), "the first enabled field takes the focus, not the disabled one before it"); + reopen(&mut fixture, &open); + assert!(on_second(&fixture), "and takes it again after a reopen"); +} + +#[trial] +fn a_dialog_moves_by_its_title_band_stays_on_screen_and_reopens_where_left() { + let open = std::rc::Rc::new(Cell::new(true)); + let mut fixture = dialog_fixture( + &open, + |dialog| dialog.remember(crate::contract::SaveKey::new("trial.dialog-band")), + |ui| { + Text::new("Body text").show(ui); + }, + ); + fixture.room(egui::vec2(900.0, 700.0)); + fixture.settle(); + let dialog = |fixture: &Fixture| fixture.by_role(Role::DIALOG).into_iter().next().expect("the dialog is shown").rect; + let band = |fixture: &Fixture| fixture.by_role(Role::HEADING).into_iter().find(|target| fixture.tree().name_of(target.node) == Some("Options")).expect("the title band"); + let start = dialog(&fixture); + + let from = start.center_bottom() - egui::vec2(0.0, 6.0); + fixture.drag_at(from, egui::vec2(60.0, 40.0)).settle(); + assert_eq!(dialog(&fixture), start, "a drag that starts in the body moves nothing"); + + let title = band(&fixture); + fixture.drag(&title, egui::vec2(80.0, 50.0)).settle(); + let moved = dialog(&fixture); + assert_eq!(moved.min - start.min, egui::vec2(80.0, 50.0), "a drag of the band moves the dialog by it"); + + let title = band(&fixture); + fixture.drag(&title, egui::vec2(5000.0, 5000.0)).settle(); + let screen = fixture.shown(); + assert!(screen.contains_rect(dialog(&fixture)), "a drag past the edge stops at it: {:?} in {screen:?}", dialog(&fixture)); + + for _ in 0..8 { + fixture.key(Key::Tab, Modifiers::NONE); + } + let band_node = band(&fixture).node; + assert_ne!(crate::testing::access::focused_key(fixture.tree()), band_node, "the title band is no Tab stop"); + + let left = dialog(&fixture); + reopen(&mut fixture, &open); + assert_eq!(dialog(&fixture), left, "a reopen under the same key starts where the dialog was left"); +} + +#[trial] +fn a_tall_body_scrolls_under_a_footer_that_stays_in_view() { + let open = std::rc::Rc::new(Cell::new(true)); + let mut fixture = dialog_fixture(&open, |dialog| dialog.buttons([FooterButton::new("OK", DialogRole::Accept)]), |ui| { + for line in 0..60 { + Text::new(format!("Line {line}")).show(ui); + } + }); + fixture.room(egui::vec2(600.0, 320.0)); + fixture.settle(); + let first = |fixture: &Fixture| fixture.by_label("Line 0").map(|target| target.rect); + let at_top = first(&fixture).expect("the first line is shown"); + let screen = fixture.shown(); + let ok = fixture.by_label("OK").expect("the footer is shown").rect; + assert!(screen.contains_rect(ok), "the footer stays inside the short window: {ok:?} in {screen:?}"); + assert!(fixture.by_label("Line 59").is_none_or(|last| !screen.contains_rect(last.rect)), "the body does not all fit: it scrolls"); + + let over = fixture.by_role(Role::DIALOG).into_iter().next().expect("the dialog is shown").rect.center(); + let wheel = egui::Event::MouseWheel { unit: egui::MouseWheelUnit::Point, delta: egui::vec2(0.0, -400.0), modifiers: Modifiers::NONE }; + fixture.frame(vec![egui::Event::PointerMoved(over), wheel]).settle(); + assert_ne!(first(&fixture), Some(at_top), "the wheel scrolled the body"); + assert!(screen.contains_rect(fixture.by_label("OK").expect("the footer is shown").rect), "the footer stays in view while the body scrolls"); + + reopen(&mut fixture, &open); + assert_eq!(first(&fixture), Some(at_top), "a reopen starts at the top"); +} + +#[trial] +fn an_armed_answer_waits_until_its_prompt_was_seen() { + let open = std::rc::Rc::new(Cell::new(true)); + let closed = std::rc::Rc::new(Cell::new(None)); + let (shown, seen) = (std::rc::Rc::clone(&open), std::rc::Rc::clone(&closed)); + let mut fixture = Fixture::new(move |ui| { + let mut now = shown.get(); + if now { + let out = Dialog::new("Options") + .opened(Bind::bound(&mut now)) + .buttons([FooterButton::new("Delete", DialogRole::Destructive).armed_after(1.0), FooterButton::new("Cancel", DialogRole::Cancel)]) + .show(ui, |_, _| {}); + if out.output.closed.is_some() { + seen.set(out.output.closed); + } + } + shown.set(now); + }); + fixture.settle(); + let press = |fixture: &mut Fixture| { + let delete = fixture.by_label("Delete").expect("the armed button is shown"); + fixture.click(&delete).idle(2); + }; + press(&mut fixture); + assert_eq!(closed.get(), None, "a click before the delay does nothing"); + fixture.key(Key::Enter, Modifiers::NONE).idle(2); + assert_eq!(closed.get(), None, "nor does Enter"); + + open.set(false); + fixture.idle(2); + open.set(true); + fixture.idle(40); + press(&mut fixture); + assert_eq!(closed.get(), None, "a frame without the prompt restarted the wait"); + + fixture.idle(90); + press(&mut fixture); + assert_eq!(closed.get(), Some(CloseReason::Activated), "after the delay the answer takes the click"); +} diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs index 62505c789..3ea9c5279 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs @@ -2,7 +2,7 @@ //! owned by a `DialogHost`. A command form is a `ParamDialog` without a preview. use super::fields::{DialogFields, FieldValue}; -use crate::patterns::presets::{NamedPresetEvent, PresetKind, PresetRow}; +use crate::patterns::presets::{NamedPresetEvent, NamedPresetRow, PickerField, PresetError, PresetKind, PresetPicker, PresetRow}; use crate::runtime::requests::{ColorRequest, EyedropperRequest, HostAnswer, ListingRequest, PathRequest}; use super::form::{FormDialog, FormDialogWords}; @@ -47,6 +47,7 @@ craft_ui::words! { /// The words of the parameter dialog beside the common OK and Cancel. pub struct ParamDialogWords { reset: "paramDialog.reset" = "Reset"; + presets: "paramDialog.presets" = "Preset"; } } @@ -102,8 +103,11 @@ impl ParamResult { /// its command succeeds, so a failed command leaves the previous values; without a remember key it does nothing. pub fn remember(&self, ctx: &Context) { if let Some((key, lifetime, values)) = &self.remember { - let _ = lifetime; // P3(forms-w1): od.OD3 - crate::runtime::memory::set_saved_value::>(ctx, key, Some(values.clone())); + let values = Some(values.clone()); + match lifetime { + Lifetime::Run => crate::runtime::memory::set_run_value::>(ctx, key, values), + _ => crate::runtime::memory::set_saved_value::>(ctx, key, values), + } } } } @@ -284,6 +288,9 @@ pub struct ParamDialog<'a> { /// Shows `reason` under the rows while the values are `refused`. #[prop(vis = "pub(crate)")] refusal: Option<(Label, DialogFields)>, + /// Shows the refusal whatever the values are: the host keeps it until it withdraws it. + #[prop(vis = "pub(crate)")] + refusal_blocks: bool, /// Centres the preview pane's view on the picture point `point` in this pass; without a picture it does nothing. #[prop(name = "centre_on", vis = "pub(crate)")] centre: Option, @@ -358,6 +365,7 @@ impl<'a> ParamDialog<'a> { hold: false, finish_held: false, refusal: None, + refusal_blocks: false, centre: None, preview_colors: Vec::new(), } @@ -372,7 +380,6 @@ impl<'a> ParamDialog<'a> { /// The answer OK gives with `fields`: with `remember`, it keeps the part of them the dialog saves. fn result(key: String, params: &[Param], remember: Option, remember_for: Lifetime, fields: DialogFields) -> ParamResult { - // P3(forms-w1): od.OD3 -- callers pass the dialog's `remember_for`. let remember = remember.map(|save| (save, remember_for, Self::remembered(params, &fields))); ParamResult { key, fields, remember, id: DialogId::NULL } } @@ -400,6 +407,7 @@ impl<'a> ParamDialog<'a> { pub fn remembered(params: &[Param], fields: &DialogFields) -> DialogFields { let kept = |param: &Param| { param.is_remembered() + && param.footer_on().is_none() && matches!( param.kind, ParamKind::Range { .. } @@ -438,7 +446,7 @@ impl<'a> ParamDialog<'a> { open, remember, remember_for, - presets: _, + presets, ok_enabled, ok_reason, ok_label, @@ -466,6 +474,7 @@ impl<'a> ParamDialog<'a> { hold, finish_held, refusal, + refusal_blocks, centre, preview_colors, } = self; @@ -487,14 +496,7 @@ impl<'a> ParamDialog<'a> { .accept_stays_open(hold) .answers(answers); if let Some(reset_to) = reset_to { - form = form.reset_with(move |_, opened, _| { - // P3(forms-w1): ex.P11 - let mut values = opened.clone(); - for (name, value) in reset_to.iter() { - values.set(name, value.clone()); - } - values - }); + form = form.reset_with(move |_, opened, _| reset_target(opened, Some(&reset_to))); } if let Some(reason) = ok_reason { form = form.ok_reason(reason); @@ -517,9 +519,23 @@ impl<'a> ParamDialog<'a> { } // The pane shows only in a dialog that previews. let preview = preview.filter(|_| previews); - if !extra_buttons.is_empty() { - form = form.extra_buttons(extra_buttons.iter().map(|(_, button)| button.clone())); // P3(forms-w1): q337 + // The footer rows' buttons follow the extra buttons. A button's label cannot change inside the pass that + // draws it, so it shows the state the previous pass left. + let footer_rows: Vec<&Param> = params.iter().filter(|param| param.footer_on().is_some()).collect(); + let footer_id = egui::Id::new(("paramDialog.footer", key.as_str())); + let flip_id = footer_id.with("flip"); + let footer_states: Vec = if footer_rows.is_empty() { Vec::new() } else { ui.data(|data| data.get_temp(footer_id)).unwrap_or_default() }; + let footer_buttons = footer_rows.iter().enumerate().map(|(at, param)| { + let on = footer_states.get(at).copied().unwrap_or(false); + let label = param.footer_on().filter(|_| on).unwrap_or_else(|| param.label.clone()); + FooterButton::new(label, DialogRole::Other).stays_open(true) + }); + let buttons: Vec = extra_buttons.iter().map(|(_, button)| button.clone()).chain(footer_buttons).collect(); + if !buttons.is_empty() { + form = form.extra_buttons(buttons); } + let presets_label = Env::of(ui).words::().presets.clone(); + let mut preset_events = Vec::new(); if let Some(note) = footer_note { form = form.footer_extra(move |ui| { Text::new(note.clone()).shade(Shade::Muted).show(ui); @@ -535,31 +551,20 @@ impl<'a> ParamDialog<'a> { let mut latest = None::; let shown = form.show(ui, |ui, cx, values| { if cx.first() && !host_opened { - let saved = remember.as_ref().and_then(|key| cx.saved::>(key).clone()); + let saved = remember.as_ref().and_then(|key| remembered_values(ui.ctx(), key, remember_for)); Self::open_values(¶ms, &patterns, saved.as_ref(), values); } - for answer in cx.take_answers() { - let answered = match &answer { - HostAnswer::Color { key, .. } | HostAnswer::Eyedropper { key, .. } | HostAnswer::Path { key, .. } => { - params.iter().find(|param| param.key == *key) - } - HostAnswer::Listing { .. } => None, - }; - let held = answered.and_then(|param| values.get(¶m.key).cloned()); - match answer { - HostAnswer::Color { key, color } | HostAnswer::Eyedropper { key, color } => set_color_field(¶ms, values, &key, color), - HostAnswer::Path { key, path } => values.set(&key, FieldValue::Text(path.to_string_lossy().into_owned())), - HostAnswer::Listing { key, files } => { - let files = files.into_iter().map(|file| FieldValue::Text(file.to_string_lossy().into_owned())).collect(); - if let Some(param) = params.iter().find(|param| param.key == key) { - values.set(param.folder_files_key(), FieldValue::List(files)); - } - } - } - if let Some(param) = answered { - param.drop_dependents(held.as_ref(), values); + apply_answers(¶ms, values, cx.take_answers()); + // A footer row pressed in the previous pass flips once; a measuring run leaves it for the real one. + if !footer_rows.is_empty() && !crate::runtime::measure::active(ui.ctx()) { + if let Some(flip) = ui.data_mut(|data| data.remove_temp::(flip_id)) { + let on = values.bool(&flip).unwrap_or(false); + values.set(flip, FieldValue::Bool(!on)); } } + if let Some(presets) = &presets { + show_presets(ui, &presets_label, presets, values, &mut preset_events); + } if let Some(canvas) = canvas { cx.keep_view_open(canvas); } @@ -603,8 +608,8 @@ impl<'a> ParamDialog<'a> { } (None, _) => show_rows(ui, values), } - // The host's refusal of the held OK stays until a value changes. - if let Some((reason, _)) = refusal.as_ref().filter(|(_, refused)| *refused == *values) { + // The host's refusal of the held OK stays until a value changes, or until the host withdraws it. + if let Some((reason, _)) = refusal.as_ref().filter(|(_, refused)| refusal_blocks || *refused == *values) { Notice::new(Tone::Bad, reason.clone()).layout(NoticeLayout::Inline).show(ui); } if let Some(BelowRows(draw)) = &below { @@ -612,7 +617,12 @@ impl<'a> ParamDialog<'a> { } *cx.memory::() = live.clone(); latest = Some(values.clone()); - true + if !footer_rows.is_empty() { + let states: Vec = footer_rows.iter().map(|param| values.bool(¶m.key).unwrap_or(false)).collect(); + ui.data_mut(|data| data.insert_temp(footer_id, states)); + } + // OK and Enter wait while a row's text does not parse. + rows.as_ref().is_none_or(|rows| !rows.unparsed) }); // `picked` is this pass's press: a second pass of the frame has none, so a press is reported once. @@ -621,11 +631,18 @@ impl<'a> ParamDialog<'a> { Some(ResetPick::Extra(at)) => extra_buttons.get(at).map(|(id, _)| id.clone()), _ => None, }; + if let Some(ResetPick::Extra(at)) = pick + && let Some(param) = at.checked_sub(extra_buttons.len()).and_then(|at| footer_rows.get(at)) + { + ui.data_mut(|data| data.insert_temp(flip_id, param.key.clone())); + crate::runtime::frame::request_repaint(ui.ctx()); + } let (result, held) = match (shown.accepted, pick, latest) { (Some(fields), _, _) => (Some(Self::result(key, ¶ms, remember, remember_for, fields)), None), (None, Some(ResetPick::Accept), Some(fields)) if hold => (None, Some(Self::result(key, ¶ms, remember, remember_for, fields))), _ => (None, None), }; + let help_link = rows.as_ref().and_then(|rows| rows.help_link.clone()); ParamDialogOutput { response: shown.response, closed: shown.closed, @@ -636,26 +653,95 @@ impl<'a> ParamDialog<'a> { comparing: shown.comparing, preview_click: shown_preview.clicked, footer_action, - presets: Vec::new(), - help_link: None, + presets: preset_events, + help_link, held, preview_centre: shown_preview.centre, } } } -/// The values `ctx` remembers under `key` for `lifetime`: the saved tier for `Saved`, the session tier for `Run`. -#[allow(dead_code)] // P3(forms-w1): od.OD3 -fn remembered_values(ctx: &Context, key: &SaveKey, lifetime: Lifetime) -> Option { - let _ = (ctx, key, lifetime); - todo!("od.OD3") +/// The values Reset restores: those from when the dialog opened, with `reset_to`'s over them. The one rule for the +/// Alt footer and for a host's reset. +fn reset_target(opened: &DialogFields, reset_to: Option<&DialogFields>) -> DialogFields { + let mut values = opened.clone(); + for (name, value) in reset_to.into_iter().flat_map(DialogFields::iter) { + values.set(name, value.clone()); + } + values } -/// Applies the host's `answers` to `values` for `params`: a colour, path or eyedropper answer writes its row. -#[allow(dead_code)] // P3(forms-w1): fl.F35 +/// The presets row above the rows: a pick writes the preset's values over `values` as one edit, and the presets made, +/// renamed or deleted come back in `events` for the host to store. +fn show_presets(ui: &mut Ui, label: &Label, presets: &ParamPresets<'_>, values: &mut DialogFields, events: &mut Vec>) { + let current = presets.values.iter().find(|(_, preset)| preset_applies(preset, values)).map(|(name, _)| name.clone()); + let picker = PresetPicker::new(label.clone(), Bind::given(current), presets.rows, Bind::kept()).field(PickerField::Name); + let taken = |name: &str| { + let same = |other: &str| other.to_lowercase() == name.to_lowercase(); + presets.built_in.iter().any(|built_in| same(built_in)) || presets.rows.iter().any(|row| same(&row.label)) + }; + let shown = NamedPresetRow::new(label.clone(), picker) + .check_name(|name| taken(name).then_some(PresetError::NameTaken)) + .built_in(|name: &String| presets.built_in.contains(name)) + .show(ui); + for event in shown.events { + match event { + NamedPresetEvent::Apply(name) => { + if let Some((_, preset)) = presets.values.iter().find(|(preset, _)| *preset == name) { + apply_preset(preset, values); + } + } + event @ (NamedPresetEvent::Create { .. } | NamedPresetEvent::Rename { .. } | NamedPresetEvent::Delete(_)) => events.push(event), + _ => {} + } + } +} + +/// Whether `values` hold every value `preset` sets. +fn preset_applies(preset: &DialogFields, values: &DialogFields) -> bool { + preset.iter().all(|(key, value)| values.get(key) == Some(value)) +} + +/// Writes the values of `preset` over `values`. +fn apply_preset(preset: &DialogFields, values: &mut DialogFields) { + for (key, value) in preset.iter() { + values.set(key, value.clone()); + } +} + +/// The values `ctx` remembers under `key` for `lifetime`: the saved tier for `Saved`, the session tier for `Run`. +fn remembered_values(ctx: &Context, key: &SaveKey, lifetime: Lifetime) -> Option { + match lifetime { + Lifetime::Run => crate::runtime::memory::run_value::>(ctx, key), + _ => MemoryStage::peek_saved::>(ctx, key), + } +} + +/// Applies the host's `answers` to `values` for `params`: a colour, path or eyedropper answer writes its row, and a +/// row that resets other rows drops them. pub(crate) fn apply_answers(params: &[Param], values: &mut DialogFields, answers: Vec) { - let _ = (params, values, answers); - todo!("fl.F35") + for answer in answers { + let answered = match &answer { + HostAnswer::Color { key, .. } | HostAnswer::Eyedropper { key, .. } | HostAnswer::Path { key, .. } => { + params.iter().find(|param| param.key == *key) + } + HostAnswer::Listing { .. } => None, + }; + let held = answered.and_then(|param| values.get(¶m.key).cloned()); + match answer { + HostAnswer::Color { key, color } | HostAnswer::Eyedropper { key, color } => set_color_field(params, values, &key, color), + HostAnswer::Path { key, path } => values.set(&key, FieldValue::Text(path.to_string_lossy().into_owned())), + HostAnswer::Listing { key, files } => { + let files = files.into_iter().map(|file| FieldValue::Text(file.to_string_lossy().into_owned())).collect(); + if let Some(param) = params.iter().find(|param| param.key == key) { + values.set(param.folder_files_key(), FieldValue::List(files)); + } + } + } + if let Some(param) = answered { + param.drop_dependents(held.as_ref(), values); + } + } } /// What the footer of an installed Reset footer reads from the body. @@ -861,6 +947,17 @@ pub struct HostedParamDialog { held: HeldAnswer, /// The picture point the next pass centres the preview on ([`centre_preview`](HostedParamDialog::centre_preview)). centre: Option, + /// The named presets the presets row lists ([`set_presets`](HostedParamDialog::set_presets)). + presets: Option, + /// The preset edits of the dialog's passes, until the host takes them. + preset_events: Vec>, +} + +/// The presets a hosted dialog lists: the rows, the values each applies and the built-in names. +struct HeldPresets { + rows: Vec>, + values: Vec<(String, DialogFields)>, + built_in: Vec, } /// What a [`HostedParamDialog`] showed in its last pass: whether the Preview check box is held for comparing, and the @@ -882,9 +979,9 @@ impl HostedParamDialog { build: impl for<'b> Fn(&'b mut DialogFields) -> ParamDialog<'b> + Send + 'static, ) -> Self { let key = key.into(); - let ParamDialog { params, remember, patterns, previews, .. } = build(&mut fields); + let ParamDialog { params, remember, remember_for, patterns, previews, .. } = build(&mut fields); let (params, patterns) = (params.into_owned(), patterns.into_owned()); - let saved = remember.and_then(|key| MemoryStage::peek_saved::>(ctx, &key)); + let saved = remember.and_then(|key| remembered_values(ctx, &key, remember_for)); ParamDialog::open_values(¶ms, &patterns, saved.as_ref(), &mut fields); let id = dialog_id(key.as_str()); HostedParamDialog { @@ -903,6 +1000,8 @@ impl HostedParamDialog { hold: false, held: HeldAnswer::new(), centre: None, + presets: None, + preset_events: Vec::new(), } } @@ -933,11 +1032,6 @@ impl HostedParamDialog { &self.fields } - /// The colour parameter whose button was pressed, once. - pub fn pick_color(&mut self) -> Option { - self.requests.take_color() - } - /// The Browse button that was pressed, once. pub fn pick_path(&mut self) -> Option { self.requests.take_path() @@ -948,11 +1042,6 @@ impl HostedParamDialog { self.requests.take_preview_click() } - /// Answers the colour request `key`: the dialog writes the colour into its values in its next pass. - pub fn answer_color(&mut self, key: impl Into, color: craft_theme::Srgba) { - self.requests.answer_color(key, color); - } - /// Answers the Browse request `key` with the chosen path. pub fn answer_path(&mut self, key: impl Into, path: std::path::PathBuf) { self.requests.answer_path(key, path); @@ -986,9 +1075,9 @@ impl HostedParamDialog { /// The Preview check box starts off. #[must_use] - pub fn preview_off(self) -> Self { - let _ = self; - todo!("ef.F1") + pub fn preview_off(mut self) -> Self { + self.preview_on = false; + self } /// The ids of the actions the custom rows requested since the last call (`CustomContext::request_action`). @@ -1024,33 +1113,43 @@ impl HostedParamDialog { /// `Some`: the host refuses the current values, and OK stays off with `reason` shown under the rows until the values /// change; `None` ends the refusal. pub fn refuse(&mut self, reason: Option