diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs index 4d1544c67..266e09f4e 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::PresetRow; +use crate::patterns::presets::{PresetKind, PresetRow}; use crate::runtime::requests::{ColorRequest, EyedropperRequest, HostAnswer, ListingRequest, PathRequest}; use super::form::{FormDialog, FormDialogWords}; @@ -12,20 +12,24 @@ use super::preview::{PreviewPane, PreviewView, PreviewZoom}; use super::rows::{ParamRows, ParamRowsOutput}; -use crate::contract::{Bind, BodyCx, NoValue, Outcome, Remember as _, SaveKey, Show as _, ShowContainer as _}; +use crate::contract::{Bind, BodyCx, NoValue, Outcome, Remember as _, Sampler as _, SaveKey, Show as _, ShowContainer as _}; -use crate::dialog::{Dialog, DialogId, DialogResult, DialogStack, FooterHooks, StackDialog, dialog_id}; +use crate::dialog::{Dialog, DialogId, DialogResult, DialogStack, FieldRefusal, FooterHooks, StackDialog, dialog_id}; +use crate::display::{Shade, Text}; use crate::layout_components::{Row, Stack}; +use crate::notices::{Notice, NoticeLayout}; use crate::runtime::env::{Env, Label}; -use crate::runtime::memory::{MemoryStage, unique}; +use crate::runtime::memory::MemoryStage; use crate::runtime::overlay::CloseReason; use crate::runtime::words::CommonWords; use crate::sections::{DialogRole, FooterButton}; +use craft_theme::Srgba; +use craft_theme::variant::Tone; use egui::load::SizedTexture; use egui::{Context, Pos2, Response, Ui}; use serde_json::Value; @@ -61,8 +65,8 @@ pub struct ParamResult { pub key: String, /// The values the user confirmed, keyed by parameter. pub fields: DialogFields, - /// The id of the dialog that filed the result, instance ids included; set by `HostedParamDialog`. - // P3(dialogs-w1): dl.K20 `ParamResult::id` + /// The id of the dialog that filed the result, instance ids included, so a family's step names the dialog that + /// answered. `HostedParamDialog` sets it; a `ParamDialog` shown on its own has no host id and leaves `Id::NULL`. pub id: DialogId, remember: Option<(SaveKey, DialogFields)>, } @@ -72,9 +76,7 @@ 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, values)) = &self.remember { - let mut stage = MemoryStage::open(ctx, unique(("craft_ui::param_result", key.as_str()))); - *stage.saved::>(key) = Some(values.clone()); - stage.write_back(); + crate::runtime::memory::set_saved_value::>(ctx, key, Some(values.clone())); } } } @@ -111,6 +113,10 @@ pub struct ParamDialogOutput { pub preview_click: Option, /// The id of the extra footer button pressed this pass (`ParamDialog::extra_buttons`). pub footer_action: Option, + /// The answer OK would have given, the pass OK was pressed on a dialog that holds its OK for the host. + pub(crate) held: Option, + /// The picture point at the centre of the view the preview pane drew this pass; `None` without a preview. + pub(crate) preview_centre: Option, } impl Outcome for ParamDialogOutput { @@ -122,7 +128,7 @@ impl Outcome for ParamDialogOutput { } /// A dialog from a parameter list: one row per [`Param`], the Preview check box with a preview pane when the host -/// gives a picture, and OK, Cancel and a footer extra. +/// gives a picture, and OK, Cancel, extra buttons and a footer note. /// /// - Keys: Tab walks the fields, Enter is OK unless a field owns it, Escape cancels. Holding Alt turns Cancel into /// Reset, which restores the values from when the dialog opened (or `reset_to`) and keeps the dialog open. @@ -131,7 +137,9 @@ impl Outcome for ParamDialogOutput { /// - Preview: the host renders from the reported values while `preview_on` and hands the picture to `preview`, the /// unfiltered one while `comparing` (the Preview check box held down). Drag pans the picture, the zoom buttons /// scale it. A dialog with a preview has its buttons in a column beside the body, with the Preview check box and -/// the footer extra under them. +/// the footer note under them. +/// - Footer: [`extra_buttons`](ParamDialog::extra_buttons) keep the dialog open and come back as +/// `ParamDialogOutput::footer_action`; [`footer_note`](ParamDialog::footer_note) is a muted line at the start edge. /// - A command form is a dialog with no preview and no remember key. #[must_use = "show the dialog with `show`"] #[derive(crate::contract::Pattern, crate::contract::Props)] @@ -189,18 +197,19 @@ pub struct ParamDialog<'a> { /// preview clicks pick a colour turns it off. The default is true. #[prop] click_centres: bool, - /// The canvas the rows' droppers sample (`ParamRows::canvas`). + /// The canvas the rows' droppers sample (`ParamRows::canvas`). While the dialog shows, its view stays usable under + /// the modal layer (`Sampler::keep_view_open`). #[prop] canvas: Option, - /// Extra footer buttons, each an id and a label; a press comes back as `ParamDialogOutput::footer_action`. + /// Extra footer buttons after OK and Cancel (Color Table's Load… and Save…), each an id and a label. They keep the + /// dialog open; a press comes back as `ParamDialogOutput::footer_action`. #[prop] extra_buttons: Vec<(String, Label)>, /// The patterns the dialog's [`ParamKind::Pattern`] rows offer. #[prop] patterns: Cow<'a, [PresetRow]>, - /// Controls before the buttons in the footer (Color Table's Load and Save). - #[prop(func = "FnMut(&mut Ui)")] - footer_extra: Option>, + /// A muted line at the footer's start edge (JPEG Options' size estimate). + footer_note: Option