diff --git a/crates/color-ui/src/ui/harmony.rs b/crates/color-ui/src/ui/harmony.rs index fb792d9554..50d8d83752 100644 --- a/crates/color-ui/src/ui/harmony.rs +++ b/crates/color-ui/src/ui/harmony.rs @@ -268,10 +268,12 @@ pub enum HarmonyMenuAction { /// Where a Color Guide cell lies. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[non_exhaustive] pub enum GuideCellAt { /// The harmony strip's cell at this index. Strip(usize), /// The variation grid's cell at this row and column. + #[non_exhaustive] Grid { /// The grid row. row: usize, @@ -282,6 +284,7 @@ pub enum GuideCellAt { /// A Color Guide cell: where it lies and the colour it shows. #[derive(Clone, Copy, Debug, PartialEq)] +#[non_exhaustive] pub struct GuideCell { /// Where the cell lies. pub at: GuideCellAt, diff --git a/crates/color-ui/src/ui/picker/channel.rs b/crates/color-ui/src/ui/picker/channel.rs index 16d466c6dc..34807fb607 100644 --- a/crates/color-ui/src/ui/picker/channel.rs +++ b/crates/color-ui/src/ui/picker/channel.rs @@ -17,6 +17,7 @@ use egui::{Color32, CornerRadius, Ui, Vec2}; /// How a channel's value steps and settles: a channel's or the alpha's. #[derive(Clone, Debug, PartialEq)] +#[non_exhaustive] pub struct ChannelRule { /// The values the channel takes, from its least to its greatest. pub range: RangeInclusive, @@ -38,6 +39,7 @@ impl ChannelRule { /// What a channel's number counts. #[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[non_exhaustive] pub enum ChannelUnit { /// No unit. None, diff --git a/crates/font-manager/src/glyphs.rs b/crates/font-manager/src/glyphs.rs index 789ac12b65..74e0be39d5 100644 --- a/crates/font-manager/src/glyphs.rs +++ b/crates/font-manager/src/glyphs.rs @@ -118,6 +118,7 @@ impl GlyphsWords { /// A grid cell: a character the face maps, or a glyph no character maps (unencoded, positional forms). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[non_exhaustive] pub enum GlyphCell { /// A character the face maps. Char(char), diff --git a/crates/imaging/src/ui/filter_gallery/mod.rs b/crates/imaging/src/ui/filter_gallery/mod.rs index f38df740e3..42e33693a1 100644 --- a/crates/imaging/src/ui/filter_gallery/mod.rs +++ b/crates/imaging/src/ui/filter_gallery/mod.rs @@ -111,6 +111,7 @@ pub enum FilterGalleryEvent { PickColor(ColorRequest), /// A Browse button was pressed on the layer `layer`: the app opens its file picker and answers with /// `set_layer_fields`, which follows the layer if it moved meanwhile. + #[non_exhaustive] PickPath { /// The layer whose parameter asked. layer: LayerId, diff --git a/crates/menu/src/shortcuts/mod.rs b/crates/menu/src/shortcuts/mod.rs index e784f02696..4bfa60ee97 100644 --- a/crates/menu/src/shortcuts/mod.rs +++ b/crates/menu/src/shortcuts/mod.rs @@ -387,6 +387,7 @@ impl craft_ui::contract::Outcome for ShortcutsOutput { /// The Hold Shortcuts setting the dialog shows and edits. #[derive(Clone, Debug, PartialEq)] +#[non_exhaustive] pub struct HoldSetting { /// Whether hold shortcuts are on. pub on: bool, @@ -396,6 +397,13 @@ pub struct HoldSetting { pub range: RangeInclusive, } +impl HoldSetting { + /// Hold shortcuts `on`, holding after `delay` seconds, with the field accepting `range`. + pub fn new(on: bool, delay: f64, range: RangeInclusive) -> Self { + HoldSetting { on, delay, range } + } +} + /// The dialog for one pass: what it edits, borrowed, and how it behaves. #[must_use = "show the dialog with `show`"] #[derive(Pattern)] diff --git a/crates/menu/tests/it/shortcuts/hold.rs b/crates/menu/tests/it/shortcuts/hold.rs index a79ac90c68..63860b9a0f 100644 --- a/crates/menu/tests/it/shortcuts/hold.rs +++ b/crates/menu/tests/it/shortcuts/hold.rs @@ -10,7 +10,7 @@ use super::fixture::{self, Rig}; /// The setting a trial starts from, at a delay inside its range. fn setting(on: bool) -> HoldSetting { - HoldSetting { on, delay: 0.5, range: 0.2..=2.0 } + HoldSetting::new(on, 0.5, 0.2..=2.0) } /// The hold texts the keymap's overrides hold for the command `key`. diff --git a/crates/menu/tests/it/shortcuts/rows.rs b/crates/menu/tests/it/shortcuts/rows.rs index eb9a2c6c69..df232b1c33 100644 --- a/crates/menu/tests/it/shortcuts/rows.rs +++ b/crates/menu/tests/it/shortcuts/rows.rs @@ -67,7 +67,7 @@ fn the_summary_lists_hold_bindings() { let mut km = fixture::keymap(Platform::Mac); km.set_holds(true); km.assign(&CommandRef::from("file.save"), Binding::parse("Hold K").expect("a hold"), Policy::Keep).expect("assigns"); - let mut rig = Rig::with_holds(km, fixture::options(), HoldSetting { on: true, delay: 0.5, range: 0.2..=2.0 }); + let mut rig = Rig::with_holds(km, fixture::options(), HoldSetting::new(true, 0.5, 0.2..=2.0)); let summarize = |rig: &mut Rig| { rig.click("Summarize…"); rig.outcomes() diff --git a/crates/ui-canvas/src/canvas/momentary.rs b/crates/ui-canvas/src/canvas/momentary.rs index 4e634a8b74..2928a1cb82 100644 --- a/crates/ui-canvas/src/canvas/momentary.rs +++ b/crates/ui-canvas/src/canvas/momentary.rs @@ -40,6 +40,7 @@ pub enum MomentaryCommands { /// What a held Shift does to the momentary Hand. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] pub enum MomentaryShift { /// Shift changes nothing: the Hand stays the Hand. #[default] diff --git a/crates/ui-contract/src/contract/overlay/placement.rs b/crates/ui-contract/src/contract/overlay/placement.rs index 4493eed378..9594062262 100644 --- a/crates/ui-contract/src/contract/overlay/placement.rs +++ b/crates/ui-contract/src/contract/overlay/placement.rs @@ -86,8 +86,16 @@ fn stored_opening(ctx: &Context, id: Id) -> Option { /// bar stay below the bar ([`OverlayUi::contain_popups_below`](super::OverlayUi::contain_popups_below)). `None`, the /// root's, lets popups take the whole safe rect. #[derive(Clone, Copy, Debug, Default, PartialEq, crate::contract::MemoProps)] +#[non_exhaustive] pub struct PopupRegion(pub Option); +impl PopupRegion { + /// Popups contained in `region`; `None` lets them take the whole safe rect. + pub fn new(region: Option) -> Self { + PopupRegion(region) + } +} + impl crate::runtime::env::EnvValue for PopupRegion { fn root() -> Self { PopupRegion(None) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs index 10b2b902a0..9b3acb2c97 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs @@ -297,6 +297,7 @@ type BelowRowsFn<'a> = Box; /// The named presets a [`ParamDialog`] offers above its rows: the preset rows, the values each applies, and the names /// the user cannot rename or delete. #[derive(Clone, Copy, Debug)] +#[non_exhaustive] pub struct ParamPresets<'a> { /// The listed presets, by name. pub rows: &'a [PresetRow], @@ -306,6 +307,13 @@ pub struct ParamPresets<'a> { pub built_in: &'a [String], } +impl<'a> ParamPresets<'a> { + /// The presets `rows`, applying `values`, of which `built_in` cannot be renamed or deleted. + pub fn new(rows: &'a [PresetRow], values: &'a [(String, DialogFields)], built_in: &'a [String]) -> Self { + ParamPresets { rows, values, built_in } + } +} + /// What `ParamDialog::below` draws under the rows. pub struct BelowRows<'a>(BelowRowsFn<'a>); @@ -1313,7 +1321,7 @@ impl StackDialog for HostedParamDialog { dialog = dialog.ok_enabled(false).ok_reason(reason.clone()); } if let Some(presets) = &self.presets { - dialog = dialog.presets(ParamPresets { rows: &presets.rows, values: &presets.values, built_in: &presets.built_in }); + dialog = dialog.presets(ParamPresets::new(&presets.rows, &presets.values, &presets.built_in)); } // The held answer also carries a refusal the host keeps on a dialog without a held OK: its notice shows the reason // under the rows, and OK is off meanwhile, so nothing is filed. diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs index 80b2358336..166c1b940d 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs @@ -142,7 +142,7 @@ fn param_dialog_with_presets(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let built_in = ["soft".to_owned()]; ParamDialog::new("blur", "Blur", Param::parse_list(SPEC)) .opened(Bind::bound(opener(ui, data))) - .presets(ParamPresets { rows: &rows, values: &values, built_in: &built_in }) + .presets(ParamPresets::new(&rows, &values, &built_in)) .show(ui) .into() } diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document/settings.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document/settings.rs index 32d428ec18..c9b95aec9e 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document/settings.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document/settings.rs @@ -91,6 +91,7 @@ impl DocumentCard { #[non_exhaustive] pub enum CardSource { /// A built-in preset; `artboard` is whether it turns Artboards on (`None`: it leaves them). + #[non_exhaustive] Preset { /// Whether the card turns Artboards on. artboard: Option, @@ -103,6 +104,13 @@ pub enum CardSource { Clipboard, } +impl CardSource { + /// A built-in preset that turns Artboards on or off, or leaves them (`None`). + pub fn preset(artboard: Option) -> Self { + CardSource::Preset { artboard } + } +} + /// What a card is built from. #[non_exhaustive] pub struct CardCx<'a, S: DocumentSettings> { diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document/stories.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document/stories.rs index 5be2d5d909..d1db0e5c02 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document/stories.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document/stories.rs @@ -101,7 +101,7 @@ impl DocumentSettings for StorySettings { } fn preset_card(_preset: &(), _cx: &CardCx<'_, Self>) -> DocumentCard { - DocumentCard::new("Preset".to_owned(), String::new(), StorySettings::default(), CardSource::Preset { artboard: None }) + DocumentCard::new("Preset".to_owned(), String::new(), StorySettings::default(), CardSource::preset(None)) } fn recent_cards(_cx: &CardCx<'_, Self>) -> Vec> { diff --git a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs index eabf5c48d1..151da62f50 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs @@ -66,6 +66,7 @@ pub enum PdfExportMode { /// The name and description a preset editor edits. #[derive(Clone, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] pub struct PresetDraft { /// The preset's name. pub name: String, diff --git a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/sections.rs b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/sections.rs index f72003c524..8849563b76 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/sections.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export/sections.rs @@ -34,6 +34,7 @@ const PERCENT: RangeInclusive = 0.0..=100.0; /// The artboards to write: all, or the typed range ("1-3, 5"). #[derive(Clone, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] pub struct ArtboardChoice { /// Only the typed range is written. pub range_only: bool, @@ -43,6 +44,7 @@ pub struct ArtboardChoice { /// The two check boxes that turn a password on. A password that is set keeps its box checked. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] pub struct PasswordSwitches { /// The check box of the open password. pub open: bool, diff --git a/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/model.rs b/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/model.rs index 544cc8e14d..7f34928759 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/model.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/model.rs @@ -220,6 +220,7 @@ pub enum TableOrder { /// A table edit and the colours it applies to. #[derive(Clone, Debug, PartialEq)] +#[non_exhaustive] pub struct ColorTableEvent { /// The edit. pub edit: ColorTableEdit, @@ -229,6 +230,7 @@ pub struct ColorTableEvent { /// What the host's table says, for the cell marks (web-safe is computed). #[derive(Clone, Debug, Default, PartialEq)] +#[non_exhaustive] pub struct TableMarks { /// The locked colours. pub locked: Vec<[u8; 3]>, @@ -247,12 +249,20 @@ pub enum WebDocument { Raster, /// A vector document: Image Size shows Anti-aliasing, Clip to Artboard and the Artboard select in place of /// Resample; an Output row follows Metadata; Slices has no HTML check. + #[non_exhaustive] Vector { /// The artboards' names. artboards: Vec, }, } +impl WebDocument { + /// A vector document with the artboards `artboards`. + pub fn vector(artboards: Vec) -> Self { + WebDocument::Vector { artboards } + } +} + /// The search Optimize to File Size… asks the host to run. #[derive(Clone, Debug, PartialEq)] #[non_exhaustive] diff --git a/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/stories.rs b/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/stories.rs index 728dec8906..2bfee2e34b 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/stories.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/save_for_web/stories.rs @@ -150,7 +150,7 @@ fn save_for_web_vector(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let start = SaveForWebOptions { format: WebFormat::Png24, clip_to_artboard: true, artboard: Some(1), ..SaveForWebOptions::default() }; let flags = extras(data, false, false); let ((options, open), options_open_at) = data.value_at("web-vector", (start, true)); - let document = WebDocument::Vector { artboards: vec!["Artboard 1".to_owned(), "Artboard 2".to_owned()] }; + let document = WebDocument::vector(vec!["Artboard 1".to_owned(), "Artboard 2".to_owned()]); let dialog = SaveForWebDialog::new("logo.vcr", size(), pictures, options_open_at.bind(options)).opened(options_open_at.bind(open)).document(document); with_extras(dialog, flags).show(ui).into() diff --git a/crates/ui-patterns/tests/it/form_dialogs/new_document.rs b/crates/ui-patterns/tests/it/form_dialogs/new_document.rs index b3ba85e808..c67f6fc8a2 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/new_document.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/new_document.rs @@ -84,7 +84,7 @@ impl DocumentSettings for Counted { } fn preset_card(_preset: &(), _cx: &CardCx<'_, Self>) -> DocumentCard { - DocumentCard::new("Preset".to_owned(), String::new(), Counted::default(), CardSource::Preset { artboard: None }) + DocumentCard::new("Preset".to_owned(), String::new(), Counted::default(), CardSource::preset(None)) } fn recent_cards(_cx: &CardCx<'_, Self>) -> Vec> { diff --git a/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs b/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs index 4f009eddd1..1559f5cb89 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/save_for_web.rs @@ -183,8 +183,9 @@ fn show_palette(host: &Rc>, fixture: &mut Fixture) { } /// The colour table events the dialog filed since the last call. -fn table_events(host: &Rc>) -> Vec { - host.borrow_mut().get_mut::().map(HostedSaveForWeb::take_table_events).expect("the dialog is open") +fn table_events(host: &Rc>) -> Vec<(ColorTableEdit, Vec<[u8; 3]>)> { + let events = host.borrow_mut().get_mut::().map(HostedSaveForWeb::take_table_events).expect("the dialog is open"); + events.into_iter().map(|event: ColorTableEvent| (event.edit, event.colors)).collect() } #[trial] @@ -237,7 +238,7 @@ fn slices_and_palette_edits_follow_the_settings() { assert_eq!(request.key, PALETTE_COLOR_KEY); host.borrow_mut().answer_color(id, PALETTE_COLOR_KEY, Srgba::rgb(1.0, 0.0, 1.0)); fixture.idle(4); - let shift = ColorTableEvent { edit: ColorTableEdit::Shift([255, 0, 255]), colors: vec![[0, 255, 0]] }; + let shift = (ColorTableEdit::Shift([255, 0, 255]), vec![[0, 255, 0]]); assert_eq!(table_events(&host), vec![shift], "the answer shifts the opened entry's colour"); let interlaced = fixture.by_label("Interlaced").expect("the Interlaced check box"); @@ -246,7 +247,7 @@ fn slices_and_palette_edits_follow_the_settings() { let colors = fixture.by_label("Colors").expect("the Colors field"); fixture.click(&colors).key(Key::ArrowUp, Modifiers::NONE).idle(4); assert_eq!(current(&host).colors, 9, "the colour count changed"); - let restore = ColorTableEvent { edit: ColorTableEdit::Restore, colors: Vec::new() }; + let restore = (ColorTableEdit::Restore, Vec::new()); assert_eq!(table_events(&host), vec![restore], "a colour-count change restores the generated table"); // A preset pick keeps the slices. @@ -285,10 +286,10 @@ fn table_edits_carry_the_selected_colors() { let lock = fixture.by_label("Lock Colors").expect("the Lock button"); fixture.click(&lock).idle(4); let selected = vec![[255, 0, 0], [0, 0, 255]]; - assert_eq!(table_events(&host), vec![ColorTableEvent { edit: ColorTableEdit::Lock, colors: selected.clone() }]); + assert_eq!(table_events(&host), vec![(ColorTableEdit::Lock, selected.clone())]); let delete = fixture.by_label("Delete Color").expect("the Delete button"); fixture.click(&delete).idle(4); - assert_eq!(table_events(&host), vec![ColorTableEvent { edit: ColorTableEdit::Delete, colors: selected }]); + assert_eq!(table_events(&host), vec![(ColorTableEdit::Delete, selected)]); } #[trial] diff --git a/crates/ui-shell/src/shell/app_shell.rs b/crates/ui-shell/src/shell/app_shell.rs index 4067074c5b..03cf843baa 100644 --- a/crates/ui-shell/src/shell/app_shell.rs +++ b/crates/ui-shell/src/shell/app_shell.rs @@ -177,7 +177,7 @@ impl Component for ShellRegion { fn content_env(&self, _: &Cx<'_, Self>, values: &mut AppValues) { if let Some((shell, popups)) = &self.shell { shell.put(values); - values.set(PopupRegion(*popups)); + values.set(PopupRegion::new(*popups)); } if let Some(set) = self.mode_set { values.set(set);