diff --git a/crates/ui-contract/src/runtime/requests.rs b/crates/ui-contract/src/runtime/requests.rs index 30db20128..9c02452e2 100644 --- a/crates/ui-contract/src/runtime/requests.rs +++ b/crates/ui-contract/src/runtime/requests.rs @@ -127,6 +127,24 @@ impl EyedropperRequest { } } +/// A request for the files of a folder, which the host lists and answers with `HostAnswer::Listing`. A dialog row that +/// shows a folder's files asks for them this way, since the framework holds no file system access of its own. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] +pub struct ListingRequest { + /// The key of the row the listing fills. + pub key: String, + /// The folder to list. + pub folder: PathBuf, +} + +impl ListingRequest { + /// A request for the files of `folder`, answered under `key`. + pub fn new(key: impl Into, folder: impl Into) -> Self { + Self { key: key.into(), folder: folder.into() } + } +} + /// What the host answered to a request, kept until the dialog applies it to its values in its next pass. #[derive(Clone, Debug, PartialEq)] pub enum HostAnswer { @@ -151,4 +169,11 @@ pub enum HostAnswer { /// The sampled colour. color: Srgba, }, + /// The files the host listed for the listing request `key`. + Listing { + /// The request's key. + key: String, + /// The files of the folder. + files: Vec, + }, } diff --git a/crates/ui-patterns/src/patterns/blend_keys.rs b/crates/ui-patterns/src/patterns/blend_keys.rs new file mode 100644 index 000000000..ce84feb5a --- /dev/null +++ b/crates/ui-patterns/src/patterns/blend_keys.rs @@ -0,0 +1,276 @@ +//! The blend mode keys, as in Photoshop: Shift+ and Shift- step through the target's modes, Shift+Alt plus a +//! letter picks one ([`BlendKeys`]). +//! +//! The app lists the modes its target accepts ([`BlendKeyEntry`]: a painting tool's own Mode menu, or the layer modes) +//! with its own key type. The keys are the [`BlendShortcut`] and [`BlendStep`] command sets; the app routes the fired +//! commands here before the single-letter tool keys and gets back the entry to set. Which target a tool has, the +//! engine command and its undo step stay the app's. +//! +//! ```ignore +//! let entries = [BlendKeyEntry::new(Mode::Normal, BlendShortcut::Normal), BlendKeyEntry::new(Mode::Multiply, BlendShortcut::Multiply)]; +//! if let Some(pick) = BlendKeys::new(&entries).current(&layer.blend).fired(&fired) { +//! app.set_blend(pick.into_key()); // one undo step +//! } +//! ``` + +use craft_ui::contract::CommandSet; +use craft_ui::runtime::commands::{CommandRef, FirePhase, Fired}; + +/// Photoshop's Shift+Alt letter positions: the 26 lettered blend modes. Darker Color, Lighter Color, Subtract and +/// Divide have no letter; list them with [`BlendKeyEntry::unlettered`]. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, CommandSet)] +#[command(prefix = "blendMode")] +#[non_exhaustive] +pub enum BlendShortcut { + /// Shift+Alt+N. + #[command(modal = "declared", label = "Normal", default = "Shift+Alt+N")] + Normal, + /// Shift+Alt+I. + #[command(modal = "declared", label = "Dissolve", default = "Shift+Alt+I")] + Dissolve, + /// Shift+Alt+Q: painting tools only. + #[command(modal = "declared", label = "Behind", default = "Shift+Alt+Q")] + Behind, + /// Shift+Alt+R: painting tools only (paints transparency). + #[command(modal = "declared", label = "Clear", default = "Shift+Alt+R")] + Clear, + /// Shift+Alt+P: groups only. + #[command(modal = "declared", label = "Pass Through", default = "Shift+Alt+P")] + PassThrough, + /// Shift+Alt+K. + #[command(modal = "declared", label = "Darken", default = "Shift+Alt+K")] + Darken, + /// Shift+Alt+M. + #[command(modal = "declared", label = "Multiply", default = "Shift+Alt+M")] + Multiply, + /// Shift+Alt+B. + #[command(modal = "declared", label = "Color Burn", default = "Shift+Alt+B")] + ColorBurn, + /// Shift+Alt+A. + #[command(modal = "declared", label = "Linear Burn", default = "Shift+Alt+A")] + LinearBurn, + /// Shift+Alt+G. + #[command(modal = "declared", label = "Lighten", default = "Shift+Alt+G")] + Lighten, + /// Shift+Alt+S. + #[command(modal = "declared", label = "Screen", default = "Shift+Alt+S")] + Screen, + /// Shift+Alt+D. + #[command(modal = "declared", label = "Color Dodge", default = "Shift+Alt+D")] + ColorDodge, + /// Shift+Alt+W. + #[command(modal = "declared", label = "Linear Dodge", default = "Shift+Alt+W")] + LinearDodge, + /// Shift+Alt+O. + #[command(modal = "declared", label = "Overlay", default = "Shift+Alt+O")] + Overlay, + /// Shift+Alt+F. + #[command(modal = "declared", label = "Soft Light", default = "Shift+Alt+F")] + SoftLight, + /// Shift+Alt+H. + #[command(modal = "declared", label = "Hard Light", default = "Shift+Alt+H")] + HardLight, + /// Shift+Alt+V. + #[command(modal = "declared", label = "Vivid Light", default = "Shift+Alt+V")] + VividLight, + /// Shift+Alt+J. + #[command(modal = "declared", label = "Linear Light", default = "Shift+Alt+J")] + LinearLight, + /// Shift+Alt+Z. + #[command(modal = "declared", label = "Pin Light", default = "Shift+Alt+Z")] + PinLight, + /// Shift+Alt+L. + #[command(modal = "declared", label = "Hard Mix", default = "Shift+Alt+L")] + HardMix, + /// Shift+Alt+E. + #[command(modal = "declared", label = "Difference", default = "Shift+Alt+E")] + Difference, + /// Shift+Alt+X. + #[command(modal = "declared", label = "Exclusion", default = "Shift+Alt+X")] + Exclusion, + /// Shift+Alt+U. + #[command(modal = "declared", label = "Hue", default = "Shift+Alt+U")] + Hue, + /// Shift+Alt+T. + #[command(modal = "declared", label = "Saturation", default = "Shift+Alt+T")] + Saturation, + /// Shift+Alt+C. + #[command(modal = "declared", label = "Color", default = "Shift+Alt+C")] + Color, + /// Shift+Alt+Y. + #[command(modal = "declared", label = "Luminosity", default = "Shift+Alt+Y")] + Luminosity, +} + +impl BlendShortcut { + /// Every position, in Photoshop's menu order (as the variants). + pub const ALL: [BlendShortcut; 26] = [ + BlendShortcut::Normal, + BlendShortcut::Dissolve, + BlendShortcut::Behind, + BlendShortcut::Clear, + BlendShortcut::PassThrough, + BlendShortcut::Darken, + BlendShortcut::Multiply, + BlendShortcut::ColorBurn, + BlendShortcut::LinearBurn, + BlendShortcut::Lighten, + BlendShortcut::Screen, + BlendShortcut::ColorDodge, + BlendShortcut::LinearDodge, + BlendShortcut::Overlay, + BlendShortcut::SoftLight, + BlendShortcut::HardLight, + BlendShortcut::VividLight, + BlendShortcut::LinearLight, + BlendShortcut::PinLight, + BlendShortcut::HardMix, + BlendShortcut::Difference, + BlendShortcut::Exclusion, + BlendShortcut::Hue, + BlendShortcut::Saturation, + BlendShortcut::Color, + BlendShortcut::Luminosity, + ]; +} + +/// Shift+= and Shift+-: the next and the previous mode of the target's list. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, CommandSet)] +#[command(prefix = "blendMode")] +#[non_exhaustive] +pub enum BlendStep { + /// Shift+=: the next mode, wrapping at the end. + #[command(modal = "declared", label = "Next Blend Mode", default = "Shift+=")] + Next, + /// Shift+-: the previous mode, wrapping at the start. + #[command(modal = "declared", label = "Previous Blend Mode", default = "Shift+-")] + Previous, +} + +/// One mode the target accepts, in the order of its menu: the app's key of the mode and its Shift+Alt+ +/// letter position, if it has one. +#[derive(Clone, Debug, PartialEq, Eq)] +#[non_exhaustive] +pub struct BlendKeyEntry { + /// The app's key of the blend mode. + pub key: K, + /// The mode's Shift+Alt+ letter position, if it has one. + pub shortcut: Option, +} + +impl BlendKeyEntry { + /// The mode `key` at letter position `shortcut`. + pub fn new(key: K, shortcut: BlendShortcut) -> Self { + Self { key, shortcut: Some(shortcut) } + } + + /// A mode without a letter (Darker Color, Lighter Color, Subtract, Divide): Shift+= and Shift+- reach + /// it, no letter does. + pub fn unlettered(key: K) -> Self { + Self { key, shortcut: None } + } + + /// Behind (Shift+Alt+Q), for a painting tool that offers it. Without such an entry Shift+Alt+Q is consumed + /// and does nothing. + pub fn behind(key: K) -> Self { + Self::new(key, BlendShortcut::Behind) + } + + /// Clear (Shift+Alt+R), for a painting tool that offers it (PhotoCraft's Brush, Pencil and Paint + /// Bucket list it after Dissolve). Without such an entry Shift+Alt+R is consumed and does nothing. + pub fn clear(key: K) -> Self { + Self::new(key, BlendShortcut::Clear) + } +} + +/// What a blend mode key picked: the entry's key, and how. +#[derive(Clone, Debug, PartialEq, Eq)] +#[non_exhaustive] +pub enum BlendKeyPick { + /// Shift+= or Shift+- stepped to this entry. + Stepped(K), + /// A Shift+Alt+ letter picked this entry. + Lettered(K), +} + +impl BlendKeyPick { + /// The picked entry's key. + pub fn key(&self) -> &K { + match self { + BlendKeyPick::Stepped(key) | BlendKeyPick::Lettered(key) => key, + } + } + + /// The picked entry's key, taken. + pub fn into_key(self) -> K { + match self { + BlendKeyPick::Stepped(key) | BlendKeyPick::Lettered(key) => key, + } + } +} + +/// The blend mode keys over the app's list of `entries`. +/// +/// - [`BlendStep`] steps to the next or previous entry, wrapping at either end; a [`current`](Self::current) that +/// isn't listed (or none) steps from the top (next) or the bottom (previous). +/// - A [`BlendShortcut`] picks the entry whose position it is. A position whose mode isn't listed (Clear or Behind for +/// layers, Pass Through for a painting tool, Overlay for the Healing Brush) picks nothing: the command is taken, so +/// the letter does not reach the single-letter tool keys. +/// - A key release picks nothing; holding a step key repeats the step. +/// - No AccessKit node: the app's blend control announces the new mode. Keys are not directional, so nothing mirrors +/// in a right-to-left interface. +#[must_use = "read the fired command with `fired`"] +pub struct BlendKeys<'a, K> { + entries: &'a [BlendKeyEntry], + current: Option<&'a K>, +} + +impl<'a, K: Clone + PartialEq> BlendKeys<'a, K> { + /// The keys over `entries`, in menu order. + pub fn new(entries: &'a [BlendKeyEntry]) -> Self { + Self { entries, current: None } + } + + /// The target's mode now, where the steps start from. + pub fn current(mut self, current: &'a K) -> Self { + self.current = Some(current); + self + } + + /// The entry a fired [`BlendStep`] or [`BlendShortcut`] picks; `None` for any other command, a release, or a + /// position the list lacks. + pub fn fired(self, fired: &Fired) -> Option> { + self.command(&fired.command, fired.phase) + } + + /// [`fired`](Self::fired) for a command and the phase it fired in. + pub fn command(self, command: &CommandRef, phase: FirePhase) -> Option> { + if phase == FirePhase::Release { + return None; + } + if let Some(step) = BlendStep::from_ref(command) { + let step = match step { + BlendStep::Next => 1, + BlendStep::Previous => -1, + }; + return stepped(self.entries, self.current, step).map(|entry| BlendKeyPick::Stepped(entry.key.clone())); + } + let shortcut = BlendShortcut::from_ref(command)?; + self.entries.iter().find(|entry| entry.shortcut == Some(shortcut)).map(|entry| BlendKeyPick::Lettered(entry.key.clone())) + } +} + +/// The entry `step` places after (or before, when negative) `current` in `entries`, wrapping; an +/// unlisted or absent `current` steps from the top (`step > 0`) or the bottom. `None` for an +/// empty list. +fn stepped<'e, K: PartialEq>(entries: &'e [BlendKeyEntry], current: Option<&K>, step: i32) -> Option<&'e BlendKeyEntry> { + // pc: crates/ui-egui/src/input/blend_keys.rs:18 `stepped` (`rem_euclid`; unlisted: 0 or n − 1). + let n = i32::try_from(entries.len()).ok().filter(|n| *n > 0)?; + let at = current.and_then(|c| entries.iter().position(|e| e.key == *c)).and_then(|i| i32::try_from(i).ok()); + let next = match at { + Some(i) => (i + step).rem_euclid(n), + None if step > 0 => 0, + None => n - 1, + }; + entries.get(usize::try_from(next).ok()?) +} diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 27a05a34a..71a688406 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -65,6 +65,8 @@ pub struct DockAreaOutput

{ /// Where each dock column was placed this pass, named by a panel of its first group, in the area's layer space. /// Hosts that anchor their own surfaces to a column read it. pub columns: Vec<(P, Rect)>, + /// The files dropped on the area's windows this pass, for the host to open. + pub window_files: Vec, /// The area's response. pub response: Response, } @@ -356,7 +358,18 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> { if shown.output.dropped.is_some() { cross_window::accept_cross_window(&ctx); } - DockAreaOutput { actions, events, focused, picked, error, edit, float_space: space, columns, response: shown.output.response } + DockAreaOutput { + actions, + events, + focused, + picked, + error, + edit, + float_space: space, + columns, + window_files: Vec::new(), + response: shown.output.response, + } // P3(panels-w1): pn.C7 } } diff --git a/crates/ui-patterns/src/patterns/dock/mod.rs b/crates/ui-patterns/src/patterns/dock/mod.rs index d419b055d..ab247d2d6 100644 --- a/crates/ui-patterns/src/patterns/dock/mod.rs +++ b/crates/ui-patterns/src/patterns/dock/mod.rs @@ -16,4 +16,7 @@ pub use panes::{ }; pub use switcher::{WorkspaceSwitcher, WorkspaceSwitcherOutput}; pub use words::WorkspaceDialogWords; -pub use workspace_dialogs::{DeleteWorkspaceDialog, DeleteWorkspaceDialogOutput, NewWorkspace, NewWorkspaceDialog, NewWorkspaceDialogOutput}; +pub use workspace_dialogs::{ + DeleteWorkspaceDialog, DeleteWorkspaceDialogOutput, HostedDeleteWorkspace, HostedNewWorkspace, NewWorkspace, NewWorkspaceDialog, + NewWorkspaceDialogOutput, +}; diff --git a/crates/ui-patterns/src/patterns/dock/workspace_dialogs.rs b/crates/ui-patterns/src/patterns/dock/workspace_dialogs.rs index 968116554..34723a5a4 100644 --- a/crates/ui-patterns/src/patterns/dock/workspace_dialogs.rs +++ b/crates/ui-patterns/src/patterns/dock/workspace_dialogs.rs @@ -7,6 +7,7 @@ mod stories; use super::words::WorkspaceDialogWords; use crate::choice::Checkbox; use crate::contract::{Bind, Entry, NoValue, Outcome, Props as _, Show as _, ShowContainer as _}; +use crate::dialog::{DialogId, DialogResult, DialogStack, StackDialog}; use crate::display::{Shade, Text}; use crate::form::{Field, Help}; use crate::patterns::form_dialogs::FormDialog; @@ -70,17 +71,21 @@ pub struct NewWorkspaceDialog<'a, P> { /// Binds the open state to `open`. #[prop(name = "opened")] open: Option>, + /// Binds the name and captures to `value`. + #[prop(name = "value")] + bound: Option>, } impl<'a, P: Clone + Eq + Hash> NewWorkspaceDialog<'a, P> { /// New Workspace over `set`, whose names it checks. pub fn new(set: &'a WorkspaceSet

) -> Self { - NewWorkspaceDialog { set, offered: WorkspaceKeeps::ALL, open: None } + NewWorkspaceDialog { set, offered: WorkspaceKeeps::ALL, open: None, bound: None } } /// Shows the dialog. pub fn show(self, ui: &mut Ui) -> NewWorkspaceDialogOutput { - let NewWorkspaceDialog { set, offered, open } = self; + let NewWorkspaceDialog { set, offered, open, bound } = self; + let _ = &bound; // P3(top-w3): tp.T20 let words = Env::of(ui).words::(); let mut form = FormDialog::::own(words.new_title.clone()); if let Some(open) = open { @@ -157,17 +162,21 @@ pub struct DeleteWorkspaceDialog<'a, P> { /// Binds the open state to `open`. #[prop(name = "opened")] open: Option>, + /// Binds the picked workspace's id to `value`. + #[prop(name = "value")] + bound: Option>, } impl<'a, P: Clone + Eq + Hash> DeleteWorkspaceDialog<'a, P> { /// Delete Workspace over the saved workspaces of `set`. pub fn new(set: &'a WorkspaceSet

) -> Self { - DeleteWorkspaceDialog { set, open: None } + DeleteWorkspaceDialog { set, open: None, bound: None } } /// Shows the dialog. pub fn show(self, ui: &mut Ui) -> DeleteWorkspaceDialogOutput { - let DeleteWorkspaceDialog { set, open } = self; + let DeleteWorkspaceDialog { set, open, bound } = self; + let _ = &bound; // P3(top-w3): tp.T21 let words = Env::of(ui).words::(); let deletable = |id: &str| id != set.current; let entries: Vec> = set @@ -199,3 +208,107 @@ impl<'a, P: Clone + Eq + Hash> DeleteWorkspaceDialog<'a, P> { DeleteWorkspaceDialogOutput { response: shown.response, closed: shown.closed, accepted: shown.accepted } } } + +/// A [`NewWorkspaceDialog`] the [`DialogHost`](crate::dialog::DialogHost) owns, over a copy of the workspace set. It +/// answers with the [`NewWorkspace`] at OK. +pub struct HostedNewWorkspace

{ + id: DialogId, + set: WorkspaceSet

, + offered: WorkspaceKeeps, + value: NewWorkspace, + open: bool, +} + +impl HostedNewWorkspace

{ + /// New Workspace over a copy of `set`, whose names it checks. + pub fn new(set: &WorkspaceSet

) -> Self { + let _ = set; + todo!("tp.T20") + } + + /// The Capture boxes the dialog shows; the default shows all three. + #[must_use] + pub fn offered(mut self, keeps: WorkspaceKeeps) -> Self { + let _ = (&mut self, keeps); + todo!("tp.T20") + } +} + +impl StackDialog for HostedNewWorkspace

{ + type Result = NewWorkspace; + + fn id(&self) -> DialogId { + self.id + } + + fn show(&mut self, ui: &mut Ui, stack: &DialogStack) -> Option> { + let _ = (ui, stack, &self.set, &self.offered, &self.value, &self.open); + todo!("tp.T20") + } + + fn key(&self) -> Option<&str> { + Some("workspace.new") + } + + fn confirm(&mut self, ctx: &egui::Context) -> Option { + let _ = ctx; + todo!("tp.T20") + } + + fn json_fields(&self) -> Option { + todo!("tp.T20") + } + + fn set_json_field(&mut self, ctx: &egui::Context, field: &str, value: serde_json::Value) -> Result<(), String> { + let _ = (ctx, field, value); + todo!("tp.T20") + } +} + +/// A [`DeleteWorkspaceDialog`] the [`DialogHost`](crate::dialog::DialogHost) owns, over a copy of the workspace set. It +/// answers with the id of the picked workspace at OK. +pub struct HostedDeleteWorkspace

{ + id: DialogId, + set: WorkspaceSet

, + value: String, + open: bool, +} + +impl HostedDeleteWorkspace

{ + /// Delete Workspace over a copy of the saved workspaces of `set`. + pub fn new(set: &WorkspaceSet

) -> Self { + let _ = set; + todo!("tp.T21") + } +} + +impl StackDialog for HostedDeleteWorkspace

{ + type Result = String; + + fn id(&self) -> DialogId { + self.id + } + + fn show(&mut self, ui: &mut Ui, stack: &DialogStack) -> Option> { + let _ = (ui, stack, &self.set, &self.value, &self.open); + todo!("tp.T21") + } + + fn key(&self) -> Option<&str> { + Some("workspace.delete") + } + + fn confirm(&mut self, ctx: &egui::Context) -> Option { + let _ = ctx; + todo!("tp.T21") + } + + fn json_fields(&self) -> Option { + todo!("tp.T21") + } + + fn set_json_field(&mut self, ctx: &egui::Context, field: &str, value: serde_json::Value) -> Result<(), String> { + let _ = (ctx, field, value); + todo!("tp.T21") + } +} diff --git a/crates/ui-patterns/src/patterns/form_dialogs/about.rs b/crates/ui-patterns/src/patterns/form_dialogs/about.rs index 3b3f680c7..8b8d53eae 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/about.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/about.rs @@ -210,9 +210,9 @@ pub struct AboutDialog<'a> { /// Binds the open state to `open`. #[prop(name = "opened")] open: Option>, - /// The tab the dialog opens on. + /// Binds the shown tab to `tab`; the dialog opens on it. #[prop] - tab: Option, + tab: Option>, } impl<'a> AboutDialog<'a> { @@ -232,6 +232,7 @@ impl<'a> AboutDialog<'a> { let title = Label::from(words.title.fill(&[("app", info.app_name.as_str())])); let shown = Shown { words: &words, writer: &writer, info, credits }; + let _ = &tab; // P3(dialogs-w4): dl.K11, the bound tab let view = RefCell::new(View::default()); let link = RefCell::new(None); let mut dialog = @@ -240,7 +241,7 @@ impl<'a> AboutDialog<'a> { dialog = dialog.opened(open); } let shown_dialog = dialog.show(ui, |ui, cx| { - *view.borrow_mut() = if cx.appeared() { View { tab: tab.unwrap_or_default(), ..View::default() } } else { cx.memory::().clone() }; + *view.borrow_mut() = if cx.appeared() { View { tab: AboutTab::default(), ..View::default() } } else { cx.memory::().clone() }; Stack::new().header(|ui, _| shown.tabs(ui, &title, &view)).show(ui, |ui, _| { let tab = view.borrow().tab; match tab { @@ -466,7 +467,7 @@ pub struct HostedAbout { id: DialogId, info: AboutInfo, credits: Credits, - tab: Option, + tab: AboutTab, link: Option, open: bool, #[cfg(feature = "testing")] @@ -480,7 +481,7 @@ impl HostedAbout { id: dialog_id(ABOUT_KEY), info, credits, - tab: None, + tab: AboutTab::default(), link: None, open: true, #[cfg(feature = "testing")] @@ -491,7 +492,7 @@ impl HostedAbout { /// The tab the dialog opens on. #[must_use] pub fn tab(mut self, tab: AboutTab) -> Self { - self.tab = Some(tab); + self.tab = tab; self } @@ -507,12 +508,28 @@ const ABOUT_KEY: &str = "help.about"; impl StackDialog for HostedAbout { type Result = (); + fn confirm(&mut self, ctx: &egui::Context) -> Option { + let _ = ctx; + todo!("dl.K11") + } + + fn json_fields(&self) -> Option { + todo!("dl.K11") + } + + fn set_json_field(&mut self, ctx: &egui::Context, field: &str, value: serde_json::Value) -> Result<(), String> { + let _ = (ctx, field, value); + todo!("dl.K11") + } + fn id(&self) -> DialogId { self.id } fn show(&mut self, ui: &mut Ui, _: &DialogStack) -> Option> { - let shown = AboutDialog { info: &self.info, credits: &self.credits, open: Some(Bind::bound(&mut self.open)), tab: self.tab }.show(ui); + let shown = + AboutDialog { info: &self.info, credits: &self.credits, open: Some(Bind::bound(&mut self.open)), tab: Some(Bind::bound(&mut self.tab)) } + .show(ui); #[cfg(feature = "testing")] { self.facts = crate::contract::Outcome::story_facts(&shown); diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs index 8c63a347e..7bfeeb83b 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs @@ -2,7 +2,8 @@ //! owned by a `DialogHost`. A command form is a `ParamDialog` without a preview. use super::fields::{DialogFields, FieldValue}; -use crate::runtime::requests::{ColorRequest, HostAnswer, PathRequest}; +use crate::patterns::presets::PresetRow; +use crate::runtime::requests::{ColorRequest, EyedropperRequest, HostAnswer, ListingRequest, PathRequest}; use super::form::{FormDialog, FormDialogWords}; use super::host_requests::HostRequests; @@ -66,9 +67,9 @@ pub struct ParamResult { impl ParamResult { /// Stores the values of a dialog built with [`ParamDialog::remember`] for the next open. The app calls it after /// its command succeeds, so a failed command leaves the previous values; without a remember key it does nothing. - pub fn remember(&self, ui: &Ui) { + pub fn remember(&self, ctx: &Context) { if let Some((key, values)) = &self.remember { - let mut stage = MemoryStage::open(ui.ctx(), unique(("craft_ui::param_result", key.as_str()))); + let mut stage = MemoryStage::open(ctx, unique(("craft_ui::param_result", key.as_str()))); *stage.saved::>(key) = Some(values.clone()); stage.write_back(); } @@ -105,6 +106,8 @@ pub struct ParamDialogOutput { /// The point of the preview picture a click landed on this pass (`PreviewOutput::clicked`): an eyedropper on the /// preview samples there. pub preview_click: Option, + /// The id of the extra footer button pressed this pass (`ParamDialog::extra_buttons`). + pub footer_action: Option, } impl Outcome for ParamDialogOutput { @@ -183,6 +186,15 @@ 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`). + #[prop] + canvas: Option, + /// Extra footer buttons, each an id and a label; 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>, @@ -245,6 +257,9 @@ impl<'a> ParamDialog<'a> { closable: true, preview: None, click_centres: true, + canvas: None, + extra_buttons: Vec::new(), + patterns: Cow::Borrowed(&[]), footer_extra: None, below: None, shaped: None, @@ -335,12 +350,16 @@ impl<'a> ParamDialog<'a> { closable, preview, click_centres, + canvas, + extra_buttons, + patterns, footer_extra, below, shaped, answers, values_opened, } = self; + let _ = (&canvas, &extra_buttons, &patterns); // P3(dialogs-w1): dl.K21, dl.K22, dl.K28 let preview_label = Env::of(ui).words::().preview.clone(); let mut form = match bound { @@ -396,6 +415,7 @@ impl<'a> ParamDialog<'a> { 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 { .. } => {} // P3(dialogs-w1): dl.K26 } } live = cx.memory::().clone(); @@ -434,8 +454,16 @@ impl<'a> ParamDialog<'a> { preview_on: shown.preview_on, comparing: shown.comparing, preview_click, + footer_action: None, // P3(dialogs-w1): dl.K22, from `FormOutput::picked` } } + + /// A note in the footer, left of the buttons (a file size estimate, say). + #[allow(dead_code)] // P3(dialogs-w1): dl.K23 + pub fn footer_note(mut self, note: impl Into