diff --git a/crates/automation/src/screenshot.rs b/crates/automation/src/screenshot.rs index 34f9ed3d2..f3456c521 100644 --- a/crates/automation/src/screenshot.rs +++ b/crates/automation/src/screenshot.rs @@ -192,6 +192,7 @@ impl Finished { } /// A screenshot request as the control surface received it. +#[non_exhaustive] pub struct ScreenshotRequest { /// The caller's token: one per pending request. pub token: u64, @@ -207,6 +208,13 @@ pub struct ScreenshotRequest { pub settle_ms: f64, } +impl ScreenshotRequest { + /// A request for `viewport` answered on `reply`: no file, no document, no settle delay. + pub fn new(token: u64, viewport: ViewportId, reply: Sender) -> Self { + Self { token, path: None, viewport, reply, document: None, settle_ms: 0.0 } + } +} + /// A request not yet queued: it waits while its viewport's geometry is not recorded. struct WaitingAdmit { token: u64, diff --git a/crates/automation/src/server.rs b/crates/automation/src/server.rs index a1a598643..875d84ed7 100644 --- a/crates/automation/src/server.rs +++ b/crates/automation/src/server.rs @@ -23,6 +23,7 @@ use crate::security::{ /// A running control server. Dropping it stops accepting connections and returns once the port is /// free, so a restart on the same port binds it again at once; connections already open end at their /// next request, once the app has dropped the request channel. +#[non_exhaustive] pub struct Listening { /// The bound address (with port 0, the port the system picked); the one a client needs. pub addr: SocketAddr, diff --git a/crates/automation/tests/it/screenshot.rs b/crates/automation/tests/it/screenshot.rs index 27388365f..56b9fa63a 100644 --- a/crates/automation/tests/it/screenshot.rs +++ b/crates/automation/tests/it/screenshot.rs @@ -39,7 +39,9 @@ fn admit_for( now: Instant, ) -> Result, String> { let (tx, rx) = channel(); - captures.admit(ScreenshotRequest { token, path: None, viewport, reply: tx, document, settle_ms: 0.0 }, now).map(|()| rx).map_err(|(_, e)| e) + let mut request = ScreenshotRequest::new(token, viewport, tx); + request.document = document; + captures.admit(request, now).map(|()| rx).map_err(|(_, e)| e) } fn admit(captures: &mut Captures, token: u64, now: Instant) -> Result, String> { diff --git a/crates/behavior/src/geometry/crop.rs b/crates/behavior/src/geometry/crop.rs index e55766996..153be1ffa 100644 --- a/crates/behavior/src/geometry/crop.rs +++ b/crates/behavior/src/geometry/crop.rs @@ -33,6 +33,7 @@ const TURN_GRID_MAX: usize = 4096; /// What a resize holds about the frame's proportions. #[derive(Clone, Copy, Debug, PartialEq)] +#[non_exhaustive] pub enum AspectHold { /// No proportion held. Free, diff --git a/crates/behavior/src/press.rs b/crates/behavior/src/press.rs index 64871d1e6..89b1ea56e 100644 --- a/crates/behavior/src/press.rs +++ b/crates/behavior/src/press.rs @@ -346,6 +346,7 @@ pub fn count_clicks(previous: Option<(Pos2, f64, u32, Mods)>, pos: Pos2, time: f #[non_exhaustive] pub enum PointerEvent { /// The pointer moved, with the pen's reading for the move when the runtime has one. + #[non_exhaustive] Moved { /// Where the pointer is. at: Pos2, @@ -377,6 +378,11 @@ pub enum PointerEvent { } impl PointerEvent { + /// The pointer moved to `at`, with the pen's reading for the move when the runtime has one. + pub const fn moved(at: Pos2, sample: Option) -> Self { + PointerEvent::Moved { at, sample } + } + /// The primary button going down at `pos`, `time`, as the `clicks`th press in a row. pub const fn pressed(pos: Pos2, time: f64, clicks: u32) -> Self { PointerEvent::Pressed { button: PointerButton::Primary, pos, time, clicks } diff --git a/crates/color/src/ui/info.rs b/crates/color/src/ui/info.rs index 19a8c11b9..46238e585 100644 --- a/crates/color/src/ui/info.rs +++ b/crates/color/src/ui/info.rs @@ -53,6 +53,7 @@ craft_ui::words! { /// A colour in 8-bit sRGB and CMYK percent. #[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[non_exhaustive] pub struct InfoColor { /// The colour in 8-bit sRGB. pub rgb: [u8; 3], @@ -61,6 +62,11 @@ pub struct InfoColor { } impl InfoColor { + /// The colour with the given 8-bit sRGB and CMYK percent values, as an app already holds them. + pub const fn from_parts(rgb: [u8; 3], cmyk: [u8; 4]) -> Self { + InfoColor { rgb, cmyk } + } + /// `color` through the document's CMYK converter: the one sRGB-and-CMYK conversion, which `SamplerReadout::new` builds /// its `rgb` and `cmyk` through. A channel that is not finite reads as 0 and the rest is clamped. pub fn new(color: Srgba, cmyk: &CmykConverter) -> Self { @@ -75,6 +81,7 @@ impl InfoColor { #[non_exhaustive] pub enum InfoMeasure { /// A plain ruler: its angle and length. + #[non_exhaustive] Line { /// The angle. angle: Label, @@ -82,6 +89,7 @@ pub enum InfoMeasure { length: Label, }, /// A protractor: the angle between its arms and the arms' lengths. + #[non_exhaustive] Protractor { /// The angle between the arms. angle: Label, diff --git a/crates/color/src/ui/samplers.rs b/crates/color/src/ui/samplers.rs index 8d44ba303..a0edd1a07 100644 --- a/crates/color/src/ui/samplers.rs +++ b/crates/color/src/ui/samplers.rs @@ -283,11 +283,13 @@ impl Component for ColorSamplerMarks<'_> { #[non_exhaustive] pub enum SamplerEvent { /// A point was placed at `at`. + #[non_exhaustive] Add { /// Where, in document pixels. at: [f64; 2], }, /// Point `index` was moved to `to`. + #[non_exhaustive] Move { /// The point's index. index: usize, @@ -295,15 +297,34 @@ pub enum SamplerEvent { to: [f64; 2], }, /// Point `index` was removed. + #[non_exhaustive] Remove { /// The point's index. index: usize, }, } +impl SamplerEvent { + /// A point placed at `at`. + pub fn add(at: [f64; 2]) -> Self { + SamplerEvent::Add { at } + } + + /// Point `index` moved to `to`. + pub fn moved(index: usize, to: [f64; 2]) -> Self { + SamplerEvent::Move { index, to } + } + + /// Point `index` removed. + pub fn removed(index: usize) -> Self { + SamplerEvent::Remove { index } + } +} + /// A point the tool carries: point `index` draws at `at`, or with `index: None` the next number draws at `at` while /// below [`MAX_SAMPLERS`]. #[derive(Clone, Copy, Debug, PartialEq)] +#[non_exhaustive] pub struct SamplerCarry { /// The point carried; `None` for a new one. pub index: Option, diff --git a/crates/color/src/ui/swatches/library.rs b/crates/color/src/ui/swatches/library.rs index 2fb99a063..f29611815 100644 --- a/crates/color/src/ui/swatches/library.rs +++ b/crates/color/src/ui/swatches/library.rs @@ -403,6 +403,7 @@ pub(super) fn value_text(color: &SwatchColor, book: &str) -> String { #[non_exhaustive] pub enum SwatchEdit { /// Adds `color` named `name` to `group`, or the first group. + #[non_exhaustive] Add { /// The group's name, `None` for the first group. group: Option, @@ -412,11 +413,13 @@ pub enum SwatchEdit { color: SwatchColor, }, /// Adds an empty group. + #[non_exhaustive] NewGroup { /// The new group's name. name: String, }, /// Renames a swatch. + #[non_exhaustive] Rename { /// The swatch's current name. swatch: String, @@ -424,6 +427,7 @@ pub enum SwatchEdit { name: String, }, /// Renames a group. + #[non_exhaustive] RenameGroup { /// The group's current name. group: String, @@ -431,16 +435,19 @@ pub enum SwatchEdit { name: String, }, /// Deletes a swatch. + #[non_exhaustive] Delete { /// The swatch's name. swatch: String, }, /// Deletes a group with its swatches. + #[non_exhaustive] DeleteGroup { /// The group's name. group: String, }, /// Moves a swatch. + #[non_exhaustive] MoveTo { /// The swatch's name. swatch: String, @@ -450,6 +457,7 @@ pub enum SwatchEdit { at: usize, }, /// Moves a group. + #[non_exhaustive] MoveGroup { /// The group's name. group: String, @@ -459,6 +467,7 @@ pub enum SwatchEdit { /// Puts the default swatches back. Reset, /// Imports `groups`, replacing the library when `replace`. + #[non_exhaustive] Import { /// The groups the file holds. groups: Vec, @@ -467,6 +476,18 @@ pub enum SwatchEdit { }, } +impl SwatchEdit { + /// Adds `color` named `name` to `group`, or the first group. + pub fn add(group: Option, name: String, color: SwatchColor) -> Self { + SwatchEdit::Add { group, name, color } + } + + /// Deletes the swatch named `swatch`. + pub fn delete(swatch: String) -> Self { + SwatchEdit::Delete { swatch } + } +} + impl SwatchLibrary { /// Runs `edit` on the library: the in-memory host's path (stories, tests). False when the edit names nothing in the /// library. diff --git a/crates/color/tests/it/panels.rs b/crates/color/tests/it/panels.rs index 6f85e9a93..f153a2d7c 100644 --- a/crates/color/tests/it/panels.rs +++ b/crates/color/tests/it/panels.rs @@ -274,7 +274,7 @@ fn swatches_panel_reports_each_edit_and_leaves_the_library() { fixture.click(&row).settle(); assert!(edits.borrow().is_empty(), "a click selects and uses, it edits nothing: {:?}", edits.borrow()); fixture.key(Key::Delete, Modifiers::NONE).settle(); - assert_eq!(*edits.borrow(), [SwatchEdit::Delete { swatch: "Red".to_owned() }], "one resolved edit, once"); + assert_eq!(*edits.borrow(), [SwatchEdit::delete("Red".to_owned())], "one resolved edit, once"); let (mut fixture, edits) = swatches_rig(groups.clone()); let row = fixture.by_label("Red, #ff0000").expect("the Red swatch"); @@ -292,7 +292,7 @@ fn swatches_panel_reports_each_edit_and_leaves_the_library() { let made = SwatchesMenu::run_command(&groups, &mut state, SwatchesCommand::NewSwatch, RED, &Default::default()); assert_eq!( made.edit, - Some(SwatchEdit::Add { group: Some("Basics".to_owned()), name: "Color Swatch 2".to_owned(), color: red }), + Some(SwatchEdit::add(Some("Basics".to_owned()), "Color Swatch 2".to_owned(), red)), "the next free number, in the selected swatch's group, with the foreground" ); assert_eq!(state.rename, Some(SwatchKey::Swatch("Color Swatch 2".to_owned())), "the new swatch opens for renaming"); diff --git a/crates/color/tests/it/sampling.rs b/crates/color/tests/it/sampling.rs index ec03e4c7e..7e815e20f 100644 --- a/crates/color/tests/it/sampling.rs +++ b/crates/color/tests/it/sampling.rs @@ -82,7 +82,7 @@ fn a_new_point_lands_at_the_release_and_a_dragged_point_moves_on_release() { tool.press_at(at); assert!(events(&tool).is_empty(), "a press only starts the carry"); tool.release_at(at); - assert_eq!(events(&tool), [SamplerEvent::Add { at: [100.0, 50.0] }]); + assert_eq!(events(&tool), [SamplerEvent::add([100.0, 50.0])]); let outside = doc_to_screen(&tool, [320.5, 50.5]); tool.press_at(at).release_at(outside); assert!(events(&tool).is_empty(), "released off the canvas places none"); @@ -96,18 +96,18 @@ fn a_new_point_lands_at_the_release_and_a_dragged_point_moves_on_release() { tool.press_at(on).release_at(on); assert!(events(&tool).is_empty(), "a click on the point's own pixel moves nothing"); tool.press_at(near).release_at(near); - assert_eq!(events(&tool), [SamplerEvent::Move { index: 0, to: [102.0, 50.0] }]); + assert_eq!(events(&tool), [SamplerEvent::moved(0, [102.0, 50.0])]); let outside = doc_to_screen(&tool, [320.5, 50.5]); tool.drag_from(on, outside - on); - assert_eq!(events(&tool), [SamplerEvent::Remove { index: 0 }], "a point dropped off the canvas is removed"); + assert_eq!(events(&tool), [SamplerEvent::removed(0)], "a point dropped off the canvas is removed"); // Alt: a click on a point removes it, off a point it adds. tool.fixture().hold(Modifiers::ALT); tool.press_at(on).release_at(on); - assert_eq!(events(&tool), [SamplerEvent::Remove { index: 0 }]); + assert_eq!(events(&tool), [SamplerEvent::removed(0)]); let empty = doc_to_screen(&tool, [200.5, 150.5]); tool.press_at(empty).release_at(empty); - assert_eq!(events(&tool), [SamplerEvent::Add { at: [200.0, 150.0] }]); + assert_eq!(events(&tool), [SamplerEvent::add([200.0, 150.0])]); tool.fixture().hold(Modifiers::NONE); // At the limit nothing is carried and one notice is set. diff --git a/crates/design-lint/src/workspace.rs b/crates/design-lint/src/workspace.rs index 0c1bba510..91637906c 100644 --- a/crates/design-lint/src/workspace.rs +++ b/crates/design-lint/src/workspace.rs @@ -27,6 +27,7 @@ const CLOSED: &[&str] = &[ "SetPosition", "States", "StateMix", + "ShowReadouts", // the one Show Transformation Values flag: a bool, fixed by meaning "CollectionEvent", // built or matched in craft-ui-patterns "ColumnAlign", // built or matched in craft-ui-widgets "ColumnEvent", // built or matched in craft-ui-widgets diff --git a/crates/draw/src/ui/artboard/bar.rs b/crates/draw/src/ui/artboard/bar.rs index 32c2318d8..bdda8014f 100644 --- a/crates/draw/src/ui/artboard/bar.rs +++ b/crates/draw/src/ui/artboard/bar.rs @@ -73,6 +73,7 @@ pub enum ArtboardBarTarget<'a> { /// The selected board. Board(&'a ArtboardItem), /// No board is selected: the size and background the next board gets. + #[non_exhaustive] Next { /// The size of the next board. size: Size, @@ -81,6 +82,13 @@ pub enum ArtboardBarTarget<'a> { }, } +impl ArtboardBarTarget<'_> { + /// No board is selected: the `size` and `background` the next board gets. + pub const fn next(size: Size, background: ArtboardBackground) -> Self { + ArtboardBarTarget::Next { size, background } + } +} + impl<'a> ArtboardBar<'a> { /// The members for `target` with the app's `presets`. pub fn new(target: ArtboardBarTarget<'a>, presets: &'a [ArtboardPreset]) -> Self { diff --git a/crates/draw/src/ui/transform/transform_box.rs b/crates/draw/src/ui/transform/transform_box.rs index 91c5be98c..857754277 100644 --- a/crates/draw/src/ui/transform/transform_box.rs +++ b/crates/draw/src/ui/transform/transform_box.rs @@ -186,6 +186,7 @@ pub enum ApplyBy { /// A double click inside the box. DoubleClick, /// A click outside the box, at `at` in document units. + #[non_exhaustive] ClickOutside { /// Where the click landed. at: Point, @@ -415,10 +416,10 @@ impl<'a> TransformBox<'a> { let (to, lines) = match (snap, grabbed) { (Some(snap), Some(grabbed)) => { let off = grip.from - grabbed; - let (at, lines) = snap.point(to - off, mods, GestureSnap { reads_control, ..GestureSnap::default() }); + let (at, lines) = snap.point(to - off, mods, GestureSnap::default().reads_control(reads_control)); (at + off, lines) } - (Some(snap), None) => snap.point(to, mods, GestureSnap { reads_control, ..GestureSnap::default() }), + (Some(snap), None) => snap.point(to, mods, GestureSnap::default().reads_control(reads_control)), (None, _) => (to, Vec::new()), }; let dragged = quad::drag(&grip.start, &grip.last, grip.part, grip.from, to, mods, &self.rules); diff --git a/crates/imaging/src/ui/adjust/hosted.rs b/crates/imaging/src/ui/adjust/hosted.rs index 7e664fc50..79098d2e8 100644 --- a/crates/imaging/src/ui/adjust/hosted.rs +++ b/crates/imaging/src/ui/adjust/hosted.rs @@ -36,6 +36,7 @@ pub enum EditPhase { /// What an adjustment editor shares with its dialog for one pass: the context, the canvas, the dialog's own picker, /// channel and clipping state, and the editor's edit phase. +#[non_exhaustive] pub struct AdjustDialogCx<'a> { /// Where the editor is shown. pub context: AdjustContext, @@ -53,6 +54,19 @@ pub struct AdjustDialogCx<'a> { pub edit: Option<(EditPhase, GestureId)>, } +impl<'a> AdjustDialogCx<'a> { + /// The context for an editor shown in `context` over the dialog's own `picker`, `channel` and `clipping` state, with + /// no canvas, no curve point to select and no edit phase; the fields set the rest. + pub fn new( + context: AdjustContext, + picker: &'a mut Option, + channel: &'a mut usize, + clipping: &'a mut Option, + ) -> Self { + Self { context, canvas: None, picker, channel, select_point: None, clipping, edit: None } + } +} + /// The clipping display as automation names it: `"shadows"`, `"highlights"` or null (`LevelsClip` has no serde). fn clipping_json(clip: Option) -> serde_json::Value { match clip { diff --git a/crates/imaging/src/ui/color_range/value.rs b/crates/imaging/src/ui/color_range/value.rs index de1ac8c8c..ec0034279 100644 --- a/crates/imaging/src/ui/color_range/value.rs +++ b/crates/imaging/src/ui/color_range/value.rs @@ -89,6 +89,7 @@ pub enum SampleSign { /// The points the user sampled, in document pixels, and the order they were made in. #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +#[non_exhaustive] pub struct ColorSamples { /// The added samples. pub add: Vec<[f64; 2]>, diff --git a/crates/imaging/src/ui/raw_develop/mod.rs b/crates/imaging/src/ui/raw_develop/mod.rs index ab5426c9b..8198f2c23 100644 --- a/crates/imaging/src/ui/raw_develop/mod.rs +++ b/crates/imaging/src/ui/raw_develop/mod.rs @@ -434,9 +434,9 @@ impl RawDevelopWorkspace { for event in self.sampler_tool.take_events() { // A refused point (the eleventh, one off the picture) is the tool's toast, not a state change. let _ = match event { - SamplerEvent::Add { at } => self.samplers.add(at, size).map(|_| ()), - SamplerEvent::Move { index, to } => self.samplers.move_point(index, to, size), - SamplerEvent::Remove { index } => self.samplers.remove(index), + SamplerEvent::Add { at, .. } => self.samplers.add(at, size).map(|_| ()), + SamplerEvent::Move { index, to, .. } => self.samplers.move_point(index, to, size), + SamplerEvent::Remove { index, .. } => self.samplers.remove(index), _ => Ok(()), }; } diff --git a/crates/imaging/src/ui/scopes/zones.rs b/crates/imaging/src/ui/scopes/zones.rs index b91f94a03..a24373459 100644 --- a/crates/imaging/src/ui/scopes/zones.rs +++ b/crates/imaging/src/ui/scopes/zones.rs @@ -114,9 +114,15 @@ impl ZoneScale { /// The values of the controls the tone zones edit, one per zone in the zones' order, each in its control's units. #[derive(Clone, Debug, Default, PartialEq)] +#[non_exhaustive] pub struct ZoneValues(pub Vec); impl ZoneValues { + /// The values of the zones in order, one per zone. + pub fn new(values: Vec) -> Self { + Self(values) + } + /// These values with zone `at` set to what `to` makes of its value and scale, held to the zone's range; `None` /// when the zone has no value or no scale. fn with(&self, scales: &[ZoneScale], at: usize, to: impl FnOnce(f32, &ZoneScale) -> f32) -> Option { diff --git a/crates/imaging/src/ui/warp/cylinder.rs b/crates/imaging/src/ui/warp/cylinder.rs index fc612dfbe..29d67b24f 100644 --- a/crates/imaging/src/ui/warp/cylinder.rs +++ b/crates/imaging/src/ui/warp/cylinder.rs @@ -62,6 +62,7 @@ craft_ui::words! { /// The cylinder's values: the box, the depths of its top and bottom edges and the wrap. #[derive(Clone, Copy, Debug, PartialEq)] +#[non_exhaustive] pub struct CylinderValues { /// The left edge of the box. pub left: f64, diff --git a/crates/imaging/tests/it/scopes.rs b/crates/imaging/tests/it/scopes.rs index 09500b46f..e9f57abfa 100644 --- a/crates/imaging/tests/it/scopes.rs +++ b/crates/imaging/tests/it/scopes.rs @@ -12,7 +12,7 @@ use std::rc::Rc; /// The zone values the rig starts from: each zone at its index, in -100 to 100. fn start_values() -> ZoneValues { - ZoneValues(vec![0.0, 1.0, 2.0, 3.0, 4.0]) + ZoneValues::new(vec![0.0, 1.0, 2.0, 3.0, 4.0]) } /// A fixture of the tone zones alone over a 200 by 100 plot at the origin, over values that start at diff --git a/crates/layers/src/ui/comps/events.rs b/crates/layers/src/ui/comps/events.rs index 09190bd5d..dff4ef3be 100644 --- a/crates/layers/src/ui/comps/events.rs +++ b/crates/layers/src/ui/comps/events.rs @@ -80,6 +80,7 @@ impl Outcome for LayerCompsOutput { /// arrive as [`LayerCompsEvent::Reorder`]. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, CommandSet)] #[command(prefix = "layerCompsPanel")] +#[non_exhaustive] pub enum LayerCompsRowCommands { /// Move the comp up. #[command(label = "Move Up")] diff --git a/crates/layers/src/ui/comps/mod.rs b/crates/layers/src/ui/comps/mod.rs index 88c6f9571..122a463a6 100644 --- a/crates/layers/src/ui/comps/mod.rs +++ b/crates/layers/src/ui/comps/mod.rs @@ -20,6 +20,7 @@ use egui::Ui; /// What a layer comp records of a layer: the options a comp row toggles. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[non_exhaustive] pub enum CompOption { /// Whether the layers are shown. Visibility, diff --git a/crates/menu/src/theme.rs b/crates/menu/src/theme.rs index a00e203d3..cdc380930 100644 --- a/crates/menu/src/theme.rs +++ b/crates/menu/src/theme.rs @@ -22,6 +22,7 @@ pub enum ThemeChoice { /// Follow the system's light or dark mode. System, /// A theme in its light (`dark: false`) or dark mode. + #[non_exhaustive] Theme { /// The theme. id: ThemeId, @@ -33,6 +34,11 @@ pub enum ThemeChoice { } impl ThemeChoice { + /// The theme `id` in its dark mode when `dark`, else its light mode. + pub fn theme(id: ThemeId, dark: bool) -> Self { + ThemeChoice::Theme { id, dark } + } + /// The choice a command made, `None` for any other command or an unknown parameter. pub fn from_command(command: &CommandRef) -> Option { if command.id != THEME_COMMAND { diff --git a/crates/print/src/ui/dialog.rs b/crates/print/src/ui/dialog.rs index 4cf459069..da5bab2dc 100644 --- a/crates/print/src/ui/dialog.rs +++ b/crates/print/src/ui/dialog.rs @@ -47,6 +47,7 @@ const MARK_LEN: f32 = 10.0; /// Which marks the preview draws. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] pub struct PrintMarks { /// Corner crop marks. pub corner_crop: bool, @@ -102,6 +103,7 @@ impl PrintSheet { /// One titled section of the app's rows (Color Management, Position and Size, Printing Marks, /// Functions, Save as PDF). +#[non_exhaustive] pub struct PrintSection { /// The section's title. pub title: Label, @@ -109,8 +111,16 @@ pub struct PrintSection { pub params: Vec, } +impl PrintSection { + /// The section titled `title` with its `params` rows. + pub fn new(title: impl Into