diff --git a/Cargo.lock b/Cargo.lock index 5124a3092..4a0a8f7d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4377,6 +4377,7 @@ dependencies = [ "serde", "serde_json", "syn 2.0.119", + "toml", "wasm-bindgen-futures", "web-time", ] diff --git a/crates/automation/Cargo.toml b/crates/automation/Cargo.toml index a9fcf894a..cd8e76439 100644 --- a/crates/automation/Cargo.toml +++ b/crates/automation/Cargo.toml @@ -17,6 +17,7 @@ harness = false workspace = true [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # The egui parts: the Actions panel, the control channel's server side (screenshots, synthetic # input) and `ui` stories. Without it the crate has no egui: `ControlOptions`, `ControlClient`, @@ -57,5 +58,5 @@ thiserror = { workspace = true } [dev-dependencies] tempfile = "3" -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } egui = { workspace = true } diff --git a/crates/automation/src/actions/mod.rs b/crates/automation/src/actions/mod.rs index a4dee0272..777272ebc 100644 --- a/crates/automation/src/actions/mod.rs +++ b/crates/automation/src/actions/mod.rs @@ -20,7 +20,7 @@ mod model; mod player; mod recording; #[cfg(test)] -mod tests; +pub(crate) mod tests; pub use file::{ActionsFile, ActionsFileError}; pub use list::{ActionList, ActionListError, LibraryEdit, MergedFile, moved_index}; diff --git a/crates/automation/src/client.rs b/crates/automation/src/client.rs index c199a14c6..d84125f58 100644 --- a/crates/automation/src/client.rs +++ b/crates/automation/src/client.rs @@ -118,4 +118,4 @@ enum Failure { #[cfg(all(test, feature = "ui"))] #[path = "client_tests.rs"] -mod client_tests; +pub(crate) mod client_tests; diff --git a/crates/automation/src/lib.rs b/crates/automation/src/lib.rs index d7bd2de74..853e3cd03 100644 --- a/crates/automation/src/lib.rs +++ b/crates/automation/src/lib.rs @@ -56,16 +56,19 @@ pub use security::AutomationError; /// The trials this crate registers, for its integration binary. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } #[cfg(all(test, feature = "screen-testing"))] extern crate self as craft_automation; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/automation/src/security.rs b/crates/automation/src/security.rs index 96ac748c6..b294c15dd 100644 --- a/crates/automation/src/security.rs +++ b/crates/automation/src/security.rs @@ -473,4 +473,4 @@ impl std::io::Read for AuthDeadlineStream { #[cfg(test)] #[path = "security_tests.rs"] -mod security_tests; +pub(crate) mod security_tests; diff --git a/crates/automation/src/ui/actions/mod.rs b/crates/automation/src/ui/actions/mod.rs index 2b9ed4304..d8a30be9f 100644 --- a/crates/automation/src/ui/actions/mod.rs +++ b/crates/automation/src/ui/actions/mod.rs @@ -14,11 +14,11 @@ mod footer; mod menu; #[cfg(feature = "screen-testing")] pub mod mock; -mod panel; +pub(crate) mod panel; mod prompt; mod rows; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod words; pub use body::{ActionMove, ActionPlace}; diff --git a/crates/automation/src/ui/agents/mod.rs b/crates/automation/src/ui/agents/mod.rs index 01b5a9115..a22425b5f 100644 --- a/crates/automation/src/ui/agents/mod.rs +++ b/crates/automation/src/ui/agents/mod.rs @@ -1,7 +1,7 @@ //! `AgentsPage`: the Agents page of Preferences, over the agent settings in the Preferences draft. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod words; pub use words::AgentsWords; diff --git a/crates/automation/tests/it/main.rs b/crates/automation/tests/it/main.rs index 89d9855b2..047ef22da 100644 --- a/crates/automation/tests/it/main.rs +++ b/crates/automation/tests/it/main.rs @@ -2,9 +2,9 @@ // Unwrapping, expecting and panicking on failure is fine in tests, unlike in shipped code. #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] -mod actions; -mod agents; -mod control; -mod dialogs; -mod screenshot; -mod synthetic; +pub(crate) mod actions; +pub(crate) mod agents; +pub(crate) mod control; +pub(crate) mod dialogs; +pub(crate) mod screenshot; +pub(crate) mod synthetic; diff --git a/crates/browse/Cargo.toml b/crates/browse/Cargo.toml index b30cf10b3..177c2a836 100644 --- a/crates/browse/Cargo.toml +++ b/crates/browse/Cargo.toml @@ -17,6 +17,7 @@ harness = false workspace = true [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # The browsing widgets (`craft_browse::ui`) and `FileThumbSource`. ui = ["dep:craft-behavior", "dep:craft-ui", "dep:egui", "dep:kurbo"] @@ -37,6 +38,6 @@ kurbo = { workspace = true, optional = true } serde = { workspace = true } [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } egui = { workspace = true } tempfile = "3" diff --git a/crates/browse/src/lib.rs b/crates/browse/src/lib.rs index afcce888d..029c8c2bc 100644 --- a/crates/browse/src/lib.rs +++ b/crates/browse/src/lib.rs @@ -20,9 +20,10 @@ pub mod ui; extern crate self as craft_browse; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/browse/src/links/mod.rs b/crates/browse/src/links/mod.rs index 1a5cef609..0884e5e4d 100644 --- a/crates/browse/src/links/mod.rs +++ b/crates/browse/src/links/mod.rs @@ -13,7 +13,7 @@ //! ``` #[cfg(test)] -mod tests; +pub(crate) mod tests; use std::collections::HashMap; use std::hash::Hash; diff --git a/crates/browse/src/places/mod.rs b/crates/browse/src/places/mod.rs index 41e140de3..831303857 100644 --- a/crates/browse/src/places/mod.rs +++ b/crates/browse/src/places/mod.rs @@ -17,7 +17,7 @@ mod cache; mod directories; #[cfg(test)] -mod tests; +pub(crate) mod tests; use std::path::{Path, PathBuf}; diff --git a/crates/browse/src/ui/bin/mod.rs b/crates/browse/src/ui/bin/mod.rs index 2e775e243..1b6389b94 100644 --- a/crates/browse/src/ui/bin/mod.rs +++ b/crates/browse/src/ui/bin/mod.rs @@ -23,8 +23,8 @@ mod free_view; mod icon; mod list; mod search; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::cell::RefCell; use std::hash::Hash; diff --git a/crates/browse/src/ui/compare/mod.rs b/crates/browse/src/ui/compare/mod.rs index 0d4d83f22..29d55f7cc 100644 --- a/crates/browse/src/ui/compare/mod.rs +++ b/crates/browse/src/ui/compare/mod.rs @@ -13,11 +13,11 @@ mod arrange; mod caption; -mod pill; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod pill; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod style; -mod tile; +pub(crate) mod tile; pub use arrange::{ArrangeSpace, ComparePair, survey_cell, survey_columns}; pub use caption::CompareCaption; diff --git a/crates/browse/src/ui/freebin/mod.rs b/crates/browse/src/ui/freebin/mod.rs index 9f922f85e..9f7b7c8f9 100644 --- a/crates/browse/src/ui/freebin/mod.rs +++ b/crates/browse/src/ui/freebin/mod.rs @@ -5,8 +5,8 @@ //! End, the marquee, the move gesture, rename, delete and the context menu. `FreeBin` adds the placement and turns the //! move gesture into the cards' new positions. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::cell::RefCell; use std::collections::HashMap; diff --git a/crates/browse/src/ui/mod.rs b/crates/browse/src/ui/mod.rs index bb6c5d2cb..7933f87d4 100644 --- a/crates/browse/src/ui/mod.rs +++ b/crates/browse/src/ui/mod.rs @@ -21,5 +21,7 @@ pub use relink::{LinkList, LinkListWords, RelinkDialog, RelinkWords, StatusBadge /// The stories and trials this crate registers for the integration binary. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } diff --git a/crates/browse/src/ui/places/mod.rs b/crates/browse/src/ui/places/mod.rs index b129fd351..88f085861 100644 --- a/crates/browse/src/ui/places/mod.rs +++ b/crates/browse/src/ui/places/mod.rs @@ -15,8 +15,8 @@ //! } //! ``` -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::path::{Path, PathBuf}; diff --git a/crates/browse/src/ui/relink/mod.rs b/crates/browse/src/ui/relink/mod.rs index 9973ea727..4a54c1a0b 100644 --- a/crates/browse/src/ui/relink/mod.rs +++ b/crates/browse/src/ui/relink/mod.rs @@ -16,10 +16,10 @@ //! ``` mod badge; -mod dialog; -mod list; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod dialog; +pub(crate) mod list; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use badge::StatusBadge; pub use dialog::{CandidateChecker, RelinkCriterion, RelinkDialog, RelinkLayout, RelinkOptions, RelinkOutcome, RelinkRow, RelinkWords}; diff --git a/crates/browse/tests/it/main.rs b/crates/browse/tests/it/main.rs index 3bfce312a..af3c15cc6 100644 --- a/crates/browse/tests/it/main.rs +++ b/crates/browse/tests/it/main.rs @@ -1,7 +1,7 @@ //! The screen tests of craft-browse, folded into the lib's test target. -mod bin; -mod freebin; -mod places; -mod relink; -mod thumbs; +pub(crate) mod bin; +pub(crate) mod freebin; +pub(crate) mod places; +pub(crate) mod relink; +pub(crate) mod thumbs; diff --git a/crates/color-ui/Cargo.toml b/crates/color-ui/Cargo.toml index f7f775023..d6cbb1c10 100644 --- a/crates/color-ui/Cargo.toml +++ b/crates/color-ui/Cargo.toml @@ -17,6 +17,7 @@ harness = false workspace = true [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # The colour widgets (`craft_color_ui::ui`). ui = ["dep:craft-behavior", "dep:craft-keymap", "dep:craft-ui", "dep:egui", "dep:craft-settings", "dep:craft-window", "craft-platform/screen", "dep:serde_json"] @@ -39,7 +40,7 @@ serde = { workspace = true } serde_json = { workspace = true, optional = true } [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } egui = { workspace = true } [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] diff --git a/crates/color-ui/src/display.rs b/crates/color-ui/src/display.rs index 00a4428df..bf891985c 100644 --- a/crates/color-ui/src/display.rs +++ b/crates/color-ui/src/display.rs @@ -298,7 +298,7 @@ impl DisplayCaches { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/color-ui/src/lib.rs b/crates/color-ui/src/lib.rs index 8daa51bd2..49a93c7ea 100644 --- a/crates/color-ui/src/lib.rs +++ b/crates/color-ui/src/lib.rs @@ -27,9 +27,10 @@ pub use web::{not_web_safe, web_safe}; extern crate self as craft_color_ui; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/color-ui/src/palette.rs b/crates/color-ui/src/palette.rs index 260060f7f..b8d97267e 100644 --- a/crates/color-ui/src/palette.rs +++ b/crates/color-ui/src/palette.rs @@ -490,7 +490,7 @@ mod aco; mod ase; mod reader; #[cfg(test)] -mod tests; +pub(crate) mod tests; mod text; use aco::{AcoColor, act_used, from_aco, parse_aco, to_aco, write_aco}; diff --git a/crates/color-ui/src/ui/area.rs b/crates/color-ui/src/ui/area.rs index a74650e80..1ded48bc6 100644 --- a/crates/color-ui/src/ui/area.rs +++ b/crates/color-ui/src/ui/area.rs @@ -13,8 +13,8 @@ use craft_ui::style::{ComponentStyle, StyleCx}; use craft_ui::value_drag::{PointMark, PointPicker}; use egui::{Mesh, Pos2, Rect, Vec2, pos2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// Vertices along each side of the area's colour mesh (PhotoCraft's 32). const MESH: usize = 32; diff --git a/crates/color-ui/src/ui/choice.rs b/crates/color-ui/src/ui/choice.rs index cc6025243..0cd393e88 100644 --- a/crates/color-ui/src/ui/choice.rs +++ b/crates/color-ui/src/ui/choice.rs @@ -1,8 +1,8 @@ //! `ColorChoice`: a choice among named colours with a custom colour, as Photoshop's pasteboard colour //! (Preferences, Interface), the Crop shield colour and the Note colour. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_theme::Srgba; use craft_ui::contract::{Bind, Entry, NoValue, Outcome, Props as _, Show as _}; diff --git a/crates/color-ui/src/ui/compare.rs b/crates/color-ui/src/ui/compare.rs index de84255b3..d45e75509 100644 --- a/crates/color-ui/src/ui/compare.rs +++ b/crates/color-ui/src/ui/compare.rs @@ -12,8 +12,8 @@ use egui::{CornerRadius, Rect, Response, Vec2, pos2}; use super::picker::ColorPickerWords; use super::warning::{ColorWarning, ColorWarningChip}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of a compare block: the size of the block and of each half, the edge round it and the gap between a /// caption and the block. diff --git a/crates/color-ui/src/ui/disc.rs b/crates/color-ui/src/ui/disc.rs index 1f3cc430c..dda1ca904 100644 --- a/crates/color-ui/src/ui/disc.rs +++ b/crates/color-ui/src/ui/disc.rs @@ -16,8 +16,8 @@ use craft_ui::runtime::focus::{ActivateKeys, FocusShape, KeepKeys, KeyUse}; use craft_ui::style::{ComponentStyle, FocusLook, MarkerLook, StyleColor, StyleCx}; use egui::{Color32, Mesh, Pos2, Response, Vec2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The disc: a press on it grabs the nearest marker within reach. const DISC: PartKey = PartKey::new("disc"); diff --git a/crates/color-ui/src/ui/droppers.rs b/crates/color-ui/src/ui/droppers.rs index 1e74fa220..1b6187e81 100644 --- a/crates/color-ui/src/ui/droppers.rs +++ b/crates/color-ui/src/ui/droppers.rs @@ -31,8 +31,8 @@ use craft_ui::runtime::env::Label; use craft_ui::runtime::requests::EyedropperRequest; use egui::{Pos2, Response, Ui, Vec2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The pipette icon's tip, in the icon's own 24-unit box. const HOTSPOT: [f32; 2] = [2.0, 22.0]; diff --git a/crates/color-ui/src/ui/eyedropper.rs b/crates/color-ui/src/ui/eyedropper.rs index a094917b4..9a238c286 100644 --- a/crates/color-ui/src/ui/eyedropper.rs +++ b/crates/color-ui/src/ui/eyedropper.rs @@ -35,8 +35,8 @@ use craft_ui::runtime::env::{Env, Label}; use craft_ui::style::DataColor; use egui::{Color32, Pos2, Response, Ui, Vec2, vec2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The Eyedropper options bar's words, English by default. diff --git a/crates/color-ui/src/ui/gradient/editor.rs b/crates/color-ui/src/ui/gradient/editor.rs index fc92f3978..1bdc268cb 100644 --- a/crates/color-ui/src/ui/gradient/editor.rs +++ b/crates/color-ui/src/ui/gradient/editor.rs @@ -17,8 +17,8 @@ use crate::gradient::{GradientStops, Sampler, StopRules}; mod bar; mod fields; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use bar::GradientBar; pub use bar::StopDrop; diff --git a/crates/color-ui/src/ui/gradient/mod.rs b/crates/color-ui/src/ui/gradient/mod.rs index f64eeca7a..8957f93ae 100644 --- a/crates/color-ui/src/ui/gradient/mod.rs +++ b/crates/color-ui/src/ui/gradient/mod.rs @@ -3,7 +3,7 @@ //! The model and the stop rules ([`GradientStops`], [`stops`]) need no egui and live in [`crate::gradient`]; they are //! re-exported here so a widget user imports the editor and its model from one path. -mod editor; +pub(crate) mod editor; mod ramp; mod value; mod words; diff --git a/crates/color-ui/src/ui/harmony.rs b/crates/color-ui/src/ui/harmony.rs index 9fbe06703..22abd4bbc 100644 --- a/crates/color-ui/src/ui/harmony.rs +++ b/crates/color-ui/src/ui/harmony.rs @@ -19,8 +19,8 @@ use super::picker::{ChannelRow, ChannelRule}; use crate::harmony::{Guide, GuideOptions, Harmony, Variation}; use craft_ui::choice::{SwatchTable, SwatchTableOutput}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The words of the harmony controls and of the Color Guide panel menu. diff --git a/crates/color-ui/src/ui/hud.rs b/crates/color-ui/src/ui/hud.rs index 412c62ea0..f8a15f453 100644 --- a/crates/color-ui/src/ui/hud.rs +++ b/crates/color-ui/src/ui/hud.rs @@ -17,8 +17,8 @@ use craft_ui::runtime::pointer; use craft_ui::style::{ComponentStyle, StyleCx, UiTokens}; use egui::{Pos2, Rect, Response, Ui, Vec2, pos2, vec2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The model the HUD picks in: saturation and brightness across and down, hue in the strip. const MODE: AreaMode = AreaMode::Hue; diff --git a/crates/color-ui/src/ui/info.rs b/crates/color-ui/src/ui/info.rs index 1c7d6ef4e..fb0486c6e 100644 --- a/crates/color-ui/src/ui/info.rs +++ b/crates/color-ui/src/ui/info.rs @@ -13,8 +13,8 @@ use egui::{Response, Ui}; use super::SamplerReadout; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// What a missing value shows. const DASH: &str = "–"; diff --git a/crates/color-ui/src/ui/lut_picker.rs b/crates/color-ui/src/ui/lut_picker.rs index 8c2609d36..afdb6a71d 100644 --- a/crates/color-ui/src/ui/lut_picker.rs +++ b/crates/color-ui/src/ui/lut_picker.rs @@ -19,8 +19,8 @@ use craft_ui::runtime::env::Label; use craft_ui::style::{ComponentStyle, StyleCx}; use egui::{Response, Vec2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The LUT picker's rows, English by default, and the built-in looks' names in diff --git a/crates/color-ui/src/ui/mod.rs b/crates/color-ui/src/ui/mod.rs index 51814b202..4f08f463d 100644 --- a/crates/color-ui/src/ui/mod.rs +++ b/crates/color-ui/src/ui/mod.rs @@ -11,39 +11,39 @@ //! Colour edits are values of a colour model ([`ModelValues`](craft_theme::ModelValues)) or of [`PickedColor`], and //! report through the edit lifecycle of the contract. -mod area; +pub(crate) mod area; mod channels; -mod choice; -mod compare; -mod disc; -mod droppers; -mod eyedropper; +pub(crate) mod choice; +pub(crate) mod compare; +pub(crate) mod disc; +pub(crate) mod droppers; +pub(crate) mod eyedropper; pub mod gradient; -mod harmony; +pub(crate) mod harmony; mod hex; -mod hud; -mod info; -mod lut_picker; -mod paint_chip; -mod pair; -mod palette; -mod panel; -mod picker; -mod picker_dialog; -mod popover; -mod profile_prompts; -mod ramp; -mod readout; -mod sample_size; -mod samplers; -mod screen_picker; -mod strip; -mod swatches; +pub(crate) mod hud; +pub(crate) mod info; +pub(crate) mod lut_picker; +pub(crate) mod paint_chip; +pub(crate) mod pair; +pub(crate) mod palette; +pub(crate) mod panel; +pub(crate) mod picker; +pub(crate) mod picker_dialog; +pub(crate) mod popover; +pub(crate) mod profile_prompts; +pub(crate) mod ramp; +pub(crate) mod readout; +pub(crate) mod sample_size; +pub(crate) mod samplers; +pub(crate) mod screen_picker; +pub(crate) mod strip; +pub(crate) mod swatches; /// The stories and trials this crate registers for the integration binary. #[cfg(feature = "screen-testing")] pub mod testing; -mod warning; -mod wheel; +pub(crate) mod warning; +pub(crate) mod wheel; pub use crate::AreaMode; pub use area::{AreaShape, ColorArea, ColorAreaStyle, smooth_mesh}; diff --git a/crates/color-ui/src/ui/paint_chip.rs b/crates/color-ui/src/ui/paint_chip.rs index 098395b95..8db24aab3 100644 --- a/crates/color-ui/src/ui/paint_chip.rs +++ b/crates/color-ui/src/ui/paint_chip.rs @@ -33,9 +33,9 @@ use super::popover::compact_picker; use super::{PickedColor, ScreenPickGesture, SwatchKey, SwatchPalette, SwatchesWords, swatch_rows}; use crate::palette::{SwatchColor, SwatchGroup}; -mod paint_list; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod paint_list; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use paint_list::{PaintLink, PaintLinkKind, PaintList, PaintListEvent, PaintListOptions, PaintListOutput, PaintRow}; diff --git a/crates/color-ui/src/ui/pair.rs b/crates/color-ui/src/ui/pair.rs index cc5779017..885a467c2 100644 --- a/crates/color-ui/src/ui/pair.rs +++ b/crates/color-ui/src/ui/pair.rs @@ -18,8 +18,8 @@ use egui::{Color32, CornerRadius, Painter, Pos2, Rect, Response, Shape, Stroke, use super::popover::compact_picker; use super::{ColorPicker, PickedColor, ScreenPickGesture}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// One of the wells, `WELL.at(0)` the primary and `WELL.at(1)` the secondary. const WELL: PartKey = PartKey::new("well"); diff --git a/crates/color-ui/src/ui/palette.rs b/crates/color-ui/src/ui/palette.rs index c97450556..14f864d46 100644 --- a/crates/color-ui/src/ui/palette.rs +++ b/crates/color-ui/src/ui/palette.rs @@ -10,8 +10,8 @@ use craft_ui::runtime::env::Label; use egui::{Response, Ui}; use std::sync::Arc; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// What a [`SwatchPalette`] reports. #[derive(Debug)] diff --git a/crates/color-ui/src/ui/panel.rs b/crates/color-ui/src/ui/panel.rs index acb53d2a1..76c85e775 100644 --- a/crates/color-ui/src/ui/panel.rs +++ b/crates/color-ui/src/ui/panel.rs @@ -29,8 +29,8 @@ use super::{ }; use crate::{CmykModel, GrayModel, not_web_safe}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The Color panel's words. @@ -821,7 +821,7 @@ impl Body<'_> { const WEB_STEP: f64 = 51.0; #[cfg(test)] -mod tests { +pub(crate) mod tests { use craft_ui::testing::trial; use super::*; diff --git a/crates/color-ui/src/ui/picker/mod.rs b/crates/color-ui/src/ui/picker/mod.rs index dd0968a17..577be288b 100644 --- a/crates/color-ui/src/ui/picker/mod.rs +++ b/crates/color-ui/src/ui/picker/mod.rs @@ -2,12 +2,12 @@ //! host adds. A container: its body lays the parts out with the form layouts, the "Field shows" choice is a //! `RadioGroup` and the channel rows share one label column. -mod channel; +pub(crate) mod channel; mod compact; mod full; -mod screen_pick; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod screen_pick; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod value; use std::sync::Arc; diff --git a/crates/color-ui/src/ui/popover.rs b/crates/color-ui/src/ui/popover.rs index d599b7455..36793dbce 100644 --- a/crates/color-ui/src/ui/popover.rs +++ b/crates/color-ui/src/ui/popover.rs @@ -11,8 +11,8 @@ use egui::{Response, Ui}; use super::{ColorPicker, ColorPickerLayout, ColorPickerOutput, PickedColor, ScreenPickGesture}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The setup closure of the picker in the popover. type Setup<'a> = Box Fn(ColorPicker<'b>) -> ColorPicker<'b> + 'a>; diff --git a/crates/color-ui/src/ui/profile_prompts.rs b/crates/color-ui/src/ui/profile_prompts.rs index 6ff093604..d0e822332 100644 --- a/crates/color-ui/src/ui/profile_prompts.rs +++ b/crates/color-ui/src/ui/profile_prompts.rs @@ -18,8 +18,8 @@ use serde_json::{Value, json}; use crate::display::MonitorProblem; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The profile prompts' words, English by default. diff --git a/crates/color-ui/src/ui/ramp.rs b/crates/color-ui/src/ui/ramp.rs index 63bb1a38d..11e269b5f 100644 --- a/crates/color-ui/src/ui/ramp.rs +++ b/crates/color-ui/src/ui/ramp.rs @@ -17,8 +17,8 @@ use egui::{Color32, CornerRadius, Mesh, Pos2, Rect, Response, Vec2, pos2}; use std::hash::{DefaultHasher, Hash, Hasher}; use std::sync::Arc; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The bar: a press picks the colour under the pointer. const BAR: PartKey = PartKey::new("bar"); diff --git a/crates/color-ui/src/ui/readout.rs b/crates/color-ui/src/ui/readout.rs index 34887e221..e7ed9e214 100644 --- a/crates/color-ui/src/ui/readout.rs +++ b/crates/color-ui/src/ui/readout.rs @@ -1,7 +1,7 @@ //! `ColorReadout`: a colour as a hex field and editable R, G and B fields (the readout of a Color panel). -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{EditEvent, EditEvents, Mixed}; use craft_theme::{ColorModel as _, RgbModel, Rgba}; diff --git a/crates/color-ui/src/ui/samplers.rs b/crates/color-ui/src/ui/samplers.rs index a0edd1a07..e33f7bf58 100644 --- a/crates/color-ui/src/ui/samplers.rs +++ b/crates/color-ui/src/ui/samplers.rs @@ -34,8 +34,8 @@ use super::{InfoColor, SampleSize, SampleSizeSelect}; use craft_ui::style::{ComponentStyle, StyleColor, StyleCx}; use egui::{Pos2, Response, Ui, Vec2, vec2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The colour samplers' words, English by default. diff --git a/crates/color-ui/src/ui/screen_picker.rs b/crates/color-ui/src/ui/screen_picker.rs index 1184d9fef..c8097e098 100644 --- a/crates/color-ui/src/ui/screen_picker.rs +++ b/crates/color-ui/src/ui/screen_picker.rs @@ -32,9 +32,9 @@ use egui::{Color32, Context, Pos2, Rect, Ui, pos2, vec2}; use super::ScreenPickGesture; -mod capture; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod capture; +#[cfg(feature = "suite")] +pub(crate) mod stories; use capture::{CaptureView, CaptureWindow}; diff --git a/crates/color-ui/src/ui/strip.rs b/crates/color-ui/src/ui/strip.rs index 2ac3a38ce..de21ac7e2 100644 --- a/crates/color-ui/src/ui/strip.rs +++ b/crates/color-ui/src/ui/strip.rs @@ -15,8 +15,8 @@ use craft_ui::runtime::focus::{ActivateKeys, KeepKeys, KeyUse}; use craft_ui::style::{ComponentStyle, DataColor, FocusLook, StyleColor, StyleCx}; use egui::{CornerRadius, Mesh, Pos2, Rect, Vec2, pos2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The strip itself: a press on it sets the value there. const STRIP: PartKey = PartKey::new("strip"); diff --git a/crates/color-ui/src/ui/swatches.rs b/crates/color-ui/src/ui/swatches.rs index 14d9b3cd0..17bed44a5 100644 --- a/crates/color-ui/src/ui/swatches.rs +++ b/crates/color-ui/src/ui/swatches.rs @@ -5,11 +5,11 @@ use craft_ui::tile_grid::TileZoom; -mod library; +pub(crate) mod library; mod menu; -mod panel; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod panel; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use library::{SwatchAt, SwatchEdit, SwatchKey, SwatchLibrary, SwatchesState, swatch_rows}; pub use menu::{SwatchesCommand, SwatchesFileOutput, SwatchesMenu, SwatchesMenuOutput}; diff --git a/crates/color-ui/src/ui/swatches/library.rs b/crates/color-ui/src/ui/swatches/library.rs index 937fd9885..b5ca7d726 100644 --- a/crates/color-ui/src/ui/swatches/library.rs +++ b/crates/color-ui/src/ui/swatches/library.rs @@ -571,7 +571,7 @@ pub fn swatch_rows(groups: &[SwatchGroup], words: &SwatchesWords) -> Vec-`. -const SHARED: &[&str] = &["ui", "screen-testing"]; +const SHARED: &[&str] = &["ui", "screen-testing", "suite"]; /// Facade features that do not build for `wasm32-unknown-unknown`, noted on their line. const NATIVE_ONLY: &[(&str, &str)] = &[ @@ -66,6 +66,11 @@ fn expected(members: &[Member]) -> String { out += &line("screen-testing", &testing, None); out += "\n"; + let mut suite = vec!["screen-testing".to_owned(), "craft-ui/suite".to_owned()]; + suite.extend(forwarded_to_all(members, "suite").into_iter().filter(|entry| entry != "craft-ui?/suite")); + out += &line("suite", &suite, None); + out += "\n"; + let mut seen: BTreeMap = BTreeMap::new(); for m in members { let mut group = String::new(); diff --git a/crates/design-lint/src/contract/mod.rs b/crates/design-lint/src/contract/mod.rs index 28449dc33..c1762af5d 100644 --- a/crates/design-lint/src/contract/mod.rs +++ b/crates/design-lint/src/contract/mod.rs @@ -21,6 +21,7 @@ mod pipeline_only; mod platform; mod pointer; mod props; +mod registry_expansion; mod runtime_egui; mod scope; mod shape; @@ -41,7 +42,7 @@ use crate::report::Finding; use sites::Site; /// Every rule id of this module, for the marker and exemption validation in [`crate::RULES`]. -pub(crate) const IDS: [&str; 40] = [ +pub(crate) const IDS: [&str; 41] = [ egui_import::ID, runtime_egui::ID, text_edit::ID, @@ -81,13 +82,14 @@ pub(crate) const IDS: [&str; 40] = [ shape::OVERLAY_FLAG, shape::REGISTRATION, unsafe_allow::ID, + registry_expansion::ID, global_state::ID, ]; type Check = fn(&Cx<'_>, &mut Vec); /// REGISTRY: add a rule by adding its `check` here and its ids to [`IDS`]. -const REGISTRY: [Check; 22] = [ +const REGISTRY: [Check; 23] = [ egui_import::check, runtime_egui::check, text_edit::check, @@ -109,6 +111,7 @@ const REGISTRY: [Check; 22] = [ entry::check, shape::check, unsafe_allow::check, + registry_expansion::check, global_state::check, ]; diff --git a/crates/design-lint/src/contract/registry_expansion.rs b/crates/design-lint/src/contract/registry_expansion.rs new file mode 100644 index 000000000..ee423f44d --- /dev/null +++ b/crates/design-lint/src/contract/registry_expansion.rs @@ -0,0 +1,140 @@ +//! Reject suite registrations hidden from the source-tree registry walker. + +use proc_macro2::{Delimiter, TokenStream, TokenTree}; +use std::str::FromStr as _; +use syn::spanned::Spanned as _; +use syn::visit::{self, Visit}; + +use super::Cx; +use crate::report::Finding; + +/// Suite items inside expansions cannot be discovered by `registry!`. +pub const ID: &str = "registry/expansion"; + +fn attribute(tree: &TokenTree) -> Option { + match tree { + TokenTree::Group(group) if group.delimiter() == Delimiter::Bracket => Some(group.stream().to_string()), + _ => None, + } +} + +fn words(attr: &str) -> Vec<&str> { + attr.split(|c: char| !c.is_alphanumeric() && c != '_').filter(|s| !s.is_empty()).collect() +} + +fn has_registration(tokens: TokenStream) -> bool { + let trees: Vec<_> = tokens.into_iter().collect(); + let mut i = 0; + while i < trees.len() { + if matches!(&trees[i], TokenTree::Punct(p) if p.as_char() == '#') { + let mut attrs = Vec::new(); + while i + 1 < trees.len() && matches!(&trees[i], TokenTree::Punct(p) if p.as_char() == '#') { + let Some(attr) = attribute(&trees[i + 1]) else { break }; + attrs.push(attr); + i += 2; + } + if attrs.is_empty() { + i += 1; + continue; + } + if attrs.iter().any(|attr| words(attr).first().is_some_and(|word| *word == "story" || *word == "trial")) { + return true; + } + let unregistered = attrs.iter().any(|attr| { + let words = words(attr); + words.first() == Some(&"component") && words.contains(&"unregistered") + }); + if !unregistered + && attrs.iter().any(|attr| { + let words = words(attr); + words.first() == Some(&"derive") && (words.contains(&"Component") || words.contains(&"Pattern")) + }) + { + return true; + } + let story_set = attrs.iter().any(|attr| { + let words = words(attr); + words.first() == Some(&"command") && words.contains(&"story") + }); + if story_set + && attrs.iter().any(|attr| { + let words = words(attr); + words.first() == Some(&"derive") && words.contains(&"CommandSet") + }) + { + return true; + } + continue; + } + if let TokenTree::Ident(ident) = &trees[i] + && ident == "register_contract" + && trees.get(i + 1).is_some_and(|t| matches!(t, TokenTree::Punct(p) if p.as_char() == '!')) + { + return true; + } + if let TokenTree::Group(group) = &trees[i] + && has_registration(group.stream()) + { + return true; + } + i += 1; + } + false +} + +struct Walk<'a, 'b> { + cx: &'a Cx<'b>, + out: &'a mut Vec, +} + +impl<'ast> Visit<'ast> for Walk<'_, '_> { + fn visit_item_macro(&mut self, item: &'ast syn::ItemMacro) { + let hidden = if item.mac.path.is_ident("include") { + syn::parse2::(item.mac.tokens.clone()) + .ok() + .and_then(|path| self.cx.path.parent().map(|parent| parent.join(path.value()))) + .and_then(|path| std::fs::read_to_string(path).ok()) + .and_then(|source| TokenStream::from_str(&source).ok()) + .is_some_and(has_registration) + } else { + has_registration(item.mac.tokens.clone()) + }; + if hidden { + self.cx.flag_span(self.out, ID, ID, item.span(), "suite registration inside a macro or include is invisible to registry!".to_owned()); + } + visit::visit_item_macro(self, item); + } +} + +pub(super) fn check(cx: &Cx<'_>, out: &mut Vec) { + Walk { cx, out }.visit_file(cx.file); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn detects_story_attributes_inside_repeated_macro_expansions() { + let source = r#"macro_rules! stories { ($($name:ident),*) => { $( #[story(Widget, covers = [])] fn $name() {} )* }; }"#; + let file = syn::parse_file(source).expect("valid macro definition"); + let syn::Item::Macro(item) = &file.items[0] else { panic!("expected macro definition") }; + assert!(has_registration(item.mac.tokens.clone())); + } + + #[test] + fn detects_trial_inside_a_proptest_invocation() { + let source = "proptest! { #![proptest_config(ProptestConfig::with_cases(48))] #[trial] fn roundtrip(value in 0u8..4) {} }"; + let file = syn::parse_file(source).expect("valid macro invocation"); + let syn::Item::Macro(item) = &file.items[0] else { panic!("expected macro invocation") }; + assert!(has_registration(item.mac.tokens.clone())); + } + + #[test] + fn detects_hidden_registrations_and_allows_unregistered_derive() { + let hidden = TokenStream::from_str("#[derive(Component)] struct A; #[trial] fn t() {} ").unwrap_or_default(); + let ordinary = TokenStream::from_str("#[derive(Component)] #[component(unregistered)] struct A; ").unwrap_or_default(); + assert!(has_registration(hidden)); + assert!(!has_registration(ordinary)); + } +} diff --git a/crates/design-lint/src/workspace.rs b/crates/design-lint/src/workspace.rs index fe66419a0..3dab5fe16 100644 --- a/crates/design-lint/src/workspace.rs +++ b/crates/design-lint/src/workspace.rs @@ -140,6 +140,8 @@ const NO_GLOBAL_STATE_PREFIXES: &[&str] = &[ /// a `static` or `thread_local!` item or [`FS`] for `std::fs`. Each group names the settled fact or environment key that /// covers it, or the later task of craft-libs#2336 that removes the state. A new item in these files is flagged. const NO_GLOBAL_STATE: &[(&str, &str)] = &[ + // Compile-time registry discovery reads the defining crate's source, never a view input. + ("crates/ui-macros/src/registry.rs", FS), // The trait's home crate: it implements `MemoProps` by hand for std and framework value types, and for the // framework's own keys the derive cannot write: a binding by its source's address, its check and the check's `fn` // (values.rs), an icon's glyph by the type of its `dyn Glyph` (icon.rs), and the write-only `Outbox` (memo_view.rs). @@ -150,6 +152,8 @@ const NO_GLOBAL_STATE: &[(&str, &str)] = &[ // Settled fact: a card's view of a story's state keys by the story value's revision, whether the start is taken, the // dialog's flags and the reset count; the view of every shown story's state is one fixed-size digest of those keys. // Both are props held as `&mut`, which the derive does not take. + // A card keys its owned story registration by the name and show function the card reads. + ("crates/ui-gallery/src/chrome/card.rs", "MemoProps"), ("crates/ui-gallery/src/viewer/picks.rs", "MemoProps"), // Settled fact: the names of a preset group key by a walk over the group and its folders (`dyn EachName`), which // the derive cannot see through. diff --git a/crates/dialogs/Cargo.toml b/crates/dialogs/Cargo.toml index abfb21bbd..160bec49e 100644 --- a/crates/dialogs/Cargo.toml +++ b/crates/dialogs/Cargo.toml @@ -48,6 +48,7 @@ log = "0.4" zbus = { version = "5", default-features = false, features = ["async-io", "blocking-api"] } [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # `craft_dialogs::ui`: `PathField` and the other egui parts of the file service. ui = ["dep:craft-behavior", "dep:craft-browse", "dep:craft-ui", "dep:egui", "dep:serde_json"] @@ -55,7 +56,7 @@ ui = ["dep:craft-behavior", "dep:craft-browse", "dep:craft-ui", "dep:egui", "dep screen-testing = ["ui", "craft-ui/testing"] [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } [lints] workspace = true diff --git a/crates/dialogs/src/lib.rs b/crates/dialogs/src/lib.rs index 230a8d2bb..48cc97dd1 100644 --- a/crates/dialogs/src/lib.rs +++ b/crates/dialogs/src/lib.rs @@ -22,11 +22,11 @@ mod filter; mod native; #[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd", target_os = "openbsd"))] -mod portal; -mod probe; +pub(crate) mod portal; +pub(crate) mod probe; pub mod save; #[cfg(test)] -mod save_tests; +pub(crate) mod save_tests; pub mod service; #[cfg(feature = "ui")] pub mod ui; @@ -34,14 +34,16 @@ pub mod ui; /// The registrations of this crate's UI types, for its integration binary. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } #[cfg(target_os = "macos")] mod macos; #[cfg(test)] -mod tests; +pub(crate) mod tests; use std::collections::VecDeque; use std::panic::{AssertUnwindSafe, catch_unwind}; @@ -406,9 +408,10 @@ fn panic_text(panic: &(dyn std::any::Any + Send)) -> Option<&str> { extern crate self as craft_dialogs; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/dialogs/src/portal.rs b/crates/dialogs/src/portal.rs index c12c54239..42739e2ba 100644 --- a/crates/dialogs/src/portal.rs +++ b/crates/dialogs/src/portal.rs @@ -434,4 +434,4 @@ pub(crate) fn save_as(mut req: SaveRequest, cancel: &Cancel) -> SaveOutcome { } #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/dialogs/src/probe.rs b/crates/dialogs/src/probe.rs index dd04f3293..14276af4c 100644 --- a/crates/dialogs/src/probe.rs +++ b/crates/dialogs/src/probe.rs @@ -189,4 +189,4 @@ fn classify_error(e: &zbus::Error) -> Option { } #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/dialogs/src/service.rs b/crates/dialogs/src/service.rs index 1aad116e3..8ae7dd72b 100644 --- a/crates/dialogs/src/service.rs +++ b/crates/dialogs/src/service.rs @@ -741,7 +741,7 @@ impl Files for FileService { } #[cfg(test)] -mod service_tests { +pub(crate) mod service_tests { //! Behaviour tests with `Dialogs::set_override` standing in for the panels. use craft_ui::testing::trial; diff --git a/crates/dialogs/src/ui/chooser.rs b/crates/dialogs/src/ui/chooser.rs index aace9402a..2668b9ebb 100644 --- a/crates/dialogs/src/ui/chooser.rs +++ b/crates/dialogs/src/ui/chooser.rs @@ -6,7 +6,7 @@ mod accept; #[cfg(test)] -mod tests; +pub(crate) mod tests; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex, PoisonError}; diff --git a/crates/dialogs/src/ui/mod.rs b/crates/dialogs/src/ui/mod.rs index 2adddf64b..8f9ea7675 100644 --- a/crates/dialogs/src/ui/mod.rs +++ b/crates/dialogs/src/ui/mod.rs @@ -1,9 +1,9 @@ //! The file service's UI part: [`PathField`], and the words of the service's native boxes. -mod chooser; -mod path_field; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod chooser; +pub(crate) mod path_field; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use chooser::{ChooserWords, FileChooser}; pub use path_field::{PathField, PathFieldOutput, PathFieldWords}; diff --git a/crates/dialogs/tests/it/main.rs b/crates/dialogs/tests/it/main.rs index 818669df3..8a3736ca8 100644 --- a/crates/dialogs/tests/it/main.rs +++ b/crates/dialogs/tests/it/main.rs @@ -2,4 +2,4 @@ // Expecting on failure is fine here, unlike in shipped code. #![allow(clippy::expect_used)] -mod files; +pub(crate) mod files; diff --git a/crates/draw/Cargo.toml b/crates/draw/Cargo.toml index bcb5b6c7e..9a8c91cb5 100644 --- a/crates/draw/Cargo.toml +++ b/crates/draw/Cargo.toml @@ -17,6 +17,7 @@ harness = false workspace = true [features] +suite = ["screen-testing", "craft-ui/suite", "craft-color-ui/suite"] default = [] # The tool widgets (`craft_draw::ui`). ui = ["dep:craft-behavior", "dep:craft-keymap", "dep:craft-ui", "dep:egui", "dep:craft-color-ui", "craft-color-ui/ui", "dep:craft-settings", "dep:serde_json"] @@ -38,5 +39,5 @@ serde = { version = "1", features = ["derive"] } serde_json = { workspace = true, optional = true } [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } egui = { workspace = true } diff --git a/crates/draw/src/geometry/mod.rs b/crates/draw/src/geometry/mod.rs index e55e53029..f2f21927a 100644 --- a/crates/draw/src/geometry/mod.rs +++ b/crates/draw/src/geometry/mod.rs @@ -2,16 +2,16 @@ pub mod artboard; #[cfg(test)] -mod artboard_tests; +pub(crate) mod artboard_tests; pub mod connector; #[cfg(test)] -mod connector_tests; +pub(crate) mod connector_tests; pub mod curvature; #[cfg(test)] -mod curvature_tests; +pub(crate) mod curvature_tests; pub mod fillet; #[cfg(test)] -mod fillet_tests; +pub(crate) mod fillet_tests; pub mod presets; pub mod shape; pub mod slice; diff --git a/crates/draw/src/lib.rs b/crates/draw/src/lib.rs index a27622d1f..9c3772468 100644 --- a/crates/draw/src/lib.rs +++ b/crates/draw/src/lib.rs @@ -9,16 +9,19 @@ pub mod ui; #[cfg(feature = "screen-testing")] pub mod testing { //! The registrations of this crate's stories, for the `tests/it` harness. - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } #[cfg(all(test, feature = "screen-testing"))] extern crate self as craft_draw; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/draw/src/stroke/mod.rs b/crates/draw/src/stroke/mod.rs index 0e9d38b51..949b8d4c1 100644 --- a/crates/draw/src/stroke/mod.rs +++ b/crates/draw/src/stroke/mod.rs @@ -12,7 +12,7 @@ use kurbo::{BezPath, CubicBez, Line, ParamCurve, ParamCurveArclen, PathEl, PathS use serde::{Deserialize, Serialize}; #[cfg(test)] -mod dash_tests; +pub(crate) mod dash_tests; /// The shortest run (between corners and path ends) and the smallest pattern total `Corners` fits. const MIN_RUN: f64 = 1e-6; diff --git a/crates/draw/src/ui/add_beside/mod.rs b/crates/draw/src/ui/add_beside/mod.rs index fb1856c79..ecc1d9042 100644 --- a/crates/draw/src/ui/add_beside/mod.rs +++ b/crates/draw/src/ui/add_beside/mod.rs @@ -2,7 +2,7 @@ //! (Photoshop) or a connected object (FigJam) there. One canvas control for the Artboard tool and the connector //! tools: its buttons are parts in the canvas's arena, so a press on one reaches the control before the tool. -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; mod words; diff --git a/crates/draw/src/ui/artboard/mod.rs b/crates/draw/src/ui/artboard/mod.rs index edab421c1..7ca0ca2b4 100644 --- a/crates/draw/src/ui/artboard/mod.rs +++ b/crates/draw/src/ui/artboard/mod.rs @@ -16,11 +16,11 @@ use craft_theme::Srgba; use std::sync::Arc; mod background; -mod bar; -mod overlay; -mod properties; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod bar; +pub(crate) mod overlay; +pub(crate) mod properties; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod tool; mod words; diff --git a/crates/draw/src/ui/brush_presets/mod.rs b/crates/draw/src/ui/brush_presets/mod.rs index 617a57bfb..c89cd0ce8 100644 --- a/crates/draw/src/ui/brush_presets/mod.rs +++ b/crates/draw/src/ui/brush_presets/mod.rs @@ -10,11 +10,11 @@ //! The app paints the tip and stroke images from its engine; the library never sees an engine type. Presets are //! keyed by the app's key type (PhotoCraft: `PresetKey`, by name). -mod panel; -mod picker; +pub(crate) mod panel; +pub(crate) mod picker; mod rows; mod settings; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; mod words; diff --git a/crates/draw/src/ui/brush_settings/mod.rs b/crates/draw/src/ui/brush_settings/mod.rs index 2c2155da5..42dc7aa02 100644 --- a/crates/draw/src/ui/brush_settings/mod.rs +++ b/crates/draw/src/ui/brush_settings/mod.rs @@ -13,13 +13,13 @@ //! draws the frame and the shared rows, and every control reports edit events the app sends to its //! tool options host. -mod ellipse; -mod panel; -mod preview; -mod rows; -mod sections; -mod size_field; -#[cfg(feature = "screen-testing")] +pub(crate) mod ellipse; +pub(crate) mod panel; +pub(crate) mod preview; +pub(crate) mod rows; +pub(crate) mod sections; +pub(crate) mod size_field; +#[cfg(feature = "suite")] pub(crate) mod stories; mod words; diff --git a/crates/draw/src/ui/connector/mod.rs b/crates/draw/src/ui/connector/mod.rs index 943bda0e3..7dfdfea41 100644 --- a/crates/draw/src/ui/connector/mod.rs +++ b/crates/draw/src/ui/connector/mod.rs @@ -7,15 +7,15 @@ //! on an object, the handles (a canvas control) take a press on the selected connector's ends and //! bends before the tool sees it. -mod bar; -mod handles; +pub(crate) mod bar; +pub(crate) mod handles; mod overlay; mod place; mod tool; mod words; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::EditEvent; use kurbo::{Point, Rect}; diff --git a/crates/draw/src/ui/corner/mod.rs b/crates/draw/src/ui/corner/mod.rs index c4e163fed..a25f4e3d8 100644 --- a/crates/draw/src/ui/corner/mod.rs +++ b/crates/draw/src/ui/corner/mod.rs @@ -6,10 +6,10 @@ //! arc the app's engine draws. mod geometry; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; mod style; -mod widgets; +pub(crate) mod widgets; mod words; use kurbo::Point; diff --git a/crates/draw/src/ui/crop/bar.rs b/crates/draw/src/ui/crop/bar.rs index c9e2f4892..f87f85a00 100644 --- a/crates/draw/src/ui/crop/bar.rs +++ b/crates/draw/src/ui/crop/bar.rs @@ -21,8 +21,8 @@ use craft_ui::runtime::requests::ColorRequest; use craft_ui::text::NumberField; use egui::{Response, Ui}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The ratio, a ratio field, a preset or W × H × Resolution changed. #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/crates/draw/src/ui/crop/mod.rs b/crates/draw/src/ui/crop/mod.rs index 2afc9b86e..bc6551221 100644 --- a/crates/draw/src/ui/crop/mod.rs +++ b/crates/draw/src/ui/crop/mod.rs @@ -8,17 +8,17 @@ //! The tool reports events and never crops the document: the app crops on [`CropEvent::Apply`] with the //! [`CropCommit`] it carries. -mod bar; +pub(crate) mod bar; mod bar_words; -mod menus; +pub(crate) mod menus; mod options; -mod perspective_bar; -mod perspective_crop; +pub(crate) mod perspective_bar; +pub(crate) mod perspective_crop; mod perspective_tool; -mod preset_list; +pub(crate) mod preset_list; mod session; mod size_cells; -mod tool; +pub(crate) mod tool; mod words; pub use bar::{CropBar, CropBarOutput, CropRatioChange}; diff --git a/crates/draw/src/ui/crop/perspective_bar.rs b/crates/draw/src/ui/crop/perspective_bar.rs index 3a7ffd72f..e8588e06d 100644 --- a/crates/draw/src/ui/crop/perspective_bar.rs +++ b/crates/draw/src/ui/crop/perspective_bar.rs @@ -11,8 +11,8 @@ use craft_ui::layout_components::Row; use craft_ui::runtime::env::Env; use egui::{Response, Ui}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The Perspective Crop options: W × H × Resolution, Front Image, Clear, a divider and Show Grid. /// diff --git a/crates/draw/src/ui/crop/perspective_crop.rs b/crates/draw/src/ui/crop/perspective_crop.rs index c4bae9736..2f58c20e3 100644 --- a/crates/draw/src/ui/crop/perspective_crop.rs +++ b/crates/draw/src/ui/crop/perspective_crop.rs @@ -487,5 +487,5 @@ pub fn grid_lines(view: &CanvasView, q: &[Point; 4], step: f32) -> Vec<[Pos2; 2] out } -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; diff --git a/crates/draw/src/ui/crop/tool.rs b/crates/draw/src/ui/crop/tool.rs index d5de11c8a..d39356acd 100644 --- a/crates/draw/src/ui/crop/tool.rs +++ b/crates/draw/src/ui/crop/tool.rs @@ -788,5 +788,5 @@ pub fn crop_to_form(words: &CropWords, frame: &CropBox) -> ParamDialog<'static> ParamDialog::command(CROP_TO_KEY, words.crop_to.clone(), params) } -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; diff --git a/crates/draw/src/ui/gradient/fill_editor.rs b/crates/draw/src/ui/gradient/fill_editor.rs index 81f6f36f7..86b8cdb5d 100644 --- a/crates/draw/src/ui/gradient/fill_editor.rs +++ b/crates/draw/src/ui/gradient/fill_editor.rs @@ -222,5 +222,5 @@ impl<'a> GradientFillEditor<'a> { } } -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; diff --git a/crates/draw/src/ui/gradient/gradient_overlay/mod.rs b/crates/draw/src/ui/gradient/gradient_overlay/mod.rs index d82d7625b..e91e10ca9 100644 --- a/crates/draw/src/ui/gradient/gradient_overlay/mod.rs +++ b/crates/draw/src/ui/gradient/gradient_overlay/mod.rs @@ -5,8 +5,8 @@ mod keys; mod parts; mod pointer; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/draw/src/ui/gradient/map/mod.rs b/crates/draw/src/ui/gradient/map/mod.rs index 177008a4a..e7c9c0e48 100644 --- a/crates/draw/src/ui/gradient/map/mod.rs +++ b/crates/draw/src/ui/gradient/map/mod.rs @@ -4,8 +4,8 @@ //! It lives here rather than with the other adjustment editors in craft-imaging because it picks from the palette's //! [`GradientGroup`] presets, and a family crate depends on no other family crate but craft-color-ui. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{EditEvent, Mixed}; use craft_ui::buttons::Button; diff --git a/crates/draw/src/ui/gradient/mod.rs b/crates/draw/src/ui/gradient/mod.rs index adfb20f35..b7eb01b2f 100644 --- a/crates/draw/src/ui/gradient/mod.rs +++ b/crates/draw/src/ui/gradient/mod.rs @@ -8,13 +8,13 @@ //! there. mod fill; -mod fill_editor; +pub(crate) mod fill_editor; pub mod gradient_line; pub mod gradient_overlay; pub mod map; -mod palette; -mod swatch; -mod tile; +pub(crate) mod palette; +pub(crate) mod swatch; +pub(crate) mod tile; pub use fill::{GradientFill, GradientStyle}; pub use fill_editor::{GradientFillEditor, GradientFillEditorOutput, GradientFillWords}; diff --git a/crates/draw/src/ui/gradient/palette/mod.rs b/crates/draw/src/ui/gradient/palette/mod.rs index 0fde15cef..b50b68cec 100644 --- a/crates/draw/src/ui/gradient/palette/mod.rs +++ b/crates/draw/src/ui/gradient/palette/mod.rs @@ -7,8 +7,8 @@ use craft_ui::patterns::presets::{CellShape, PresetBrowser, PresetEvent, PresetR use craft_ui::runtime::env::{Env, Label}; use egui::{Response, Ui}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_color_ui::ui::gradient::{GradientRamp, GradientStops, Sampler, StopRows, default_sampler}; diff --git a/crates/draw/src/ui/gradient/swatch.rs b/crates/draw/src/ui/gradient/swatch.rs index f982221ea..7b295e525 100644 --- a/crates/draw/src/ui/gradient/swatch.rs +++ b/crates/draw/src/ui/gradient/swatch.rs @@ -12,8 +12,8 @@ use craft_color_ui::ui::gradient::{GradientRamp, GradientStops, Sampler, StopRow use super::GradientTile; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of a gradient swatch: the colour swatch's height, corners and ring. #[derive(Clone, Debug, PartialEq, ComponentStyle)] diff --git a/crates/draw/src/ui/measure/mod.rs b/crates/draw/src/ui/measure/mod.rs index 034445420..333082e42 100644 --- a/crates/draw/src/ui/measure/mod.rs +++ b/crates/draw/src/ui/measure/mod.rs @@ -5,12 +5,12 @@ //! The Ruler line is document state outside the undo history: the tool reports `EditEvent>` and the //! app stores the line. -mod bar; +pub(crate) mod bar; mod distances; mod model; -mod overlay; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod overlay; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod tool; mod words; diff --git a/crates/draw/src/ui/paint_bar.rs b/crates/draw/src/ui/paint_bar.rs index 74a61e601..fec07db9e 100644 --- a/crates/draw/src/ui/paint_bar.rs +++ b/crates/draw/src/ui/paint_bar.rs @@ -20,8 +20,8 @@ use craft_ui::runtime::env::{Env, Label, UnitKind}; use craft_ui::text::{NumberField, RangeAlert}; use egui::{Response, Ui}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod words; pub use words::PaintBarWords; diff --git a/crates/draw/src/ui/paths/mod.rs b/crates/draw/src/ui/paths/mod.rs index d751cff17..64d180b76 100644 --- a/crates/draw/src/ui/paths/mod.rs +++ b/crates/draw/src/ui/paths/mod.rs @@ -4,9 +4,9 @@ mod footer; mod menu; mod model; -mod panel; +pub(crate) mod panel; mod rows; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; mod words; diff --git a/crates/draw/src/ui/pattern/mod.rs b/crates/draw/src/ui/pattern/mod.rs index b74f303af..18f81b6a2 100644 --- a/crates/draw/src/ui/pattern/mod.rs +++ b/crates/draw/src/ui/pattern/mod.rs @@ -5,8 +5,8 @@ use craft_theme::Srgba; mod dialog; -mod editor; -#[cfg(feature = "screen-testing")] +pub(crate) mod editor; +#[cfg(feature = "suite")] pub(crate) mod stories; mod words; diff --git a/crates/draw/src/ui/pen/bezier/mod.rs b/crates/draw/src/ui/pen/bezier/mod.rs index 801b3d2d8..fbca9ff8a 100644 --- a/crates/draw/src/ui/pen/bezier/mod.rs +++ b/crates/draw/src/ui/pen/bezier/mod.rs @@ -5,8 +5,8 @@ mod hit_test; mod mark; mod model; mod ops; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod style; mod tools; mod words; diff --git a/crates/draw/src/ui/pen/mod.rs b/crates/draw/src/ui/pen/mod.rs index 61395d61a..69160afd6 100644 --- a/crates/draw/src/ui/pen/mod.rs +++ b/crates/draw/src/ui/pen/mod.rs @@ -8,8 +8,8 @@ mod auto; pub(crate) mod bezier; mod curvature_mode; mod mode; -mod options; -#[cfg(feature = "screen-testing")] +pub(crate) mod options; +#[cfg(feature = "suite")] pub(crate) mod stories; mod tool; mod words; diff --git a/crates/draw/src/ui/picture_fill/mod.rs b/crates/draw/src/ui/picture_fill/mod.rs index 99f742b10..383d13392 100644 --- a/crates/draw/src/ui/picture_fill/mod.rs +++ b/crates/draw/src/ui/picture_fill/mod.rs @@ -7,9 +7,9 @@ //! if let Some(request) = out.requests.take_path() { /* open the file dialog, store the picture, set `fill.source` */ } //! ``` -mod editor; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod editor; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod words; pub use editor::{PICTURE_FILL_KEY, PictureFillEditor, PictureFillOutput}; diff --git a/crates/draw/src/ui/shape/mod.rs b/crates/draw/src/ui/shape/mod.rs index 0ccad43ad..02995f04d 100644 --- a/crates/draw/src/ui/shape/mod.rs +++ b/crates/draw/src/ui/shape/mod.rs @@ -10,14 +10,14 @@ use crate::stroke::StrokeStyle; use super::shape_drag::{BoxConstraints, ShapeDragOptions, ShapeKind}; -mod arrowheads; -mod bar; -mod gear; -mod mode_select; -mod panel; -#[cfg(feature = "screen-testing")] +pub(crate) mod arrowheads; +pub(crate) mod bar; +pub(crate) mod gear; +pub(crate) mod mode_select; +pub(crate) mod panel; +#[cfg(feature = "suite")] pub(crate) mod stories; -mod stroke_cells; +pub(crate) mod stroke_cells; mod words; pub use arrowheads::{ArrowheadsOutput, ArrowheadsPopover}; diff --git a/crates/draw/src/ui/shape_presets.rs b/crates/draw/src/ui/shape_presets.rs index 579b431a7..b9f92030f 100644 --- a/crates/draw/src/ui/shape_presets.rs +++ b/crates/draw/src/ui/shape_presets.rs @@ -11,8 +11,8 @@ use craft_ui::style::UiTokens; use egui::{Color32, Mesh, Painter, Pos2, Rect, Shape, Stroke, Ui, pos2}; use kurbo::{BezPath, PathEl}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The error bound, in points, when the glyph's curves are flattened. const FLATTEN_TOLERANCE: f64 = 0.1; diff --git a/crates/draw/src/ui/slice/mod.rs b/crates/draw/src/ui/slice/mod.rs index 8ce3f4f59..5b19a6580 100644 --- a/crates/draw/src/ui/slice/mod.rs +++ b/crates/draw/src/ui/slice/mod.rs @@ -35,11 +35,11 @@ use craft_behavior::{Axis, CancelReason, EditEvent, GestureId, Mixed}; use craft_keymap::Mods; use std::sync::Arc; -mod bar; +pub(crate) mod bar; mod dialogs; -mod overlay; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod overlay; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod tool; mod words; diff --git a/crates/draw/src/ui/stroke/mod.rs b/crates/draw/src/ui/stroke/mod.rs index 7eb02bec6..5b9e5ef5e 100644 --- a/crates/draw/src/ui/stroke/mod.rs +++ b/crates/draw/src/ui/stroke/mod.rs @@ -5,10 +5,10 @@ //! and named stroke types. The editor edits geometry only; width, colour and paint are the host's //! controls. The value is [`StrokeStyle`], re-exported here. -mod button; -mod editor; +pub(crate) mod button; +pub(crate) mod editor; mod preview; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; mod words; diff --git a/crates/draw/src/ui/symmetry/mod.rs b/crates/draw/src/ui/symmetry/mod.rs index a4676ddea..431dc6c1f 100644 --- a/crates/draw/src/ui/symmetry/mod.rs +++ b/crates/draw/src/ui/symmetry/mod.rs @@ -5,12 +5,12 @@ //! Stroke reflection, path symmetry and the brush engine stay in the app's paint engine; the library carries only the //! axis geometry the screens need. -mod handles; -mod menu; +pub(crate) mod handles; +pub(crate) mod menu; mod model; -mod overlay; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod overlay; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod transform; pub use handles::{SymmetryHandles, SymmetryHandlesOutput, SymmetryHandlesStyle}; diff --git a/crates/draw/src/ui/transform/mod.rs b/crates/draw/src/ui/transform/mod.rs index 49a19f07c..11a22a114 100644 --- a/crates/draw/src/ui/transform/mod.rs +++ b/crates/draw/src/ui/transform/mod.rs @@ -2,10 +2,10 @@ //! the open session around them ([`TransformSession`], [`TransformOverlay`], [`TransformTool`], [`TransformBar`]). mod session; -mod session_bar; -mod session_overlay; -mod transform_box; -mod transform_fields; +pub(crate) mod session_bar; +pub(crate) mod session_overlay; +pub(crate) mod transform_box; +pub(crate) mod transform_fields; pub use session::{ Interpolation, TransformChoice, TransformEdit, TransformMenuWords, TransformPhase, TransformPreset, TransformRequest, TransformResult, diff --git a/crates/draw/src/ui/transform/session_bar.rs b/crates/draw/src/ui/transform/session_bar.rs index d0d9a8247..c4a722465 100644 --- a/crates/draw/src/ui/transform/session_bar.rs +++ b/crates/draw/src/ui/transform/session_bar.rs @@ -1,7 +1,7 @@ //! `TransformBar`: the options bar of an open Free Transform session. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::session::{TransformEdit, TransformPhase, TransformSession, TransformSettings, TransformWarp}; use super::transform_fields::{TransformFields, TransformGroups, TransformRow, size_unit_of}; diff --git a/crates/draw/src/ui/transform/session_overlay.rs b/crates/draw/src/ui/transform/session_overlay.rs index c86781be7..e28ceddc8 100644 --- a/crates/draw/src/ui/transform/session_overlay.rs +++ b/crates/draw/src/ui/transform/session_overlay.rs @@ -1,8 +1,8 @@ //! `TransformOverlay`: the open session's box on the canvas, which shows a [`TransformBox`](super::TransformBox) //! and turns its reports into [`TransformEdit`]s, and `TransformTool`: the canvas tool of the open session. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::CancelReason; use craft_behavior::geometry::SnapLine; diff --git a/crates/draw/src/ui/transform/transform_box.rs b/crates/draw/src/ui/transform/transform_box.rs index 1202fca41..903e30fc8 100644 --- a/crates/draw/src/ui/transform/transform_box.rs +++ b/crates/draw/src/ui/transform/transform_box.rs @@ -2,8 +2,8 @@ //! corners, edges, reference point, inside and outside are parts in the canvas's arena; the value is the box in //! document units. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::geometry::quad::{self, BoxAllow, BoxDrag, BoxPart, BoxRules, BoxState, ScaleRule, TransformMode}; use craft_behavior::geometry::{SNAP_PX, SnapKind, SnapKinds, SnapLine, SnapSuspend}; diff --git a/crates/draw/src/ui/transform/transform_fields.rs b/crates/draw/src/ui/transform/transform_fields.rs index dc7b81f3f..d57e02130 100644 --- a/crates/draw/src/ui/transform/transform_fields.rs +++ b/crates/draw/src/ui/transform/transform_fields.rs @@ -1,8 +1,8 @@ //! `TransformFields`: the X, Y, W, H, angle and skew fields of a transform box, as an options-bar strip or a panel's //! rows. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod units; use self::units::Conversion; diff --git a/crates/draw/tests/it/main.rs b/crates/draw/tests/it/main.rs index 6aac5e510..cae0ff9cf 100644 --- a/crates/draw/tests/it/main.rs +++ b/crates/draw/tests/it/main.rs @@ -1,60 +1,60 @@ //! The screen tests of craft-draw, folded into the lib's test target. // draw-shape -mod add_beside; -mod corner; -mod shape_cells; +pub(crate) mod add_beside; +pub(crate) mod corner; +pub(crate) mod shape_cells; // draw-gradient-b -mod gradient_fill; -mod gradient_map; -mod gradient_overlay; +pub(crate) mod gradient_fill; +pub(crate) mod gradient_map; +pub(crate) mod gradient_overlay; // draw-connector -mod connector; -mod shape_drag; +pub(crate) mod connector; +pub(crate) mod shape_drag; // draw-paths -mod paths_panel; +pub(crate) mod paths_panel; // draw-pen-a -mod bezier; +pub(crate) mod bezier; // draw-pen-b -mod pen; +pub(crate) mod pen; // draw-crop-b -mod crop_size; -mod crop_tool; -mod perspective_crop; +pub(crate) mod crop_size; +pub(crate) mod crop_tool; +pub(crate) mod perspective_crop; // draw-artboard -mod artboard; +pub(crate) mod artboard; // draw-bars -mod measure; -mod slice; -mod slice_divide; +pub(crate) mod measure; +pub(crate) mod slice; +pub(crate) mod slice_divide; // draw-stroke -mod stroke_button; -mod stroke_editor; +pub(crate) mod stroke_button; +pub(crate) mod stroke_editor; // draw-brush-presets -mod brush_presets; -mod brush_size; -mod paint_bar; +pub(crate) mod brush_presets; +pub(crate) mod brush_size; +pub(crate) mod paint_bar; // draw-transform-a -mod transform_box; -mod transform_session; +pub(crate) mod transform_box; +pub(crate) mod transform_session; // draw-transform-b -mod symmetry; -mod transform_fields; +pub(crate) mod symmetry; +pub(crate) mod transform_fields; // draw-presets -mod presets; +pub(crate) mod presets; // dialogs-w13 -mod pattern_fill; +pub(crate) mod pattern_fill; diff --git a/crates/feature-root/Cargo.toml b/crates/feature-root/Cargo.toml index e21c56c8d..3392e7ef4 100644 --- a/crates/feature-root/Cargo.toml +++ b/crates/feature-root/Cargo.toml @@ -31,22 +31,22 @@ workspace = true [dependencies] craft-ui-gallery = { path = "../ui-gallery", default-features = false } # The gallery's optional domain crates, with the gallery's features (`cl doctor` checks that the lists match). -craft-automation = { workspace = true, features = ["screen-testing"] } -craft-browse = { workspace = true, features = ["screen-testing"] } -craft-color-ui = { workspace = true, features = ["screen-testing"] } -craft-draw = { workspace = true, features = ["screen-testing"] } -craft-imaging = { workspace = true, features = ["screen-testing"] } -craft-layers = { workspace = true, features = ["screen-testing"] } -craft-menu = { workspace = true, features = ["screen-testing"] } -craft-pages = { workspace = true, features = ["screen-testing"] } -craft-print = { workspace = true, features = ["screen-testing"] } -craft-review = { workspace = true, features = ["screen-testing"] } -craft-table = { workspace = true, features = ["screen-testing"] } -craft-text = { workspace = true, features = ["screen-testing", "find"] } -craft-theme-store = { workspace = true, features = ["screen-testing"] } -craft-timeline = { workspace = true, features = ["screen-testing", "xml", "otio"] } +craft-automation = { workspace = true, features = ["suite"] } +craft-browse = { workspace = true, features = ["suite"] } +craft-color-ui = { workspace = true, features = ["suite"] } +craft-draw = { workspace = true, features = ["suite"] } +craft-imaging = { workspace = true, features = ["suite"] } +craft-layers = { workspace = true, features = ["suite"] } +craft-menu = { workspace = true, features = ["suite"] } +craft-pages = { workspace = true, features = ["suite"] } +craft-print = { workspace = true, features = ["suite"] } +craft-review = { workspace = true, features = ["suite"] } +craft-table = { workspace = true, features = ["suite"] } +craft-text = { workspace = true, features = ["suite", "find"] } +craft-theme-store = { workspace = true, features = ["suite"] } +craft-timeline = { workspace = true, features = ["suite", "xml", "otio"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -craft-dialogs = { workspace = true, features = ["screen-testing"] } -craft-font-manager = { workspace = true, features = ["screen-testing"] } -craft-update = { workspace = true, features = ["screen-testing"] } +craft-dialogs = { workspace = true, features = ["suite"] } +craft-font-manager = { workspace = true, features = ["suite"] } +craft-update = { workspace = true, features = ["suite"] } diff --git a/crates/font-manager/Cargo.toml b/crates/font-manager/Cargo.toml index c8f5148bc..f3a18f1c6 100644 --- a/crates/font-manager/Cargo.toml +++ b/crates/font-manager/Cargo.toml @@ -12,6 +12,7 @@ repository.workspace = true test = false [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # `FontsPanel`: the whole interface as one egui panel (it builds for the web too), with the picker, the Glyphs panel, the axis sliders and the # Missing Fonts dialog. @@ -40,13 +41,13 @@ log = { version = "0.4", optional = true } skrifa = { version = "0.44", default-features = false, features = ["std"] } [dev-dependencies] -craft-font-manager = { path = ".", features = ["screen-testing"] } +craft-font-manager = { path = ".", features = ["suite"] } [[test]] name = "it" path = "tests/it/main.rs" harness = false -required-features = ["screen-testing"] +required-features = ["suite"] [lints] workspace = true diff --git a/crates/font-manager/src/axes.rs b/crates/font-manager/src/axes.rs index 6401367c6..84b61a6f1 100644 --- a/crates/font-manager/src/axes.rs +++ b/crates/font-manager/src/axes.rs @@ -3,7 +3,7 @@ //! and reading them from a font are always available; the sliders are on `ui`. #[cfg(feature = "ui")] -mod sliders; +pub(crate) mod sliders; #[cfg(feature = "ui")] pub use sliders::*; diff --git a/crates/font-manager/src/axes/sliders.rs b/crates/font-manager/src/axes/sliders.rs index 0e09b95af..f9e4ee499 100644 --- a/crates/font-manager/src/axes/sliders.rs +++ b/crates/font-manager/src/axes/sliders.rs @@ -1,7 +1,7 @@ //! The row of sliders that edits the axes of a face (Photoshop's Properties › Character axis sliders; FigCraft's axis panel). -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/font-manager/src/glyphs.rs b/crates/font-manager/src/glyphs.rs index 0a20f136f..3d9bbca2d 100644 --- a/crates/font-manager/src/glyphs.rs +++ b/crates/font-manager/src/glyphs.rs @@ -2,8 +2,8 @@ //! Currency, ...), a grid of glyph cells drawn by the app's text engine, a zoom slider, and the recently used //! glyphs in a row at the top. Double-click or Enter inserts the glyph where the app can insert. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/font-manager/src/lib.rs b/crates/font-manager/src/lib.rs index ce2598faa..f3bb0d1ac 100644 --- a/crates/font-manager/src/lib.rs +++ b/crates/font-manager/src/lib.rs @@ -25,7 +25,7 @@ pub mod glyphs; #[cfg(feature = "ui")] pub mod missing; #[cfg(feature = "ui")] -mod panel; +pub(crate) mod panel; #[cfg(feature = "ui")] pub mod picker; @@ -40,5 +40,7 @@ pub use panel::{ /// The registered stories and trials of this crate. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } diff --git a/crates/font-manager/src/missing.rs b/crates/font-manager/src/missing.rs index ec9d859d1..f476d771c 100644 --- a/crates/font-manager/src/missing.rs +++ b/crates/font-manager/src/missing.rs @@ -2,8 +2,8 @@ //! are not installed, and the dialog that lists them with a replacement for each (Photoshop's //! "missing fonts" warning on open; VectorCraft's and FigCraft's Document Fonts lists). -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::borrow::Cow; use std::sync::Arc; diff --git a/crates/font-manager/src/panel/app.rs b/crates/font-manager/src/panel/app.rs index e3feab10d..3074a0a14 100644 --- a/crates/font-manager/src/panel/app.rs +++ b/crates/font-manager/src/panel/app.rs @@ -1,8 +1,8 @@ //! The panel's model, what the host calls, and the view: the tabs and search across the top, the filters at the //! reading start, the family cards, the details sheet and the download consent. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::collections::HashMap; use std::sync::Arc; diff --git a/crates/font-manager/src/panel/browse.rs b/crates/font-manager/src/panel/browse.rs index 574b36113..e9c71b7cf 100644 --- a/crates/font-manager/src/panel/browse.rs +++ b/crates/font-manager/src/panel/browse.rs @@ -1,9 +1,9 @@ //! The tabs and search, the filters, the sample toolbar and the list of family cards. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; -mod cards; +pub(crate) mod cards; use std::borrow::Cow; use std::sync::Arc; diff --git a/crates/font-manager/src/panel/details.rs b/crates/font-manager/src/panel/details.rs index f38fe36c1..b38054330 100644 --- a/crates/font-manager/src/panel/details.rs +++ b/crates/font-manager/src/panel/details.rs @@ -1,9 +1,9 @@ //! The details sheet: a family's every style in its own face, its facts and languages, and //! installing or removing it whole or a style at a time. -mod rows; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod rows; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/font-manager/src/panel/mod.rs b/crates/font-manager/src/panel/mod.rs index 0efc27e10..4746d488b 100644 --- a/crates/font-manager/src/panel/mod.rs +++ b/crates/font-manager/src/panel/mod.rs @@ -3,16 +3,16 @@ mod i18n; -mod app; +pub(crate) mod app; pub(crate) mod browse; -mod details; +pub(crate) mod details; pub(crate) mod faces; #[cfg(feature = "screen-testing")] pub(crate) mod fixtures; pub(crate) mod jobs; pub(crate) mod samples; -mod sources; -mod specimen; +pub(crate) mod sources; +pub(crate) mod specimen; pub use app::{ FontsCommand, FontsPanel, FontsPanelOutput, FontsPanelSettings, FontsPanelView, FontsPanelWords, Options, Preset, Tab, install_interface_fonts, diff --git a/crates/font-manager/src/panel/sources.rs b/crates/font-manager/src/panel/sources.rs index e46f24eeb..3c87a484e 100644 --- a/crates/font-manager/src/panel/sources.rs +++ b/crates/font-manager/src/panel/sources.rs @@ -2,8 +2,8 @@ //! added (never curated, and flagged when their file changed since it was added), adding one, //! and downloading them all again. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/font-manager/src/panel/specimen.rs b/crates/font-manager/src/panel/specimen.rs index 83e1181d9..fad35bc7d 100644 --- a/crates/font-manager/src/panel/specimen.rs +++ b/crates/font-manager/src/panel/specimen.rs @@ -12,8 +12,8 @@ use crate::Catalog; use crate::FaceInfo; use crate::panel::faces::{self, Owner, Shown}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The ink of a sample: the text colour for a face that drew, the muted one for the interface face standing in. #[derive(Clone, Debug, PartialEq, ComponentStyle)] diff --git a/crates/font-manager/src/picker.rs b/crates/font-manager/src/picker.rs index dea89edb8..dea1d1d7b 100644 --- a/crates/font-manager/src/picker.rs +++ b/crates/font-manager/src/picker.rs @@ -3,10 +3,10 @@ //! drawn in their own face, favourites (stars), recent families at the top, class and feature filters above the //! list and a "similar fonts" filter. Behaviour follows Photoshop's font menu. -mod rank; +pub(crate) mod rank; mod rows; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/font-manager/src/picker/rank.rs b/crates/font-manager/src/picker/rank.rs index fd27c0509..7d6637864 100644 --- a/crates/font-manager/src/picker/rank.rs +++ b/crates/font-manager/src/picker/rank.rs @@ -377,7 +377,7 @@ pub(super) fn list(catalog: &Arc, infos: &Infos, listing: &Listing<'_>, } #[cfg(test)] -mod tests { +pub(crate) mod tests { use craft_ui::testing::trial; use super::{ARABIC_CORE, has_arabic_sample}; diff --git a/crates/font-manager/tests/it/main.rs b/crates/font-manager/tests/it/main.rs index 76d76dfab..cb108c42e 100644 --- a/crates/font-manager/tests/it/main.rs +++ b/crates/font-manager/tests/it/main.rs @@ -1,11 +1,15 @@ //! The integration binary of craft-font-manager: every test is a registered trial. -mod missing; -mod panel; -mod picker; +pub(crate) mod missing; +pub(crate) mod panel; +pub(crate) mod picker; -use craft_font_manager::testing::registered; +craft_ui::registry!(); fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), ®istered()); + craft_ui::testing::run( + module_path!(), + env!("CARGO_PKG_NAME"), + &craft_ui::testing::Registry::of(&[register, craft_font_manager::testing::register]), + ); } diff --git a/crates/imaging/Cargo.toml b/crates/imaging/Cargo.toml index b1149aa36..c4fd9b76a 100644 --- a/crates/imaging/Cargo.toml +++ b/crates/imaging/Cargo.toml @@ -17,6 +17,7 @@ harness = false workspace = true [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # The editing widgets (`craft_imaging::ui`). ui = ["craft-color-ui/ui", "dep:serde_json", "dep:craft-behavior", "dep:craft-keymap", "dep:craft-ui", "dep:egui", "dep:kurbo"] @@ -37,7 +38,7 @@ serde = { workspace = true } serde_json = { workspace = true, optional = true } [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } craft-ui-test-kit = { workspace = true } craft-window = { workspace = true } egui = { workspace = true } diff --git a/crates/imaging/src/layer_style/mod.rs b/crates/imaging/src/layer_style/mod.rs index 5c4176b2a..7b31d5e18 100644 --- a/crates/imaging/src/layer_style/mod.rs +++ b/crates/imaging/src/layer_style/mod.rs @@ -30,7 +30,7 @@ mod drag; mod model; mod spec; #[cfg(test)] -mod tests; +pub(crate) mod tests; pub use contour::{Contour, ContourPoint}; pub use draft::LayerStyleDraft; diff --git a/crates/imaging/src/lib.rs b/crates/imaging/src/lib.rs index 52bc4632b..631f47adf 100644 --- a/crates/imaging/src/lib.rs +++ b/crates/imaging/src/lib.rs @@ -16,16 +16,19 @@ pub mod wide_angle; /// The registered stories and suite cases of the widgets, for `tests/it`. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } #[cfg(all(test, feature = "screen-testing"))] extern crate self as craft_imaging; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/imaging/src/scopes/mod.rs b/crates/imaging/src/scopes/mod.rs index 7e4019ae0..01096b674 100644 --- a/crates/imaging/src/scopes/mod.rs +++ b/crates/imaging/src/scopes/mod.rs @@ -15,7 +15,7 @@ mod clipping; mod statistics; #[cfg(test)] -mod tests; +pub(crate) mod tests; mod vectorscope; pub use clipping::{ChannelMask, ClippedChannels, ClippingMask, clipping}; diff --git a/crates/imaging/src/trace/mod.rs b/crates/imaging/src/trace/mod.rs index 799194c35..492e3e1f3 100644 --- a/crates/imaging/src/trace/mod.rs +++ b/crates/imaging/src/trace/mod.rs @@ -15,7 +15,7 @@ use std::hash::{Hash, Hasher}; #[cfg(test)] -mod tests; +pub(crate) mod tests; /// One boundary segment in document pixels, from one end to the other. Every segment is /// horizontal or vertical. diff --git a/crates/imaging/src/ui/adjust/basic.rs b/crates/imaging/src/ui/adjust/basic.rs index 543bb9223..dfb53cbae 100644 --- a/crates/imaging/src/ui/adjust/basic.rs +++ b/crates/imaging/src/ui/adjust/basic.rs @@ -1,11 +1,11 @@ //! Photoshop's four small adjustments: Brightness/Contrast, Threshold, Color Balance and Photo Filter. -mod brightness_contrast; -mod color_balance; -mod photo_filter; -#[cfg(feature = "screen-testing")] -mod stories; -mod threshold; +pub(crate) mod brightness_contrast; +pub(crate) mod color_balance; +pub(crate) mod photo_filter; +#[cfg(feature = "suite")] +pub(crate) mod stories; +pub(crate) mod threshold; pub use brightness_contrast::{BrightnessContrast, BrightnessContrastEditor}; pub use color_balance::{ColorBalance, ColorBalanceEditor, ColorBalanceOutput, ColorBalanceTone}; diff --git a/crates/imaging/src/ui/adjust/curves_panel.rs b/crates/imaging/src/ui/adjust/curves_panel.rs index f01d19b13..9f401fbd2 100644 --- a/crates/imaging/src/ui/adjust/curves_panel.rs +++ b/crates/imaging/src/ui/adjust/curves_panel.rs @@ -3,8 +3,8 @@ //! and the hint line; and the ⌘/Ctrl-click-on-the-image helper //! ([`CurvesPanel::add_point_from_sample`]). -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/imaging/src/ui/adjust/hue_saturation.rs b/crates/imaging/src/ui/adjust/hue_saturation.rs index 82f81bc04..ebaec581b 100644 --- a/crates/imaging/src/ui/adjust/hue_saturation.rs +++ b/crates/imaging/src/ui/adjust/hue_saturation.rs @@ -1,8 +1,8 @@ //! [`HueSaturationEditor`]: Master and six colour ranges, Colorize, the two spectrum bars and the four range thumbs //! that wrap at 360°. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::Mixed; use craft_theme::{Hsb, Srgba}; diff --git a/crates/imaging/src/ui/adjust/levels_editor.rs b/crates/imaging/src/ui/adjust/levels_editor.rs index 26c3762d3..5f1bc2ad4 100644 --- a/crates/imaging/src/ui/adjust/levels_editor.rs +++ b/crates/imaging/src/ui/adjust/levels_editor.rs @@ -1,8 +1,8 @@ //! [`LevelsEditor`]: a levels adjustment's histogram, input thumbs and fields, output bar, thumbs //! and fields, editing one channel's [`Levels`]. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::ops::RangeInclusive; diff --git a/crates/imaging/src/ui/adjust/levels_panel.rs b/crates/imaging/src/ui/adjust/levels_panel.rs index 62951796c..aa0ef971d 100644 --- a/crates/imaging/src/ui/adjust/levels_panel.rs +++ b/crates/imaging/src/ui/adjust/levels_panel.rs @@ -1,8 +1,8 @@ //! [`LevelsPanel`]: the Levels adjustment around the [`LevelsEditor`]: the point pickers, the //! Channel select, Auto and the editor over the shown channel's histogram. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/imaging/src/ui/adjust/mixers.rs b/crates/imaging/src/ui/adjust/mixers.rs index 97bbef63b..155fa450c 100644 --- a/crates/imaging/src/ui/adjust/mixers.rs +++ b/crates/imaging/src/ui/adjust/mixers.rs @@ -1,10 +1,10 @@ //! The channel-mixing adjustments: Black & White, Channel Mixer and Selective Color. -mod black_white; -mod channel_mixer; -mod selective_color; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod black_white; +pub(crate) mod channel_mixer; +pub(crate) mod selective_color; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use black_white::{BlackWhite, BlackWhiteEditor, BlackWhiteOutput}; pub use channel_mixer::{ChannelMixer, ChannelMixerEditor}; diff --git a/crates/imaging/src/ui/adjust/mod.rs b/crates/imaging/src/ui/adjust/mod.rs index 021d1cb48..1e773ef6f 100644 --- a/crates/imaging/src/ui/adjust/mod.rs +++ b/crates/imaging/src/ui/adjust/mod.rs @@ -15,21 +15,21 @@ //! //! Gradient Map is `craft_draw::ui::gradient::map`, beside the gradient editor it builds on. -mod basic; +pub(crate) mod basic; mod context; -mod curves_panel; +pub(crate) mod curves_panel; mod hosted; -mod hue_saturation; +pub(crate) mod hue_saturation; mod kinds; mod labels; -mod levels_editor; -mod levels_panel; -mod mixers; -mod panel; -mod session; -mod sliders; +pub(crate) mod levels_editor; +pub(crate) mod levels_panel; +pub(crate) mod mixers; +pub(crate) mod panel; +pub(crate) mod session; +pub(crate) mod sliders; mod style; -mod tone; +pub(crate) mod tone; pub use basic::{ BrightnessContrast, BrightnessContrastEditor, ColorBalance, ColorBalanceEditor, ColorBalanceOutput, ColorBalanceTone, PhotoFilter, diff --git a/crates/imaging/src/ui/adjust/panel.rs b/crates/imaging/src/ui/adjust/panel.rs index cce9abba3..3e69d8df5 100644 --- a/crates/imaging/src/ui/adjust/panel.rs +++ b/crates/imaging/src/ui/adjust/panel.rs @@ -1,7 +1,7 @@ //! [`AdjustmentsPanel`]: the grid of adjustment buttons a document panel offers for adding an adjustment layer. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{Metrics, NavShape, Roving, Sense}; use craft_ui::buttons::IconButton; diff --git a/crates/imaging/src/ui/adjust/session.rs b/crates/imaging/src/ui/adjust/session.rs index 039a312dd..c0c2cf1bd 100644 --- a/crates/imaging/src/ui/adjust/session.rs +++ b/crates/imaging/src/ui/adjust/session.rs @@ -1,8 +1,8 @@ //! [`AdjustSession`]: the Properties panel's memory of the settings it found on an adjustment //! layer, so Reset returns to them once the user edited. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The settings an adjustment layer had when the Properties panel started showing it, and whether /// the panel edited them since (or since the last Reset). A plain value the app keeps per panel; diff --git a/crates/imaging/src/ui/adjust/sliders.rs b/crates/imaging/src/ui/adjust/sliders.rs index 9ec8dcd6b..d64de0bb6 100644 --- a/crates/imaging/src/ui/adjust/sliders.rs +++ b/crates/imaging/src/ui/adjust/sliders.rs @@ -5,8 +5,8 @@ //! rows' edits are lifted onto the editor's value ([`Run`]), so one slider drag, one typed number or one reset is one //! gesture of the whole value. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::ops::RangeInclusive; use std::sync::Arc; diff --git a/crates/imaging/src/ui/adjust/tone.rs b/crates/imaging/src/ui/adjust/tone.rs index 711bdd0dc..e14d03d44 100644 --- a/crates/imaging/src/ui/adjust/tone.rs +++ b/crates/imaging/src/ui/adjust/tone.rs @@ -5,8 +5,8 @@ //! The library reports the sample; turning it into a Levels or Curves value needs the document's //! colour management and mode, so the app does that, as with the Eyedropper. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{CancelReason, Cursor, IconId, PaintedCursor}; use craft_theme::Srgba; diff --git a/crates/imaging/src/ui/blur_pins/mod.rs b/crates/imaging/src/ui/blur_pins/mod.rs index ff5c99259..23e9538bc 100644 --- a/crates/imaging/src/ui/blur_pins/mod.rs +++ b/crates/imaging/src/ui/blur_pins/mod.rs @@ -18,9 +18,9 @@ mod grab; mod model; -mod overlay; -mod panel; -#[cfg(feature = "screen-testing")] +pub(crate) mod overlay; +pub(crate) mod panel; +#[cfg(feature = "suite")] pub(crate) mod stories; mod style; mod words; diff --git a/crates/imaging/src/ui/channels/mod.rs b/crates/imaging/src/ui/channels/mod.rs index 12272b4c5..875a16d1f 100644 --- a/crates/imaging/src/ui/channels/mod.rs +++ b/crates/imaging/src/ui/channels/mod.rs @@ -5,9 +5,9 @@ mod footer; mod labels; mod menu; mod model; -mod panel; +pub(crate) mod panel; mod rows; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; pub use footer::ChannelsFooterButton; diff --git a/crates/imaging/src/ui/color_range/mod.rs b/crates/imaging/src/ui/color_range/mod.rs index 4cae58410..e9d0c436f 100644 --- a/crates/imaging/src/ui/color_range/mod.rs +++ b/crates/imaging/src/ui/color_range/mod.rs @@ -10,11 +10,11 @@ //! - [`ColorRangeValue`]: the command's parameters. [`ColorSamples`] holds the sampled points and the order they were //! made in; its `pick` is also Replace Color's sampling rule. -mod dialog; +pub(crate) mod dialog; mod hosted; mod labels; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod value; pub use dialog::{ColorRangeDialog, ColorRangeOutput}; diff --git a/crates/imaging/src/ui/curve/mod.rs b/crates/imaging/src/ui/curve/mod.rs index 8ecb410ac..6ac9b238e 100644 --- a/crates/imaging/src/ui/curve/mod.rs +++ b/crates/imaging/src/ui/curve/mod.rs @@ -1,11 +1,11 @@ //! The curve editor: the tone curve value and its point rules, the graph, the preview and the gradient ramp. -mod editor; -mod graph; +pub(crate) mod editor; +pub(crate) mod graph; mod model; -mod preview; -mod ramp; -#[cfg(feature = "screen-testing")] +pub(crate) mod preview; +pub(crate) mod ramp; +#[cfg(feature = "suite")] pub(crate) mod stories; mod words; diff --git a/crates/imaging/src/ui/fill/mod.rs b/crates/imaging/src/ui/fill/mod.rs index 7653eea8d..e419bc8ec 100644 --- a/crates/imaging/src/ui/fill/mod.rs +++ b/crates/imaging/src/ui/fill/mod.rs @@ -22,14 +22,14 @@ //! [`FullWindowDialog`]: craft_ui::dialog::FullWindowDialog //! [`EditHistory`]: craft_behavior::EditHistory -mod bar; +pub(crate) mod bar; mod commands; mod lasso; mod overlay; -mod panel; -mod preview_pane; +pub(crate) mod panel; +pub(crate) mod preview_pane; mod session; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; mod tool; mod words; diff --git a/crates/imaging/src/ui/filter_gallery/mod.rs b/crates/imaging/src/ui/filter_gallery/mod.rs index 1452e91ed..ca7f5ad08 100644 --- a/crates/imaging/src/ui/filter_gallery/mod.rs +++ b/crates/imaging/src/ui/filter_gallery/mod.rs @@ -21,12 +21,12 @@ //! [`EditHistory`]: craft_behavior::EditHistory mod catalog; -mod parameters; +pub(crate) mod parameters; mod session; -mod stack; -#[cfg(feature = "screen-testing")] +pub(crate) mod stack; +#[cfg(feature = "suite")] pub(crate) mod stories; -mod tree; +pub(crate) mod tree; mod words; pub use catalog::{FilterCatalog, FilterCategory, FilterGallerySource, FilterIndex, GalleryFilter, GalleryThumb}; diff --git a/crates/imaging/src/ui/histogram/mod.rs b/crates/imaging/src/ui/histogram/mod.rs index ab2799cf6..da219a9ba 100644 --- a/crates/imaging/src/ui/histogram/mod.rs +++ b/crates/imaging/src/ui/histogram/mod.rs @@ -7,8 +7,8 @@ mod data; pub mod paint; -mod plot; -#[cfg(feature = "screen-testing")] +pub(crate) mod plot; +#[cfg(feature = "suite")] pub(crate) mod stories; mod words; diff --git a/crates/imaging/src/ui/layer_style/blend_if/mod.rs b/crates/imaging/src/ui/layer_style/blend_if/mod.rs index 21d6a8f8f..9f35c0d94 100644 --- a/crates/imaging/src/ui/layer_style/blend_if/mod.rs +++ b/crates/imaging/src/ui/layer_style/blend_if/mod.rs @@ -1,7 +1,7 @@ //! `BlendIfBar`: one Blend If slider (This Layer or Underlying Layer) with its four handles, over `ThumbRow`. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{EditEvents, Mixed}; use craft_ui::contract::{Bind, EditResponse, Props as _, Show as _, ShowContainer as _}; diff --git a/crates/imaging/src/ui/layer_style/contour/mod.rs b/crates/imaging/src/ui/layer_style/contour/mod.rs index c9f7914f5..c2f410b15 100644 --- a/crates/imaging/src/ui/layer_style/contour/mod.rs +++ b/crates/imaging/src/ui/layer_style/contour/mod.rs @@ -2,8 +2,8 @@ //! the contour as a curve. mod editor; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/imaging/src/ui/layer_style/mod.rs b/crates/imaging/src/ui/layer_style/mod.rs index ecaa2ceea..1af53d05a 100644 --- a/crates/imaging/src/ui/layer_style/mod.rs +++ b/crates/imaging/src/ui/layer_style/mod.rs @@ -22,16 +22,16 @@ //! } //! ``` -mod blend_if; +pub(crate) mod blend_if; mod blending; -mod contour; -mod dialog; -mod hosted; +pub(crate) mod contour; +pub(crate) mod dialog; +pub(crate) mod hosted; mod labels; mod list; mod page; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod styles; pub use blend_if::{BlendIfBar, BlendIfWords}; diff --git a/crates/imaging/src/ui/layer_style/stories.rs b/crates/imaging/src/ui/layer_style/stories.rs index 522739f13..9a8fbf0c9 100644 --- a/crates/imaging/src/ui/layer_style/stories.rs +++ b/crates/imaging/src/ui/layer_style/stories.rs @@ -157,28 +157,62 @@ fn layer_style_styles(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { host(ui, data, || page_of(&[EffectKind::DropShadow], Some(LayerStylePage::Styles)), &rgb(&words)) } -/// One story per effect kind: the dialog on that effect's page. -macro_rules! effect_stories { - ($($name:ident => $kind:ident),* $(,)?) => { - $( - #[story(LayerStyleDialog<'static>, covers = [], drive = Drive::Never)] - fn $name(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { - let words = Env::of(ui).words::(); - host(ui, data, || page_of(&[EffectKind::$kind], None), &rgb(&words)) - } - )* - }; +#[story(LayerStyleDialog<'static>, covers = [], drive = Drive::Never)] +fn layer_style_bevel_emboss(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let words = Env::of(ui).words::(); + host(ui, data, || page_of(&[EffectKind::BevelEmboss], None), &rgb(&words)) } -effect_stories! { - layer_style_bevel_emboss => BevelEmboss, - layer_style_stroke => Stroke, - layer_style_inner_shadow => InnerShadow, - layer_style_inner_glow => InnerGlow, - layer_style_satin => Satin, - layer_style_color_overlay => ColorOverlay, - layer_style_gradient_overlay => GradientOverlay, - layer_style_pattern_overlay => PatternOverlay, - layer_style_outer_glow => OuterGlow, - layer_style_drop_shadow => DropShadow, +#[story(LayerStyleDialog<'static>, covers = [], drive = Drive::Never)] +fn layer_style_stroke(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let words = Env::of(ui).words::(); + host(ui, data, || page_of(&[EffectKind::Stroke], None), &rgb(&words)) +} + +#[story(LayerStyleDialog<'static>, covers = [], drive = Drive::Never)] +fn layer_style_inner_shadow(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let words = Env::of(ui).words::(); + host(ui, data, || page_of(&[EffectKind::InnerShadow], None), &rgb(&words)) +} + +#[story(LayerStyleDialog<'static>, covers = [], drive = Drive::Never)] +fn layer_style_inner_glow(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let words = Env::of(ui).words::(); + host(ui, data, || page_of(&[EffectKind::InnerGlow], None), &rgb(&words)) +} + +#[story(LayerStyleDialog<'static>, covers = [], drive = Drive::Never)] +fn layer_style_satin(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let words = Env::of(ui).words::(); + host(ui, data, || page_of(&[EffectKind::Satin], None), &rgb(&words)) +} + +#[story(LayerStyleDialog<'static>, covers = [], drive = Drive::Never)] +fn layer_style_color_overlay(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let words = Env::of(ui).words::(); + host(ui, data, || page_of(&[EffectKind::ColorOverlay], None), &rgb(&words)) +} + +#[story(LayerStyleDialog<'static>, covers = [], drive = Drive::Never)] +fn layer_style_gradient_overlay(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let words = Env::of(ui).words::(); + host(ui, data, || page_of(&[EffectKind::GradientOverlay], None), &rgb(&words)) +} + +#[story(LayerStyleDialog<'static>, covers = [], drive = Drive::Never)] +fn layer_style_pattern_overlay(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let words = Env::of(ui).words::(); + host(ui, data, || page_of(&[EffectKind::PatternOverlay], None), &rgb(&words)) +} + +#[story(LayerStyleDialog<'static>, covers = [], drive = Drive::Never)] +fn layer_style_outer_glow(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let words = Env::of(ui).words::(); + host(ui, data, || page_of(&[EffectKind::OuterGlow], None), &rgb(&words)) +} + +#[story(LayerStyleDialog<'static>, covers = [], drive = Drive::Never)] +fn layer_style_drop_shadow(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let words = Env::of(ui).words::(); + host(ui, data, || page_of(&[EffectKind::DropShadow], None), &rgb(&words)) } diff --git a/crates/imaging/src/ui/liquify/canvas.rs b/crates/imaging/src/ui/liquify/canvas.rs index a51bef5db..d50245784 100644 --- a/crates/imaging/src/ui/liquify/canvas.rs +++ b/crates/imaging/src/ui/liquify/canvas.rs @@ -1,7 +1,7 @@ //! Liquify's canvas: the canvas tool, the backdrop layering, the freeze mask source, the lasso line, the mesh. mod backdrop; -mod lasso; +pub(crate) mod lasso; mod mesh; pub(super) use backdrop::MaskAtTexel; diff --git a/crates/imaging/src/ui/liquify/mod.rs b/crates/imaging/src/ui/liquify/mod.rs index b0346aebf..a33eb6154 100644 --- a/crates/imaging/src/ui/liquify/mod.rs +++ b/crates/imaging/src/ui/liquify/mod.rs @@ -44,11 +44,11 @@ //! [`FullWindowSide`]: craft_ui::dialog::FullWindowSide //! [`EditHistory`]: craft_behavior::EditHistory -mod canvas; +pub(crate) mod canvas; mod commands; -mod panel; +pub(crate) mod panel; mod session; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; mod tools; mod words; diff --git a/crates/imaging/src/ui/mask_view/mod.rs b/crates/imaging/src/ui/mask_view/mod.rs index a4ad4e47f..db736cdf5 100644 --- a/crates/imaging/src/ui/mask_view/mod.rs +++ b/crates/imaging/src/ui/mask_view/mod.rs @@ -20,10 +20,10 @@ //! SelectionOverlay::new("Selection", &proxy_mask).visible(state.view.recipe().ants).reduction(k).show_at(ui, canvas_rect); //! ``` -mod controls; +pub(crate) mod controls; mod keys; mod state; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; pub use controls::{MaskViewControls, MaskViewControlsOutput}; diff --git a/crates/imaging/src/ui/raw_develop/mod.rs b/crates/imaging/src/ui/raw_develop/mod.rs index 66e3023c0..98f0249be 100644 --- a/crates/imaging/src/ui/raw_develop/mod.rs +++ b/crates/imaging/src/ui/raw_develop/mod.rs @@ -13,14 +13,14 @@ //! [`FullWindowWorkspace`]: craft_ui::dialog::FullWindowWorkspace mod commands; -mod controls; -mod filmstrip; +pub(crate) mod controls; +pub(crate) mod filmstrip; mod mixer; mod preview; -mod scopes; +pub(crate) mod scopes; mod source; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod words; use std::cell::RefCell; diff --git a/crates/imaging/src/ui/scopes/mod.rs b/crates/imaging/src/ui/scopes/mod.rs index eff571c3e..b81bdee44 100644 --- a/crates/imaging/src/ui/scopes/mod.rs +++ b/crates/imaging/src/ui/scopes/mod.rs @@ -24,15 +24,15 @@ //! | Clipping | [`ClipWarning`], [`ClippingOverlay`], [`ClippingMode`], [`ClippingWarnings`], [`ClippingDiagnostic`] | //! | Vectorscope alone | [`VectorscopePlot`], [`scope_point`] | -mod clipping; +pub(crate) mod clipping; mod menu; -mod panel; +pub(crate) mod panel; mod plot; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; -mod vectorscope; +pub(crate) mod vectorscope; mod words; -mod zones; +pub(crate) mod zones; pub use clipping::{ClipWarning, ClippingDiagnostic, ClippingFrame, ClippingMode, ClippingOverlay, ClippingWarnings}; pub use menu::{ScopeCommand, ScopeMenuAction}; diff --git a/crates/imaging/src/ui/select/mod.rs b/crates/imaging/src/ui/select/mod.rs index 780ddceeb..ca49a38e4 100644 --- a/crates/imaging/src/ui/select/mod.rs +++ b/crates/imaging/src/ui/select/mod.rs @@ -55,7 +55,7 @@ mod lasso; mod magnetic; mod marquee; mod polygon; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; pub mod operations; diff --git a/crates/imaging/src/ui/select_mask/mod.rs b/crates/imaging/src/ui/select_mask/mod.rs index 4982a9b00..3d8ed06ce 100644 --- a/crates/imaging/src/ui/select_mask/mod.rs +++ b/crates/imaging/src/ui/select_mask/mod.rs @@ -38,12 +38,12 @@ //! [`EditHistory`]: craft_behavior::EditHistory //! [`FullWindowWorkspace`]: craft_ui::dialog::FullWindowWorkspace -mod bar; +pub(crate) mod bar; mod commands; mod edits; -mod panel; +pub(crate) mod panel; mod session; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; mod tools; mod words; diff --git a/crates/imaging/src/ui/select_mask/stories.rs b/crates/imaging/src/ui/select_mask/stories.rs index 40a341d2b..2bfd781a7 100644 --- a/crates/imaging/src/ui/select_mask/stories.rs +++ b/crates/imaging/src/ui/select_mask/stories.rs @@ -81,27 +81,35 @@ fn viewing(view: MaskViewMode) -> SelectMaskSettings { SelectMaskSettings { view, ..SelectMaskSettings::default() } } -/// One story per view: the workspace with that view chosen. -macro_rules! view_story { - ($name:ident, $view:expr) => { - #[story(SelectMaskWorkspace, covers = [], drive = Drive::Never)] - fn $name(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { - show_workspace(ui, data, viewing($view), false) - } - }; -} - #[story(SelectMaskWorkspace, covers = [Default], drive = Drive::Never)] fn workspace(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { show_workspace(ui, data, SelectMaskSettings::default(), false) } -view_story!(view_marching_ants, MaskViewMode::MarchingAnts); -view_story!(view_overlay, MaskViewMode::Overlay); -view_story!(view_on_black, MaskViewMode::OnBlack); -view_story!(view_on_white, MaskViewMode::OnWhite); -view_story!(view_black_and_white, MaskViewMode::BlackAndWhite); -view_story!(view_on_layers, MaskViewMode::OnLayers); +#[story(SelectMaskWorkspace, covers = [], drive = Drive::Never)] +fn view_marching_ants(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + show_workspace(ui, data, viewing(MaskViewMode::MarchingAnts), false) +} +#[story(SelectMaskWorkspace, covers = [], drive = Drive::Never)] +fn view_overlay(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + show_workspace(ui, data, viewing(MaskViewMode::Overlay), false) +} +#[story(SelectMaskWorkspace, covers = [], drive = Drive::Never)] +fn view_on_black(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + show_workspace(ui, data, viewing(MaskViewMode::OnBlack), false) +} +#[story(SelectMaskWorkspace, covers = [], drive = Drive::Never)] +fn view_on_white(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + show_workspace(ui, data, viewing(MaskViewMode::OnWhite), false) +} +#[story(SelectMaskWorkspace, covers = [], drive = Drive::Never)] +fn view_black_and_white(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + show_workspace(ui, data, viewing(MaskViewMode::BlackAndWhite), false) +} +#[story(SelectMaskWorkspace, covers = [], drive = Drive::Never)] +fn view_on_layers(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + show_workspace(ui, data, viewing(MaskViewMode::OnLayers), false) +} #[story(SelectMaskWorkspace, covers = [], drive = Drive::Never)] fn workspace_with_refinements(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { diff --git a/crates/imaging/src/ui/selection/mod.rs b/crates/imaging/src/ui/selection/mod.rs index 96bab02a5..849aa4e49 100644 --- a/crates/imaging/src/ui/selection/mod.rs +++ b/crates/imaging/src/ui/selection/mod.rs @@ -9,8 +9,8 @@ //! [`PreviewMode`]: crate::selection::PreviewMode //! [`QuickMaskLook`]: crate::selection::QuickMaskLook -mod overlay; -#[cfg(feature = "screen-testing")] +pub(crate) mod overlay; +#[cfg(feature = "suite")] pub(crate) mod stories; pub use overlay::{OutlineSource, PointMap, SelectionOverlay, SelectionOverlayOutput, SelectionWords}; diff --git a/crates/imaging/src/ui/transform_preview/mod.rs b/crates/imaging/src/ui/transform_preview/mod.rs index d89c55877..3c2af1c32 100644 --- a/crates/imaging/src/ui/transform_preview/mod.rs +++ b/crates/imaging/src/ui/transform_preview/mod.rs @@ -20,7 +20,7 @@ //! ``` mod maps; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; mod styled; mod textures; diff --git a/crates/imaging/src/ui/vanishing_point/editor/mod.rs b/crates/imaging/src/ui/vanishing_point/editor/mod.rs index 10d6f2b8f..ed41f5ebc 100644 --- a/crates/imaging/src/ui/vanishing_point/editor/mod.rs +++ b/crates/imaging/src/ui/vanishing_point/editor/mod.rs @@ -2,7 +2,7 @@ //! ([`VanishingPointPass`]) and its two faces on a canvas, [`VanishingPointTool`] (Create Plane, the paste and Stamp //! presses) and [`VanishingPlanes`] (the planes on the canvas, each corner and edge node a part). -mod control; +pub(crate) mod control; mod tool; mod work; diff --git a/crates/imaging/src/ui/vanishing_point/mod.rs b/crates/imaging/src/ui/vanishing_point/mod.rs index 507b004ba..c78d00647 100644 --- a/crates/imaging/src/ui/vanishing_point/mod.rs +++ b/crates/imaging/src/ui/vanishing_point/mod.rs @@ -20,14 +20,14 @@ //! [`FullWindowDialog`]: craft_ui::dialog::FullWindowDialog //! [`EditHistory`]: craft_behavior::EditHistory -mod bar; +pub(crate) mod bar; mod command; mod commands; mod draw; -mod editor; +pub(crate) mod editor; mod new_plane; mod planes; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; mod style; mod words; diff --git a/crates/imaging/src/ui/warp/cylinder.rs b/crates/imaging/src/ui/warp/cylinder.rs index c5b29e473..526229537 100644 --- a/crates/imaging/src/ui/warp/cylinder.rs +++ b/crates/imaging/src/ui/warp/cylinder.rs @@ -21,8 +21,8 @@ use egui::{CornerRadius, Pos2, Rect, Response, Vec2}; use super::WarpMesh; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The bend of both arcs the Cylinder starts with, in units of the half axis: about a quarter of the width. const DEFAULT_DEPTH: f64 = 0.5; diff --git a/crates/imaging/src/ui/warp/mod.rs b/crates/imaging/src/ui/warp/mod.rs index 32987fa8a..5712e026f 100644 --- a/crates/imaging/src/ui/warp/mod.rs +++ b/crates/imaging/src/ui/warp/mod.rs @@ -5,15 +5,15 @@ //! Perspective Warp ([`perspective`]), the Cylinder warp's editor ([`CylinderWarp`]) and the one painter of a deformed mesh's lines //! (`MeshLines`). -mod cylinder; -mod fields; -mod grid; -mod mesh; +pub(crate) mod cylinder; +pub(crate) mod fields; +pub(crate) mod grid; +pub(crate) mod mesh; mod model; pub mod perspective; pub mod pin; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use cylinder::{CylinderHandle, CylinderValues, CylinderWarp, CylinderWarpOutput, CylinderWarpStyle}; pub use fields::{WarpFieldValues, WarpFields, WarpFieldsEdit, WarpFieldsOutput, WarpFieldsWords, WarpGridChoice, WarpStyleEntry}; diff --git a/crates/imaging/src/ui/warp/perspective/mod.rs b/crates/imaging/src/ui/warp/perspective/mod.rs index 585877dcd..b82705888 100644 --- a/crates/imaging/src/ui/warp/perspective/mod.rs +++ b/crates/imaging/src/ui/warp/perspective/mod.rs @@ -2,10 +2,10 @@ //! ([`PerspectiveSession`], [`PerspectiveWarp`], [`PerspectiveBar`]). The warp map is the app's; //! the warped picture is drawn by the transform preview through `PreviewMap::function`. -mod bar; -mod overlay; +pub(crate) mod bar; +pub(crate) mod overlay; mod session; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; pub use bar::{PerspectiveBar, PerspectiveBarOutput, PerspectiveBarWords}; diff --git a/crates/imaging/src/ui/warp/pin/mod.rs b/crates/imaging/src/ui/warp/pin/mod.rs index a0fc21393..dc6215a01 100644 --- a/crates/imaging/src/ui/warp/pin/mod.rs +++ b/crates/imaging/src/ui/warp/pin/mod.rs @@ -2,10 +2,10 @@ //! [`PinWarpBar`]). The solver is the app's ([`PinSolver`]); the warped picture is drawn by the //! transform preview through `PreviewMap::pins`. -mod bar; -mod overlay; +pub(crate) mod bar; +pub(crate) mod overlay; mod session; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; pub use bar::{PinWarpBar, PinWarpBarOutput, PinWarpBarWords}; diff --git a/crates/imaging/src/ui/wide_angle/mod.rs b/crates/imaging/src/ui/wide_angle/mod.rs index 99593ec61..81cfb07bb 100644 --- a/crates/imaging/src/ui/wide_angle/mod.rs +++ b/crates/imaging/src/ui/wide_angle/mod.rs @@ -15,10 +15,10 @@ //! [`EditHistory`]: craft_behavior::EditHistory mod commands; -mod lines; -mod panel; +pub(crate) mod lines; +pub(crate) mod panel; mod session; -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; mod tool; mod words; diff --git a/crates/imaging/tests/it/main.rs b/crates/imaging/tests/it/main.rs index a6c7a4b9b..2a7b0442b 100644 --- a/crates/imaging/tests/it/main.rs +++ b/crates/imaging/tests/it/main.rs @@ -1,28 +1,28 @@ //! The screen tests of craft-imaging, folded into the lib's test target. -mod adjust_editors; -mod adjust_tone; -mod blur_pins; -mod channels_delete; -mod color_range; -mod contour_field; -mod curve; -mod fill; -mod filter_gallery; -mod histogram; -mod hosted_dialogs; -mod layer_style; -mod liquify; -mod live_preview; -mod perspective_warp; -mod pin_warp; -mod raw_develop; -mod scopes; -mod select; -mod select_mask; -mod selection; -mod threshold; -mod transform_preview; -mod vanishing_point; -mod warp; -mod wide_angle; +pub(crate) mod adjust_editors; +pub(crate) mod adjust_tone; +pub(crate) mod blur_pins; +pub(crate) mod channels_delete; +pub(crate) mod color_range; +pub(crate) mod contour_field; +pub(crate) mod curve; +pub(crate) mod fill; +pub(crate) mod filter_gallery; +pub(crate) mod histogram; +pub(crate) mod hosted_dialogs; +pub(crate) mod layer_style; +pub(crate) mod liquify; +pub(crate) mod live_preview; +pub(crate) mod perspective_warp; +pub(crate) mod pin_warp; +pub(crate) mod raw_develop; +pub(crate) mod scopes; +pub(crate) mod select; +pub(crate) mod select_mask; +pub(crate) mod selection; +pub(crate) mod threshold; +pub(crate) mod transform_preview; +pub(crate) mod vanishing_point; +pub(crate) mod warp; +pub(crate) mod wide_angle; diff --git a/crates/layers/Cargo.toml b/crates/layers/Cargo.toml index f3d58a9d1..eede73357 100644 --- a/crates/layers/Cargo.toml +++ b/crates/layers/Cargo.toml @@ -16,8 +16,9 @@ workspace = true # UI-only: egui and craft-ui are plain dependencies, so there is no `ui` feature. [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] -# The stories, `mock` and the integration tests (`tests/it`). +# The test kit and `mock` helpers. screen-testing = ["craft-ui/testing"] [dependencies] @@ -37,4 +38,4 @@ serde_json = { workspace = true } name = "it" path = "tests/it/main.rs" harness = false -required-features = ["screen-testing"] +required-features = ["suite"] diff --git a/crates/layers/src/lib.rs b/crates/layers/src/lib.rs index 1881cc192..df20b8777 100644 --- a/crates/layers/src/lib.rs +++ b/crates/layers/src/lib.rs @@ -17,7 +17,9 @@ pub mod testing { use egui::accesskit::NodeId; use egui::{Context, Rect}; - craft_ui::testing_registered!(); + #[cfg(feature = "suite")] + + craft_ui::registry!(); /// The rect of the thumbnail that shows `part` of the layer `info`, in the row whose node is `row`, as the row /// recorded it last pass; `None` when the row shows no such thumbnail. `row` is the layer's row, or for diff --git a/crates/layers/src/ui/comps/mod.rs b/crates/layers/src/ui/comps/mod.rs index 122a463a6..29a752082 100644 --- a/crates/layers/src/ui/comps/mod.rs +++ b/crates/layers/src/ui/comps/mod.rs @@ -3,8 +3,8 @@ mod body; mod events; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod words; pub use events::{LayerCompsEvent, LayerCompsOutput, LayerCompsRowCommands}; diff --git a/crates/layers/src/ui/filter/mod.rs b/crates/layers/src/ui/filter/mod.rs index 09566dff0..beb2e9023 100644 --- a/crates/layers/src/ui/filter/mod.rs +++ b/crates/layers/src/ui/filter/mod.rs @@ -5,8 +5,8 @@ //! plain code, so a host's control channel can read and set the criteria (PhotoCraft's //! `ui.set layerFilter {by, kinds, name, effect, mode, attribute, color, smart}`) without the panel. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{EditEvent, IconId, Mixed, SelectionChange}; use craft_theme::{ControlSize, LabelColor}; diff --git a/crates/layers/src/ui/options/mod.rs b/crates/layers/src/ui/options/mod.rs index 9511e2752..6169c156a 100644 --- a/crates/layers/src/ui/options/mod.rs +++ b/crates/layers/src/ui/options/mod.rs @@ -3,8 +3,8 @@ //! `LayersSettings` is the panel's persisted section (`.settings(&mut ..)` on the panel); //! `LayersOptions` is the value the dialog edits and returns, held by the settings. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_ui::choice::{Checkbox, Radio, RadioGroup}; use craft_ui::contract::{Bind, FieldLayout, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel}; diff --git a/crates/layers/src/ui/panel/mod.rs b/crates/layers/src/ui/panel/mod.rs index 1402b2661..94aa032d6 100644 --- a/crates/layers/src/ui/panel/mod.rs +++ b/crates/layers/src/ui/panel/mod.rs @@ -11,8 +11,8 @@ mod events; mod footer; mod menu; mod row; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use drag::{LayersDrag, document_hash}; pub use events::{ diff --git a/crates/layers/src/ui/rows/mod.rs b/crates/layers/src/ui/rows/mod.rs index 71d97e9e5..614f7a586 100644 --- a/crates/layers/src/ui/rows/mod.rs +++ b/crates/layers/src/ui/rows/mod.rs @@ -1,7 +1,7 @@ //! `BlendRows`: Blend mode, Opacity, Lock and Fill as one block. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{EditEvent, EditEvents, IconId}; use craft_theme::ControlSize; diff --git a/crates/layers/tests/it/main.rs b/crates/layers/tests/it/main.rs index 0fb972e0e..6060bcd6f 100644 --- a/crates/layers/tests/it/main.rs +++ b/crates/layers/tests/it/main.rs @@ -1,14 +1,16 @@ //! The integration binary of craft-layers: every test is a registered trial. -mod blend_rows; -mod comps; -mod panel_drag_menu; -mod panel_filter; -mod panel_input; -mod panel_order; -mod panel_reveal; -mod panel_rows; +pub(crate) mod blend_rows; +pub(crate) mod comps; +pub(crate) mod panel_drag_menu; +pub(crate) mod panel_filter; +pub(crate) mod panel_input; +pub(crate) mod panel_order; +pub(crate) mod panel_reveal; +pub(crate) mod panel_rows; + +craft_ui::registry!(); fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_layers::testing::registered()); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register, craft_layers::testing::register])); } diff --git a/crates/menu/Cargo.toml b/crates/menu/Cargo.toml index 7876d5d3b..6e4c20eb1 100644 --- a/crates/menu/Cargo.toml +++ b/crates/menu/Cargo.toml @@ -25,9 +25,12 @@ serde = { workspace = true } serde_json = { workspace = true } [features] +suite = ["screen-testing", "craft-ui/suite"] screen-testing = ["craft-ui/testing"] [dev-dependencies] +# The menu integration runner needs the suite runner even when only screen-testing is selected. +craft-ui = { workspace = true, features = ["suite"] } # `default_fonts` so that the shortcuts dialog and native menu tests lay out text. egui = { workspace = true } diff --git a/crates/menu/src/bar.rs b/crates/menu/src/bar.rs index 20effdb29..1003e6708 100644 --- a/crates/menu/src/bar.rs +++ b/crates/menu/src/bar.rs @@ -8,8 +8,8 @@ //! choice reaches the app as a fired command with [`craft_ui::runtime::commands::FireSource::Menu`]. //! `Builtin::Quit` and `Builtin::Minimize` act on the root window through the runtime. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_keymap::{CommandRef, Platform}; use craft_ui::contract::{MemoProps, MemoView, Show as _, Stateless}; diff --git a/crates/menu/src/keytips.rs b/crates/menu/src/keytips.rs index 4592bfe54..faf29c351 100644 --- a/crates/menu/src/keytips.rs +++ b/crates/menu/src/keytips.rs @@ -1,8 +1,8 @@ //! `Keytips`: the Alt and F10 key hints of a ribbon. Badges over its tabs and controls name the letters that pick a //! tab or run a command, so the whole ribbon is reachable from the keyboard without moving focus off the document. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/menu/src/lib.rs b/crates/menu/src/lib.rs index 3c569058a..544c66114 100644 --- a/crates/menu/src/lib.rs +++ b/crates/menu/src/lib.rs @@ -101,7 +101,7 @@ mod documents; mod driver; mod help; mod keymap; -mod keytips; +pub(crate) mod keytips; mod language; mod layout; mod modal; @@ -138,5 +138,7 @@ pub use theme::{THEME_COMMAND, ThemeChoice, ThemeLabels, ThemeMenu, ThemeRow}; #[cfg(feature = "screen-testing")] /// The stories and words this crate registers, for the story tests. pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } diff --git a/crates/menu/src/ribbon.rs b/crates/menu/src/ribbon.rs index 6253fee5c..d40728871 100644 --- a/crates/menu/src/ribbon.rs +++ b/crates/menu/src/ribbon.rs @@ -1,10 +1,10 @@ //! The ribbon: a tab strip over a scrolling row of command groups. -mod gallery; +pub(crate) mod gallery; mod group; mod plan; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::borrow::Cow; use std::fmt::Debug; diff --git a/crates/menu/src/ribbon/gallery.rs b/crates/menu/src/ribbon/gallery.rs index 42e5f3b01..f26bb2528 100644 --- a/crates/menu/src/ribbon/gallery.rs +++ b/crates/menu/src/ribbon/gallery.rs @@ -25,8 +25,8 @@ use egui::{ColorImage, CornerRadius, Rect, Response, Ui, Vec2}; use super::GroupLevel; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; const TILE: PartKey = PartKey::new("tile"); const UP: PartKey = PartKey::new("up"); diff --git a/crates/menu/src/shortcuts/mod.rs b/crates/menu/src/shortcuts/mod.rs index a9e236f5a..e0a6de399 100644 --- a/crates/menu/src/shortcuts/mod.rs +++ b/crates/menu/src/shortcuts/mod.rs @@ -104,17 +104,17 @@ macro_rules! fill { mod codec; mod import_offer; -mod keyboard; +pub(crate) mod keyboard; mod pages; -mod recorder; +pub(crate) mod recorder; mod review; mod rows; mod sets; mod state; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub mod summary; -mod view; +pub(crate) mod view; mod words; pub use codec::ChordCodec; diff --git a/crates/menu/src/shortcuts/recorder.rs b/crates/menu/src/shortcuts/recorder.rs index affa21849..283776d9a 100644 --- a/crates/menu/src/shortcuts/recorder.rs +++ b/crates/menu/src/shortcuts/recorder.rs @@ -17,8 +17,8 @@ use craft_ui::runtime::focus::{self, FocusTarget, KeepKeys, KeyUse}; use craft_ui::style::{ComponentStyle, FocusLook, Ink, StyleCx, SurfaceKind, SurfaceLook, TextLook, TypeRole}; use egui::{Rect, Response, Ui, Vec2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The field claims bare Escape while recording, so it reaches the field as a chord (the keymap's recorder reads it as /// cancel) and neither leaves the row nor closes the dialog. diff --git a/crates/menu/src/shortcuts/view.rs b/crates/menu/src/shortcuts/view.rs index eb777588a..4676fc69f 100644 --- a/crates/menu/src/shortcuts/view.rs +++ b/crates/menu/src/shortcuts/view.rs @@ -7,10 +7,10 @@ mod bars; mod detail; mod header; -mod lists; -#[cfg(feature = "screen-testing")] -mod stories; -mod table; +pub(crate) mod lists; +#[cfg(feature = "suite")] +pub(crate) mod stories; +pub(crate) mod table; use std::borrow::Cow; diff --git a/crates/menu/tests/it/main.rs b/crates/menu/tests/it/main.rs index 0a5fd90c0..f7279b42b 100644 --- a/crates/menu/tests/it/main.rs +++ b/crates/menu/tests/it/main.rs @@ -2,15 +2,17 @@ #[cfg(target_os = "macos")] mod appkit; -mod keytips; -mod layout; -mod memo; -mod mnemonic; -mod native; -mod ribbon; -mod ribbon_gallery; +pub(crate) mod keytips; +pub(crate) mod layout; +pub(crate) mod memo; +pub(crate) mod mnemonic; +pub(crate) mod native; +pub(crate) mod ribbon; +pub(crate) mod ribbon_gallery; mod sample; -mod shortcuts; +pub(crate) mod shortcuts; + +craft_ui::registry!(); #[cfg(target_os = "macos")] const APPKIT_CHILD: &str = "--craft-menu-appkit-child"; @@ -31,5 +33,9 @@ fn main() { if std::env::args_os().skip(1).eq([std::ffi::OsString::from(APPKIT_CHILD)]) { return appkit::run(); } - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_menu::testing::registered()); + #[cfg(feature = "suite")] + let registry = craft_ui::testing::Registry::of(&[register, craft_menu::testing::register]); + #[cfg(not(feature = "suite"))] + let registry = craft_ui::testing::Registry::of(&[register]); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), ®istry); } diff --git a/crates/menu/tests/it/shortcuts/mod.rs b/crates/menu/tests/it/shortcuts/mod.rs index 5fd2a0e53..acb727361 100644 --- a/crates/menu/tests/it/shortcuts/mod.rs +++ b/crates/menu/tests/it/shortcuts/mod.rs @@ -1,8 +1,8 @@ //! The Keyboard Shortcuts dialog, driven pass by pass through `craft_ui::testing::Fixture`. mod fixture; -mod import_offer; -mod lists; -mod recorder; -mod rows; -mod sets; -mod tabs; +pub(crate) mod import_offer; +pub(crate) mod lists; +pub(crate) mod recorder; +pub(crate) mod rows; +pub(crate) mod sets; +pub(crate) mod tabs; diff --git a/crates/pages/Cargo.toml b/crates/pages/Cargo.toml index 660275aea..52189fd08 100644 --- a/crates/pages/Cargo.toml +++ b/crates/pages/Cargo.toml @@ -17,6 +17,7 @@ harness = false workspace = true [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # The page widgets (`craft_pages::ui`), on craft-ui. ui = ["dep:craft-behavior", "dep:craft-keymap", "dep:craft-ui", "dep:craft-theme", "dep:egui", "craft-text/ui"] @@ -35,6 +36,6 @@ craft-theme = { workspace = true, optional = true } egui = { workspace = true, optional = true } [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } egui = { workspace = true } craft-i18n = { workspace = true } diff --git a/crates/pages/src/lib.rs b/crates/pages/src/lib.rs index 0052021e8..e92aef7ba 100644 --- a/crates/pages/src/lib.rs +++ b/crates/pages/src/lib.rs @@ -22,11 +22,11 @@ pub mod layout; #[cfg(test)] -mod layout_tests; +pub(crate) mod layout_tests; pub mod numbering; pub mod range; #[cfg(test)] -mod range_tests; +pub(crate) mod range_tests; pub mod setup; #[cfg(feature = "ui")] pub mod ui; @@ -45,16 +45,19 @@ pub use setup::{ /// The stories and trials this crate registers. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } #[cfg(all(test, feature = "screen-testing"))] extern crate self as craft_pages; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/pages/src/ui/column_bar.rs b/crates/pages/src/ui/column_bar.rs index 13fb5497a..7d4fbc344 100644 --- a/crates/pages/src/ui/column_bar.rs +++ b/crates/pages/src/ui/column_bar.rs @@ -2,8 +2,8 @@ //! column widths. A divider moves only the two columns it divides (`craft_behavior::divider`, `Give::Pair`); each keeps //! its least share, and the other columns keep theirs. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::divider::{Give, Segment, resize, travel}; use craft_behavior::{Axis, Metrics, PartKey}; diff --git a/crates/pages/src/ui/grid.rs b/crates/pages/src/ui/grid.rs index 063bee593..c09dbda65 100644 --- a/crates/pages/src/ui/grid.rs +++ b/crates/pages/src/ui/grid.rs @@ -2,8 +2,8 @@ //! boundaries (violet) and the baseline grid (light blue, from its zoom threshold) are hairlines drawn over the //! pages, under the selection. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::view::PlacedPage; use craft_behavior::{Input, Metrics, Sense}; diff --git a/crates/pages/src/ui/header_footer.rs b/crates/pages/src/ui/header_footer.rs index 52611db91..bdc93c1b5 100644 --- a/crates/pages/src/ui/header_footer.rs +++ b/crates/pages/src/ui/header_footer.rs @@ -3,8 +3,8 @@ //! empty, a double click (or Enter on the focused section) starts editing it, and the app's editor takes the section's //! rectangle. What a section holds, its fields and the editor are the app's. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::kurbo::Point; use craft_behavior::{HitLevel, HitPriority, Input, Intent, Metrics, PartKey, Sense}; diff --git a/crates/pages/src/ui/list.rs b/crates/pages/src/ui/list.rs index b6498c983..a43d75b84 100644 --- a/crates/pages/src/ui/list.rs +++ b/crates/pages/src/ui/list.rs @@ -20,8 +20,8 @@ //! } //! ``` -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{ColumnKey, ColumnWidth, EditEvent, IconId, Mixed, Selection, SelectionChange, keyed}; use craft_ui::contract::{ diff --git a/crates/pages/src/ui/margins.rs b/crates/pages/src/ui/margins.rs index 29f4f996c..efcf5c34d 100644 --- a/crates/pages/src/ui/margins.rs +++ b/crates/pages/src/ui/margins.rs @@ -2,8 +2,8 @@ //! each ruler is the margin, the white the text area; the pointer over an edge shows a resize cursor and the margin's //! name, and a drag moves the margin as one edit gesture (one undo step). -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::ops::RangeInclusive; diff --git a/crates/pages/src/ui/marks.rs b/crates/pages/src/ui/marks.rs index da2516dc0..f1c32e4be 100644 --- a/crates/pages/src/ui/marks.rs +++ b/crates/pages/src/ui/marks.rs @@ -3,8 +3,8 @@ //! ° no-break spaces, ¶ paragraph ends, # the end of a story. Extras: the overset mark (a red + in the out port) on a //! frame whose story does not fit, and frame outlines with their in and out ports. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::kurbo::{Point, Rect}; use craft_behavior::{CanvasView, Input, Metrics, Sense}; diff --git a/crates/pages/src/ui/page_rulers.rs b/crates/pages/src/ui/page_rulers.rs index e19df84a0..d93d4a906 100644 --- a/crates/pages/src/ui/page_rulers.rs +++ b/crates/pages/src/ui/page_rulers.rs @@ -2,8 +2,8 @@ //! [`PageRulers`], which joins a [`TextRuler`], a [`VerticalRuler`] and //! [`MarginHandles`] around the page. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::kurbo::Point; use craft_behavior::{ diff --git a/crates/pages/src/ui/preview.rs b/crates/pages/src/ui/preview.rs index 9c0736c42..dfe1b5864 100644 --- a/crates/pages/src/ui/preview.rs +++ b/crates/pages/src/ui/preview.rs @@ -2,8 +2,8 @@ //! Files preview and VectorCraft's Place PDF page choice show it: the page as large as fits, "Page 3 of 12" under it, //! the arrow and Page keys to step from anywhere in the preview, Escape or Close to leave. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::view::PageSource; use craft_behavior::IconId; diff --git a/crates/pages/src/ui/range.rs b/crates/pages/src/ui/range.rs index abfe9ae5e..4ca48892c 100644 --- a/crates/pages/src/ui/range.rs +++ b/crates/pages/src/ui/range.rs @@ -2,8 +2,8 @@ //! page choices, showing the pages back in the same format; and `PageRangeOptions`, the All pages / Pages from-to / Subset rows of //! Acrobat's Page Range Options. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{Codec, NotAValue, NumberCodec}; use craft_ui::buttons::IconButton; diff --git a/crates/pages/src/ui/reading.rs b/crates/pages/src/ui/reading.rs index 21fc7a7c1..efab6a379 100644 --- a/crates/pages/src/ui/reading.rs +++ b/crates/pages/src/ui/reading.rs @@ -23,8 +23,8 @@ use egui::{CornerRadius, Pos2, Rect, Response, Ui, Vec2, pos2, vec2}; use super::view::PageSource; use crate::layout::SCREEN_POINTS_PER_POINT; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The page-turn parts: one over each gap between the columns and one over each side margin, indexed from the left. /// A click on one turns toward its side and a swipe starting on one turns by the swipe's direction. diff --git a/crates/pages/src/ui/setup.rs b/crates/pages/src/ui/setup.rs index c73f45061..b97e73a46 100644 --- a/crates/pages/src/ui/setup.rs +++ b/crates/pages/src/ui/setup.rs @@ -8,8 +8,8 @@ //! if let Some(choice) = PageLayoutMenus::new(&doc.page_setup()).unit(prefs.unit).margins(ui, &margins_button) { doc.apply(choice) } //! ``` -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::ops::RangeInclusive; diff --git a/crates/pages/src/ui/table/mod.rs b/crates/pages/src/ui/table/mod.rs index 3fb3b081d..ef77b1bf3 100644 --- a/crates/pages/src/ui/table/mod.rs +++ b/crates/pages/src/ui/table/mod.rs @@ -6,8 +6,8 @@ pub mod edges; pub mod properties; pub mod selection; pub mod size_picker; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use edges::{BorderEdges, BorderPreset, EdgeKey, EdgeLook, EdgePicker, EdgePickerStyle, EdgePickerWords, SampleArea}; pub use properties::{CellAlign, RowHeight, TableChange, TableProperties, TablePropertiesOutput, TablePropertiesWords, TableValues, TextDirection}; diff --git a/crates/pages/src/ui/text_selection.rs b/crates/pages/src/ui/text_selection.rs index 0380d181e..9af332b07 100644 --- a/crates/pages/src/ui/text_selection.rs +++ b/crates/pages/src/ui/text_selection.rs @@ -17,8 +17,8 @@ use egui::{CornerRadius, Pos2, Response, Vec2, pos2}; use super::view::PlacedPage; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// A page's text as the selection reads it, glyph by glyph in reading order. Rectangles are page points (origin /// top-left). diff --git a/crates/pages/src/ui/thumbnails.rs b/crates/pages/src/ui/thumbnails.rs index 2f5e54fbe..0a293d644 100644 --- a/crates/pages/src/ui/thumbnails.rs +++ b/crates/pages/src/ui/thumbnails.rs @@ -20,8 +20,8 @@ //! } //! ``` -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::view::PageSource; use craft_behavior::{EditEvent, IconId, Selection, SelectionChange, keyed}; diff --git a/crates/pages/src/ui/view.rs b/crates/pages/src/ui/view.rs index cb5ce1c0c..a476ef701 100644 --- a/crates/pages/src/ui/view.rs +++ b/crates/pages/src/ui/view.rs @@ -18,9 +18,9 @@ //! if let Some(view) = reply.and_then(|reply| reply.view) { out.adopt(&mut view_state, &view); } //! ``` -mod pictures; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod pictures; +#[cfg(feature = "suite")] +pub(crate) mod stories; use self::pictures::{PageMetrics, PagePictures}; use super::access::AccessDescriber; diff --git a/crates/pages/tests/it/main.rs b/crates/pages/tests/it/main.rs index bfc963c2a..2d3261062 100644 --- a/crates/pages/tests/it/main.rs +++ b/crates/pages/tests/it/main.rs @@ -1,10 +1,10 @@ //! The screen tests of craft-pages, folded into the lib's test target. -mod access; -mod range; -mod rulers; -mod setup; -mod size_picker; -mod text_tables; -mod thumbnails; -mod views; +pub(crate) mod access; +pub(crate) mod range; +pub(crate) mod rulers; +pub(crate) mod setup; +pub(crate) mod size_picker; +pub(crate) mod text_tables; +pub(crate) mod thumbnails; +pub(crate) mod views; diff --git a/crates/print/Cargo.toml b/crates/print/Cargo.toml index a159747fa..cfd44560c 100644 --- a/crates/print/Cargo.toml +++ b/crates/print/Cargo.toml @@ -14,6 +14,7 @@ autotests = false harness = false [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # The printer and job settings widgets (`craft_print::ui`). ui = ["dep:craft-behavior", "dep:craft-ui", "dep:egui"] @@ -74,7 +75,7 @@ wasm-bindgen = "0.2" web-sys = { version = "0.3", features = ["Blob", "BlobPropertyBag", "Url", "HtmlIFrameElement", "HtmlElement", "Element", "Node", "Document", "Window", "CssStyleDeclaration"] } [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } tempfile = "3" roxmltree = "0.21" miniz_oxide = "0.9" diff --git a/crates/print/src/cups/mod.rs b/crates/print/src/cups/mod.rs index 94df2070b..970745d5a 100644 --- a/crates/print/src/cups/mod.rs +++ b/crates/print/src/cups/mod.rs @@ -16,7 +16,7 @@ #[cfg(test)] #[cfg(unix)] -mod tests; +pub(crate) mod tests; use super::{Duplex, Error, Job, Printer, Scaling}; use std::io::{Read, Write}; diff --git a/crates/print/src/lib.rs b/crates/print/src/lib.rs index 3308cafa4..c2e2765d7 100644 --- a/crates/print/src/lib.rs +++ b/crates/print/src/lib.rs @@ -17,19 +17,19 @@ pub mod cups; pub mod spool; #[cfg(any(test, windows))] -mod progress; +pub(crate) mod progress; #[cfg(any(test, windows))] -mod sheets; +pub(crate) mod sheets; #[cfg(test)] -mod spool_tests; +pub(crate) mod spool_tests; #[cfg(test)] -mod tests; +pub(crate) mod tests; #[cfg(any(test, windows))] -mod ticket; +pub(crate) mod ticket; #[cfg(windows)] -mod windows; +pub(crate) mod windows; #[cfg(any(test, windows))] -mod xml; +pub(crate) mod xml; /// Native Windows driver settings, printable geometry and explicit RGB/GDI transport. /// Callers perform ICC conversion and compose page pixels/vector strokes. Other platforms @@ -45,7 +45,9 @@ pub mod ui; /// The registrations of this crate's UI types, for its integration binary. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } /// A system spooler failure. Document permissions belong to the caller. @@ -1093,9 +1095,10 @@ pub fn command_preview(job: &Job) -> Result, Error> { extern crate self as craft_print; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/print/src/progress.rs b/crates/print/src/progress.rs index a02de2865..faf4d8d62 100644 --- a/crates/print/src/progress.rs +++ b/crates/print/src/progress.rs @@ -26,7 +26,7 @@ pub(crate) fn run( } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/print/src/sheets.rs b/crates/print/src/sheets.rs index 4b61925e6..1893fd2a3 100644 --- a/crates/print/src/sheets.rs +++ b/crates/print/src/sheets.rs @@ -51,4 +51,4 @@ pub(crate) use update::Repeat; #[cfg(test)] #[path = "tests/pdf_bounds.rs"] -mod tests; +pub(crate) mod tests; diff --git a/crates/print/src/spool_tests.rs b/crates/print/src/spool_tests.rs index 1a0bdfc02..4627f3bc2 100644 --- a/crates/print/src/spool_tests.rs +++ b/crates/print/src/spool_tests.rs @@ -199,13 +199,18 @@ fn stand_in_print_helper() { } /// Launches [`stand_in_print_helper`] over `directory` in `mode`, marking its stages in `marks`. -fn helper_command(directory: &Path, marks: &Path, mode: &str) -> std::io::Result { +fn helper_command(directory: &Path, marks: &Path, mode: &str, may_be_killed: bool) -> std::io::Result { let mut command = Command::new(std::env::current_exe()?); command .args(["--exact", "spool_tests::stand_in_print_helper", "--nocapture", "--"]) .env(PRINT_DIR, directory) .env(PRINT_MARKS, marks) .env(PRINT_MODE, mode); + // A force-killed child can leave a partial LLVM profile; keep it in this trial's + // temporary directory while normally exiting children retain their coverage. + if may_be_killed && std::env::var_os("LLVM_PROFILE_FILE").is_some() { + command.env("LLVM_PROFILE_FILE", marks.join("killed-%p-%m.profraw")); + } Ok(command) } @@ -224,14 +229,19 @@ fn wait_for(path: &Path) { } /// Runs `submission` on a thread with the child in `mode`; the receiver gets its input folder. -fn submit_in(submission: &Submission, marks: &Path, mode: &'static str) -> (std::thread::JoinHandle>, Receiver) { +fn submit_in( + submission: &Submission, + marks: &Path, + mode: &'static str, + may_be_killed: bool, +) -> (std::thread::JoinHandle>, Receiver) { let worker = submission.clone(); let marks = marks.to_path_buf(); let (folder, folders) = channel(); let running = std::thread::spawn(move || { worker.submit_with(PDF, &job(), |directory| { folder.send(directory.to_path_buf()).unwrap(); - helper_command(directory, &marks, mode) + helper_command(directory, &marks, mode, may_be_killed) }) }); (running, folders) @@ -261,7 +271,7 @@ fn a_cancel_during_startup_never_starts_the_driver() { worker.submit_with(PDF, &job(), |directory| { started.send(directory.to_path_buf()).unwrap(); wait.recv().unwrap(); - helper_command(directory, &held, "held") + helper_command(directory, &held, "held", true) }) }); let directory = starting.recv_timeout(LIMIT).unwrap(); @@ -272,7 +282,7 @@ fn a_cancel_during_startup_never_starts_the_driver() { // Cancelled while the child is waking and has not acknowledged anything. let submission = Submission::new(); - let (running, folders) = submit_in(&submission, marks.path(), "waking"); + let (running, folders) = submit_in(&submission, marks.path(), "waking", true); let directory = folders.recv_timeout(LIMIT).unwrap(); wait_for(&marks.path().join("waking")); assert!(submission.cancel(), "a process without a start grant cannot send anything"); @@ -286,7 +296,7 @@ fn a_cancel_during_startup_never_starts_the_driver() { fn a_refusal_while_sending_keeps_the_job() { let marks = tempfile::tempdir().unwrap(); let submission = Submission::new(); - let (running, folders) = submit_in(&submission, marks.path(), "sending"); + let (running, folders) = submit_in(&submission, marks.path(), "sending", false); let directory = folders.recv_timeout(LIMIT).unwrap(); wait_for(&marks.path().join("sending")); assert!(!submission.cancel(), "a sending job refuses cancellation"); @@ -303,7 +313,7 @@ fn a_refusal_while_sending_keeps_the_job() { fn a_cancelled_driver_does_not_block_the_next_job() { let marks = tempfile::tempdir().unwrap(); let submission = Submission::new(); - let (running, folders) = submit_in(&submission, marks.path(), "held"); + let (running, folders) = submit_in(&submission, marks.path(), "held", true); let directory = folders.recv_timeout(LIMIT).unwrap(); wait_for(&marks.path().join("driver")); assert!(!directory.join("input.pdf").exists(), "the stalled driver retains no plaintext PDF"); @@ -311,7 +321,7 @@ fn a_cancelled_driver_does_not_block_the_next_job() { assert!(submission.cancel(), "a stalled driver still acknowledges cancellation"); let next_marks = tempfile::tempdir().unwrap(); let next = Submission::new(); - assert_eq!(next.submit_with(PDF, &job(), |dir| helper_command(dir, next_marks.path(), "ready")), Ok("spooled synthetic job".into())); + assert_eq!(next.submit_with(PDF, &job(), |dir| helper_command(dir, next_marks.path(), "ready", false)), Ok("spooled synthetic job".into())); assert_eq!(running.join().unwrap(), Err(CANCELLED.into())); assert!(!directory.exists(), "the reaped helper's PDF and settings were removed"); assert!(!next.cancel(), "a completed job keeps its receipt"); @@ -328,7 +338,7 @@ fn helper_crashes_are_errors_and_inputs_are_bounded() { Submission::new() .submit_with(PDF, &job(), |dir| { inputs = Some(dir.to_path_buf()); - helper_command(dir, marks.path(), "crash") + helper_command(dir, marks.path(), "crash", false) }) .is_err() ); @@ -353,7 +363,7 @@ fn helper_crashes_are_errors_and_inputs_are_bounded() { let folder = tempfile::tempdir().unwrap(); std::fs::write(folder.path().join("job.json"), serde_json::to_vec(&Request::from_job(&job())).unwrap()).unwrap(); std::fs::write(folder.path().join("input.pdf"), PDF).unwrap(); - let mut child = helper_command(folder.path(), marks.path(), "held") + let mut child = helper_command(folder.path(), marks.path(), "held", false) .unwrap() .stdin(Stdio::piped()) .stdout(Stdio::null()) diff --git a/crates/print/src/tests.rs b/crates/print/src/tests.rs index 10b8a3199..cc86e6da6 100644 --- a/crates/print/src/tests.rs +++ b/crates/print/src/tests.rs @@ -2,7 +2,7 @@ use super::*; use crate as spool; use craft_ui::testing::trial; -mod windows_native; +pub(crate) mod windows_native; /// Set on the child process when a test runs this test binary as a stand-in for `lp`. const STAND_IN_LP: &str = "CRAFT_STAND_IN_LP"; @@ -210,7 +210,7 @@ fn macos_offers_auto_select_where_the_driver_would_pick_its_default_tray() { } #[cfg(all(unix, not(target_arch = "wasm32")))] -mod lpstat_limits { +pub(crate) mod lpstat_limits { use super::*; use craft_ui::testing::trial; use std::process::Command; diff --git a/crates/print/src/ticket.rs b/crates/print/src/ticket.rs index 7436a7b67..fdcc07760 100644 --- a/crates/print/src/ticket.rs +++ b/crates/print/src/ticket.rs @@ -868,4 +868,4 @@ pub(crate) fn job_filename(title: &str) -> String { } #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/print/src/ui/mod.rs b/crates/print/src/ui/mod.rs index 5ee97c047..6d3f937a7 100644 --- a/crates/print/src/ui/mod.rs +++ b/crates/print/src/ui/mod.rs @@ -1,10 +1,10 @@ //! Printer selection and asynchronous job feedback, independent of any spooler or document. //! Hosts provide workers; applications own PDF generation, commands and translated wording. -mod dialog; -mod panel; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod dialog; +pub(crate) mod panel; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use dialog::{HostedPrint, PrintAnswer, PrintDialog, PrintDialogOutput, PrintDialogWords, PrintFinish, PrintMarks, PrintSection, PrintSheet}; pub use panel::{PrintPanel, PrintPanelOutput, PrintWords}; diff --git a/crates/print/src/windows.rs b/crates/print/src/windows.rs index f3fbc88e2..d783201ee 100644 --- a/crates/print/src/windows.rs +++ b/crates/print/src/windows.rs @@ -438,7 +438,7 @@ pub(crate) fn submit_with_progress(pdf: &[u8], job: &Job, progress: &mut dyn FnM } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/print/src/xml.rs b/crates/print/src/xml.rs index e1a9cd467..348bc88ce 100644 --- a/crates/print/src/xml.rs +++ b/crates/print/src/xml.rs @@ -125,7 +125,7 @@ fn attribute_name(tag: &[u8]) -> &[u8] { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/print/tests/it/main.rs b/crates/print/tests/it/main.rs index 302b1dd4f..26e17f8f9 100644 --- a/crates/print/tests/it/main.rs +++ b/crates/print/tests/it/main.rs @@ -2,5 +2,5 @@ // Unwrapping, expecting and panicking on failure is fine in tests, unlike in shipped code. #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] -mod dialog; -mod print; +pub(crate) mod dialog; +pub(crate) mod print; diff --git a/crates/review/Cargo.toml b/crates/review/Cargo.toml index f0b37d6ff..7e8dcb0c8 100644 --- a/crates/review/Cargo.toml +++ b/crates/review/Cargo.toml @@ -17,6 +17,7 @@ harness = false workspace = true [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # The review widgets (`craft_review::ui`). ui = ["dep:craft-keymap", "dep:craft-pages", "craft-pages/ui", "dep:craft-ui", "dep:craft-host", "dep:craft-theme", "dep:egui", "dep:image"] @@ -37,6 +38,6 @@ kurbo = { workspace = true, features = ["serde"] } serde = { workspace = true } [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } egui = { workspace = true } serde_json = { workspace = true } diff --git a/crates/review/src/lib.rs b/crates/review/src/lib.rs index c27a790fd..931b7f571 100644 --- a/crates/review/src/lib.rs +++ b/crates/review/src/lib.rs @@ -20,13 +20,15 @@ pub mod ui; /// The stories and word sets the integration tests register. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } #[cfg(test)] -mod annotate_tests; +pub(crate) mod annotate_tests; #[cfg(test)] -mod versions_tests; +pub(crate) mod versions_tests; #[cfg(feature = "ui")] pub use annotate::AnnotationEdit; @@ -40,9 +42,10 @@ pub use versions::{Branch, BranchId, BranchState, HistoryRow, Version, VersionId extern crate self as craft_review; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/review/src/ui/annotate.rs b/crates/review/src/ui/annotate.rs index 7472397a7..c546cc9d7 100644 --- a/crates/review/src/ui/annotate.rs +++ b/crates/review/src/ui/annotate.rs @@ -1,10 +1,10 @@ //! The annotation tool on the canvas, the overlay that draws annotations, and the toolbar. -mod overlay; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod overlay; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod tool; -mod toolbar; +pub(crate) mod toolbar; mod words; pub use overlay::{AnnotationOverlay, AnnotationOverlayStyle}; diff --git a/crates/review/src/ui/avatar.rs b/crates/review/src/ui/avatar.rs index 325d6e530..fbc552fcd 100644 --- a/crates/review/src/ui/avatar.rs +++ b/crates/review/src/ui/avatar.rs @@ -9,8 +9,8 @@ use egui::{Color32, Rect, Response, Vec2}; use crate::collab::initials; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// Paints a round face filling `rect`: `fill` with the initials of `name` centred on it, in the ink that reads on `fill`. pub fn paint_avatar(ui: &PaintUi<'_>, rect: Rect, name: &str, fill: DataColor) { diff --git a/crates/review/src/ui/balloons.rs b/crates/review/src/ui/balloons.rs index 540a6bdb2..a8c1d75fb 100644 --- a/crates/review/src/ui/balloons.rs +++ b/crates/review/src/ui/balloons.rs @@ -16,8 +16,8 @@ use super::comments::{CardActions, CardEvent, CommentEdit, CommentRow, CommentsP use crate::comments::{CommentThread, ThreadId}; use crate::revisions::Revision; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The most detail lines of a revision a card shows. const DETAIL_LINES: usize = 8; diff --git a/crates/review/src/ui/chat.rs b/crates/review/src/ui/chat.rs index 5afeb7313..6cd659d4c 100644 --- a/crates/review/src/ui/chat.rs +++ b/crates/review/src/ui/chat.rs @@ -14,8 +14,8 @@ use egui::{Color32, CornerRadius, Pos2, Rect, Response, Ui, Vec2}; use crate::collab::CollabRequest; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The chat box's words, English by default. diff --git a/crates/review/src/ui/comments.rs b/crates/review/src/ui/comments.rs index 5dd95be01..a9e009a66 100644 --- a/crates/review/src/ui/comments.rs +++ b/crates/review/src/ui/comments.rs @@ -11,11 +11,11 @@ //! } //! ``` -mod list; +pub(crate) mod list; mod menus; -mod row; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod row; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::collections::BTreeMap; diff --git a/crates/review/src/ui/join.rs b/crates/review/src/ui/join.rs index 78b8a6119..713c0aabe 100644 --- a/crates/review/src/ui/join.rs +++ b/crates/review/src/ui/join.rs @@ -12,8 +12,8 @@ use egui::{Response, Ui}; use crate::collab::{CollabRequest, CollabTransport, JoinState}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The field's words, English by default. diff --git a/crates/review/src/ui/presence.rs b/crates/review/src/ui/presence.rs index f229a24ad..9c28ea751 100644 --- a/crates/review/src/ui/presence.rs +++ b/crates/review/src/ui/presence.rs @@ -22,8 +22,8 @@ use super::avatar::Avatar; use super::chat::{BubbleLook, paint_chat_bubble}; use crate::collab::{CHAT_FADE_S, CHAT_HOLD_S, CollabRequest, CollabTransport, Participant, ParticipantId, chat_alpha}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// Most selection outlines drawn for one person. const MAX_OUTLINES: usize = 500; diff --git a/crates/review/src/ui/revisions.rs b/crates/review/src/ui/revisions.rs index 7d74a3662..60f56bf82 100644 --- a/crates/review/src/ui/revisions.rs +++ b/crates/review/src/ui/revisions.rs @@ -16,8 +16,8 @@ use egui::{CornerRadius, Response, Ui, Vec2}; use crate::revisions::{Revision, RevisionAction, RevisionKind}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The detail lines a card shows. const DETAIL_LINES: usize = 8; diff --git a/crates/review/src/ui/signature.rs b/crates/review/src/ui/signature.rs index 0053b9f9d..ba98ddb50 100644 --- a/crates/review/src/ui/signature.rs +++ b/crates/review/src/ui/signature.rs @@ -28,8 +28,8 @@ use egui::{ColorImage, Pos2, Rect, Vec2}; use crate::signature::{MAX_IMAGE_BYTES, MAX_IMAGE_SIDE, MAX_SIGNATURE_CHARS, SavedSignature, SignatureDraft, SignatureImage, SignatureTab}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The pad's width over its height. const PAD_ASPECT: f32 = 460.0 / 150.0; diff --git a/crates/review/src/ui/thread.rs b/crates/review/src/ui/thread.rs index 6687ef653..79fb335bb 100644 --- a/crates/review/src/ui/thread.rs +++ b/crates/review/src/ui/thread.rs @@ -6,10 +6,10 @@ //! ``` mod mention; -mod pins; -mod popover; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod pins; +pub(crate) mod popover; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use mention::{insert_mention, mention_matches, mention_query}; pub use pins::{CommentPin, CommentPins, CommentPinsOutput, PinCluster, PinMove, cluster}; diff --git a/crates/review/src/ui/versions.rs b/crates/review/src/ui/versions.rs index bcd7877d1..cebc5f335 100644 --- a/crates/review/src/ui/versions.rs +++ b/crates/review/src/ui/versions.rs @@ -29,8 +29,8 @@ use crate::versions::{Branch, BranchId, BranchState, HistoryRow, Version, Versio /// The most lines of a version's description a row shows. const DESCRIPTION_LINES: u8 = 3; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The panel's words, English by default. diff --git a/crates/review/src/ui/vote.rs b/crates/review/src/ui/vote.rs index 9937b547a..d85e00150 100644 --- a/crates/review/src/ui/vote.rs +++ b/crates/review/src/ui/vote.rs @@ -13,8 +13,8 @@ use egui::{Response, Ui}; use crate::collab::{CollabRequest, CollabTransport, VoteScope}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// Votes per person a new vote starts with. const DEFAULT_VOTES: u32 = 3; diff --git a/crates/review/tests/it/main.rs b/crates/review/tests/it/main.rs index bb97756a9..c9eb9a9ce 100644 --- a/crates/review/tests/it/main.rs +++ b/crates/review/tests/it/main.rs @@ -1,6 +1,6 @@ //! The screen tests of craft-review, folded into the lib's test target. -mod annotate; -mod balloons; -mod collab; -mod comments; +pub(crate) mod annotate; +pub(crate) mod balloons; +pub(crate) mod collab; +pub(crate) mod comments; diff --git a/crates/story-render/src/main.rs b/crates/story-render/src/main.rs index b0e46c5a8..2094e8736 100644 --- a/crates/story-render/src/main.rs +++ b/crates/story-render/src/main.rs @@ -137,7 +137,7 @@ fn options() -> Result { /// What a job renders. enum Shown { /// One story in a card's story body. - Story(&'static StoryRegistration), + Story(Box), /// The Overview card of one story group, which the card's frames show. Card(Arc), } @@ -202,7 +202,7 @@ fn jobs(options: &Options) -> Vec { name: component.name.clone(), level: entry.level.title(), crate_name: story.registration.crate_name, - shown: Shown::Story(story.registration), + shown: Shown::Story(Box::new(story.registration)), surface: entry.surface, story: story.registration.story.name.to_owned(), title: story.registration.story.caption(&component.name), @@ -265,7 +265,7 @@ fn settle(fixture: &mut Fixture) { /// The story in a card's body, with its dialog open when the card holds one behind its button, under the command /// states the gallery gives it. A story that shows an open popup ([`Required::Open`]) is shown after its own drive, /// which opens it, as the suite runs it: the fixture, and the rect the story showed in. -fn story(registration: &'static StoryRegistration, surface: Surface, env: &RootEnv, options: &Options) -> (Fixture, Option) { +fn story(registration: StoryRegistration, surface: Surface, env: &RootEnv, options: &Options) -> (Fixture, Option) { let body = StoryBody::new("sheet", registration, surface, options.room, Pad::Regular); let state = Rc::new(RefCell::new(CardState::default())); let flow = Rc::new(Cell::new(None)); @@ -332,7 +332,7 @@ fn card(spec: &Arc, env: &RootEnv, options: &Options) -> (Fixture, Option< fn render(job: &Job, renderer: &mut Renderer, env: &RootEnv, options: &Options) -> Result { let (mut fixture, shown, dialog) = match &job.shown { Shown::Story(registration) => { - let (fixture, shown) = story(registration, job.surface, env, options); + let (fixture, shown) = story(**registration, job.surface, env, options); (fixture, shown, false) } Shown::Card(spec) => card(spec, env, options), diff --git a/crates/table/Cargo.toml b/crates/table/Cargo.toml index c1573bdb9..ae1866289 100644 --- a/crates/table/Cargo.toml +++ b/crates/table/Cargo.toml @@ -15,6 +15,7 @@ test = false workspace = true [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # The table widgets (`craft_table::ui`). ui = ["dep:craft-ui", "dep:craft-behavior", "dep:craft-keymap", "dep:craft-theme", "dep:egui"] @@ -29,11 +30,11 @@ craft-ui = { workspace = true, optional = true } egui = { workspace = true, optional = true } [dev-dependencies] -craft-table = { path = ".", features = ["screen-testing"] } +craft-table = { path = ".", features = ["suite"] } egui = { workspace = true } [[test]] name = "it" path = "tests/it/main.rs" harness = false -required-features = ["screen-testing"] +required-features = ["suite"] diff --git a/crates/table/src/ui/chart.rs b/crates/table/src/ui/chart.rs index 74ec98171..c0c3de9e8 100644 --- a/crates/table/src/ui/chart.rs +++ b/crates/table/src/ui/chart.rs @@ -5,8 +5,8 @@ use craft_ui::primitives::{DataStrokeWidth, Draw, PaintShape, TextRun}; use craft_ui::style::{DataColor, StyleColor}; use egui::{CornerRadius, Pos2, Rect, pos2, vec2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// A document line width never shrinks below this share of its width at 100 % zoom (a zoom floor, not a size). const MIN_STROKE_ZOOM: f32 = 0.5; diff --git a/crates/table/src/ui/conditions.rs b/crates/table/src/ui/conditions.rs index a154d9d48..3c75105a8 100644 --- a/crates/table/src/ui/conditions.rs +++ b/crates/table/src/ui/conditions.rs @@ -18,8 +18,8 @@ use craft_ui::style::SurfaceKind; use craft_ui::text::{NumberField, TextField}; use egui::{Response, Ui}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The builder's words, English by default. diff --git a/crates/table/src/ui/error_tag.rs b/crates/table/src/ui/error_tag.rs index c91db70db..237d85c9e 100644 --- a/crates/table/src/ui/error_tag.rs +++ b/crates/table/src/ui/error_tag.rs @@ -16,8 +16,8 @@ use craft_ui::runtime::env::WordSet as _; use craft_ui::style::{ComponentStyle, FocusLook, IconLook, StyleCx, SurfaceLook}; use egui::{Rect, Response, Vec2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The tag's accessible name, English by default (Excel's). diff --git a/crates/table/src/ui/fields.rs b/crates/table/src/ui/fields.rs index a94e17f20..cb9ef6ddb 100644 --- a/crates/table/src/ui/fields.rs +++ b/crates/table/src/ui/fields.rs @@ -21,8 +21,8 @@ use craft_ui::sections::Panel; use craft_ui::style::{SurfaceKind, TypeRole}; use egui::{Id, Response, Ui}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The pane's words, English by default. diff --git a/crates/table/src/ui/filter.rs b/crates/table/src/ui/filter.rs index 2bd5488cd..1f504337c 100644 --- a/crates/table/src/ui/filter.rs +++ b/crates/table/src/ui/filter.rs @@ -11,8 +11,8 @@ use craft_ui::primitives::IconSpec; use craft_ui::style::{ComponentStyle, FocusLook, IconLook, StyleCx, SurfaceLook}; use egui::{Rect, Response, Vec2, pos2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The filter button's words, English by default. diff --git a/crates/table/src/ui/grid.rs b/crates/table/src/ui/grid.rs index 5fb00d400..c62058180 100644 --- a/crates/table/src/ui/grid.rs +++ b/crates/table/src/ui/grid.rs @@ -25,9 +25,9 @@ mod input; mod model; mod paint; mod reference; -mod row; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod row; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use geometry::{GridLayout, HEADER_MIN_ZOOM, SheetGeometry, SheetMetrics}; pub use model::{CellEdit, CellProblem, ColumnFilter, GridEdit, GridMenuTarget, GridModel, GridState}; diff --git a/crates/table/src/ui/mod.rs b/crates/table/src/ui/mod.rs index 00004d16c..d4f9984ea 100644 --- a/crates/table/src/ui/mod.rs +++ b/crates/table/src/ui/mod.rs @@ -30,7 +30,9 @@ pub mod stats; /// The registrations of the table widgets' stories and trials. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } pub use chart::{ChartPrimitive, HAlign, VAlign, paint_chart}; diff --git a/crates/table/src/ui/outline.rs b/crates/table/src/ui/outline.rs index 40ea459f5..04723faac 100644 --- a/crates/table/src/ui/outline.rs +++ b/crates/table/src/ui/outline.rs @@ -12,8 +12,8 @@ use egui::{CornerRadius, Pos2, Rect, Response, Vec2, pos2, vec2}; use super::grid::{CellAt, CellRange, SheetGeometry, column_letters}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The band buttons' accessible names, English by default (Excel's). diff --git a/crates/table/src/ui/slicer.rs b/crates/table/src/ui/slicer.rs index a3cf1863b..35bcf293a 100644 --- a/crates/table/src/ui/slicer.rs +++ b/crates/table/src/ui/slicer.rs @@ -17,8 +17,8 @@ use craft_ui::sections::{HeaderStrength, TitleRow}; use craft_ui::style::{ComponentStyle, Flags, FocusLook, Stateful, StyleColor, StyleCx, SurfaceKind, SurfaceLook, TextLook, TypeRole, UiTokens}; use egui::{Rect, Response, Ui, Vec2, pos2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The slicer's words, English by default. diff --git a/crates/table/src/ui/stats.rs b/crates/table/src/ui/stats.rs index 22ff65ea5..02c41d4e4 100644 --- a/crates/table/src/ui/stats.rs +++ b/crates/table/src/ui/stats.rs @@ -15,8 +15,8 @@ use craft_ui::runtime::env::Label; use craft_ui::style::{ComponentStyle, FocusLook, StyleCx, TextLook}; use egui::{Rect, Response, Vec2}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The statistics' names, English by default (Excel's). diff --git a/crates/table/tests/it/main.rs b/crates/table/tests/it/main.rs index 431f050a6..c5458921c 100644 --- a/crates/table/tests/it/main.rs +++ b/crates/table/tests/it/main.rs @@ -1,13 +1,13 @@ //! The integration binary of craft-table: every test is a registered trial. -mod conditions; -mod grid; -mod outline; -mod refpick; -mod slicer; +pub(crate) mod conditions; +pub(crate) mod grid; +pub(crate) mod outline; +pub(crate) mod refpick; +pub(crate) mod slicer; -use craft_table::ui::testing::registered; +craft_ui::registry!(); fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), ®istered()); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register, craft_table::ui::testing::register])); } diff --git a/crates/text/Cargo.toml b/crates/text/Cargo.toml index 39be25683..f173f309a 100644 --- a/crates/text/Cargo.toml +++ b/crates/text/Cargo.toml @@ -45,13 +45,14 @@ serde_json = { workspace = true, optional = true } [dev-dependencies] unicode-segmentation = "1.13" -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } [[example]] name = "hyphgen" required-features = ["generator"] [features] +suite = ["screen-testing", "craft-ui/suite"] positioned = ["dep:kurbo"] default = ["hyphen", "bidi", "segment"] # Hyphenation points; English (bundled dictionary and patterns) needs no further feature. diff --git a/crates/text/src/bidi/mod.rs b/crates/text/src/bidi/mod.rs index 51c6ec50d..f245a0d64 100644 --- a/crates/text/src/bidi/mod.rs +++ b/crates/text/src/bidi/mod.rs @@ -415,4 +415,4 @@ fn l1_reset(class: BidiClass, trailing: &mut bool) -> bool { } #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/text/src/composer.rs b/crates/text/src/composer.rs index df80f4711..a3ff19eb8 100644 --- a/crates/text/src/composer.rs +++ b/crates/text/src/composer.rs @@ -341,7 +341,7 @@ pub fn compose_with( } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/text/src/hyphen/dict.rs b/crates/text/src/hyphen/dict.rs index bb5bec930..33e155b19 100644 --- a/crates/text/src/hyphen/dict.rs +++ b/crates/text/src/hyphen/dict.rs @@ -154,7 +154,7 @@ pub fn parse_hyphenated(s: &str) -> (String, u64) { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/text/src/hyphen/mod.rs b/crates/text/src/hyphen/mod.rs index 31b130494..9eed829f2 100644 --- a/crates/text/src/hyphen/mod.rs +++ b/crates/text/src/hyphen/mod.rs @@ -16,7 +16,7 @@ #[cfg(feature = "generator")] pub mod dict; #[cfg(not(feature = "generator"))] -mod dict; +pub(crate) mod dict; #[cfg(feature = "generator")] pub mod patgen; mod patterns; @@ -516,4 +516,4 @@ fn heuristic_points(c: &[char]) -> Vec { } #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/text/src/lib.rs b/crates/text/src/lib.rs index 8b1230a65..b13506f45 100644 --- a/crates/text/src/lib.rs +++ b/crates/text/src/lib.rs @@ -37,20 +37,20 @@ pub mod bidi; #[cfg(feature = "find")] pub mod find; #[cfg(all(test, feature = "find"))] -mod find_tests; +pub(crate) mod find_tests; #[cfg(feature = "hyphen")] pub mod hyphen; pub mod linebreak; pub mod lists; #[cfg(test)] -mod lists_tests; +pub(crate) mod lists_tests; pub mod quotes; #[cfg(feature = "segment")] pub mod segment; #[cfg(feature = "spell")] pub mod spell; #[cfg(all(test, feature = "spell"))] -mod spell_tests; +pub(crate) mod spell_tests; pub mod styles; #[cfg(feature = "ui")] pub mod ui; @@ -58,18 +58,21 @@ pub mod ui; /// The stories and trials of the crate's UI, registered in craft-ui's registry. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } #[cfg(all(test, feature = "screen-testing"))] extern crate self as craft_text; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } /// Paragraph-wide line composition with stateful line measurement. diff --git a/crates/text/src/linebreak/mod.rs b/crates/text/src/linebreak/mod.rs index 895ad4bc9..88f3dbb68 100644 --- a/crates/text/src/linebreak/mod.rs +++ b/crates/text/src/linebreak/mod.rs @@ -23,7 +23,7 @@ mod greedy; mod knuth_plass; #[cfg(test)] -mod tests; +pub(crate) mod tests; use std::ops::Range; diff --git a/crates/text/src/positioned.rs b/crates/text/src/positioned.rs index 0c15132a3..11217990f 100644 --- a/crates/text/src/positioned.rs +++ b/crates/text/src/positioned.rs @@ -136,7 +136,7 @@ impl PositionedGlyph { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/text/src/segment/mod.rs b/crates/text/src/segment/mod.rs index 9aadf9a78..6a783a401 100644 --- a/crates/text/src/segment/mod.rs +++ b/crates/text/src/segment/mod.rs @@ -23,7 +23,7 @@ mod complex; mod kinsoku; #[cfg(test)] -mod tests; +pub(crate) mod tests; use std::ops::Range; diff --git a/crates/text/src/ui/character.rs b/crates/text/src/ui/character.rs index 37c4eaaa8..8f73f468a 100644 --- a/crates/text/src/ui/character.rs +++ b/crates/text/src/ui/character.rs @@ -30,11 +30,11 @@ use craft_ui::text::{NamedOr, NumberName, NumberPick, NumberValue as _}; use egui::{Response, Ui}; pub(crate) mod paragraph; -mod paragraph_dialog; +pub(crate) mod paragraph_dialog; pub(crate) mod rows; -#[cfg(feature = "screen-testing")] -mod stories; -mod style_options; +#[cfg(feature = "suite")] +pub(crate) mod stories; +pub(crate) mod style_options; pub use paragraph::{ParagraphChange, ParagraphControls, ParagraphControlsOutput, ParagraphDirection, ParagraphValues, ParagraphWords, TextAlign}; pub use paragraph_dialog::{ diff --git a/crates/text/src/ui/character/style_options.rs b/crates/text/src/ui/character/style_options.rs index d0f100b66..cf1620355 100644 --- a/crates/text/src/ui/character/style_options.rs +++ b/crates/text/src/ui/character/style_options.rs @@ -30,8 +30,8 @@ use crate::ui::length::DocUnit; #[cfg(feature = "font-picker")] use super::FontPickerSource; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The words of the style options editor, English by default: the three short alignment names its rows show. The diff --git a/crates/text/src/ui/columns.rs b/crates/text/src/ui/columns.rs index abff0e7f9..a20e11d76 100644 --- a/crates/text/src/ui/columns.rs +++ b/crates/text/src/ui/columns.rs @@ -23,8 +23,8 @@ use craft_ui::text::{NumberField, NumberOutput}; use egui::{Pos2, Rect, Ui, Vec2, pos2, vec2}; use std::cell::Cell; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The most columns PowerPoint takes; the /// dialog's limit without [`word`](TextColumnsDialog::word) and the default for a host that diff --git a/crates/text/src/ui/editor.rs b/crates/text/src/ui/editor.rs index ddc86013a..fad53f083 100644 --- a/crates/text/src/ui/editor.rs +++ b/crates/text/src/ui/editor.rs @@ -23,8 +23,8 @@ mod commands; mod edits; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::ops::Range; diff --git a/crates/text/src/ui/find.rs b/crates/text/src/ui/find.rs index 045a8bb89..9e9c7d0b2 100644 --- a/crates/text/src/ui/find.rs +++ b/crates/text/src/ui/find.rs @@ -3,11 +3,11 @@ //! Replace and Go To tabs, Search Options, Replace and Replace All) and PowerPoint's simpler Find / Replace, on the //! dialog stack. Both search with [`crate::find`]; the document's text and the replacing are the app's. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; -mod bar; -mod dialog; +pub(crate) mod bar; +pub(crate) mod dialog; pub use bar::{FindBar, FindBarOutput, FindBarState, FindStep}; pub use dialog::{FindReplaceDialog, FindRequest, FindTab, GoToKind, GoToTarget}; diff --git a/crates/text/src/ui/hyperlink.rs b/crates/text/src/ui/hyperlink.rs index 695b5a0bc..e4378fd07 100644 --- a/crates/text/src/ui/hyperlink.rs +++ b/crates/text/src/ui/hyperlink.rs @@ -22,8 +22,8 @@ use craft_ui::sections::{DialogRole, FooterButton}; use craft_ui::text::TextField; use egui::{Context, Response, Ui}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The dialog's words, English by default. diff --git a/crates/text/src/ui/notes.rs b/crates/text/src/ui/notes.rs index c55c616e2..ec81cc79b 100644 --- a/crates/text/src/ui/notes.rs +++ b/crates/text/src/ui/notes.rs @@ -5,8 +5,8 @@ //! //! The notes are the app's; [`NotesText`] is the shape the editor reads and writes. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod text; diff --git a/crates/text/src/ui/path_text.rs b/crates/text/src/ui/path_text.rs index c9473f093..78debe5b0 100644 --- a/crates/text/src/ui/path_text.rs +++ b/crates/text/src/ui/path_text.rs @@ -1,7 +1,7 @@ //! `PathTextMarkers`: the start, end and overflow marks of text laid on a path, a canvas control. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::kurbo::{Point, Vec2 as PathVec}; use craft_behavior::{ diff --git a/crates/text/src/ui/ruler.rs b/crates/text/src/ui/ruler.rs index 335988398..3cdd41639 100644 --- a/crates/text/src/ui/ruler.rs +++ b/crates/text/src/ui/ruler.rs @@ -28,8 +28,8 @@ mod geometry; mod items; mod paint; mod run; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The ruler's number writing and snap step, which the page rulers share so every ruler counts one unit alike. pub use run::{nudge_size, ruler_text, snap_step}; diff --git a/crates/text/src/ui/spelling.rs b/crates/text/src/ui/spelling.rs index 97951e67f..183d764f0 100644 --- a/crates/text/src/ui/spelling.rs +++ b/crates/text/src/ui/spelling.rs @@ -41,8 +41,8 @@ use egui::{Context, Response, Ui}; use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The dialog's words, English by default. diff --git a/crates/text/src/ui/style_panel.rs b/crates/text/src/ui/style_panel.rs index 53b87ee00..d1372b934 100644 --- a/crates/text/src/ui/style_panel.rs +++ b/crates/text/src/ui/style_panel.rs @@ -19,8 +19,8 @@ use egui::{Response, Ui}; use std::cell::Cell; mod picker; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use picker::{NamedStyleRow, StylePreview, style_rows}; diff --git a/crates/text/src/ui/tabs_dialog.rs b/crates/text/src/ui/tabs_dialog.rs index 94d648810..e5ba8e73f 100644 --- a/crates/text/src/ui/tabs_dialog.rs +++ b/crates/text/src/ui/tabs_dialog.rs @@ -30,8 +30,8 @@ use egui::Ui; use std::borrow::Cow; use std::cell::{Cell, RefCell}; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The OK footer button's index, in the order the buttons are given. const OK: usize = 0; diff --git a/crates/text/src/ui/type_bar.rs b/crates/text/src/ui/type_bar.rs index 10d3b6214..b5acaf4c0 100644 --- a/crates/text/src/ui/type_bar.rs +++ b/crates/text/src/ui/type_bar.rs @@ -29,8 +29,8 @@ use crate::ui::type_options::{TextAntiAlias, TextOrientation, TypeOptionWords}; #[cfg(feature = "font-picker")] use crate::ui::character::FontPickerSource; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The type bar's tooltips, English by default (PhotoCraft's). Family, alignment and direction names are diff --git a/crates/text/tests/it/main.rs b/crates/text/tests/it/main.rs index 735e921e2..dad1d148f 100644 --- a/crates/text/tests/it/main.rs +++ b/crates/text/tests/it/main.rs @@ -2,17 +2,17 @@ // Unwrapping, expecting and panicking on failure is fine in tests, unlike in shipped code. #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] -mod editor; +pub(crate) mod editor; #[cfg(feature = "find")] -mod find; -mod hyperlink; -mod notes; -mod paragraph; -mod path_text; +pub(crate) mod find; +pub(crate) mod hyperlink; +pub(crate) mod notes; +pub(crate) mod paragraph; +pub(crate) mod path_text; -mod ruler; -mod style_options; -mod style_panel; -mod tabs; +pub(crate) mod ruler; +pub(crate) mod style_options; +pub(crate) mod style_panel; +pub(crate) mod tabs; -mod character; +pub(crate) mod character; diff --git a/crates/theme-editor/Cargo.toml b/crates/theme-editor/Cargo.toml index 117c883be..2df8725a8 100644 --- a/crates/theme-editor/Cargo.toml +++ b/crates/theme-editor/Cargo.toml @@ -13,6 +13,7 @@ autotests = false harness = false [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # The panels' stories. screen-testing = ["craft-ui/testing"] @@ -24,7 +25,7 @@ craft-ui = { workspace = true } egui = { workspace = true } [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } [lints] workspace = true diff --git a/crates/theme-editor/src/lib.rs b/crates/theme-editor/src/lib.rs index 22bb4063d..2730241e4 100644 --- a/crates/theme-editor/src/lib.rs +++ b/crates/theme-editor/src/lib.rs @@ -4,14 +4,14 @@ #![warn(missing_docs)] -mod browser; +pub(crate) mod browser; mod chip; -mod detail; -mod layer; -mod problems; +pub(crate) mod detail; +pub(crate) mod layer; +pub(crate) mod problems; mod rows; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod subject; mod words; @@ -26,10 +26,13 @@ pub use words::summary; /// The stories this crate registers for the integration binary. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/theme-store/Cargo.toml b/crates/theme-store/Cargo.toml index d92130fcd..7e46b9911 100644 --- a/crates/theme-store/Cargo.toml +++ b/crates/theme-store/Cargo.toml @@ -14,6 +14,7 @@ autotests = false harness = false [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # `craft_theme_store::ui`: the Preferences appearance page and its theme chips. ui = ["dep:craft-behavior", "dep:craft-ui", "dep:egui"] @@ -33,7 +34,7 @@ craft-atomic = { workspace = true } dirs = "7" [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } tempfile = "3" [lints] diff --git a/crates/theme-store/src/client.rs b/crates/theme-store/src/client.rs index 72cea2c6d..263f4cc7d 100644 --- a/crates/theme-store/src/client.rs +++ b/crates/theme-store/src/client.rs @@ -334,7 +334,7 @@ impl SuiteClient { } #[cfg(test)] -mod tests; +pub(crate) mod tests; /// The suite as a reading page sees it: [`SuiteClient::shown`] and the latest snapshot, as of [`SuiteClient::view`]. #[derive(Clone)] diff --git a/crates/theme-store/src/lib.rs b/crates/theme-store/src/lib.rs index ce039617d..b20d4708c 100644 --- a/crates/theme-store/src/lib.rs +++ b/crates/theme-store/src/lib.rs @@ -37,17 +37,17 @@ #![warn(missing_docs)] mod backend; -mod client; +pub(crate) mod client; mod copy; mod dir; #[cfg(not(target_arch = "wasm32"))] mod disk; -mod selection; +pub(crate) mod selection; mod store; pub mod testing; #[cfg(feature = "ui")] pub mod ui; -mod watch; +pub(crate) mod watch; pub use backend::{FileStamp, LibraryFile}; pub use client::{SuiteClient, SuiteView}; @@ -61,18 +61,19 @@ pub use store::{Imported, LOCK_TIMEOUT, Library, ParseCounts, Problem, Saved, St pub use watch::{Op, OpOutput, RESULTS_KEPT, STAT_INTERVAL, Snapshot, SuiteWatch, VERIFY_INTERVAL}; #[cfg(test)] -mod tests; +pub(crate) mod tests; #[cfg(test)] extern crate self as craft_theme_store; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] #[path = "../tests/two_processes.rs"] -mod two_processes; +pub(crate) mod two_processes; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/theme-store/src/selection.rs b/crates/theme-store/src/selection.rs index 6add0ca2f..04ee17dad 100644 --- a/crates/theme-store/src/selection.rs +++ b/crates/theme-store/src/selection.rs @@ -384,7 +384,7 @@ impl fmt::Display for SelectionError { impl std::error::Error for SelectionError {} #[cfg(test)] -mod tests { +pub(crate) mod tests { use craft_ui::testing::trial; use serde_json::json; diff --git a/crates/theme-store/src/ui/mod.rs b/crates/theme-store/src/ui/mod.rs index cd11f8476..6c9737701 100644 --- a/crates/theme-store/src/ui/mod.rs +++ b/crates/theme-store/src/ui/mod.rs @@ -1,12 +1,12 @@ //! The Preferences appearance page over the suite selection: [`AppearancePage`] and its [`ThemeChip`]s. -mod chip; -mod page; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod chip; +pub(crate) mod page; +#[cfg(feature = "suite")] +pub(crate) mod stories; -#[cfg(feature = "screen-testing")] -craft_ui::testing_registered!(); +#[cfg(feature = "suite")] +craft_ui::registry!(); pub use chip::{ThemeChip, ThemeChipOutput, ThemeChipStyle}; pub use page::{AppearancePage, AppearancePageOutput, AppearanceWords}; diff --git a/crates/theme-store/src/watch.rs b/crates/theme-store/src/watch.rs index 1bed2bb8e..64c2184bc 100644 --- a/crates/theme-store/src/watch.rs +++ b/crates/theme-store/src/watch.rs @@ -915,4 +915,4 @@ impl Engine { } #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/timeline/Cargo.toml b/crates/timeline/Cargo.toml index a588eb43a..165a0c499 100644 --- a/crates/timeline/Cargo.toml +++ b/crates/timeline/Cargo.toml @@ -17,6 +17,7 @@ harness = false workspace = true [features] +suite = ["screen-testing", "craft-ui/suite"] default = [] # The timeline widgets (`craft_timeline::ui`). ui = ["dep:craft-behavior", "dep:craft-keymap", "dep:craft-theme", "dep:craft-ui", "dep:egui"] @@ -40,7 +41,7 @@ serde_json = { workspace = true, optional = true } web-time = "1.1" [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } egui = { workspace = true } proptest = { workspace = true } serde_json = { workspace = true } diff --git a/crates/timeline/src/ale.rs b/crates/timeline/src/ale.rs index eeaeb2e25..3024353e5 100644 --- a/crates/timeline/src/ale.rs +++ b/crates/timeline/src/ale.rs @@ -183,7 +183,7 @@ pub fn row_range(doc: &AleDoc, row: usize) -> Option<(Tick, Tick)> { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use crate::timecode::format_timecode_frames; use craft_ui::testing::trial; diff --git a/crates/timeline/src/build.rs b/crates/timeline/src/build.rs index 306c95cef..d1ef56133 100644 --- a/crates/timeline/src/build.rs +++ b/crates/timeline/src/build.rs @@ -429,7 +429,7 @@ pub fn gain_to_db(g: f64) -> f64 { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use crate::fx::Standard; use crate::time::TimeRange; diff --git a/crates/timeline/src/edl.rs b/crates/timeline/src/edl.rs index d4c5a2cb1..82681a0d9 100644 --- a/crates/timeline/src/edl.rs +++ b/crates/timeline/src/edl.rs @@ -419,7 +419,7 @@ pub fn write(header: &OutHeader, events: &[OutEvent]) -> String { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; @@ -595,7 +595,7 @@ M2 A001 -012.0 00;00;00;00\n\ } #[cfg(test)] -mod report_limit_tests { +pub(crate) mod report_limit_tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/timeline/src/fcpxml.rs b/crates/timeline/src/fcpxml.rs index 83bb63597..ac61f0c16 100644 --- a/crates/timeline/src/fcpxml.rs +++ b/crates/timeline/src/fcpxml.rs @@ -1441,7 +1441,7 @@ fn marker_xml(m: &Marker, local: Tick, rate: FrameRate) -> String { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/timeline/src/interchange.rs b/crates/timeline/src/interchange.rs index 25cff8e29..745f93732 100644 --- a/crates/timeline/src/interchange.rs +++ b/crates/timeline/src/interchange.rs @@ -1098,7 +1098,7 @@ pub fn decode_text(bytes: &[u8]) -> String { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/timeline/src/lib.rs b/crates/timeline/src/lib.rs index 38f91b735..1c6b85a19 100644 --- a/crates/timeline/src/lib.rs +++ b/crates/timeline/src/lib.rs @@ -50,7 +50,7 @@ pub mod report; pub mod time; pub mod timecode; #[cfg(feature = "xml")] -mod xml; +pub(crate) mod xml; #[cfg(feature = "ui")] pub mod ui; @@ -69,33 +69,36 @@ pub use time::{TICKS_PER_SECOND, Tick, TimeRange, TimeView}; pub use timecode::{TimeDisplay, TimeFormat, TimecodeError, format_time, parse_frames, parse_time}; #[cfg(test)] -mod cache_tests; +pub(crate) mod cache_tests; #[cfg(test)] -mod clips_tests; +pub(crate) mod clips_tests; #[cfg(test)] -mod clock_tests; +pub(crate) mod clock_tests; #[cfg(test)] -mod frames_tests; +pub(crate) mod frames_tests; #[cfg(test)] -mod preflight_tests; +pub(crate) mod preflight_tests; #[cfg(test)] -mod time_tests; +pub(crate) mod time_tests; #[cfg(test)] -mod timecode_tests; +pub(crate) mod timecode_tests; /// The stories and trials this crate registers. #[cfg(feature = "screen-testing")] pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } #[cfg(all(test, feature = "screen-testing"))] extern crate self as craft_timeline; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/timeline/src/otio.rs b/crates/timeline/src/otio.rs index 544071dd2..849377d46 100644 --- a/crates/timeline/src/otio.rs +++ b/crates/timeline/src/otio.rs @@ -1242,7 +1242,7 @@ impl Imp<'_, '_, '_> { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/timeline/src/path.rs b/crates/timeline/src/path.rs index 5b6a268fb..ec9de541d 100644 --- a/crates/timeline/src/path.rs +++ b/crates/timeline/src/path.rs @@ -224,7 +224,7 @@ pub fn extension(path: &str) -> String { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/timeline/src/rate.rs b/crates/timeline/src/rate.rs index 5a66e8db6..6cffa793a 100644 --- a/crates/timeline/src/rate.rs +++ b/crates/timeline/src/rate.rs @@ -63,7 +63,7 @@ pub fn rate_from_f64(r: f64) -> FrameRate { // --------------------------------------------------------------------------------------------- #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/timeline/src/report.rs b/crates/timeline/src/report.rs index 7ef375170..1c815e1a5 100644 --- a/crates/timeline/src/report.rs +++ b/crates/timeline/src/report.rs @@ -96,7 +96,7 @@ impl std::fmt::Display for Report { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/timeline/src/ui/graph.rs b/crates/timeline/src/ui/graph.rs index 0f90f62bf..cdf5450c2 100644 --- a/crates/timeline/src/ui/graph.rs +++ b/crates/timeline/src/ui/graph.rs @@ -1,8 +1,8 @@ //! `GraphEditor`: keyframed values (or their speed) as curves over time (N1.08), a leaf with a content painter for the //! plot and parts for the keys, the handles and the bottom bar. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::kurbo; use craft_behavior::{ diff --git a/crates/timeline/src/ui/keyframes.rs b/crates/timeline/src/ui/keyframes.rs index fb5aa620f..4442ae4d3 100644 --- a/crates/timeline/src/ui/keyframes.rs +++ b/crates/timeline/src/ui/keyframes.rs @@ -1,7 +1,7 @@ //! Keyframe lanes, the keyframe navigator and the animation toggle (N1.04). -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/timeline/src/ui/markers.rs b/crates/timeline/src/ui/markers.rs index 897e1f542..0b6592cca 100644 --- a/crates/timeline/src/ui/markers.rs +++ b/crates/timeline/src/ui/markers.rs @@ -1,8 +1,8 @@ //! Markers on a ruler or a clip bar, and the Marker dialog (N1.12). -mod dialog; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod dialog; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use dialog::{MarkerDialog, MarkerDialogAction, MarkerDialogResult, MarkerDraft}; diff --git a/crates/timeline/src/ui/overview.rs b/crates/timeline/src/ui/overview.rs index 42c349c2f..deb082072 100644 --- a/crates/timeline/src/ui/overview.rs +++ b/crates/timeline/src/ui/overview.rs @@ -1,7 +1,7 @@ //! The whole timeline in miniature (N1.13). -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{Axis, Metrics, PointerButton, PressPhase, Sense}; use craft_ui::contract::{ diff --git a/crates/timeline/src/ui/panel.rs b/crates/timeline/src/ui/panel.rs index c9b1f656b..bb0257096 100644 --- a/crates/timeline/src/ui/panel.rs +++ b/crates/timeline/src/ui/panel.rs @@ -872,8 +872,8 @@ pub struct TopStripStyle { metrics: Metrics, } -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The model of the pattern's registration probe: no tracks. struct EmptySequence(crate::time::TimeView); diff --git a/crates/timeline/src/ui/preview.rs b/crates/timeline/src/ui/preview.rs index 75486fe73..9ebf0c3ed 100644 --- a/crates/timeline/src/ui/preview.rs +++ b/crates/timeline/src/ui/preview.rs @@ -1,7 +1,7 @@ //! A decoded frame fitted in a panel, with a status line. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{Axis, Metrics, Sense}; use craft_theme::Stateful; diff --git a/crates/timeline/src/ui/render_queue.rs b/crates/timeline/src/ui/render_queue.rs index 38694bad9..3d7a9c519 100644 --- a/crates/timeline/src/ui/render_queue.rs +++ b/crates/timeline/src/ui/render_queue.rs @@ -1,7 +1,7 @@ //! The render (export) queue list. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::borrow::Cow; use std::cell::RefCell; diff --git a/crates/timeline/src/ui/ruler.rs b/crates/timeline/src/ui/ruler.rs index a5b132deb..132528b7b 100644 --- a/crates/timeline/src/ui/ruler.rs +++ b/crates/timeline/src/ui/ruler.rs @@ -1,8 +1,8 @@ //! `TimelineRuler`: the time ruler across the top of a timeline (N1.01), a leaf that reads the `TimeAxis` of the //! `TimelineView` around it. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{Axis, CursorIcon, HitLevel, HitPriority, Metrics, NavMove, PartKey, PointerButton, PressPhase, RulerUnits, Sense, Ticks}; use craft_ui::canvas::{Rulers, StepLadder, TickRule}; diff --git a/crates/timeline/src/ui/stack.rs b/crates/timeline/src/ui/stack.rs index 84346cb84..8211a767f 100644 --- a/crates/timeline/src/ui/stack.rs +++ b/crates/timeline/src/ui/stack.rs @@ -817,5 +817,5 @@ pub(crate) fn set_event(before: T, after: T, label: &str) -> EditEvent { EditEvent::set(Mixed::Same(before), after, Arc::from(label), None) } -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; diff --git a/crates/timeline/src/ui/timecode.rs b/crates/timeline/src/ui/timecode.rs index 096363dec..18e914e9a 100644 --- a/crates/timeline/src/ui/timecode.rs +++ b/crates/timeline/src/ui/timecode.rs @@ -1,8 +1,8 @@ //! The timecode field, its codec and the Timecode panel. -mod readout; -#[cfg(feature = "screen-testing")] -mod stories; +pub(crate) mod readout; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::nav::LARGE_STEPS; use craft_behavior::{Caret, Codec, IconId, NavMove, NotAValue, PartKey, Sense, ValueDrag}; diff --git a/crates/timeline/src/ui/transport.rs b/crates/timeline/src/ui/transport.rs index b8c8a457d..0e7056311 100644 --- a/crates/timeline/src/ui/transport.rs +++ b/crates/timeline/src/ui/transport.rs @@ -1,7 +1,7 @@ //! A monitor's transport bar and the compact media controls. -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use craft_behavior::{EditEvents, IconId}; use craft_ui::bars::{Bar, BarKind}; diff --git a/crates/timeline/src/ui/view.rs b/crates/timeline/src/ui/view.rs index 611e4b352..47bee7cf0 100644 --- a/crates/timeline/src/ui/view.rs +++ b/crates/timeline/src/ui/view.rs @@ -633,5 +633,5 @@ impl Outcome for TimelineViewOutput { } } -#[cfg(feature = "screen-testing")] +#[cfg(feature = "suite")] pub(crate) mod stories; diff --git a/crates/timeline/src/xml.rs b/crates/timeline/src/xml.rs index da76c396b..900f6aa9a 100644 --- a/crates/timeline/src/xml.rs +++ b/crates/timeline/src/xml.rs @@ -145,7 +145,7 @@ impl XmlWriter { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/timeline/tests/it/fcp7.rs b/crates/timeline/tests/it/fcp7.rs index f26e952c8..5af8c63c3 100644 --- a/crates/timeline/tests/it/fcp7.rs +++ b/crates/timeline/tests/it/fcp7.rs @@ -447,54 +447,89 @@ fn gen_clip() -> impl Strategy { ) } -proptest! { - #![proptest_config(ProptestConfig::with_cases(48))] - #[trial] - fn xmeml_roundtrip(clips in prop::collection::vec(gen_clip(), 1..20), ri in 0usize..5) { - let rate = [FrameRate::FPS_23_976, FrameRate::FPS_25, FrameRate::FPS_29_97, FrameRate::FPS_59_94, FrameRate::FPS_24][ri]; - let mut p = Project::new("P"); - let ms = [media(&mut p, "/x/one.mov", true, true, rate), media(&mut p, "/x/two.mov", true, true, rate), media(&mut p, "/y/three four.mxf", true, true, rate)]; - let s = sequence(&mut p, "S", rate, false); - let mut ends = [0i64; 3]; - let mut prev: [Option; 3] = [None; 3]; - let mut aends = [0i64; 3]; - for g in &clips { - let t = ends[g.track] + g.gap; - let v = clip(&mut p, s, TrackKind::Video, g.track, ms[g.media], t..t + (g.dur), g.src); - { - let q = p.sequence_mut(s).unwrap(); - let (_, it) = q.find_item_mut(v).unwrap(); - it.enabled = g.enabled; - match g.speed { - 1 => it.speed = 2.0, - 2 => it.speed = 0.5, - 3 => it.reverse = true, +#[trial] +fn xmeml_roundtrip() { + let mut config = ProptestConfig::with_cases(48); + config.source_file = Some(file!()); + let mut runner = proptest::test_runner::TestRunner::new(config); + runner + .run(&(prop::collection::vec(gen_clip(), 1..20), 0usize..5), |(clips, ri)| { + let rate = [FrameRate::FPS_23_976, FrameRate::FPS_25, FrameRate::FPS_29_97, FrameRate::FPS_59_94, FrameRate::FPS_24][ri]; + let mut p = Project::new("P"); + let ms = [ + media(&mut p, "/x/one.mov", true, true, rate), + media(&mut p, "/x/two.mov", true, true, rate), + media(&mut p, "/y/three four.mxf", true, true, rate), + ]; + let s = sequence(&mut p, "S", rate, false); + let mut ends = [0i64; 3]; + let mut prev: [Option; 3] = [None; 3]; + let mut aends = [0i64; 3]; + for g in &clips { + let t = ends[g.track] + g.gap; + let v = clip(&mut p, s, TrackKind::Video, g.track, ms[g.media], t..t + (g.dur), g.src); + { + let q = p.sequence_mut(s).unwrap(); + let (_, it) = q.find_item_mut(v).unwrap(); + it.enabled = g.enabled; + match g.speed { + 1 => it.speed = 2.0, + 2 => it.speed = 0.5, + 3 => it.reverse = true, + _ => {} + } + } + let d = g.tr_len; + let adjacent = g.gap == 0 && prev[g.track].is_some(); + match g.tr { + 0 if adjacent => transition( + &mut p, + s, + (TrackKind::Video, g.track), + "cross_dissolve", + (prev[g.track], Some(v)), + t - d / 2..t - d / 2 + (d), + TransitionAlign::CenterAtCut, + ), + 1 if adjacent => transition( + &mut p, + s, + (TrackKind::Video, g.track), + "dip_to_white", + (prev[g.track], Some(v)), + t..t + (d), + TransitionAlign::StartAtCut, + ), + 2 if adjacent => transition( + &mut p, + s, + (TrackKind::Video, g.track), + "push", + (prev[g.track], Some(v)), + t - d..t - d + (d), + TransitionAlign::EndAtCut, + ), + 3 if !adjacent => { + transition(&mut p, s, (TrackKind::Video, g.track), "cross_dissolve", (None, Some(v)), t..t + (d), TransitionAlign::StartAtCut) + } _ => {} } + if g.audio && aends[g.track] <= t { + let a = clip(&mut p, s, TrackKind::Audio, g.track, ms[g.media], t..t + (g.dur), g.src); + link(&mut p, s, &[v, a]); + aends[g.track] = t + g.dur; + } + ends[g.track] = t + g.dur; + prev[g.track] = Some(v); } - let d = g.tr_len; - let adjacent = g.gap == 0 && prev[g.track].is_some(); - match g.tr { - 0 if adjacent => transition(&mut p, s, (TrackKind::Video, g.track), "cross_dissolve", (prev[g.track], Some(v)), t - d / 2..t - d / 2 + (d), TransitionAlign::CenterAtCut), - 1 if adjacent => transition(&mut p, s, (TrackKind::Video, g.track), "dip_to_white", (prev[g.track], Some(v)), t..t + (d), TransitionAlign::StartAtCut), - 2 if adjacent => transition(&mut p, s, (TrackKind::Video, g.track), "push", (prev[g.track], Some(v)), t - d..t - d + (d), TransitionAlign::EndAtCut), - 3 if !adjacent => transition(&mut p, s, (TrackKind::Video, g.track), "cross_dissolve", (None, Some(v)), t..t + (d), TransitionAlign::StartAtCut), - _ => {} - } - if g.audio && aends[g.track] <= t { - let a = clip(&mut p, s, TrackKind::Audio, g.track, ms[g.media], t..t + (g.dur), g.src); - link(&mut p, s, &[v, a]); - aends[g.track] = t + g.dur; - } - ends[g.track] = t + g.dur; - prev[g.track] = Some(v); - } - let (imp, text, _) = fcp7_roundtrip(&p, s, &xopts()); - let si = only_seq(&imp); - prop_assert_eq!(structure(&imp.project, si, TrackKind::Video), structure(&p, s, TrackKind::Video), "{}", text); - prop_assert_eq!(structure(&imp.project, si, TrackKind::Audio), structure(&p, s, TrackKind::Audio)); - prop_assert_eq!(links(&imp.project, si), links(&p, s)); - } + let (imp, text, _) = fcp7_roundtrip(&p, s, &xopts()); + let si = only_seq(&imp); + prop_assert_eq!(structure(&imp.project, si, TrackKind::Video), structure(&p, s, TrackKind::Video), "{}", text); + prop_assert_eq!(structure(&imp.project, si, TrackKind::Audio), structure(&p, s, TrackKind::Audio)); + prop_assert_eq!(links(&imp.project, si), links(&p, s)); + Ok(()) + }) + .unwrap(); } #[trial] diff --git a/crates/timeline/tests/it/fcpxml.rs b/crates/timeline/tests/it/fcpxml.rs index 2e68828b7..060439994 100644 --- a/crates/timeline/tests/it/fcpxml.rs +++ b/crates/timeline/tests/it/fcpxml.rs @@ -424,76 +424,102 @@ fn gen_clip() -> impl Strategy { ) } -proptest! { - #![proptest_config(ProptestConfig::with_cases(48))] - #[trial] - fn fcpxml_roundtrip(clips in prop::collection::vec(gen_clip(), 1..20), ri in 0usize..5) { - let rate = [FrameRate::FPS_23_976, FrameRate::FPS_25, FrameRate::FPS_29_97, FrameRate::FPS_59_94, FrameRate::FPS_24][ri]; - let mut p = Project::new("P"); - let ms = [media(&mut p, "/x/one.mov", true, true, rate), media(&mut p, "/x/two.mov", true, true, rate), media(&mut p, "/y/three four.mxf", true, true, rate)]; - let wav = media(&mut p, "/y/vo.wav", false, true, rate); - let s = sequence(&mut p, "S", rate, false); - let mut ends = [0i64; 3]; - let mut prev: [Option; 3] = [None; 3]; - let mut aends = [0i64; 3]; - for g in &clips { - let t = ends[g.track] + g.gap; - let v = clip(&mut p, s, TrackKind::Video, g.track, ms[g.media], t..t + (g.dur), g.src); - { - let q = p.sequence_mut(s).unwrap(); - let (_, it) = q.find_item_mut(v).unwrap(); - it.enabled = g.enabled; - match g.speed { - 1 => it.speed = 2.0, - 2 => it.speed = 0.5, - 3 => it.reverse = true, - _ => {} +#[trial] +fn fcpxml_roundtrip() { + let mut config = ProptestConfig::with_cases(48); + config.source_file = Some(file!()); + let mut runner = proptest::test_runner::TestRunner::new(config); + runner + .run(&(prop::collection::vec(gen_clip(), 1..20), 0usize..5), |(clips, ri)| { + let rate = [FrameRate::FPS_23_976, FrameRate::FPS_25, FrameRate::FPS_29_97, FrameRate::FPS_59_94, FrameRate::FPS_24][ri]; + let mut p = Project::new("P"); + let ms = [ + media(&mut p, "/x/one.mov", true, true, rate), + media(&mut p, "/x/two.mov", true, true, rate), + media(&mut p, "/y/three four.mxf", true, true, rate), + ]; + let wav = media(&mut p, "/y/vo.wav", false, true, rate); + let s = sequence(&mut p, "S", rate, false); + let mut ends = [0i64; 3]; + let mut prev: [Option; 3] = [None; 3]; + let mut aends = [0i64; 3]; + for g in &clips { + let t = ends[g.track] + g.gap; + let v = clip(&mut p, s, TrackKind::Video, g.track, ms[g.media], t..t + (g.dur), g.src); + { + let q = p.sequence_mut(s).unwrap(); + let (_, it) = q.find_item_mut(v).unwrap(); + it.enabled = g.enabled; + match g.speed { + 1 => it.speed = 2.0, + 2 => it.speed = 0.5, + 3 => it.reverse = true, + _ => {} + } } - } - let d = g.tr_len; - let adjacent = g.gap == 0 && prev[g.track].is_some(); - if g.track == 0 { - match g.tr { - 0 if adjacent && d >= 2 => transition(&mut p, s, (TrackKind::Video, 0), "cross_dissolve", (prev[0], Some(v)), t - d / 2..t - d / 2 + (d), TransitionAlign::CenterAtCut), - 1 if adjacent => transition(&mut p, s, (TrackKind::Video, 0), "dip_to_white", (prev[0], Some(v)), t..t + (d), TransitionAlign::StartAtCut), - 2 if adjacent => transition(&mut p, s, (TrackKind::Video, 0), "push", (prev[0], Some(v)), t - d..t - d + (d), TransitionAlign::EndAtCut), - 3 if !adjacent => transition(&mut p, s, (TrackKind::Video, 0), "cross_dissolve", (None, Some(v)), t..t + (d), TransitionAlign::StartAtCut), - _ => {} - } - } - if aends[g.track] <= t { - match g.audio { - // linked, same-numbered audio track, identical timing - 1 => { - let a = clip(&mut p, s, TrackKind::Audio, g.track, ms[g.media], t..t + (g.dur), g.src); - { - let q = p.sequence_mut(s).unwrap(); - let (sp, rv, en) = { let (_, it) = q.find_item(v).unwrap(); (it.speed, it.reverse, it.enabled) }; - let (_, ai) = q.find_item_mut(a).unwrap(); - ai.speed = sp; - ai.reverse = rv; - ai.enabled = en; + let d = g.tr_len; + let adjacent = g.gap == 0 && prev[g.track].is_some(); + if g.track == 0 { + match g.tr { + 0 if adjacent && d >= 2 => transition( + &mut p, + s, + (TrackKind::Video, 0), + "cross_dissolve", + (prev[0], Some(v)), + t - d / 2..t - d / 2 + (d), + TransitionAlign::CenterAtCut, + ), + 1 if adjacent => { + transition(&mut p, s, (TrackKind::Video, 0), "dip_to_white", (prev[0], Some(v)), t..t + (d), TransitionAlign::StartAtCut) } - link(&mut p, s, &[v, a]); - aends[g.track] = t + g.dur; + 2 if adjacent => { + transition(&mut p, s, (TrackKind::Video, 0), "push", (prev[0], Some(v)), t - d..t - d + (d), TransitionAlign::EndAtCut) + } + 3 if !adjacent => { + transition(&mut p, s, (TrackKind::Video, 0), "cross_dissolve", (None, Some(v)), t..t + (d), TransitionAlign::StartAtCut) + } + _ => {} } - // independent audio-only clip - 2 => { - clip(&mut p, s, TrackKind::Audio, g.track, wav, t..t + (g.dur), g.src); - aends[g.track] = t + g.dur; - } - _ => {} } + if aends[g.track] <= t { + match g.audio { + // linked, same-numbered audio track, identical timing + 1 => { + let a = clip(&mut p, s, TrackKind::Audio, g.track, ms[g.media], t..t + (g.dur), g.src); + { + let q = p.sequence_mut(s).unwrap(); + let (sp, rv, en) = { + let (_, it) = q.find_item(v).unwrap(); + (it.speed, it.reverse, it.enabled) + }; + let (_, ai) = q.find_item_mut(a).unwrap(); + ai.speed = sp; + ai.reverse = rv; + ai.enabled = en; + } + link(&mut p, s, &[v, a]); + aends[g.track] = t + g.dur; + } + // independent audio-only clip + 2 => { + clip(&mut p, s, TrackKind::Audio, g.track, wav, t..t + (g.dur), g.src); + aends[g.track] = t + g.dur; + } + _ => {} + } + } + ends[g.track] = t + g.dur; + prev[g.track] = Some(v); } - ends[g.track] = t + g.dur; - prev[g.track] = Some(v); - } - let (imp, text, _) = roundtrip(&p, s, Format::Fcpxml, &xopts()); - let si = only_seq(&imp); - prop_assert_eq!(structure(&imp.project, si, TrackKind::Video), structure(&p, s, TrackKind::Video), "{}", text); - prop_assert_eq!(structure(&imp.project, si, TrackKind::Audio), structure(&p, s, TrackKind::Audio), "{}", text); - prop_assert_eq!(links(&imp.project, si), links(&p, s)); - } + let (imp, text, _) = roundtrip(&p, s, Format::Fcpxml, &xopts()); + let si = only_seq(&imp); + prop_assert_eq!(structure(&imp.project, si, TrackKind::Video), structure(&p, s, TrackKind::Video), "{}", text); + prop_assert_eq!(structure(&imp.project, si, TrackKind::Audio), structure(&p, s, TrackKind::Audio), "{}", text); + prop_assert_eq!(links(&imp.project, si), links(&p, s)); + Ok(()) + }) + .unwrap(); } /// filmcraft#2195: a relative `src` is a URL like an absolute one: `boats%20b.mov` is the file `boats b.mov`. diff --git a/crates/timeline/tests/it/main.rs b/crates/timeline/tests/it/main.rs index deca537c0..4f6c90176 100644 --- a/crates/timeline/tests/it/main.rs +++ b/crates/timeline/tests/it/main.rs @@ -2,16 +2,16 @@ //! the `xml` and `otio` features the interchange round trips. #[cfg(all(feature = "xml", feature = "otio"))] -mod fcp7; +pub(crate) mod fcp7; #[cfg(all(feature = "xml", feature = "otio"))] -mod fcpxml; -mod features; -mod lanes; +pub(crate) mod fcpxml; +pub(crate) mod features; +pub(crate) mod lanes; #[cfg(all(feature = "xml", feature = "otio"))] -mod otio; -mod panel; -mod ruler; +pub(crate) mod otio; +pub(crate) mod panel; +pub(crate) mod ruler; #[cfg(all(feature = "xml", feature = "otio"))] mod support; -mod timecode; -mod transport; +pub(crate) mod timecode; +pub(crate) mod transport; diff --git a/crates/timeline/tests/it/otio.rs b/crates/timeline/tests/it/otio.rs index 74d333c4e..df0d35d14 100644 --- a/crates/timeline/tests/it/otio.rs +++ b/crates/timeline/tests/it/otio.rs @@ -478,60 +478,95 @@ fn gen_clip() -> impl Strategy { ) } -proptest! { - #![proptest_config(ProptestConfig::with_cases(48))] - #[trial] - fn otio_roundtrip(clips in prop::collection::vec(gen_clip(), 1..20), ri in 0usize..5) { - let rate = [FrameRate::FPS_23_976, FrameRate::FPS_25, FrameRate::FPS_29_97, FrameRate::FPS_59_94, FrameRate::FPS_24][ri]; - let mut p = Project::new("P"); - let ms = [media(&mut p, "/x/one.mov", true, true, rate), media(&mut p, "/x/two.mov", true, true, rate), media(&mut p, "/y/three four.mxf", true, true, rate)]; - let s = sequence(&mut p, "S", rate, rate == FrameRate::FPS_29_97); - let mut ends = [0i64; 3]; - let mut prev: [Option; 3] = [None; 3]; - let mut aend = [Tick::ZERO; 3]; - for g in &clips { - let t = ends[g.track] + g.gap; - let v = clip(&mut p, s, TrackKind::Video, g.track, ms[g.media], t..t + (g.dur), g.src); - { - let q = p.sequence_mut(s).unwrap(); - let (_, it) = q.find_item_mut(v).unwrap(); - it.enabled = g.enabled; - match g.speed { - 1 => it.speed = 2.0, - 2 => it.speed = 0.5, - 3 => it.reverse = true, - 4 => it.frame_hold = Some(rate.tick_of(g.src + 3)), +#[trial] +fn otio_roundtrip() { + let mut config = ProptestConfig::with_cases(48); + config.source_file = Some(file!()); + let mut runner = proptest::test_runner::TestRunner::new(config); + runner + .run(&(prop::collection::vec(gen_clip(), 1..20), 0usize..5), |(clips, ri)| { + let rate = [FrameRate::FPS_23_976, FrameRate::FPS_25, FrameRate::FPS_29_97, FrameRate::FPS_59_94, FrameRate::FPS_24][ri]; + let mut p = Project::new("P"); + let ms = [ + media(&mut p, "/x/one.mov", true, true, rate), + media(&mut p, "/x/two.mov", true, true, rate), + media(&mut p, "/y/three four.mxf", true, true, rate), + ]; + let s = sequence(&mut p, "S", rate, rate == FrameRate::FPS_29_97); + let mut ends = [0i64; 3]; + let mut prev: [Option; 3] = [None; 3]; + let mut aend = [Tick::ZERO; 3]; + for g in &clips { + let t = ends[g.track] + g.gap; + let v = clip(&mut p, s, TrackKind::Video, g.track, ms[g.media], t..t + (g.dur), g.src); + { + let q = p.sequence_mut(s).unwrap(); + let (_, it) = q.find_item_mut(v).unwrap(); + it.enabled = g.enabled; + match g.speed { + 1 => it.speed = 2.0, + 2 => it.speed = 0.5, + 3 => it.reverse = true, + 4 => it.frame_hold = Some(rate.tick_of(g.src + 3)), + _ => {} + } + } + let d = g.tr_len; + let adjacent = g.gap == 0 && prev[g.track].is_some(); + match g.tr { + 0 if adjacent => transition( + &mut p, + s, + (TrackKind::Video, g.track), + "cross_dissolve", + (prev[g.track], Some(v)), + t - d / 2..t - d / 2 + (d), + TransitionAlign::CenterAtCut, + ), + 1 if adjacent => transition( + &mut p, + s, + (TrackKind::Video, g.track), + "dip_to_white", + (prev[g.track], Some(v)), + t..t + (d), + TransitionAlign::StartAtCut, + ), + 2 if adjacent => transition( + &mut p, + s, + (TrackKind::Video, g.track), + "push", + (prev[g.track], Some(v)), + t - d..t - d + (d), + TransitionAlign::EndAtCut, + ), + 3 if !adjacent => { + transition(&mut p, s, (TrackKind::Video, g.track), "cross_dissolve", (None, Some(v)), t..t + (d), TransitionAlign::StartAtCut) + } _ => {} } + // Audio at sample (not frame) positions, linked to the video. + let at = rate.tick_of(t) + Tick(TICKS_PER_SECOND / 48_000 * g.subframe % rate.frame_duration().0.max(1)); + if g.audio && aend[g.track] <= at { + let a = clip(&mut p, s, TrackKind::Audio, g.track, ms[g.media], t..t + (g.dur), g.src); + let q = p.sequence_mut(s).unwrap(); + let (_, ai) = q.find_item_mut(a).unwrap(); + ai.start = at; + aend[g.track] = ai.end(); + link(&mut p, s, &[v, a]); + } + ends[g.track] = t + g.dur; + prev[g.track] = Some(v); } - let d = g.tr_len; - let adjacent = g.gap == 0 && prev[g.track].is_some(); - match g.tr { - 0 if adjacent => transition(&mut p, s, (TrackKind::Video, g.track), "cross_dissolve", (prev[g.track], Some(v)), t - d / 2..t - d / 2 + (d), TransitionAlign::CenterAtCut), - 1 if adjacent => transition(&mut p, s, (TrackKind::Video, g.track), "dip_to_white", (prev[g.track], Some(v)), t..t + (d), TransitionAlign::StartAtCut), - 2 if adjacent => transition(&mut p, s, (TrackKind::Video, g.track), "push", (prev[g.track], Some(v)), t - d..t - d + (d), TransitionAlign::EndAtCut), - 3 if !adjacent => transition(&mut p, s, (TrackKind::Video, g.track), "cross_dissolve", (None, Some(v)), t..t + (d), TransitionAlign::StartAtCut), - _ => {} - } - // Audio at sample (not frame) positions, linked to the video. - let at = rate.tick_of(t) + Tick(TICKS_PER_SECOND / 48_000 * g.subframe % rate.frame_duration().0.max(1)); - if g.audio && aend[g.track] <= at { - let a = clip(&mut p, s, TrackKind::Audio, g.track, ms[g.media], t..t + (g.dur), g.src); - let q = p.sequence_mut(s).unwrap(); - let (_, ai) = q.find_item_mut(a).unwrap(); - ai.start = at; - aend[g.track] = ai.end(); - link(&mut p, s, &[v, a]); - } - ends[g.track] = t + g.dur; - prev[g.track] = Some(v); - } - let (imp, text, _) = roundtrip(&p, s, Format::Otio, &xopts()); - let si = only_seq(&imp); - prop_assert_eq!(structure(&imp.project, si, TrackKind::Video), structure(&p, s, TrackKind::Video), "{}", text); - prop_assert_eq!(structure(&imp.project, si, TrackKind::Audio), structure(&p, s, TrackKind::Audio)); - prop_assert_eq!(links(&imp.project, si), links(&p, s)); - } + let (imp, text, _) = roundtrip(&p, s, Format::Otio, &xopts()); + let si = only_seq(&imp); + prop_assert_eq!(structure(&imp.project, si, TrackKind::Video), structure(&p, s, TrackKind::Video), "{}", text); + prop_assert_eq!(structure(&imp.project, si, TrackKind::Audio), structure(&p, s, TrackKind::Audio)); + prop_assert_eq!(links(&imp.project, si), links(&p, s)); + Ok(()) + }) + .unwrap(); } #[trial] diff --git a/crates/ui-canvas/Cargo.toml b/crates/ui-canvas/Cargo.toml index fe58c3059..b111ff8b8 100644 --- a/crates/ui-canvas/Cargo.toml +++ b/crates/ui-canvas/Cargo.toml @@ -15,6 +15,7 @@ test = false workspace = true [features] +suite = ["testing", "craft-ui-panels/suite"] default = [] # `craft_ui::testing` with the canvas test helpers (`ToolFixture`, `tool_story`, `canvas_story`). testing = ["craft-ui-panels/testing"] @@ -31,10 +32,10 @@ serde = { workspace = true } serde_json = { workspace = true } [dev-dependencies] -craft-ui-canvas = { path = ".", features = ["testing"] } +craft-ui-canvas = { path = ".", features = ["suite"] } craft-behavior = { workspace = true } craft-keymap = { workspace = true, features = ["egui"] } -craft-ui-test-kit = { workspace = true } +craft-ui-test-kit = { workspace = true, features = ["suite"] } egui = { workspace = true } [[test]] diff --git a/crates/ui-canvas/src/canvas/crop/mod.rs b/crates/ui-canvas/src/canvas/crop/mod.rs index 9a6b641b1..906c5d810 100644 --- a/crates/ui-canvas/src/canvas/crop/mod.rs +++ b/crates/ui-canvas/src/canvas/crop/mod.rs @@ -5,8 +5,8 @@ mod gesture; mod paint; mod shield; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::words::CanvasWords; use super::{CanvasSpace, NUDGE, NUDGE_FAR, canvas_snap, canvas_space, context_click, readout}; diff --git a/crates/ui-canvas/src/canvas/full_window.rs b/crates/ui-canvas/src/canvas/full_window.rs index 8634c82fc..8e3b79625 100644 --- a/crates/ui-canvas/src/canvas/full_window.rs +++ b/crates/ui-canvas/src/canvas/full_window.rs @@ -21,10 +21,10 @@ use egui::Ui; pub use hosted::{FullWindowWorkspace, HostedWorkspace, WorkspaceCx, WorkspacePass}; mod hosted; -#[cfg(feature = "testing")] -mod stories; -#[cfg(feature = "testing")] -mod trials; +#[cfg(feature = "suite")] +pub(crate) mod stories; +#[cfg(feature = "suite")] +pub(crate) mod trials; /// The style of a full-window dialog: the surface comes from the container. #[derive(Clone, Debug, Default, PartialEq, ComponentStyle)] diff --git a/crates/ui-canvas/src/canvas/full_window/trials.rs b/crates/ui-canvas/src/canvas/full_window/trials.rs index 6fed71d36..fd807eb57 100644 --- a/crates/ui-canvas/src/canvas/full_window/trials.rs +++ b/crates/ui-canvas/src/canvas/full_window/trials.rs @@ -36,7 +36,7 @@ fn a_footer_letter_activates_its_button_in_a_full_window_dialog() { } /// The sample workspace on a dialog host, run once per frame. -mod hosting { +pub(crate) mod hosting { use super::super::HostedWorkspace; use super::super::stories::{BrushChanged, BrushWorkspace, Flat}; use crate::contract::Role; diff --git a/crates/ui-canvas/src/canvas/full_window_parts.rs b/crates/ui-canvas/src/canvas/full_window_parts.rs index 93aa1264b..df7aaf354 100644 --- a/crates/ui-canvas/src/canvas/full_window_parts.rs +++ b/crates/ui-canvas/src/canvas/full_window_parts.rs @@ -1,14 +1,14 @@ //! The parts of a full-window dialog's body: the side column, the zoom bar, the title text, the status line and the //! canvas region, with the view they share. `FullWindowDialog` is the shell they fill. -mod canvas; -mod side; -mod status; -#[cfg(feature = "testing")] -mod stories; -mod title; +pub(crate) mod canvas; +pub(crate) mod side; +pub(crate) mod status; +#[cfg(feature = "suite")] +pub(crate) mod stories; +pub(crate) mod title; mod view; -mod zoom_bar; +pub(crate) mod zoom_bar; pub use canvas::{FullWindowCanvas, FullWindowCanvasOutput, RasterOverlay}; pub use side::{FullWindowSide, FullWindowSideOutput, FullWindowSideStyle, SideFooter}; diff --git a/crates/ui-canvas/src/canvas/mod.rs b/crates/ui-canvas/src/canvas/mod.rs index 453cad77a..1e4895efe 100644 --- a/crates/ui-canvas/src/canvas/mod.rs +++ b/crates/ui-canvas/src/canvas/mod.rs @@ -7,7 +7,7 @@ //! commands routed to it ([`ViewCommands`]), keeps the document in view with Overscroll off, eases a zoom under //! Animated Zoom, publishes the view it shows as a [`CanvasSpace`] to its body, and reports the view the app copies. -mod crop; +pub(crate) mod crop; mod frame_step; // The full-window dialog family; `dialog` re-exports it. pub(crate) mod full_window; @@ -15,8 +15,8 @@ pub(crate) mod full_window_parts; mod march; mod readout; mod space; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; #[cfg(feature = "testing")] pub(crate) mod testing; mod words; @@ -42,14 +42,14 @@ pub use tool_host::{ContextRequest, ContextSource, StandInKey, ToolHost, ToolHos mod raster_source; pub use raster_source::{PixelRect, RasterSource}; -mod pasteboard; -mod split; +pub(crate) mod pasteboard; +pub(crate) mod split; pub use pasteboard::{PageBorder, PageFrame, Pasteboard, PasteboardColor, PasteboardOutput, PasteboardStyle}; pub use split::{SplitAt, SplitLayout, SplitPane, SplitStyle, SplitViews, SplitViewsOutput}; pub use words::SplitWords; mod app_paint; -mod raster; +pub(crate) mod raster; pub use app_paint::AppPaint; pub use raster::{DetailPlan, Extent, RasterDisplay, RasterDisplayOutput, RasterStyle, snap_to_texels}; @@ -65,8 +65,8 @@ pub use space::{BackgroundPress, BodyKeys, CanvasRulers, context_click}; // canvas-navigate-a mod momentary; -mod navigate; -mod rotate; +pub(crate) mod navigate; +pub(crate) mod rotate; mod tools; mod zoom_motion; @@ -79,15 +79,15 @@ pub use rotate::{RotateView, RotateViewOutput, RotateViewStyle, ViewTurn}; pub use tools::{HandTool, LayerBounds, RotateViewTool, ViewCommands, ViewRequest, ViewTarget, ZoomTool}; pub use zoom_motion::{HoldZoom, ZoomAnimation, ZoomDrag, easing_view}; -mod rulers; -mod scrollbars; +pub(crate) mod rulers; +pub(crate) mod scrollbars; pub use rulers::{ INCH_EIGHTHS, INCH_SIXTEENTHS, LABEL_STEP_MIN, RulerCommands, RulerMargins, RulerPart, RulerTick, Rulers, RulersOutput, StepLadder, TickRule, }; pub use scrollbars::{CanvasScrollbars, CanvasScrollbarsOutput}; // canvas-navigator-a -mod navigator; +pub(crate) mod navigator; pub use navigator::{ Navigator, NavigatorCommands, NavigatorOutput, NavigatorPreview, NavigatorZoomRow, NavigatorZoomRowOutput, preview_rect, proxy_quad, view_center_for, zoom_to_document_rect, diff --git a/crates/ui-canvas/src/canvas/navigate/mod.rs b/crates/ui-canvas/src/canvas/navigate/mod.rs index 8994c684e..35430cdec 100644 --- a/crates/ui-canvas/src/canvas/navigate/mod.rs +++ b/crates/ui-canvas/src/canvas/navigate/mod.rs @@ -6,12 +6,12 @@ //! `craft_behavior::canvas::zoom` and clamp to the [`ZoomLadder`](craft_behavior::ZoomLadder). With Overscroll off //! the caller clamps the result with the canvas's scroll limits. -mod autoscroll; -mod bar; +pub(crate) mod autoscroll; +pub(crate) mod bar; mod keys; mod options; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod wheel; pub(crate) use autoscroll::{MiddleAutoscroll, paint_mark}; diff --git a/crates/ui-canvas/src/canvas/navigator/mod.rs b/crates/ui-canvas/src/canvas/navigator/mod.rs index 87d4d7c8c..db3dbd034 100644 --- a/crates/ui-canvas/src/canvas/navigator/mod.rs +++ b/crates/ui-canvas/src/canvas/navigator/mod.rs @@ -10,11 +10,11 @@ //! | The panel menu | [`NavigatorCommands`] | mod menu; -mod preview; +pub(crate) mod preview; mod proxy; -#[cfg(feature = "testing")] -mod stories; -mod zoom_row; +#[cfg(feature = "suite")] +pub(crate) mod stories; +pub(crate) mod zoom_row; pub use menu::NavigatorCommands; pub use preview::{Navigator, NavigatorOutput, NavigatorPreview, NavigatorStyle}; diff --git a/crates/ui-canvas/src/canvas/navigator_panel.rs b/crates/ui-canvas/src/canvas/navigator_panel.rs index eea453822..0d194f056 100644 --- a/crates/ui-canvas/src/canvas/navigator_panel.rs +++ b/crates/ui-canvas/src/canvas/navigator_panel.rs @@ -8,8 +8,8 @@ use craft_behavior::kurbo::Size; use craft_behavior::{CanvasView, EditEvents}; use egui::{Response, Ui}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// What the Navigator panel reports. #[derive(Debug)] diff --git a/crates/ui-canvas/src/canvas/pasteboard/mod.rs b/crates/ui-canvas/src/canvas/pasteboard/mod.rs index ecc5d9c90..f7a62f005 100644 --- a/crates/ui-canvas/src/canvas/pasteboard/mod.rs +++ b/crates/ui-canvas/src/canvas/pasteboard/mod.rs @@ -3,8 +3,8 @@ //! preferences; the default colour is the canvas surround. Artboards show their names above them, and a click on a //! name selects the artboard. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::space::canvas_space; use crate::contract::{Access, Common, Component, Cx, MeasureCx, Name, NoValue, Outcome, PaintUi, PartsCx, Props as _, Role}; diff --git a/crates/ui-canvas/src/canvas/raster/mod.rs b/crates/ui-canvas/src/canvas/raster/mod.rs index 8aa376bbd..cc95aa33f 100644 --- a/crates/ui-canvas/src/canvas/raster/mod.rs +++ b/crates/ui-canvas/src/canvas/raster/mod.rs @@ -15,8 +15,8 @@ //! The display takes no pointer and no keys and declares no parts: a press on it reaches the canvas's tool. mod detail; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use detail::{DetailPlan, snap_to_texels}; diff --git a/crates/ui-canvas/src/canvas/rulers/mod.rs b/crates/ui-canvas/src/canvas/rulers/mod.rs index e87cb88a3..7ddad1a13 100644 --- a/crates/ui-canvas/src/canvas/rulers/mod.rs +++ b/crates/ui-canvas/src/canvas/rulers/mod.rs @@ -2,8 +2,8 @@ //! control (20.6). The strips and the corner are parts at handle priority in the canvas's arena. A drag from a strip //! reports a guide being placed; a drag from the corner moves the zero point. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod ticks; pub use ticks::{INCH_EIGHTHS, INCH_SIXTEENTHS, LABEL_STEP_MIN, RulerTick, StepLadder, TickRule}; diff --git a/crates/ui-canvas/src/canvas/scrollbars/mod.rs b/crates/ui-canvas/src/canvas/scrollbars/mod.rs index 6c2bb011c..3dbda4a52 100644 --- a/crates/ui-canvas/src/canvas/scrollbars/mod.rs +++ b/crates/ui-canvas/src/canvas/scrollbars/mod.rs @@ -10,8 +10,8 @@ //! The bars measure the view along the screen axes, so on a rotated view they show the extent of the unrotated //! document. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::words::CanvasWords; use crate::contract::overlay::{Anchor, Place}; diff --git a/crates/ui-canvas/src/canvas/split/mod.rs b/crates/ui-canvas/src/canvas/split/mod.rs index 0f2804e87..dc1994baa 100644 --- a/crates/ui-canvas/src/canvas/split/mod.rs +++ b/crates/ui-canvas/src/canvas/split/mod.rs @@ -7,8 +7,8 @@ //! the [`SplitAt`] the caller binds ([`SplitAt::placed`]). A linked pane follows the active view's zoom and position //! ([`SplitViews::follow`]). -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::words::SplitWords; use crate::contract::{ diff --git a/crates/ui-canvas/src/canvas_controls/brush/mod.rs b/crates/ui-canvas/src/canvas_controls/brush/mod.rs index 25475f0c5..a71511bc2 100644 --- a/crates/ui-canvas/src/canvas_controls/brush/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/brush/mod.rs @@ -22,14 +22,14 @@ //! [`BrushCursor::tip_cell`] at the canvas rect in the canvas body, and the tool hands //! [`BrushResize::readout_rows`] to `ToolContext::readout`. -mod cursor; -mod falloff; +pub(crate) mod cursor; +pub(crate) mod falloff; mod resize; -mod source_marker; -#[cfg(feature = "testing")] -mod stories; +pub(crate) mod source_marker; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod tip; -mod trail; +pub(crate) mod trail; pub use cursor::{BrushCursor, BrushCursorOptions, PaintingCursor, TipCell, TipCellStyle}; pub use falloff::{FalloffPreview, FalloffPreviewStyle, TipFalloff}; diff --git a/crates/ui-canvas/src/canvas_controls/grid/mod.rs b/crates/ui-canvas/src/canvas_controls/grid/mod.rs index ce934a786..913c66555 100644 --- a/crates/ui-canvas/src/canvas_controls/grid/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/grid/mod.rs @@ -2,8 +2,8 @@ //! the document grid of Preferences > Guides, Grid & Slices. Display only: it senses nothing, so the host's menu item //! carries the state. Show it before guides and frames. -#[cfg(feature = "testing")] -pub(super) mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use crate::canvas::{CanvasSpace, GuideLine, canvas_space}; use crate::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role}; diff --git a/crates/ui-canvas/src/canvas_controls/guides/mod.rs b/crates/ui-canvas/src/canvas_controls/guides/mod.rs index 7918af4a4..47899d7a9 100644 --- a/crates/ui-canvas/src/canvas_controls/guides/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/guides/mod.rs @@ -3,8 +3,8 @@ mod place; pub mod reading; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use reading::GuideReading; diff --git a/crates/ui-canvas/src/canvas_controls/marquee/mod.rs b/crates/ui-canvas/src/canvas_controls/marquee/mod.rs index 410bfa559..82d680ccd 100644 --- a/crates/ui-canvas/src/canvas_controls/marquee/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/marquee/mod.rs @@ -2,8 +2,8 @@ //! selection band or an outline being drawn over the canvas, mapped from document geometry through the canvas's view. //! It takes no pointer and no key: the press, the drag and the modifier rules are the canvas tool's. -#[cfg(feature = "testing")] -pub(super) mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::words::CanvasControlWords; use crate::canvas::{MARCH_SECONDS, MARCH_TICK, canvas_space, march_shift}; diff --git a/crates/ui-canvas/src/canvas_controls/mod.rs b/crates/ui-canvas/src/canvas_controls/mod.rs index eefed7a98..58d1094cb 100644 --- a/crates/ui-canvas/src/canvas_controls/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/mod.rs @@ -4,8 +4,8 @@ mod words; // Guides and smart guides. -mod guides; -mod smart_guides; +pub(crate) mod guides; +pub(crate) mod smart_guides; pub(crate) use smart_guides::paint_lines; pub use guides::{GuideCommands, GuideStyle, Guides, GuidesOutput, reading}; @@ -14,12 +14,12 @@ pub use words::CanvasControlWords; // Selection outlines, grids and previews (canvas-controls-b). mod bands; -mod grid; -mod line_preview; -mod marquee; -mod outline; -mod pixel_grid; -mod task_bar; +pub(crate) mod grid; +pub(crate) mod line_preview; +pub(crate) mod marquee; +pub(crate) mod outline; +pub(crate) mod pixel_grid; +pub(crate) mod task_bar; pub use bands::{range_bands, rect_around}; pub use grid::{CanvasGrid, GridAxis, GridCrowding, GridLine, GridLines, GridStyle, MAX_LINES}; diff --git a/crates/ui-canvas/src/canvas_controls/outline/mod.rs b/crates/ui-canvas/src/canvas_controls/outline/mod.rs index 150ffeb5b..a0a71e84c 100644 --- a/crates/ui-canvas/src/canvas_controls/outline/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/outline/mod.rs @@ -3,8 +3,8 @@ //! share one stroking function over `kit::outline` (halo and line) and `kit::dashed`. mod hover; -#[cfg(feature = "testing")] -pub(super) mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use crate::canvas::canvas_space; use crate::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role}; diff --git a/crates/ui-canvas/src/canvas_controls/pixel_grid/mod.rs b/crates/ui-canvas/src/canvas_controls/pixel_grid/mod.rs index 5901a8598..22e0290d2 100644 --- a/crates/ui-canvas/src/canvas_controls/pixel_grid/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/pixel_grid/mod.rs @@ -7,8 +7,8 @@ //! display and keeps the merged line segments per revision and padded region in the control's memory, so panning //! within the padding costs nothing and the work is bounded by the viewport. -#[cfg(feature = "testing")] -pub(super) mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use crate::canvas::{PixelRect, RasterSource, canvas_space}; use crate::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, Props as _, Role}; diff --git a/crates/ui-canvas/src/canvas_controls/smart_guides/mod.rs b/crates/ui-canvas/src/canvas_controls/smart_guides/mod.rs index 265c9b2b1..9f8011346 100644 --- a/crates/ui-canvas/src/canvas_controls/smart_guides/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/smart_guides/mod.rs @@ -1,8 +1,8 @@ //! `SmartGuides`: the alignment lines and distances shown while something moves, a canvas control that only paints //! (20.6). It has no parts, so a press never lands on it. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use crate::canvas::{CanvasRulers, canvas_space}; use crate::contract::{Common, Component, Cx, MeasureCx, PaintUi, Role}; diff --git a/crates/ui-canvas/src/canvas_controls/task_bar.rs b/crates/ui-canvas/src/canvas_controls/task_bar.rs index 2e3a2773d..d76711327 100644 --- a/crates/ui-canvas/src/canvas_controls/task_bar.rs +++ b/crates/ui-canvas/src/canvas_controls/task_bar.rs @@ -1,7 +1,7 @@ //! `TaskBar`: the contextual task bar over a canvas, hung below its anchor until the user moves it. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::CanvasControlWords; use crate::bars::{Bar, BarKind}; diff --git a/crates/ui-canvas/src/lib.rs b/crates/ui-canvas/src/lib.rs index b1c40a728..faeef0e77 100644 --- a/crates/ui-canvas/src/lib.rs +++ b/crates/ui-canvas/src/lib.rs @@ -13,10 +13,10 @@ extern crate self as craft_ui; #[doc(hidden)] pub use craft_ui_panels::canvas_data; #[cfg(feature = "testing")] +pub use craft_ui_panels::registry; +#[cfg(feature = "suite")] #[doc(hidden)] pub use craft_ui_panels::story_kit; -#[cfg(feature = "testing")] -pub use craft_ui_panels::testing_registered; #[doc(hidden)] pub use craft_ui_panels::{__private, __register_command_set, __register_contract, __register_pattern}; pub use craft_ui_panels::{InstallError, InstallSpec, contract, fonts, install, layout, primitives, runtime, style, words}; @@ -51,5 +51,6 @@ pub mod testing { }; pub use craft_ui_panels::testing::*; - crate::testing_registered!(); + #[cfg(feature = "suite")] + crate::registry!(); } diff --git a/crates/ui-canvas/tests/it/canvas/mod.rs b/crates/ui-canvas/tests/it/canvas/mod.rs index 6d686a2d5..c41e3e397 100644 --- a/crates/ui-canvas/tests/it/canvas/mod.rs +++ b/crates/ui-canvas/tests/it/canvas/mod.rs @@ -1,35 +1,35 @@ //! `Canvas` (20.6): a press away from every canvas control's parts reaches the tool. -mod crop; +pub(crate) mod crop; -mod editor; +pub(crate) mod editor; -mod navigate; +pub(crate) mod navigate; -mod navigator; +pub(crate) mod navigator; -mod opacity_keys; +pub(crate) mod opacity_keys; -mod press_focus; +pub(crate) mod press_focus; -mod pasteboard; +pub(crate) mod pasteboard; -mod raster; +pub(crate) mod raster; -mod rulers; +pub(crate) mod rulers; -mod scrollbars; +pub(crate) mod scrollbars; -mod snap; +pub(crate) mod snap; -mod split; +pub(crate) mod split; -mod story_canvas; +pub(crate) mod story_canvas; -mod tool; +pub(crate) mod tool; -mod tool_keys; +pub(crate) mod tool_keys; -mod tool_story; +pub(crate) mod tool_story; -mod tools; +pub(crate) mod tools; diff --git a/crates/ui-canvas/tests/it/canvas_controls/mod.rs b/crates/ui-canvas/tests/it/canvas_controls/mod.rs index 37938ec64..411a1115e 100644 --- a/crates/ui-canvas/tests/it/canvas_controls/mod.rs +++ b/crates/ui-canvas/tests/it/canvas_controls/mod.rs @@ -1,13 +1,13 @@ //! The canvas controls: `Guides`, `SmartGuides`, selection outlines, grids and brush overlays on a `Canvas`. -mod brush; +pub(crate) mod brush; -mod grid; +pub(crate) mod grid; -mod guides; +pub(crate) mod guides; -mod marquee; +pub(crate) mod marquee; -mod outline; +pub(crate) mod outline; -mod task_bar; +pub(crate) mod task_bar; diff --git a/crates/ui-canvas/tests/it/contract/derives.rs b/crates/ui-canvas/tests/it/contract/derives.rs index 4c6f41ab2..acdb5fb42 100644 --- a/crates/ui-canvas/tests/it/contract/derives.rs +++ b/crates/ui-canvas/tests/it/contract/derives.rs @@ -166,7 +166,11 @@ impl CanvasTool for IdleTool { /// Every probe linked into this binary, the integration binary's own fixtures included. fn probes() -> Vec { - craft_ui::contract::registrations().into_iter().filter_map(|registration| registration.probe().copied()).collect() + craft_ui::testing::Registry::of(&[crate::register, craft_ui::testing::register]) + .registrations() + .iter() + .filter_map(|registration| registration.probe().copied()) + .collect() } fn named(name: &str) -> Vec { diff --git a/crates/ui-canvas/tests/it/contract/mod.rs b/crates/ui-canvas/tests/it/contract/mod.rs index f5437025d..6067f7da1 100644 --- a/crates/ui-canvas/tests/it/contract/mod.rs +++ b/crates/ui-canvas/tests/it/contract/mod.rs @@ -1,3 +1,3 @@ //! The component contract and the show pipeline: the steps each shape runs, and the rules the steps keep. -mod derives; +pub(crate) mod derives; diff --git a/crates/ui-canvas/tests/it/full_window_parts.rs b/crates/ui-canvas/tests/it/full_window_parts.rs index a803f723d..2de2dc5ee 100644 --- a/crates/ui-canvas/tests/it/full_window_parts.rs +++ b/crates/ui-canvas/tests/it/full_window_parts.rs @@ -39,7 +39,7 @@ fn a_zoom_command_ends_the_fit_and_fit_returns_to_it() { } /// The canvas's navigation: the wheel, the middle button and the Hand tool it falls back to. -mod canvas_navigation { +pub(crate) mod canvas_navigation { use craft_behavior::PixelSize; use craft_behavior::kurbo::Point; use craft_ui::canvas::{NavigationOptions, PixelRect, RasterSource}; @@ -130,7 +130,7 @@ mod canvas_navigation { } /// The momentary tools every full-window canvas runs. -mod momentary { +pub(crate) mod momentary { use craft_behavior::{CancelReason, PixelSize}; use craft_ui::canvas::{CanvasTool, PixelRect, RasterSource, ToolAction, ToolContext, ToolPath, ToolPointer}; use craft_ui::contract::{Bind, ShowContainer as _}; @@ -221,7 +221,7 @@ mod momentary { } /// Escape on a focused canvas inside a full-window dialog. -mod escape { +pub(crate) mod escape { use craft_behavior::{CancelReason, Intent, PixelSize}; use craft_ui::canvas::{CanvasTool, PixelRect, RasterSource, ToolAction, ToolContext, ToolKey, ToolPath, ToolPointer}; use craft_ui::contract::{Bind, ShowContainer as _}; @@ -319,7 +319,7 @@ mod escape { } /// A full-window dialog in a window of its own. -mod own_window { +pub(crate) mod own_window { use craft_ui::contract::{Bind, ShowContainer as _}; use craft_ui::dialog::{DialogResult, FullWindowDialog}; use craft_ui::runtime::overlay::CloseReason; @@ -365,7 +365,7 @@ mod own_window { } /// An overlay drawn through a frame. -mod mapped_overlay { +pub(crate) mod mapped_overlay { use craft_behavior::PixelSize; use craft_behavior::geometry::quad::Homography; use craft_behavior::kurbo::{Point, Rect}; diff --git a/crates/ui-canvas/tests/it/main.rs b/crates/ui-canvas/tests/it/main.rs index a94a0c3c1..1893ba675 100644 --- a/crates/ui-canvas/tests/it/main.rs +++ b/crates/ui-canvas/tests/it/main.rs @@ -3,15 +3,19 @@ // The test files name the library as `craft_ui`, as the crates that use it do. extern crate craft_ui_canvas as craft_ui; -mod canvas; -mod canvas_controls; -mod contract; +pub(crate) mod canvas; +pub(crate) mod canvas_controls; +pub(crate) mod contract; // full-window parts -mod full_window_parts; +pub(crate) mod full_window_parts; // end of full-window parts -use craft_ui::testing::registered; +craft_ui::registry!(); fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), ®istered()); + craft_ui::testing::run( + module_path!(), + env!("CARGO_PKG_NAME"), + &craft_ui::testing::Registry::of(&[register, craft_ui::testing::register, craft_ui_test_kit::testing::register]), + ); } diff --git a/crates/ui-contract/Cargo.toml b/crates/ui-contract/Cargo.toml index 38b98b400..016f990e9 100644 --- a/crates/ui-contract/Cargo.toml +++ b/crates/ui-contract/Cargo.toml @@ -16,10 +16,10 @@ workspace = true [features] default = [] -# `craft_ui::testing`: the fixture and suite runner, with the snapshot renderer. One feature for all of the test kit, -# so every test build of every crate asks the runtime for the same thing and builds it once; a crate that depends on -# the runtime through another framework crate cannot name the runtime's features on the command line. -testing = ["dep:libtest-mimic", "snapshot", "craft-platform/testing"] +# `craft_ui::testing`: the fixture and helpers used by application tests. +# The suite runner, stories, registrations and snapshots are opt-in. +testing = ["craft-platform/testing"] +suite = ["testing", "dep:libtest-mimic", "snapshot"] # `craft_ui::testing::snapshot`: stories rendered to images offscreen (desktop only). snapshot = ["dep:egui_kittest", "dep:image"] # Draw colour glyphs (COLR, sbix, CBDT), e.g. colour emoji. @@ -101,14 +101,14 @@ flate2 = { version = "1", default-features = false, features = ["rust_backend"] epaint_default_fonts = { version = "0.37", features = ["monochrome_emoji_fonts"] } [dev-dependencies] -craft-ui-contract = { path = ".", features = ["testing"] } +craft-ui-contract = { path = ".", features = ["suite"] } craft-behavior = { workspace = true } craft-fonts-build = { workspace = true } craft-host = { workspace = true } craft-i18n = { workspace = true } craft-keymap = { workspace = true, features = ["egui"] } craft-theme = { workspace = true } -craft-ui-test-kit = { workspace = true } +craft-ui-test-kit = { workspace = true, features = ["suite"] } craft-window = { workspace = true } egui = { workspace = true } # The oracle for the deflated default faces (`tests/it/fonts/on_demand.rs`). diff --git a/crates/ui-contract/src/contract/body.rs b/crates/ui-contract/src/contract/body.rs index 0ebaf221d..f567b938e 100644 --- a/crates/ui-contract/src/contract/body.rs +++ b/crates/ui-contract/src/contract/body.rs @@ -33,7 +33,7 @@ pub use regions::pad_of; #[doc(hidden)] pub use reorder::REORDER_BAND; pub use scroll::{STRIP_BACK, STRIP_FORWARD}; -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) use window::MOVE_BAND; use window::WindowMode; pub(crate) use window::keep_inside; diff --git a/crates/ui-contract/src/contract/items.rs b/crates/ui-contract/src/contract/items.rs index 0b0255421..33945b5aa 100644 --- a/crates/ui-contract/src/contract/items.rs +++ b/crates/ui-contract/src/contract/items.rs @@ -61,7 +61,7 @@ where mod drag; mod edge; pub(super) mod empty_text; -mod header; +pub(crate) mod header; mod marquee; mod request; diff --git a/crates/ui-contract/src/contract/label.rs b/crates/ui-contract/src/contract/label.rs index 8c583a794..b5f065803 100644 --- a/crates/ui-contract/src/contract/label.rs +++ b/crates/ui-contract/src/contract/label.rs @@ -4,7 +4,7 @@ pub use crate::runtime::access::scope::FieldLabelRole; -mod leaf; +pub(crate) mod leaf; mod place; mod props; mod step; diff --git a/crates/ui-contract/src/contract/level.rs b/crates/ui-contract/src/contract/level.rs index fa45435a6..0ce705053 100644 --- a/crates/ui-contract/src/contract/level.rs +++ b/crates/ui-contract/src/contract/level.rs @@ -215,7 +215,7 @@ fn pascal(segment: &str) -> String { #[non_exhaustive] pub struct CatalogEntry { /// The registration (the first of a generic type's instantiations). - pub registration: &'static Registration, + pub registration: Registration, /// The type's level. pub level: Level, /// The surface its stories sit on. @@ -230,7 +230,7 @@ impl CatalogEntry { /// How a viewer lays out the type's story group named `group` (`Story::group_name`): the layout `STORY_LAYOUTS` /// declares for it, else stacked. pub fn story_layout(&self, group: &str) -> StoryLayout { - let (target, short) = table_key(self.registration); + let (target, short) = table_key(&self.registration); STORY_LAYOUTS.iter().find(|row| row.0 == target && row.1 == short && row.2 == group).map_or(StoryLayout::Stacked, |row| row.3) } } @@ -267,10 +267,10 @@ fn kit_module(module: &str) -> bool { /// The display name is the type's name without module path or type arguments. Two registered types that share it /// each take the last module segments of their paths in front of it (`DockButton`, then `DockGroupButton`) /// until the names differ. -pub fn catalog(registrations: &[&'static Registration]) -> Catalog { - let mut types: BTreeMap<&'static str, &'static Registration> = BTreeMap::new(); +pub fn catalog(registrations: &[&Registration]) -> Catalog { + let mut types: BTreeMap<&'static str, Registration> = BTreeMap::new(); for ®istration in registrations.iter().filter(|registration| !kit_module(parts(registration).0)) { - types.entry(base_path(parts(registration).1)).or_insert(registration); + types.entry(base_path(parts(registration).1)).or_insert(*registration); } let mut by_short: BTreeMap<&str, Vec<&'static str>> = BTreeMap::new(); for &path in types.keys() { @@ -281,13 +281,13 @@ pub fn catalog(registrations: &[&'static Registration]) -> Catalog { for &path in &paths { let registration = types[path]; let name = qualified(path, short, &paths); - match level_of(registration) { + match level_of(®istration) { Some(level) => { - let surface = surface_of(registration); - let type_name = parts(registration).1; + let surface = surface_of(®istration); + let type_name = parts(®istration).1; out.entries.push(CatalogEntry { registration, level, surface, type_name, name }); } - None => out.unleveled.push(parts(registration).1), + None => out.unleveled.push(parts(®istration).1), } } } @@ -351,18 +351,13 @@ pub fn story_title(type_name: &str, story: &str) -> String { text[..1].to_uppercase() + &text[1..] } -/// Every library registration linked into the running binary: the types of the library crates, not the fixtures of -/// an integration binary. -fn linked() -> Vec<&'static Registration> { - super::registrations().into_iter().filter(|registration| registration.crate_target() == registration.crate_name().replace('-', "_")).collect() -} - /// The rows of the surface and story layout tables whose type is not among `linked`, in every crate that has a type /// there, and the layout rows whose story group none of the type's linked stories has. The library's crates are /// linked together only above them, so the craft-ui facade's trials run it with every registration of the library. #[cfg(feature = "testing")] #[doc(hidden)] -pub fn stale_table_rows(linked: &[&'static Registration]) -> Vec { +pub fn stale_table_rows(registry: &crate::testing::Registry) -> Vec { + let linked: Vec<_> = registry.registrations().iter().collect(); let named: std::collections::HashSet<(&str, &str)> = linked.iter().map(|registration| table_key(registration)).collect(); let mut crates: std::collections::HashSet<&str> = named.iter().map(|(target, _)| *target).collect(); // The library's rows are checked whenever one of its crates is linked, whatever key its types get. @@ -376,7 +371,7 @@ pub fn stale_table_rows(linked: &[&'static Registration]) -> Vec { let keys: std::collections::HashMap<&str, (&str, &str)> = linked.iter().map(|registration| (parts(registration).1, table_key(registration))).collect(); let mut groups: std::collections::HashMap<(&str, &str), Vec> = std::collections::HashMap::new(); - for entry in crate::testing::stories() { + for entry in registry.stories() { if let Some(&key) = keys.get((entry.type_name)()) { groups.entry(key).or_default().push(entry.story.group_name(key.1)); } @@ -390,25 +385,6 @@ pub fn stale_table_rows(linked: &[&'static Registration]) -> Vec { stale } -/// Guards against a registered type that no row places (it would list under no level) and against names a -/// viewer cannot show as one identifier or that two types share (the tree would list two rows alike). -#[crate::testing::trial] -fn catalog_names_are_unique_pascal_case_and_every_type_has_a_level() { - let catalog = catalog(&linked()); - assert!(catalog.unleveled.is_empty(), "types with no level: {:?}", catalog.unleveled); - let mut seen = std::collections::HashSet::new(); - for entry in &catalog.entries { - let mut chars = entry.name.chars(); - assert!( - chars.next().is_some_and(|first| first.is_ascii_uppercase()) && chars.all(|c| c.is_ascii_alphanumeric()), - "`{}` ({}) is not a PascalCase identifier", - entry.name, - entry.type_name - ); - assert!(seen.insert((entry.level, entry.name.to_lowercase())), "`{}` is listed twice in {:?}", entry.name, entry.level); - } -} - /// Guards the story title rule: the type's words come off the front, the rest reads as a sentence. #[crate::testing::trial] fn story_titles_drop_the_type_prefix_and_use_sentence_case() { diff --git a/crates/ui-contract/src/contract/mod.rs b/crates/ui-contract/src/contract/mod.rs index 3c8f80cc2..239cf78aa 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -13,12 +13,12 @@ pub mod ghost; mod group; mod held; mod hosted; -mod items; -mod label; +pub(crate) mod items; +pub(crate) mod label; mod lazy; -#[cfg(feature = "testing")] -mod level; -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] +pub(crate) mod level; +#[cfg(feature = "suite")] mod level_table; mod looks; mod memo; @@ -93,7 +93,7 @@ pub use label::colon_of; pub use label::{CellWidth, FieldLabelRole, FieldLayout, GlyphLabel, InsideLabel, LabelKind, LabelScheme, Scrub, SideLabel}; pub use lazy::Lazy; #[doc(hidden)] -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub use level::{Catalog, CatalogEntry, Level, StoryLayout, Surface, catalog, stale_table_rows, story_title}; pub use looks::Looks; pub use memo::{MemoKey, MemoProps, Stateless}; @@ -103,9 +103,6 @@ pub use pages::Pages; pub use paint_ui::PaintUi; pub use props::{Common, Props, Resolved, Tooltip, TooltipAt, TooltipSpec, TooltipWhen}; #[doc(hidden)] -#[cfg(feature = "testing")] -pub use registry::registrations; -#[doc(hidden)] pub use registry::{CollectionEntry, ContainerEntry, Exemption, LeafEntry, PatternKind, PatternProbe, Probe, Registration, ShowEntry}; pub use sampler::{CanvasGesture, Sampler}; pub use settle::SettleCx; @@ -123,7 +120,7 @@ use std::hash::Hash; use std::ops::Deref; pub use crate::runtime::drag::{DragPreview, DropMark, DropTarget, DropZone, OsFile, OsFiles, WindowDropTarget}; -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) use body::MOVE_BAND; pub use craft_behavior::ColumnKey; pub use craft_behavior::DropOperation; diff --git a/crates/ui-contract/src/contract/registry.rs b/crates/ui-contract/src/contract/registry.rs index d200a2e6c..7d4c43ffc 100644 --- a/crates/ui-contract/src/contract/registry.rs +++ b/crates/ui-contract/src/contract/registry.rs @@ -370,27 +370,12 @@ impl Registration { } } -#[cfg(feature = "testing")] -inventory::collect!(Registration); - -/// Every registration in the running binary, by crate, module and type name. -#[doc(hidden)] -#[cfg(feature = "testing")] -pub fn registrations() -> Vec<&'static Registration> { - let mut all: Vec<_> = inventory::iter::().collect(); - all.sort_by_key(|registration| match registration { - Registration::Component(probe) => (probe.crate_name, probe.crate_target, probe.module, probe.type_name()), - Registration::Pattern(probe) => (probe.crate_name, probe.crate_target, probe.module, probe.type_name()), - }); - all -} - /// Registers the component type `$ty` of shape `$shape` (`leaf`, `container` or `collection`) with its declarations: /// `$overlay`, the `($case, $reason)` exemptions, the optional `$sample` constructor (`fn() -> $ty`, leaves only) /// and the `$purpose` line of its doc comment. #[doc(hidden)] #[macro_export] -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] macro_rules! __register_contract { ($ty:ty, $shape:ident, $overlay:expr, [$(($case:expr, $reason:expr)),*], [], $purpose:expr) => { const _: () = { @@ -416,16 +401,18 @@ macro_rules! __register_contract { /// The registration static of `__register_contract!`; `$with` is the probe's further builder calls. #[doc(hidden)] #[macro_export] -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] macro_rules! __register_probe { ($ty:ty, $shape:ident, $overlay:expr, [$(($case:expr, $reason:expr)),*], $purpose:expr, $($with:tt)*) => { const EXEMPT: &[$crate::contract::Exemption] = &[$($crate::contract::Exemption::new($case, $reason)),*]; - $crate::__private::inventory::submit! { - $crate::contract::Registration::component( - $crate::contract::Probe::$shape::<$ty>(env!("CARGO_PKG_NAME"), env!("CARGO_CRATE_NAME"), module_path!(), $overlay, EXEMPT) - .with_purpose($purpose) - $($with)*, - ) + impl $crate::testing::Registered for $ty { + fn registration() -> $crate::contract::Registration { + $crate::contract::Registration::component( + $crate::contract::Probe::$shape::<$ty>(env!("CARGO_PKG_NAME"), env!("CARGO_CRATE_NAME"), module_path!(), $overlay, EXEMPT) + .with_purpose($purpose) + $($with)*, + ) + } } }; } @@ -434,32 +421,34 @@ macro_rules! __register_probe { /// `PatternProbe` constructor of its kind: `PatternProbe::of`, `canvas::tool_probe` or `dialog::dialog_probe`. #[doc(hidden)] #[macro_export] -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] macro_rules! __register_pattern { ($ty:ty, $purpose:expr) => { $crate::__register_pattern!($ty, $purpose, $crate::contract::PatternProbe::of); }; ($ty:ty, $purpose:expr, $($probe:tt)+) => { - $crate::__private::inventory::submit! { - $crate::contract::Registration::pattern( - $($probe)+::<$ty>(env!("CARGO_PKG_NAME"), env!("CARGO_CRATE_NAME"), module_path!(), $purpose), - ) + impl $crate::testing::Registered for $ty { + fn registration() -> $crate::contract::Registration { + $crate::contract::Registration::pattern( + $($probe)+::<$ty>(env!("CARGO_PKG_NAME"), env!("CARGO_CRATE_NAME"), module_path!(), $purpose), + ) + } } }; } -/// Registers the pattern type `$ty`; without the `testing` feature there is nothing to register. +/// Registers the pattern type `$ty`; without the `suite` feature there is nothing to register. #[doc(hidden)] #[macro_export] -#[cfg(not(feature = "testing"))] +#[cfg(not(feature = "suite"))] macro_rules! __register_pattern { ($ty:ty, $purpose:expr $(, $($probe:tt)+)?) => {}; } -/// Registers the component type `$ty`; without the `testing` feature there is nothing to register. +/// Registers the component type `$ty`; without the `suite` feature there is nothing to register. #[doc(hidden)] #[macro_export] -#[cfg(not(feature = "testing"))] +#[cfg(not(feature = "suite"))] macro_rules! __register_contract { ($ty:ty, $shape:ident, $overlay:expr, [$(($case:expr, $reason:expr)),*], [$($sample:path)?], $purpose:expr) => {}; } diff --git a/crates/ui-contract/src/lib.rs b/crates/ui-contract/src/lib.rs index 9a6007b49..418ddd0ee 100644 --- a/crates/ui-contract/src/lib.rs +++ b/crates/ui-contract/src/lib.rs @@ -10,7 +10,7 @@ // The derives' output names the crate as `craft_ui`, here as in every other crate. extern crate self as craft_ui; -pub use craft_ui_macros::words; +pub use craft_ui_macros::{registry, words}; pub mod contract; pub mod fonts; diff --git a/crates/ui-contract/src/runtime/commands/board.rs b/crates/ui-contract/src/runtime/commands/board.rs index e80cfddde..7269f8bc7 100644 --- a/crates/ui-contract/src/runtime/commands/board.rs +++ b/crates/ui-contract/src/runtime/commands/board.rs @@ -858,7 +858,7 @@ pub(crate) fn install(ctx: &Context, stories: bool) -> Result<(), registry::Comm /// A keymap with the chords it binds to the edit commands and to the window's keys. #[derive(Clone)] -struct BuiltKeymap { +pub(crate) struct BuiltKeymap { keymap: Arc, edit_chords: Arc<[(EditCommand, Chord)]>, window_shortcuts: Arc<[(WindowShortcut, Chord)]>, @@ -994,23 +994,17 @@ fn build_keymap(registry: ®istry::Registry, app: Option<&AppCatalog>, platfor BuiltKeymap { keymap: Arc::new(keymap), edit_chords, window_shortcuts, shown_text: Arc::new(shown_text) } } -/// The keymap of each shared registry (with or without the stories' sets) on each platform with no overrides. It -/// depends on nothing else, so every context of the process shares it. -static DEFAULT_KEYMAPS: std::sync::Mutex> = std::sync::Mutex::new(Vec::new()); - -/// The keymap of `registry` and `app` on `platform` under `overrides`: built once per platform for the shared -/// registry with no overrides and no catalog, else built here. +/// Builds or reuses a keymap owned by this exact command registry. fn keymap_for(registry: &Arc, app: Option<&AppCatalog>, platform: Platform, overrides: Option<&Arc>) -> BuiltKeymap { - if app.is_some() || overrides.is_some() || !registry::Registry::is_shared(registry) { + if app.is_some() || overrides.is_some() { return build_keymap(registry, app, platform, overrides); } - let mut kept = DEFAULT_KEYMAPS.lock().unwrap_or_else(std::sync::PoisonError::into_inner); - let stories = registry.has_stories(); - if let Some((.., built)) = kept.iter().find(|(on, with, _)| *on == platform && *with == stories) { + let mut kept = registry.keymaps.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + if let Some((_, built)) = kept.iter().find(|(on, _)| *on == platform) { return built.clone(); } let built = build_keymap(registry, None, platform, None); - kept.push((platform, stories, built.clone())); + kept.push((platform, built.clone())); built } diff --git a/crates/ui-contract/src/runtime/commands/mod.rs b/crates/ui-contract/src/runtime/commands/mod.rs index c53e067da..888392774 100644 --- a/crates/ui-contract/src/runtime/commands/mod.rs +++ b/crates/ui-contract/src/runtime/commands/mod.rs @@ -14,6 +14,8 @@ pub use library::{EditCommands, NavCommand, WindowCommand}; pub use registry::CommandDefError; #[doc(hidden)] pub use registry::{SetEntry, sets}; +#[cfg(feature = "suite")] +pub(crate) use registry::{StorySelection, configure_story_sets, with_story_sets}; #[doc(hidden)] pub use board::declare_child; diff --git a/crates/ui-contract/src/runtime/commands/registry.rs b/crates/ui-contract/src/runtime/commands/registry.rs index 115552e22..040290132 100644 --- a/crates/ui-contract/src/runtime/commands/registry.rs +++ b/crates/ui-contract/src/runtime/commands/registry.rs @@ -27,8 +27,6 @@ pub struct SetEntry { pub typing: Option, /// The defaults of one platform, which replace the command's other defaults there. pub platform_defaults: fn() -> Result, CommandDefError>, - /// A story's set (`#[command(story)]`): loaded only by an install that shows stories. - pub story: bool, } impl SetEntry { @@ -42,13 +40,7 @@ impl SetEntry { typing: Option, platform_defaults: fn() -> Result, CommandDefError>, ) -> Self { - SetEntry { name, defs, no_default_on, edits, holds, typing, platform_defaults, story: false } - } - - /// The entry as a story's set. - pub const fn story(mut self) -> Self { - self.story = true; - self + SetEntry { name, defs, no_default_on, edits, holds, typing, platform_defaults } } } @@ -70,9 +62,6 @@ macro_rules! __register_command_set { ($ty:ty) => { $crate::__register_command_set!(@entry $ty, ::core::convert::identity); }; - ($ty:ty, story) => { - $crate::__register_command_set!(@entry $ty, $crate::runtime::commands::SetEntry::story); - }; (@entry $ty:ty, $mark:expr) => { const _: () = { $crate::__private::inventory::submit! { @@ -153,6 +142,56 @@ impl std::error::Error for CommandDefError {} /// The shared registries: the app's sets, and the app's sets with the stories' (`[apps, with stories]`). static LOADED: [OnceLock>; 2] = [OnceLock::new(), OnceLock::new()]; +/// One selected set of story commands and its lazily loaded definitions. +#[cfg(feature = "suite")] +pub(crate) struct StorySelection { + sets: Vec, + loaded: OnceLock>, +} + +#[cfg(feature = "suite")] +impl StorySelection { + pub(crate) fn new(sets: Vec) -> Self { + Self { sets, loaded: OnceLock::new() } + } + + fn shared(&self) -> Result, CommandDefError> { + if let Some(loaded) = self.loaded.get() { + return Ok(loaded.clone()); + } + let loaded = Arc::new(Registry::load_selected(true, &self.sets)?); + Ok(self.loaded.get_or_init(|| loaded).clone()) + } +} + +#[cfg(feature = "suite")] +thread_local! { + static STORY_SETS: std::cell::RefCell>> = const { std::cell::RefCell::new(None) }; +} + +/// Selects story commands for contexts created on this thread. +#[cfg(feature = "suite")] +pub(crate) fn configure_story_sets(selection: Arc) -> bool { + if selection.shared().is_err() { + return false; + } + STORY_SETS.with(|current| *current.borrow_mut() = Some(selection)); + true +} + +/// Runs one trial with its selection and restores the caller's selection. +#[cfg(feature = "suite")] +pub(crate) fn with_story_sets(selection: &Arc, f: impl FnOnce() -> R) -> R { + struct Restore(Option>); + impl Drop for Restore { + fn drop(&mut self) { + STORY_SETS.with(|current| *current.borrow_mut() = self.0.take()); + } + } + let previous = STORY_SETS.with(|current| current.borrow_mut().replace(selection.clone())); + let _restore = Restore(previous); + f() +} /// Indexes the definition at `at` under its id `id`; an id already in `index` is refused (`Duplicate`). The registry /// and an app's catalog index their definitions through it. @@ -178,15 +217,24 @@ pub(crate) struct Registry { holds: HashMap, /// The scopes whose keys are meant for typing (`CommandSet::TYPING`). typing: HashSet<&'static str>, - /// Whether the stories' sets are loaded. - stories: bool, + /// Default keymaps are shared by contexts using this exact registry. + pub(crate) keymaps: std::sync::Mutex>, } impl Registry { /// Loads every linked set; the stories' sets only with `stories`. pub(crate) fn load(stories: bool) -> Result { - let mut registry = Registry { stories, ..Registry::default() }; - for entry in sets().into_iter().filter(|entry| stories || !entry.story) { + Self::load_selected(stories, &[]) + } + + fn load_selected(stories: bool, story_sets: &[SetEntry]) -> Result { + let mut registry = Registry::default(); + let mut entries = sets(); + if stories { + entries.extend(story_sets.iter()); + entries.sort_by_key(|entry| (entry.name)()); + } + for entry in entries { for def in (entry.defs)()? { registry.add(def)?; } @@ -204,6 +252,13 @@ impl Registry { /// The registry of every linked set (the stories' sets only with `stories`), loaded once per process: the sets are /// static, so every context shares one. A load that fails is not kept, so each install reports its error. pub(crate) fn shared(stories: bool) -> Result, CommandDefError> { + #[cfg(feature = "suite")] + if stories { + let selection = STORY_SETS.with(|current| current.borrow().clone()); + if let Some(selection) = selection { + return selection.shared(); + } + } let slot = &LOADED[usize::from(stories)]; if let Some(loaded) = slot.get() { return Ok(loaded.clone()); @@ -212,16 +267,6 @@ impl Registry { Ok(slot.get_or_init(|| registry).clone()) } - /// Whether `registry` is one [`Registry::shared`] loaded. - pub(crate) fn is_shared(registry: &Arc) -> bool { - LOADED[usize::from(registry.stories)].get().is_some_and(|loaded| Arc::ptr_eq(loaded, registry)) - } - - /// Whether the stories' sets are loaded. - pub(crate) fn has_stories(&self) -> bool { - self.stories - } - fn add(&mut self, def: CommandDef) -> Result<(), CommandDefError> { index_id(&mut self.index, &def.command.id, self.defs.len())?; self.defs.push(def); diff --git a/crates/ui-contract/src/runtime/egui/access.rs b/crates/ui-contract/src/runtime/egui/access.rs index 4b482d982..be6d1ac13 100644 --- a/crates/ui-contract/src/runtime/egui/access.rs +++ b/crates/ui-contract/src/runtime/egui/access.rs @@ -121,7 +121,7 @@ pub(crate) fn node_id(id: Id) -> NodeId { pub(crate) type NodeRole = accesskit::Role; /// The AccessKit vocabulary the testing kit reads a tree in. -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) use accesskit::{Role, Toggled}; /// The AccessKit node number of `id`, the key an action request's target is matched by. diff --git a/crates/ui-contract/src/runtime/egui/areas.rs b/crates/ui-contract/src/runtime/egui/areas.rs index 0f8a761d9..bf7c2d9be 100644 --- a/crates/ui-contract/src/runtime/egui/areas.rs +++ b/crates/ui-contract/src/runtime/egui/areas.rs @@ -420,19 +420,19 @@ pub(crate) fn popup_open(ctx: &Context) -> bool { } /// A host's own egui popup `id` at `at`, shown while egui's memory holds it open. -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) fn host_popup(ui: &Ui, id: egui::Id, at: Pos2) { egui::Popup::new(id, ui.ctx().clone(), at, ui.layer_id()).open_memory(None).show(|ui| ui.allocate_space(ui.spacing().interact_size)); } /// Opens the host's egui popup `id`. -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) fn open_host_popup(ctx: &Context, id: egui::Id) { egui::Popup::open_id(ctx, id); } /// Whether the host's egui popup `id` is open. -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) fn host_popup_open(ctx: &Context, id: egui::Id) -> bool { egui::Popup::is_id_open(ctx, id) } diff --git a/crates/ui-contract/src/runtime/egui/fixture.rs b/crates/ui-contract/src/runtime/egui/fixture.rs index f1da96997..f21e99a85 100644 --- a/crates/ui-contract/src/runtime/egui/fixture.rs +++ b/crates/ui-contract/src/runtime/egui/fixture.rs @@ -365,6 +365,7 @@ pub(crate) fn allow_zoom_keys(ctx: &Context) { /// Sets egui's click options, as an app does for its own widgets: the longest movement and the longest press that /// still count as a click. +#[cfg(feature = "suite")] pub(crate) fn set_click_options(ctx: &Context, distance: f32, seconds: f64) { ctx.options_mut(|options| { options.input_options.max_click_dist = distance; @@ -374,17 +375,20 @@ pub(crate) fn set_click_options(ctx: &Context, distance: f32, seconds: f64) { /// Sets egui's surrender option, the app's rule for its own focused widgets: with `never`, a click elsewhere leaves /// their focus; otherwise egui's default, which surrenders it on a click elsewhere. +#[cfg(feature = "suite")] pub(crate) fn set_app_surrender(ctx: &Context, never: bool) { let rule = if never { egui::SurrenderFocusOn::Never } else { egui::SurrenderFocusOn::Clicks }; ctx.options_mut(|options| options.input_options.surrender_focus_on = rule); } /// Whether egui's surrender option is egui's default, a click elsewhere. +#[cfg(feature = "suite")] pub(crate) fn app_surrenders_on_click(ctx: &Context) -> bool { ctx.options(|options| options.input_options.surrender_focus_on == egui::SurrenderFocusOn::Clicks) } /// egui's click options: the longest movement and the longest press that still count as a click. +#[cfg(feature = "suite")] pub(crate) fn click_options(ctx: &Context) -> (f32, f64) { ctx.options(|options| (options.input_options.max_click_dist, options.input_options.max_click_duration)) } @@ -482,29 +486,34 @@ pub(crate) fn focusable_widget(ui: &mut Ui, id: egui::Id) -> Rect { /// A host's own single-line egui text field of `id` over `text`, as an app that keeps its own widgets beside the /// framework's draws it; returns its rect. +#[cfg(feature = "suite")] pub(crate) fn host_field(ui: &mut Ui, id: egui::Id, text: &mut String) -> Rect { ui.add(egui::TextEdit::singleline(text).id(id)).rect } /// Gives the host's own egui widget `id` key focus, as the host's code does. +#[cfg(feature = "suite")] pub(crate) fn host_focus(ctx: &Context, id: egui::Id) { ctx.memory_mut(|memory| memory.request_focus(id)); } /// A host's own clickable egui widget `id` at `rect`, a focus stop for egui's own focus moves; returns whether egui /// reports a click on it, by egui's click options. +#[cfg(feature = "suite")] pub(crate) fn host_button(ui: &Ui, id: egui::Id, rect: Rect) -> bool { ui.interact(rect, id, egui::Sense::click()).clicked() } /// A host's own egui drag area `id` at `rect`; returns whether egui reports it dragged and whether its drag stopped /// this pass. +#[cfg(feature = "suite")] pub(crate) fn host_drag_area(ui: &Ui, id: egui::Id, rect: Rect) -> (bool, bool) { let response = ui.interact(rect, id, egui::Sense::drag()); (response.dragged(), response.drag_stopped()) } /// A host's own selectable egui label of `text`; returns its rect. +#[cfg(feature = "suite")] pub(crate) fn host_label(ui: &mut Ui, text: &str) -> Rect { ui.add(egui::Label::new(text).selectable(true)).rect } diff --git a/crates/ui-contract/src/runtime/egui/widgets.rs b/crates/ui-contract/src/runtime/egui/widgets.rs index 6bf6f57ca..b4f84f054 100644 --- a/crates/ui-contract/src/runtime/egui/widgets.rs +++ b/crates/ui-contract/src/runtime/egui/widgets.rs @@ -75,7 +75,7 @@ pub(crate) fn note_node(_: &Context, _: Id) {} /// A scroll region the runtime showed: `view` is the rect that shows it and cuts what lies outside, `content` the rect /// of what it holds, which scrolls through the view along the region's axes and lies within the view along the others. -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] #[derive(Clone, Copy, Debug)] pub(crate) struct ScrollRegion { pub view: Rect, @@ -83,7 +83,7 @@ pub(crate) struct ScrollRegion { } /// Notes a scroll region of the running pass, for the suite's size cases. -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) fn note_scroll_region(ctx: &Context, view: Rect, content: Rect) { noted::with(ctx, |pass| pass.scrolls.push(ScrollRegion { view, content })); // The view cuts what lies outside it, as a clip does: a replay cut by the clip around it cuts the view too. @@ -94,11 +94,11 @@ pub(crate) fn note_scroll_region(ctx: &Context, view: Rect, content: Rect) { ); } -#[cfg(not(feature = "testing"))] +#[cfg(not(feature = "suite"))] pub(crate) fn note_scroll_region(_: &Context, _: Rect, _: Rect) {} /// The scroll regions the runtime noted in the root viewport's latest pass. -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) fn scroll_regions(ctx: &Context) -> Vec { noted::scrolls(ctx) } @@ -140,6 +140,7 @@ pub(crate) mod noted { pub(super) struct Pass { pub(super) widgets: HashSet, pub(super) nodes: HashSet, + #[cfg(feature = "suite")] pub(super) scrolls: Vec, } @@ -155,6 +156,7 @@ pub(crate) mod noted { } /// The root viewport's scroll regions of its latest pass. + #[cfg(feature = "suite")] pub(super) fn scrolls(ctx: &Context) -> Vec { crate::runtime::pass_state::with(ctx, |noted: &mut Noted| noted.pass.scrolls.clone()) } diff --git a/crates/ui-contract/src/runtime/keys.rs b/crates/ui-contract/src/runtime/keys.rs index f104baba8..f8d80f3f1 100644 --- a/crates/ui-contract/src/runtime/keys.rs +++ b/crates/ui-contract/src/runtime/keys.rs @@ -33,7 +33,7 @@ pub use input::{down, keyed}; pub use intents::Intents; #[doc(hidden)] pub use intents::intents_of; -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) use intents::lent_taken; #[doc(hidden)] pub use intents::settle; diff --git a/crates/ui-contract/src/runtime/keys/intents.rs b/crates/ui-contract/src/runtime/keys/intents.rs index a0b6e41ef..192e5ebdb 100644 --- a/crates/ui-contract/src/runtime/keys/intents.rs +++ b/crates/ui-contract/src/runtime/keys/intents.rs @@ -400,7 +400,7 @@ pub(crate) fn give_back(ctx: &Context, to: Id, lent: Lent) { /// How many lent keys session members have taken so far in the current viewport: a check of keyboard parity reads /// it before and after its input, since a lent key is the session control's, not the focused component's. -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) fn lent_taken(ctx: &Context) -> u64 { current(ctx, |stage| stage.lent_taken) } diff --git a/crates/ui-contract/src/runtime/overlay.rs b/crates/ui-contract/src/runtime/overlay.rs index a6f1fcdce..d43456fd0 100644 --- a/crates/ui-contract/src/runtime/overlay.rs +++ b/crates/ui-contract/src/runtime/overlay.rs @@ -421,7 +421,7 @@ pub fn family(ctx: &Context, id: Id) -> SmallVec<[Id; 4]> { } /// Every layer of the running viewport shown last frame, not exiting, parent first. -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) fn open_entries(ctx: &Context) -> Vec { with_pass(ctx, |pass| pass.last.iter().filter(|entry| !entry.exiting).cloned().collect()) } diff --git a/crates/ui-contract/src/runtime/pass_state.rs b/crates/ui-contract/src/runtime/pass_state.rs index 47a8da311..2dc04e1d0 100644 --- a/crates/ui-contract/src/runtime/pass_state.rs +++ b/crates/ui-contract/src/runtime/pass_state.rs @@ -321,8 +321,8 @@ fn park(held: Held) { Service::::run(&held.ctx, |parked| parked.0 = Some(held.state)); } -#[cfg(feature = "testing")] -mod binding_tests { +#[cfg(all(feature = "testing", any(test, feature = "suite")))] +pub(crate) mod binding_tests { use super::{PassState, bound, hold, in_component_tree, visit, with_component_tree}; use crate::testing::trial; use egui::Context; diff --git a/crates/ui-contract/src/runtime/pointer.rs b/crates/ui-contract/src/runtime/pointer.rs index 4d309774f..d32f5b886 100644 --- a/crates/ui-contract/src/runtime/pointer.rs +++ b/crates/ui-contract/src/runtime/pointer.rs @@ -561,7 +561,7 @@ pub(crate) fn part_bounds(ctx: &Context, owner: Id, part: craft_behavior::PartRe } /// Whether the part `part` of `owner` (the arena root or a member) senses all of `sense` in last pass's shape record. -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) fn part_senses(ctx: &Context, owner: Id, part: craft_behavior::PartRef, sense: craft_behavior::Sense) -> bool { let viewport = pass::current_viewport(ctx); PerViewport::::with(ctx, viewport, |record| { @@ -596,7 +596,7 @@ fn owned_part_bounds(ctx: &Context, owner: impl Fn(Id) -> bool, part: craft_beha /// The bounds of the part `part` that senses `sense`, on a component other than `subject` and lying inside the /// subject's own shapes in last pass's shape record: where a component's child keeps the part a drive acts on. When /// several children match, the first by top edge, then start edge, then root id. -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] pub(crate) fn child_part_bounds(ctx: &Context, subject: Id, part: craft_behavior::PartRef, sense: craft_behavior::Sense) -> Option { let viewport = pass::current_viewport(ctx); PerViewport::::with(ctx, viewport, |record| { diff --git a/crates/ui-contract/src/testing/index.rs b/crates/ui-contract/src/testing/index.rs index 846377d92..89b9e50ee 100644 --- a/crates/ui-contract/src/testing/index.rs +++ b/crates/ui-contract/src/testing/index.rs @@ -49,7 +49,7 @@ fn shape_rank(shape: &str) -> usize { } /// The components and patterns of `registered`, ordered by level (the gallery's order), shape, then name. -fn registered_rows(registered: &[&'static Registration]) -> Vec { +fn registered_rows(registered: &[&Registration]) -> Vec { let mut rows = Vec::new(); for entry in catalog(registered).entries { let level = entry.level; @@ -77,12 +77,12 @@ fn registered_rows(registered: &[&'static Registration]) -> Vec { } /// The types of `registered` that have no purpose: their types lack a doc comment. -pub fn types_without_purpose(registered: &[&'static Registration]) -> Vec { +pub fn types_without_purpose(registered: &[&Registration]) -> Vec { registered_rows(registered).into_iter().filter(|row| row.purpose.is_empty()).map(|row| format!("{}::{}", row.module, row.name)).collect() } /// The text of `docs/components-index.md` for the workspace at `root` and the types of `registered`. -pub fn components_index(root: &Path, registered: &[&'static Registration]) -> String { +pub fn components_index(root: &Path, registered: &[&Registration]) -> String { let mut out = String::from("# Built components\n\n"); out.push_str("Generated by `cargo run -p craft-ui-gallery --bin components-index`; edit the doc comments, not this file.\n\n"); diff --git a/crates/ui-contract/src/testing/mod.rs b/crates/ui-contract/src/testing/mod.rs index 27c05cfeb..12c245f68 100644 --- a/crates/ui-contract/src/testing/mod.rs +++ b/crates/ui-contract/src/testing/mod.rs @@ -14,24 +14,33 @@ pub mod face_runs; pub mod fixture; pub mod focus; pub mod frames; -mod host_key_trials; -mod icon_trials; +#[cfg(feature = "suite")] +pub(crate) mod host_key_trials; +#[cfg(feature = "suite")] +pub(crate) mod icon_trials; +#[cfg(feature = "suite")] pub mod index; pub mod input; -mod key_trials; +#[cfg(feature = "suite")] +pub(crate) mod key_trials; pub mod layout; pub mod memory; pub mod pictures; pub mod pointer; +#[cfg(feature = "suite")] +mod registry; pub mod relations; -mod replay_trials; +#[cfg(feature = "suite")] +pub(crate) mod replay_trials; pub mod sensing; #[cfg(all(feature = "snapshot", not(target_arch = "wasm32")))] pub mod snapshot; mod stage; -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub mod story; pub mod style; +#[cfg(feature = "suite")] pub mod suite; pub mod surface; pub mod text; @@ -52,11 +61,12 @@ pub use crate::runtime::measure::{ pub use craft_ui_macros::{story, trial}; pub use fixture::{Fixture, Impure, Room, Target}; pub use frames::Frames; +#[cfg(feature = "suite")] +pub use registry::{Registered, Registry}; pub use stage::{room_height, stage, stage_fitting, stage_width}; #[doc(hidden)] pub use story::{ CollectionKind, Drive, EditKind, Grip, Required, Story, StoryData, StoryOutput, StoryRegistration, StorySnapshot, ValueAt, show_as_only_item, - stories, }; pub use windows::install_spec; @@ -94,69 +104,41 @@ impl Trial { } } -inventory::collect!(Trial); - -/// Every `#[trial]` linked into the running binary, by full name. -pub fn trials() -> Vec<&'static Trial> { - let mut all: Vec<_> = inventory::iter::().collect(); - all.sort_by_key(|trial| trial.full_name()); - all -} - /// Runs a test executable and exits: the `#[trial]`s declared in the crate whose root module is `crate_root` or in /// `package`'s library crate, and the suite's trials over `registered`. Every test executable's `main` calls it, with /// its own `module_path!()`. -pub fn run(crate_root: &str, package: &'static str, registered: &[&'static Registration]) -> ! { +#[cfg(feature = "suite")] +pub fn run(crate_root: &str, package: &'static str, registry: &Registry) -> ! { + if !registry.install_story_sets() { + eprintln!("the selected story commands are invalid"); + std::process::exit(1); + } let library = package.replace('-', "_"); let own = |module: &str| { [crate_root, library.as_str()].into_iter().any(|root| module.strip_prefix(root).is_some_and(|rest| rest.is_empty() || rest.starts_with("::"))) }; - let mut tests: Vec = trials() - .into_iter() + let mut tests: Vec = registry + .trials() + .iter() .filter(|trial| own(trial.module)) .map(|trial| { let run = trial.run; + let story_sets = registry.story_selection(); libtest_mimic::Trial::test(trial.full_name(), move || { - run(); - Ok(()) + crate::runtime::commands::with_story_sets(&story_sets, || { + run(); + Ok(()) + }) }) .with_ignored_flag(trial.ignored) }) .collect(); - tests.extend(suite::trials(package, registered)); + tests.extend(suite::trials(package, registry)); // A trial that re-runs its executable as a stand-in for another program passes that program's arguments after // `--`; they are the stand-in's, not the runner's. let args = libtest_mimic::Arguments::from_iter(std::env::args().take_while(|arg| arg != "--")); libtest_mimic::run(&args, tests).exit() } -/// Every registration declared in the library crate of the package `crate_name` and linked into the running -/// binary, by module and type name. Types declared in the package's integration binaries are fixtures, not the package's. -pub fn registered_in(crate_name: &str) -> Vec<&'static Registration> { - let library = crate_name.replace('-', "_"); - crate::contract::registrations() - .into_iter() - .filter(|registration| registration.crate_name() == crate_name && registration.crate_target() == library) - .collect() -} - -/// Writes `pub fn registered()` for the invoking package: its library crate's registrations in the running binary. -/// A crate invokes it once, in its `testing` module, and its integration binary calls the function by name. The -/// call references the library, so the linker includes it; the registrations are constructors in the library's -/// object files, which run as long as those files are linked. -#[macro_export] -macro_rules! testing_registered { - () => { - /// Every registration of this package linked into the running binary. - pub fn registered() -> ::std::vec::Vec<&'static $crate::testing::Registration> { - $crate::testing::registered_in(env!("CARGO_PKG_NAME")) - } - }; -} - -testing_registered!(); - -#[doc(hidden)] -pub mod __private { - pub use inventory; -} +#[cfg(feature = "suite")] +craft_ui_macros::registry!(); diff --git a/crates/ui-contract/src/testing/registry.rs b/crates/ui-contract/src/testing/registry.rs new file mode 100644 index 000000000..6568fcc12 --- /dev/null +++ b/crates/ui-contract/src/testing/registry.rs @@ -0,0 +1,90 @@ +//! Explicit registrations selected by a test executable or the gallery. + +use super::{StoryRegistration, Trial}; +use crate::contract::Registration; +use crate::runtime::commands::SetEntry; + +/// A component or pattern whose derive supplies its suite registration. +pub trait Registered { + /// The registration for this concrete type. + fn registration() -> Registration; +} + +/// The suite items selected by a caller. +#[derive(Default)] +pub struct Registry { + registrations: Vec, + stories: Vec, + trials: Vec, + story_sets: Vec, + selection: std::sync::OnceLock>, +} + +impl Registry { + /// Collects the items contributed by each selected crate. + pub fn of(crates: &[fn(&mut Registry)]) -> Self { + let mut registry = Self::default(); + for register in crates { + register(&mut registry); + } + registry.registrations.sort_by_key(|entry| match entry { + Registration::Component(probe) => (probe.crate_name, probe.crate_target, probe.module, probe.type_name()), + Registration::Pattern(probe) => (probe.crate_name, probe.crate_target, probe.module, probe.type_name()), + }); + registry.stories.sort_by_key(|story| ((story.type_name)(), (story.registration)().crate_name() != story.crate_name, story.file, story.line)); + registry.trials.sort_by_key(Trial::full_name); + registry.story_sets.sort_by_key(|entry| (entry.name)()); + registry + } + + /// Adds a component or pattern registration. + pub fn add_registration(&mut self, registration: Registration) { + self.registrations.push(registration); + } + + /// Adds a story. + pub fn add_story(&mut self, story: StoryRegistration) { + self.stories.push(story); + } + + /// Adds a trial. + pub fn add_trial(&mut self, trial: Trial) { + self.trials.push(trial); + } + + /// Adds a command set used by stories. + pub fn add_story_set(&mut self, set: SetEntry) { + let _ = self.selection.take(); + self.story_sets.push(set); + } + + /// The selected components and patterns. + pub fn registrations(&self) -> &[Registration] { + &self.registrations + } + + /// The selected stories. + pub fn stories(&self) -> &[StoryRegistration] { + &self.stories + } + + /// The selected trials. + pub fn trials(&self) -> &[Trial] { + &self.trials + } + + /// Selects story command sets for contexts created on the current thread. + /// Returns false if the selected definitions are invalid. + pub fn install_story_sets(&self) -> bool { + crate::runtime::commands::configure_story_sets(self.story_selection()) + } + + pub(crate) fn story_selection(&self) -> std::sync::Arc { + self.selection.get_or_init(|| std::sync::Arc::new(crate::runtime::commands::StorySelection::new(self.story_sets.clone()))).clone() + } + + /// The selected story command sets. + pub fn story_sets(&self) -> &[SetEntry] { + &self.story_sets + } +} diff --git a/crates/ui-contract/src/testing/story.rs b/crates/ui-contract/src/testing/story.rs index 449ca6619..e27a5eebf 100644 --- a/crates/ui-contract/src/testing/story.rs +++ b/crates/ui-contract/src/testing/story.rs @@ -149,12 +149,14 @@ impl Story { /// The name of the story's group as a story of the type whose display name is `type_name`: its group, else its /// caption. + #[cfg(feature = "suite")] pub fn group_name(&self, type_name: &str) -> String { self.group.map_or_else(|| self.caption(type_name), str::to_owned) } /// The story's caption as a story of the type whose display name is `type_name`: its title, else the one its /// name makes ([`crate::contract::story_title`]). + #[cfg(feature = "suite")] pub fn caption(&self, type_name: &str) -> String { self.title.map_or_else(|| crate::contract::story_title(type_name, self.name), str::to_owned) } @@ -181,6 +183,7 @@ impl Story { /// A story registered by `#[story]`, linked to its type by the type's registered name. #[doc(hidden)] +#[derive(Clone, Copy)] #[non_exhaustive] pub struct StoryRegistration { /// The package that declares the story. @@ -189,6 +192,8 @@ pub struct StoryRegistration { pub crate_target: &'static str, /// The registered name of the type the story shows. pub type_name: fn() -> &'static str, + /// The registration of the type shown by this story. + pub registration: fn() -> crate::contract::Registration, /// The story. pub story: Story, /// The source file of the declaration. @@ -199,8 +204,14 @@ pub struct StoryRegistration { impl StoryRegistration { /// The registration `#[story]` writes. - pub const fn new(crate_name: &'static str, crate_target: &'static str, type_name: fn() -> &'static str, story: Story) -> Self { - StoryRegistration { crate_name, crate_target, type_name, story, file: "", line: 0 } + pub const fn new( + crate_name: &'static str, + crate_target: &'static str, + type_name: fn() -> &'static str, + registration: fn() -> crate::contract::Registration, + story: Story, + ) -> Self { + StoryRegistration { crate_name, crate_target, type_name, registration, story, file: "", line: 0 } } /// The registration declared at `line` of `file`. @@ -211,27 +222,6 @@ impl StoryRegistration { } } -inventory::collect!(StoryRegistration); - -/// Every story linked into the running binary, by type name; of each type, the stories of the package that registers -/// it first, then those other packages declare; each in the order they are declared in. -#[doc(hidden)] -pub fn stories() -> Vec<&'static StoryRegistration> { - let homes: HashMap<&str, &str> = crate::contract::registrations() - .into_iter() - .filter_map(|registration| { - let name = registration.probe().map(|probe| probe.type_name()).or_else(|| registration.pattern_probe().map(|probe| probe.type_name()))?; - Some((name, registration.crate_name())) - }) - .collect(); - let mut all: Vec<_> = inventory::iter::().collect(); - all.sort_by_key(|entry| { - let name = (entry.type_name)(); - (name, homes.get(name) != Some(&entry.crate_name), entry.file, entry.line) - }); - all -} - /// The values a story shows, by name. Each is a `Value`, so the runner compares them before and after a drive. #[derive(Default)] pub struct StoryData { diff --git a/crates/ui-contract/src/testing/suite.rs b/crates/ui-contract/src/testing/suite.rs index b025b4904..037d70f80 100644 --- a/crates/ui-contract/src/testing/suite.rs +++ b/crates/ui-contract/src/testing/suite.rs @@ -31,16 +31,17 @@ pub use size::{reflowed, text_size_case}; pub use states::required_states; pub use variants::rtl_case; +use super::Registry; use super::fixture::Fixture; -use super::story::{Story, stories}; +use super::story::Story; use crate::contract::{PatternProbe, Probe, Registration, ShapeKind}; use libtest_mimic::{Failed, Trial}; use std::cell::OnceCell; use std::panic::{AssertUnwindSafe, catch_unwind}; /// What a case reads: the registered type, the stories written for it, and what the cases share of them. -struct Subject { - probe: &'static Probe, +struct Subject<'a> { + probe: &'a Probe, stories: Vec, /// The stories are the home package's, the one that registers the type. Stories another package declares for the /// type run only the per-story cases there; the cases about the type as a whole (its required states, its @@ -62,8 +63,8 @@ struct Base { plan: drive::Plan, } -impl Subject { - fn new(probe: &'static Probe, stories: Vec, home: bool) -> Self { +impl<'a> Subject<'a> { + fn new(probe: &'a Probe, stories: Vec, home: bool) -> Self { let bases = stories.iter().map(|_| OnceCell::new()).collect(); Subject { probe, stories, home, bases, style_sources: OnceCell::new(), style_ctx: OnceCell::new() } } @@ -171,8 +172,8 @@ fn panic_text(payload: Box) -> String { /// The cases of `group` over the stories of the type `probe` describes, and with `check_exemptions` the check that /// each exemption names a known case. `home`: the stories are the package's that registers the type ([`Subject::home`]). -fn run_group(probe: &'static Probe, group: &'static Group, check_exemptions: bool, home: bool, stories: Vec) -> Result<(), Failed> { - let subject = Subject::new(probe, stories, home); +fn run_group(probe: Probe, group: &'static Group, check_exemptions: bool, home: bool, stories: Vec) -> Result<(), Failed> { + let subject = Subject::new(&probe, stories, home); let mut failures = Vec::new(); if check_exemptions && home { for exemption in probe.exempt { @@ -182,7 +183,7 @@ fn run_group(probe: &'static Probe, group: &'static Group, check_exemptions: boo } } for case in group.cases() { - if !runs_for(case, probe) { + if !runs_for(case, &probe) { continue; } match catch_unwind(AssertUnwindSafe(|| (case.run)(&subject))) { @@ -197,10 +198,11 @@ fn run_group(probe: &'static Probe, group: &'static Group, check_exemptions: boo /// The trials of one package: a trial per registered type and group of cases, `suite::::`; the same for /// each type another linked package registers and this package has stories of, over those stories and without the /// cases about the type as a whole (`Subject::home`); and one per story naming a type that is not linked. -pub fn trials(package: &'static str, registered: &[&'static Registration]) -> Vec { +pub fn trials(package: &'static str, registry: &Registry) -> Vec { let library = package.replace('-', "_"); - let own: Vec<_> = stories().into_iter().filter(|entry| entry.crate_name == package && entry.crate_target == library).collect(); - let probes: Vec<&'static Probe> = registered.iter().copied().filter_map(Registration::probe).collect(); + let own: Vec<_> = registry.stories().iter().filter(|entry| entry.crate_name == package && entry.crate_target == library).collect(); + let own_registrations = registry.registrations().iter().filter(|entry| entry.crate_name() == package && entry.crate_target() == library); + let probes: Vec = own_registrations.clone().filter_map(Registration::probe).copied().collect(); let mut trials = Vec::new(); for probe in probes.iter().copied() { let mut stories: Vec = own.iter().filter(|entry| (entry.type_name)() == probe.type_name()).map(|entry| entry.story).collect(); @@ -209,18 +211,23 @@ pub fn trials(package: &'static str, registered: &[&'static Registration]) -> Ve } for (index, group) in GROUPS.iter().enumerate() { let stories = stories.clone(); + let story_sets = registry.story_selection(); let name = format!("suite::{}::{}", probe.type_name(), group.name); - trials.push(Trial::test(name, move || run_group(probe, group, index == 0, true, stories))); + trials.push(Trial::test(name, move || { + crate::runtime::commands::with_story_sets(&story_sets, || run_group(probe, group, index == 0, true, stories)) + })); } } - let patterns: Vec<&'static PatternProbe> = registered.iter().copied().filter_map(Registration::pattern_probe).collect(); + let patterns: Vec = own_registrations.filter_map(Registration::pattern_probe).copied().collect(); for pattern in &patterns { let stories: Vec = own.iter().filter(|entry| (entry.type_name)() == pattern.type_name()).map(|entry| entry.story).collect(); let name = pattern.type_name(); - trials.push(Trial::test(format!("suite::{name}"), move || pattern::run(name, &stories).map_err(Failed::from))); + let story_sets = registry.story_selection(); + trials.push(Trial::test(format!("suite::{name}"), move || { + crate::runtime::commands::with_story_sets(&story_sets, || pattern::run(name, &stories).map_err(Failed::from)) + })); } // Stories of a type another linked package registers run that type's cases here, as its visitors. - let linked = crate::contract::registrations(); let mut visited: Vec<&'static str> = Vec::new(); for entry in &own { let name = (entry.type_name)(); @@ -231,21 +238,28 @@ pub fn trials(package: &'static str, registered: &[&'static Registration]) -> Ve continue; } let stories: Vec = own.iter().filter(|entry| (entry.type_name)() == name).map(|entry| entry.story).collect(); - if let Some(probe) = linked.iter().copied().find_map(|registration| registration.probe().filter(|probe| probe.type_name() == name)) { + let registration = (entry.registration)(); + if let Some(probe) = registration.probe().copied() { visited.push(name); for group in GROUPS { let stories = stories.clone(); - trials.push(Trial::test(format!("suite::{name}::{}", group.name), move || run_group(probe, group, false, false, stories))); + let story_sets = registry.story_selection(); + trials.push(Trial::test(format!("suite::{name}::{}", group.name), move || { + crate::runtime::commands::with_story_sets(&story_sets, || run_group(probe, group, false, false, stories)) + })); } - } else if linked.iter().any(|registration| registration.pattern_probe().is_some_and(|pattern| pattern.type_name() == name)) { + } else if registration.pattern_probe().is_some() { visited.push(name); - trials.push(Trial::test(format!("suite::{name}"), move || pattern::run(name, &stories).map_err(Failed::from))); + let story_sets = registry.story_selection(); + trials.push(Trial::test(format!("suite::{name}"), move || { + crate::runtime::commands::with_story_sets(&story_sets, || pattern::run(name, &stories).map_err(Failed::from)) + })); } else { let message = format!("the story `{}` shows `{name}`, which is not in the linked registrations", entry.story.name); trials.push(Trial::test(format!("suite::stories::{}", entry.story.name), move || Err(Failed::from(message)))); } } - for entry in stories().into_iter().filter(|entry| entry.crate_name == package && entry.crate_target != library) { + for entry in registry.stories().iter().filter(|entry| entry.crate_name == package && entry.crate_target != library) { let message = format!( "the story `{}` is declared in the target `{}`; stories live in the library crate's `stories` module", entry.story.name, entry.crate_target diff --git a/crates/ui-contract/src/testing/suite/style.rs b/crates/ui-contract/src/testing/suite/style.rs index efbbb545d..311eab4fb 100644 --- a/crates/ui-contract/src/testing/suite/style.rs +++ b/crates/ui-contract/src/testing/suite/style.rs @@ -32,7 +32,7 @@ pub(super) enum Source { /// The styles of `subject` the stories resolve, read once for the style cases: each story settled, then each of its /// drives run once. One entry per style key, variant and size; the cases resolve each again under the themes they /// measure. -fn sources(subject: &Subject) -> Result<&[Source], String> { +fn sources<'a>(subject: &'a Subject<'_>) -> Result<&'a [Source], String> { subject.style_sources.get_or_init(|| read_sources(subject)).as_deref().map_err(Clone::clone) } @@ -68,7 +68,7 @@ fn read_sources(subject: &Subject) -> Result, String> { /// The context the style cases resolve looks in, one per type. A style hook that measures text needs the fonts, which /// egui installs in its first frame; the style cache keys each look by its key, env, variant and size, so the looks /// resolved before stand in for nothing else. -fn measuring_ctx(subject: &Subject) -> &egui::Context { +fn measuring_ctx<'a>(subject: &'a Subject<'_>) -> &'a egui::Context { subject.style_ctx.get_or_init(|| { let ctx = egui::Context::default(); drop(crate::runtime::egui::fixture::run_frame_shapes(&ctx, 0.0, egui::vec2(800.0, 600.0), |_| {})); diff --git a/crates/ui-contract/tests/it/access/mod.rs b/crates/ui-contract/tests/it/access/mod.rs index d0e364f4e..91b1a2546 100644 --- a/crates/ui-contract/tests/it/access/mod.rs +++ b/crates/ui-contract/tests/it/access/mod.rs @@ -1,13 +1,13 @@ //! The accessibility emitter: the label scope and merge rule, announcements, modal inertness, viewports. -mod bounds; -mod controls; -mod face_record; -mod face_state; -mod focus; -mod levels; -mod nodes; -mod scope; -mod static_text; -mod sub_node_keys; -mod viewports; +pub(crate) mod bounds; +pub(crate) mod controls; +pub(crate) mod face_record; +pub(crate) mod face_state; +pub(crate) mod focus; +pub(crate) mod levels; +pub(crate) mod nodes; +pub(crate) mod scope; +pub(crate) mod static_text; +pub(crate) mod sub_node_keys; +pub(crate) mod viewports; diff --git a/crates/ui-contract/tests/it/body/mod.rs b/crates/ui-contract/tests/it/body/mod.rs index ef7344a76..75236c9a4 100644 --- a/crates/ui-contract/tests/it/body/mod.rs +++ b/crates/ui-contract/tests/it/body/mod.rs @@ -1,5 +1,5 @@ //! The body step and the mount host: regions, scrolling, move and resize, and viewport mounts. -mod mounts; -mod nesting; -mod placement; +pub(crate) mod mounts; +pub(crate) mod nesting; +pub(crate) mod placement; diff --git a/crates/ui-contract/tests/it/canvas/mod.rs b/crates/ui-contract/tests/it/canvas/mod.rs index 7c25209c0..44064d75b 100644 --- a/crates/ui-contract/tests/it/canvas/mod.rs +++ b/crates/ui-contract/tests/it/canvas/mod.rs @@ -1,4 +1,4 @@ //! `Canvas` (20.6): a press away from every canvas control's parts reaches the tool. -mod outside_polygon; -mod past_the_clip; +pub(crate) mod outside_polygon; +pub(crate) mod past_the_clip; diff --git a/crates/ui-contract/tests/it/collection/mod.rs b/crates/ui-contract/tests/it/collection/mod.rs index 93a6b4998..880d56a3d 100644 --- a/crates/ui-contract/tests/it/collection/mod.rs +++ b/crates/ui-contract/tests/it/collection/mod.rs @@ -1,14 +1,14 @@ //! The item step: scrolling, the lead and selection, rename, the empty state, trees and large sources, over //! collections written on the contract only. -mod drag; -mod drops; -mod keys; +pub(crate) mod drag; +pub(crate) mod drops; +pub(crate) mod keys; pub(crate) mod kit; -mod list; -mod reorder_groups; -mod review; -mod rows; -mod sweep_apply; +pub(crate) mod list; +pub(crate) mod reorder_groups; +pub(crate) mod review; +pub(crate) mod rows; +pub(crate) mod sweep_apply; pub(crate) mod table; -mod table_trials; +pub(crate) mod table_trials; diff --git a/crates/ui-contract/tests/it/contract/level.rs b/crates/ui-contract/tests/it/contract/level.rs new file mode 100644 index 000000000..10565db96 --- /dev/null +++ b/crates/ui-contract/tests/it/contract/level.rs @@ -0,0 +1,23 @@ +//! Catalog names across the linked library crates. + +/// Guards against a registered type that no row places (it would list under no level) and against names a +/// viewer cannot show as one identifier or that two types share (the tree would list two rows alike). +#[craft_ui::testing::trial] +fn catalog_names_are_unique_pascal_case_and_every_type_has_a_level() { + let registry = craft_ui::testing::Registry::of(&[craft_ui::testing::register, craft_ui_test_kit::testing::register]); + let linked: Vec<_> = + registry.registrations().iter().filter(|registration| registration.crate_target() == registration.crate_name().replace('-', "_")).collect(); + let catalog = craft_ui::contract::catalog(&linked); + assert!(catalog.unleveled.is_empty(), "types with no level: {:?}", catalog.unleveled); + let mut seen = std::collections::HashSet::new(); + for entry in &catalog.entries { + let mut chars = entry.name.chars(); + assert!( + chars.next().is_some_and(|first| first.is_ascii_uppercase()) && chars.all(|c| c.is_ascii_alphanumeric()), + "`{}` ({}) is not a PascalCase identifier", + entry.name, + entry.type_name + ); + assert!(seen.insert((entry.level, entry.name.to_lowercase())), "`{}` is listed twice in {:?}", entry.name, entry.level); + } +} diff --git a/crates/ui-contract/tests/it/contract/mod.rs b/crates/ui-contract/tests/it/contract/mod.rs index 3c39bfedc..556140903 100644 --- a/crates/ui-contract/tests/it/contract/mod.rs +++ b/crates/ui-contract/tests/it/contract/mod.rs @@ -1,11 +1,12 @@ //! The component contract and the show pipeline: the steps each shape runs, and the rules the steps keep. -mod fixes; -mod gesture; -mod hit_order; -mod memo_key; -mod pages; -mod pointer; -mod style; -mod tracked_bind; -mod visited_type; +pub(crate) mod fixes; +pub(crate) mod gesture; +pub(crate) mod hit_order; +pub(crate) mod level; +pub(crate) mod memo_key; +pub(crate) mod pages; +pub(crate) mod pointer; +pub(crate) mod style; +pub(crate) mod tracked_bind; +pub(crate) mod visited_type; diff --git a/crates/ui-contract/tests/it/contract/visited_type.rs b/crates/ui-contract/tests/it/contract/visited_type.rs index c29953156..dee591092 100644 --- a/crates/ui-contract/tests/it/contract/visited_type.rs +++ b/crates/ui-contract/tests/it/contract/visited_type.rs @@ -42,31 +42,48 @@ fn plain_box(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { // The visitor's story covers no state: a Default story is the registering package's to have. Its file sorts before // the home story's. -craft_ui::testing::__private::inventory::submit! { - StoryRegistration::new(VISITOR, "craft_ui_visitor", std::any::type_name::, Story::new("plain_box", plain_box)).at("a.rs", 1) +fn visitor_story() -> StoryRegistration { + StoryRegistration::new( + VISITOR, + "craft_ui_visitor", + std::any::type_name::, + ::registration, + Story::new("plain_box", plain_box), + ) + .at("a.rs", 1) } -craft_ui::testing::__private::inventory::submit! { +fn home_story() -> StoryRegistration { StoryRegistration::new( env!("CARGO_PKG_NAME"), "craft_ui_contract", std::any::type_name::, + ::registration, Story::new("home_box", plain_box).covers(&[Required::Default]), ) .at("z.rs", 1) } +pub(crate) fn register_fixture(registry: &mut craft_ui::testing::Registry) { + registry.add_story(visitor_story()); + registry.add_story(home_story()); +} + +fn fixture_registry() -> craft_ui::testing::Registry { + craft_ui::testing::Registry::of(&[register_fixture]) +} + #[trial] fn a_types_own_stories_list_before_another_packages() { let visited = std::any::type_name::(); - let names: Vec<&str> = - craft_ui::testing::stories().into_iter().filter(|entry| (entry.type_name)() == visited).map(|entry| entry.story.name).collect(); + let registry = fixture_registry(); + let names: Vec<&str> = registry.stories().iter().filter(|entry| (entry.type_name)() == visited).map(|entry| entry.story.name).collect(); assert_eq!(names, ["home_box", "plain_box"], "the registering package's story comes first"); } #[trial] fn stories_of_another_packages_type_run_its_cases_in_the_declaring_package() { - let trials = craft_ui::testing::suite::trials(VISITOR, &[]); + let trials = craft_ui::testing::suite::trials(VISITOR, &fixture_registry()); let names: Vec = trials.iter().map(|trial| trial.name().to_owned()).collect(); let visited = std::any::type_name::(); assert!(names.contains(&format!("suite::{visited}::reads")), "the visitor runs the visited type's cases: {names:?}"); diff --git a/crates/ui-contract/tests/it/fonts/mod.rs b/crates/ui-contract/tests/it/fonts/mod.rs index 810abc821..f64fde082 100644 --- a/crates/ui-contract/tests/it/fonts/mod.rs +++ b/crates/ui-contract/tests/it/fonts/mod.rs @@ -1,7 +1,7 @@ //! Interface fonts. -mod document; -mod face_run; -mod on_demand; -mod served; -mod stack; +pub(crate) mod document; +pub(crate) mod face_run; +pub(crate) mod on_demand; +pub(crate) mod served; +pub(crate) mod stack; diff --git a/crates/ui-contract/tests/it/layout/mod.rs b/crates/ui-contract/tests/it/layout/mod.rs index 0491eb06f..5d04599e3 100644 --- a/crates/ui-contract/tests/it/layout/mod.rs +++ b/crates/ui-contract/tests/it/layout/mod.rs @@ -1,4 +1,4 @@ -mod body; -mod fill; -mod memory; -mod overlay_bar; +pub(crate) mod body; +pub(crate) mod fill; +pub(crate) mod memory; +pub(crate) mod overlay_bar; diff --git a/crates/ui-contract/tests/it/main.rs b/crates/ui-contract/tests/it/main.rs index c62277815..bbc639e4e 100644 --- a/crates/ui-contract/tests/it/main.rs +++ b/crates/ui-contract/tests/it/main.rs @@ -3,27 +3,37 @@ // The test files name the library as `craft_ui`, as the crates that use it do. extern crate craft_ui_contract as craft_ui; -mod access; +pub(crate) mod access; pub(crate) mod body; -mod canvas; -mod collection; -mod contract; -mod drag; -mod egui_surface; -mod fonts; -mod icon_ids; -mod keys_consumed; -mod layout; -mod motion; -mod paint; +pub(crate) mod canvas; +pub(crate) mod collection; +pub(crate) mod contract; +pub(crate) mod drag; +pub(crate) mod egui_surface; +pub(crate) mod fonts; +pub(crate) mod icon_ids; +pub(crate) mod keys_consumed; +pub(crate) mod layout; +pub(crate) mod motion; +pub(crate) mod paint; -mod runtime; +pub(crate) mod runtime; -mod style; -mod text; +pub(crate) mod story_command_subsets; +pub(crate) mod style; +pub(crate) mod text; -use craft_ui::testing::registered; +craft_ui::registry!(); fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), ®istered()); + craft_ui::testing::run( + module_path!(), + env!("CARGO_PKG_NAME"), + &craft_ui::testing::Registry::of(&[ + register, + craft_ui::testing::register, + craft_ui_test_kit::testing::register, + contract::visited_type::register_fixture, + ]), + ); } diff --git a/crates/ui-contract/tests/it/motion/mod.rs b/crates/ui-contract/tests/it/motion/mod.rs index 8a4c649d4..31c8001a0 100644 --- a/crates/ui-contract/tests/it/motion/mod.rs +++ b/crates/ui-contract/tests/it/motion/mod.rs @@ -1,5 +1,5 @@ //! The motion service (13) and background results (14). -mod pending; -mod state; -mod timers; +pub(crate) mod pending; +pub(crate) mod state; +pub(crate) mod timers; diff --git a/crates/ui-contract/tests/it/paint/mod.rs b/crates/ui-contract/tests/it/paint/mod.rs index 2f42bfe96..ec94d91e2 100644 --- a/crates/ui-contract/tests/it/paint/mod.rs +++ b/crates/ui-contract/tests/it/paint/mod.rs @@ -1,9 +1,9 @@ -mod backdrop; +pub(crate) mod backdrop; -mod painters; +pub(crate) mod painters; -mod surround; +pub(crate) mod surround; -mod text_place; +pub(crate) mod text_place; -mod texture_store; +pub(crate) mod texture_store; diff --git a/crates/ui-contract/tests/it/runtime/mod.rs b/crates/ui-contract/tests/it/runtime/mod.rs index 44af1552c..7944a64f2 100644 --- a/crates/ui-contract/tests/it/runtime/mod.rs +++ b/crates/ui-contract/tests/it/runtime/mod.rs @@ -1,20 +1,20 @@ -mod alt_code; -mod chord_fallthrough; +pub(crate) mod alt_code; +pub(crate) mod chord_fallthrough; // `clipboard.rs` is platform-w3's trial (F-28); this file is shell-w1's, so its line is written here. -mod clipboard; -mod control_click; -mod cursor; -mod elapsed; -mod env; -mod frame; -mod latch; -mod memory; -mod pen; -mod pointer; -mod theme_app; -mod wheel; -mod window_move; -mod windows; -mod words; +pub(crate) mod clipboard; +pub(crate) mod control_click; +pub(crate) mod cursor; +pub(crate) mod elapsed; +pub(crate) mod env; +pub(crate) mod frame; +pub(crate) mod latch; +pub(crate) mod memory; +pub(crate) mod pen; +pub(crate) mod pointer; +pub(crate) mod theme_app; +pub(crate) mod wheel; +pub(crate) mod window_move; +pub(crate) mod windows; +pub(crate) mod words; -mod screenshot; +pub(crate) mod screenshot; diff --git a/crates/ui-contract/tests/it/story_command_subsets.rs b/crates/ui-contract/tests/it/story_command_subsets.rs new file mode 100644 index 000000000..4ade27046 --- /dev/null +++ b/crates/ui-contract/tests/it/story_command_subsets.rs @@ -0,0 +1,68 @@ +//! Story command selections stay with each context. + +use craft_ui::contract::CommandSet; +use craft_ui::runtime::commands::resolve; +use craft_ui::testing::{Fixture, Registry, trial}; +use std::sync::{Arc, Barrier}; + +#[derive(Clone, Copy, Debug, PartialEq, Eq, CommandSet)] +#[command(prefix = "subsetAlpha", story)] +enum Alpha { + #[command(label = "Subset Alpha")] + Run, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, CommandSet)] +#[command(prefix = "subsetBeta", story)] +enum Beta { + #[command(label = "Subset Beta")] + Run, +} + +fn alpha(registry: &mut Registry) { + registry.add_story_set(__registry_command_alpha()); +} +fn beta(registry: &mut Registry) { + registry.add_story_set(__registry_command_beta()); +} + +fn selected(alpha_selected: bool, barrier: Arc) { + let registry = if alpha_selected { Registry::of(&[alpha]) } else { Registry::of(&[beta]) }; + barrier.wait(); + assert!(registry.install_story_sets()); + let mut fixture = Fixture::new(|_| {}); + fixture.settle(); + let alpha_label = resolve(fixture.ctx(), Alpha::Run).label.clone(); + let beta_label = resolve(fixture.ctx(), Beta::Run).label.clone(); + assert_eq!(alpha_label.as_ref() == "Subset Alpha", alpha_selected); + assert_eq!(beta_label.as_ref() == "Subset Beta", !alpha_selected); +} + +#[trial] +fn separate_story_command_subsets_can_run_concurrently() { + let alpha_registry = Registry::of(&[alpha]); + let beta_registry = Registry::of(&[beta]); + assert!(alpha_registry.install_story_sets()); + let mut first = Fixture::new(|_| {}); + first.settle(); + assert!(beta_registry.install_story_sets()); + let mut second = Fixture::new(|_| {}); + second.settle(); + assert_eq!(resolve(first.ctx(), Alpha::Run).label.as_ref(), "Subset Alpha"); + assert_ne!(resolve(first.ctx(), Beta::Run).label.as_ref(), "Subset Beta"); + assert_eq!(resolve(second.ctx(), Beta::Run).label.as_ref(), "Subset Beta"); + assert_ne!(resolve(second.ctx(), Alpha::Run).label.as_ref(), "Subset Alpha"); + let builds = craft_ui::runtime::commands::keymap_builds(); + let mut another = Fixture::new(|_| {}); + another.settle(); + assert_eq!(craft_ui::runtime::commands::keymap_builds(), builds, "a second context reuses its registry's keymap"); + + let barrier = Arc::new(Barrier::new(2)); + let first = { + let barrier = barrier.clone(); + std::thread::spawn(move || selected(true, barrier)) + }; + let second = std::thread::spawn(move || selected(false, barrier)); + assert!(first.join().is_ok()); + assert!(second.join().is_ok()); +} diff --git a/crates/ui-contract/tests/it/style/mod.rs b/crates/ui-contract/tests/it/style/mod.rs index 890d3ceac..02daabf49 100644 --- a/crates/ui-contract/tests/it/style/mod.rs +++ b/crates/ui-contract/tests/it/style/mod.rs @@ -1,4 +1,4 @@ -mod cache; -mod library_theme; -mod surface_look; -mod theme_scope; +pub(crate) mod cache; +pub(crate) mod library_theme; +pub(crate) mod surface_look; +pub(crate) mod theme_scope; diff --git a/crates/ui-contract/tests/it/text/mod.rs b/crates/ui-contract/tests/it/text/mod.rs index de84ade0c..35907c463 100644 --- a/crates/ui-contract/tests/it/text/mod.rs +++ b/crates/ui-contract/tests/it/text/mod.rs @@ -1,2 +1,2 @@ -mod editor; -mod input_cap; +pub(crate) mod editor; +pub(crate) mod input_cap; diff --git a/crates/ui-gallery/Cargo.toml b/crates/ui-gallery/Cargo.toml index 1e9167542..4e59501e5 100644 --- a/crates/ui-gallery/Cargo.toml +++ b/crates/ui-gallery/Cargo.toml @@ -48,7 +48,7 @@ review = ["dep:craft-review"] table = ["dep:craft-table"] text = ["dep:craft-text"] # The theme panels are linked in every build (the Theme workspace uses them); the feature adds their stories. -theme-editor = ["craft-theme-editor/screen-testing"] +theme-editor = ["craft-theme-editor/suite"] theme-store = ["dep:craft-theme-store"] timeline = ["dep:craft-timeline"] dialogs = ["dep:craft-dialogs"] @@ -64,7 +64,7 @@ harness = false workspace = true [dependencies] -craft-ui = { workspace = true, features = ["app", "testing"] } +craft-ui = { workspace = true, features = ["app", "suite"] } craft-i18n = { workspace = true } craft-theme = { workspace = true } craft-theme-editor = { workspace = true } @@ -82,29 +82,30 @@ serde = { workspace = true } serde_json = { workspace = true } web-time = "1.1" -# The domain crates' stories, registered under each crate's `screen-testing`. -craft-automation = { workspace = true, features = ["screen-testing"], optional = true } -craft-browse = { workspace = true, features = ["screen-testing"], optional = true } -craft-color-ui = { workspace = true, features = ["screen-testing"], optional = true } -craft-draw = { workspace = true, features = ["screen-testing"], optional = true } -craft-imaging = { workspace = true, features = ["screen-testing"], optional = true } -craft-layers = { workspace = true, features = ["screen-testing"], optional = true } -craft-menu = { workspace = true, features = ["screen-testing"], optional = true } -craft-pages = { workspace = true, features = ["screen-testing"], optional = true } -craft-print = { workspace = true, features = ["screen-testing"], optional = true } -craft-review = { workspace = true, features = ["screen-testing"], optional = true } -craft-table = { workspace = true, features = ["screen-testing"], optional = true } -craft-text = { workspace = true, features = ["screen-testing", "find"], optional = true } -craft-theme-store = { workspace = true, features = ["screen-testing"], optional = true } -craft-timeline = { workspace = true, features = ["screen-testing"], optional = true } +# The domain crates' stories, registered under each crate's `suite`. +craft-automation = { workspace = true, features = ["suite"], optional = true } +craft-browse = { workspace = true, features = ["suite"], optional = true } +craft-color-ui = { workspace = true, features = ["suite"], optional = true } +craft-draw = { workspace = true, features = ["suite"], optional = true } +craft-imaging = { workspace = true, features = ["suite"], optional = true } +craft-layers = { workspace = true, features = ["suite"], optional = true } +craft-menu = { workspace = true, features = ["suite"], optional = true } +craft-pages = { workspace = true, features = ["suite"], optional = true } +craft-print = { workspace = true, features = ["suite"], optional = true } +craft-review = { workspace = true, features = ["suite"], optional = true } +craft-table = { workspace = true, features = ["suite"], optional = true } +craft-text = { workspace = true, features = ["suite", "find"], optional = true } +craft-theme-store = { workspace = true, features = ["suite"], optional = true } +craft-timeline = { workspace = true, features = ["suite"], optional = true } # Native only: these crates do not build for the web, so their stories are not in the web gallery. [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -craft-dialogs = { workspace = true, features = ["screen-testing"], optional = true } -craft-font-manager = { workspace = true, features = ["screen-testing"], optional = true } -craft-update = { workspace = true, features = ["screen-testing"], optional = true } +craft-dialogs = { workspace = true, features = ["suite"], optional = true } +craft-font-manager = { workspace = true, features = ["suite"], optional = true } +craft-update = { workspace = true, features = ["suite"], optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen-futures = "0.4" [dev-dependencies] +toml = { version = "1.1", default-features = false, features = ["std", "parse", "serde"] } diff --git a/crates/ui-gallery/src/bin/components-index.rs b/crates/ui-gallery/src/bin/components-index.rs index 184daefac..5b8a83c2e 100644 --- a/crates/ui-gallery/src/bin/components-index.rs +++ b/crates/ui-gallery/src/bin/components-index.rs @@ -20,7 +20,9 @@ fn workspace_root() -> PathBuf { fn main() -> ExitCode { let root = workspace_root(); - let text = components_index(&root, &library_registrations()); + let registry = library_registrations(); + let registrations: Vec<_> = registry.registrations().iter().collect(); + let text = components_index(&root, ®istrations); let target = root.join(OUTPUT); if std::env::args().any(|argument| argument == "--check") { let current = fs::read_to_string(&target).unwrap_or_default(); diff --git a/crates/ui-gallery/src/chrome/card.rs b/crates/ui-gallery/src/chrome/card.rs index 810142667..d5011402b 100644 --- a/crates/ui-gallery/src/chrome/card.rs +++ b/crates/ui-gallery/src/chrome/card.rs @@ -60,21 +60,29 @@ pub struct Look { } /// One story a card shows. -#[derive(MemoProps)] #[non_exhaustive] pub struct CardStory<'a> { /// The index of the story in the catalog: the key of its state. pub index: usize, /// The story. - #[memo_props(address = "registrations are static items")] - pub story: &'static StoryRegistration, + pub story: StoryRegistration, /// The story's caption. pub caption: &'a str, } +// The card reads only the story's name and show function; registry values are owned copies. +impl MemoProps for CardStory<'_> { + fn key(&self, key: &mut craft_ui::contract::MemoKey) { + self.index.key(key); + self.caption.key(key); + self.story.story.name.key(key); + key.feed_hash(&self.story.story.show); + } +} + impl<'a> CardStory<'a> { /// The story at catalog index `index`, under `caption`. - pub fn new(index: usize, story: &'static StoryRegistration, caption: &'a str) -> Self { + pub fn new(index: usize, story: StoryRegistration, caption: &'a str) -> Self { CardStory { index, story, caption } } } @@ -287,7 +295,7 @@ pub struct StoryBody { /// The id scope of the story: unique among the stories of a pass. pub key: String, /// The story. - pub story: &'static StoryRegistration, + pub story: StoryRegistration, /// The surface the story sits on. pub surface: Surface, /// The most a story that fills takes. @@ -317,7 +325,7 @@ pub struct BodyShown { impl StoryBody { /// The body of `story` on `surface`, in the window's look, with ungated wheel takers. - pub fn new(key: impl Into, story: &'static StoryRegistration, surface: Surface, room: f32, panel_pad: Pad) -> Self { + pub fn new(key: impl Into, story: StoryRegistration, surface: Surface, room: f32, panel_pad: Pad) -> Self { StoryBody { key: key.into(), story, surface, room, look: Look::default(), gated: false, panel_pad, caption: None, inspect: None } } diff --git a/crates/ui-gallery/src/chrome/overview.rs b/crates/ui-gallery/src/chrome/overview.rs index 1ed768f7b..4c8dea5ae 100644 --- a/crates/ui-gallery/src/chrome/overview.rs +++ b/crates/ui-gallery/src/chrome/overview.rs @@ -40,7 +40,7 @@ pub struct SpecStory { /// The index of the story in the catalog. pub index: usize, /// The story's registration. - pub story: &'static StoryRegistration, + pub story: StoryRegistration, /// The story's caption. pub caption: String, } diff --git a/crates/ui-gallery/src/foundations/mod.rs b/crates/ui-gallery/src/foundations/mod.rs index 8a5c6daea..c856176a1 100644 --- a/crates/ui-gallery/src/foundations/mod.rs +++ b/crates/ui-gallery/src/foundations/mod.rs @@ -1,10 +1,10 @@ //! The Foundations level: demos of the theme's tokens and of the edit lifecycle, which every component builds on. -mod colours; -mod edit_policy; -mod pointers; -mod stories; -mod surfaces; +pub(crate) mod colours; +pub(crate) mod edit_policy; +pub(crate) mod pointers; +pub(crate) mod stories; +pub(crate) mod surfaces; pub use colours::Colours; pub use edit_policy::EditPolicy; diff --git a/crates/ui-gallery/src/lib.rs b/crates/ui-gallery/src/lib.rs index 85e9b8240..a83fd504d 100644 --- a/crates/ui-gallery/src/lib.rs +++ b/crates/ui-gallery/src/lib.rs @@ -17,59 +17,75 @@ pub const WINDOW: [f32; 2] = [1280.0, 800.0]; /// /// Each entry is a function of its crate that is passed by pointer, so the linker keeps that crate's object files and /// the story registrations in them, which a release build for the web would otherwise drop. -type Registered = fn() -> Vec<&'static craft_ui::testing::Registration>; +type Registered = fn(&mut craft_ui::testing::Registry); #[allow(unused_mut, clippy::vec_init_then_push)] fn crates() -> Vec<(&'static str, Registered)> { let mut crates: Vec<(&'static str, Registered)> = Vec::new(); #[cfg(feature = "automation")] - crates.push(("craft-automation", craft_automation::testing::registered)); + crates.push(("craft-automation", craft_automation::testing::register)); #[cfg(feature = "browse")] - crates.push(("craft-browse", craft_browse::ui::testing::registered)); + crates.push(("craft-browse", craft_browse::ui::testing::register)); #[cfg(feature = "color-ui")] - crates.push(("craft-color-ui", craft_color_ui::ui::testing::registered)); + crates.push(("craft-color-ui", craft_color_ui::ui::testing::register)); #[cfg(feature = "draw")] - crates.push(("craft-draw", craft_draw::testing::registered)); + crates.push(("craft-draw", craft_draw::testing::register)); #[cfg(feature = "imaging")] - crates.push(("craft-imaging", craft_imaging::testing::registered)); + crates.push(("craft-imaging", craft_imaging::testing::register)); #[cfg(feature = "layers")] - crates.push(("craft-layers", craft_layers::testing::registered)); + crates.push(("craft-layers", craft_layers::testing::register)); #[cfg(feature = "menu")] - crates.push(("craft-menu", craft_menu::testing::registered)); + crates.push(("craft-menu", craft_menu::testing::register)); #[cfg(feature = "pages")] - crates.push(("craft-pages", craft_pages::testing::registered)); + crates.push(("craft-pages", craft_pages::testing::register)); #[cfg(feature = "print")] - crates.push(("craft-print", craft_print::testing::registered)); + crates.push(("craft-print", craft_print::testing::register)); #[cfg(feature = "review")] - crates.push(("craft-review", craft_review::testing::registered)); + crates.push(("craft-review", craft_review::testing::register)); #[cfg(feature = "table")] - crates.push(("craft-table", craft_table::ui::testing::registered)); + crates.push(("craft-table", craft_table::ui::testing::register)); #[cfg(feature = "text")] - crates.push(("craft-text", craft_text::testing::registered)); + crates.push(("craft-text", craft_text::testing::register)); #[cfg(feature = "theme-editor")] - crates.push(("craft-theme-editor", craft_theme_editor::testing::registered)); + crates.push(("craft-theme-editor", craft_theme_editor::testing::register)); #[cfg(feature = "theme-store")] - crates.push(("craft-theme-store", craft_theme_store::ui::registered)); + crates.push(("craft-theme-store", craft_theme_store::ui::register)); #[cfg(feature = "timeline")] - crates.push(("craft-timeline", craft_timeline::testing::registered)); + crates.push(("craft-timeline", craft_timeline::testing::register)); // These do not build for the web, so their stories are in the native gallery only. #[cfg(all(feature = "dialogs", not(target_arch = "wasm32")))] - crates.push(("craft-dialogs", craft_dialogs::testing::registered)); + crates.push(("craft-dialogs", craft_dialogs::testing::register)); #[cfg(all(feature = "font-manager", not(target_arch = "wasm32")))] - crates.push(("craft-font-manager", craft_font_manager::testing::registered)); + crates.push(("craft-font-manager", craft_font_manager::testing::register)); #[cfg(all(feature = "update", not(target_arch = "wasm32")))] - crates.push(("craft-update", craft_update::testing::registered)); - std::hint::black_box(crates) + crates.push(("craft-update", craft_update::testing::register)); + crates } -/// How many registrations each linked crate contributes, with the viewer's own, and how many stories there are in all. +/// Adds the viewer and each selected dependency to a registry. +pub fn register_all(registry: &mut craft_ui::testing::Registry) { + craft_ui::testing::register_library(registry); + testing::register(registry); + for (_, register) in crates() { + register(registry); + } +} + +/// The registry of the viewer and the crates whose stories it shows. +pub fn registry() -> craft_ui::testing::Registry { + craft_ui::testing::Registry::of(&[register_all]) +} + +/// How many registrations each selected crate contributes, and how many stories there are in all. pub fn linked_counts() -> (Vec<(&'static str, usize)>, usize) { - let mut counts: Vec<(&'static str, usize)> = crates().into_iter().map(|(name, registered)| (name, registered().len())).collect(); - counts.push((env!("CARGO_PKG_NAME"), testing::registered().len())); - (counts, craft_ui::testing::stories().len()) + let registry = registry(); + let mut counts: Vec<_> = + crates().into_iter().map(|(name, _)| (name, registry.registrations().iter().filter(|entry| entry.crate_name() == name).count())).collect(); + counts.push((env!("CARGO_PKG_NAME"), registry.registrations().iter().filter(|entry| entry.crate_name() == env!("CARGO_PKG_NAME")).count())); + (counts, registry.stories().len()) } /// The test registry of this package's stories. pub mod testing { - craft_ui::testing_registered!(); + craft_ui::registry!(); } diff --git a/crates/ui-gallery/src/main.rs b/crates/ui-gallery/src/main.rs index e7343b4d8..035cd405b 100644 --- a/crates/ui-gallery/src/main.rs +++ b/crates/ui-gallery/src/main.rs @@ -13,8 +13,15 @@ fn spec() -> AppSpec { } #[cfg(not(target_arch = "wasm32"))] -fn main() -> eframe::Result { - craft_ui::shell::app::run(spec(), |_| Gallery::open()) +fn main() { + if !craft_ui_gallery::registry().install_story_sets() { + eprintln!("the selected story commands are invalid"); + std::process::exit(1); + } + if let Err(error) = craft_ui::shell::app::run(spec(), |_| Gallery::open()) { + eprintln!("{error}"); + std::process::exit(1); + } } /// The web build: the gallery on the page's `gallery_canvas`, started by trunk's bundle. The number of stories goes @@ -25,6 +32,10 @@ fn main() { use eframe::web_sys::{HtmlCanvasElement, console, window}; wasm_bindgen_futures::spawn_local(async { + if !craft_ui_gallery::registry().install_story_sets() { + console::error_1(&JsValue::from_str("the selected story commands are invalid")); + return; + } let (counts, stories) = craft_ui_gallery::linked_counts(); let per_crate: Vec = counts.iter().map(|(name, count)| format!("{name}={count}")).collect(); console::log_1(&JsValue::from_str(&format!("craft-ui-gallery: {stories} stories; registrations by crate: {}", per_crate.join(" ")))); diff --git a/crates/ui-gallery/src/mock/mod.rs b/crates/ui-gallery/src/mock/mod.rs index 76030611a..3592485a6 100644 --- a/crates/ui-gallery/src/mock/mod.rs +++ b/crates/ui-gallery/src/mock/mod.rs @@ -2,11 +2,11 @@ //! composed from library components only. mod commands; -mod editor; +pub(crate) mod editor; mod model; mod panels; -mod stories; -mod tools; +pub(crate) mod stories; +pub(crate) mod tools; mod words; pub use commands::AppCommand; diff --git a/crates/ui-gallery/src/viewer/catalog.rs b/crates/ui-gallery/src/viewer/catalog.rs index 454d0d055..9cc77b8b0 100644 --- a/crates/ui-gallery/src/viewer/catalog.rs +++ b/crates/ui-gallery/src/viewer/catalog.rs @@ -1,7 +1,7 @@ //! What the viewer lists: every registered story, grouped by the component it shows. use craft_ui::contract::{self, Level, MemoProps, Probe, Registration, Tracked}; -use craft_ui::testing::{StoryRegistration, stories}; +use craft_ui::testing::StoryRegistration; use std::collections::HashMap; use std::sync::OnceLock; @@ -10,7 +10,7 @@ use std::sync::OnceLock; #[non_exhaustive] pub struct Entry { /// The registration. - pub registration: &'static StoryRegistration, + pub registration: StoryRegistration, /// The registered name of the type the story shows. pub type_name: &'static str, } @@ -107,8 +107,23 @@ pub fn fold_filter(filter: &str) -> String { /// The registry's catalog of the types linked into the running binary: each one's level and plain name. pub(crate) fn linked_catalog() -> &'static contract::Catalog { + linked_catalog_from(None) +} + +fn linked_catalog_from(registry: Option<&craft_ui::testing::Registry>) -> &'static contract::Catalog { static CATALOG: OnceLock = OnceLock::new(); - CATALOG.get_or_init(|| contract::catalog(&contract::registrations())) + CATALOG.get_or_init(|| { + let owned; + let registry = match registry { + Some(registry) => registry, + None => { + owned = crate::registry(); + &owned + } + }; + let registrations: Vec<_> = registry.registrations().iter().collect(); + contract::catalog(®istrations) + }) } /// The plain name of the component registered as `type_name`; the registered name when the registry lists no such type. @@ -116,9 +131,8 @@ pub fn display_name(type_name: &str) -> String { linked_catalog().entry(type_name).map_or_else(|| type_name.to_owned(), |entry| entry.name.clone()) } -/// Every story linked into the viewer, ordered by type then story name. -pub fn entries() -> Vec { - stories().into_iter().map(|registration| Entry { registration, type_name: (registration.type_name)() }).collect() +fn entries_from(registry: &craft_ui::testing::Registry) -> Vec { + registry.stories().iter().map(|registration| Entry { registration: *registration, type_name: (registration.type_name)() }).collect() } /// What a registration says about a type: where it is declared and what it is for. @@ -130,16 +144,15 @@ pub struct Declared { /// The first sentence of the type's doc comment. pub purpose: &'static str, /// The component probe; `None` for a pattern. - pub probe: Option<&'static Probe>, + pub probe: Option, } -/// The registration of each registered component and pattern type, by the type's registered name. -pub fn declared() -> HashMap<&'static str, Declared> { +fn declared_from(registry: &craft_ui::testing::Registry) -> HashMap<&'static str, Declared> { let mut out = HashMap::new(); - for registration in contract::registrations() { + for registration in registry.registrations() { match registration { Registration::Component(probe) => { - out.insert(probe.type_name(), Declared { module: probe.module, purpose: probe.purpose, probe: Some(probe) }); + out.insert(probe.type_name(), Declared { module: probe.module, purpose: probe.purpose, probe: Some(*probe) }); } Registration::Pattern(probe) => { out.insert(probe.type_name(), Declared { module: probe.module, purpose: probe.purpose, probe: None }); @@ -193,8 +206,10 @@ pub struct Catalog { impl Catalog { /// The catalog of the stories linked into the running binary. pub fn linked() -> Self { - let entries = entries(); - let declared = declared(); + let registry = crate::registry(); + linked_catalog_from(Some(®istry)); + let entries = entries_from(®istry); + let declared = declared_from(®istry); let components = components(&entries); Catalog::new(entries, components, declared) } diff --git a/crates/ui-gallery/tests/it/main.rs b/crates/ui-gallery/tests/it/main.rs index cef5bd8db..7a62e596f 100644 --- a/crates/ui-gallery/tests/it/main.rs +++ b/crates/ui-gallery/tests/it/main.rs @@ -1,12 +1,13 @@ //! The viewer's integration tests: one binary, run by `libtest-mimic` over the registered trials. -mod mock; -mod overview; -mod panels; -mod viewer; +pub(crate) mod mock; +pub(crate) mod overview; +pub(crate) mod panels; +pub(crate) mod registry; +pub(crate) mod viewer; -use craft_ui_gallery::testing::registered; +craft_ui::registry!(); fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), ®istered()); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register, craft_ui_gallery::register_all])); } diff --git a/crates/ui-gallery/tests/it/registry.rs b/crates/ui-gallery/tests/it/registry.rs new file mode 100644 index 000000000..eeb7e4f99 --- /dev/null +++ b/crates/ui-gallery/tests/it/registry.rs @@ -0,0 +1,50 @@ +//! The gallery registry must follow its manifest's suite dependencies. + +use craft_ui::testing::trial; +use std::collections::BTreeSet; + +fn suite_dependencies(table: &toml::Table, found: &mut BTreeSet) { + for (name, value) in table { + let Some(dependency) = value.as_table() else { continue }; + if name != "craft-ui" + && dependency + .get("features") + .and_then(toml::Value::as_array) + .is_some_and(|features| features.iter().any(|feature| feature.as_str() == Some("suite"))) + { + found.insert(name.clone()); + } + } +} + +#[trial] +fn gallery_registers_each_suite_dependency() { + let manifest: toml::Value = toml::from_str(include_str!("../../Cargo.toml")).expect("gallery manifest parses"); + let mut dependencies = BTreeSet::new(); + if let Some(table) = manifest.get("dependencies").and_then(toml::Value::as_table) { + suite_dependencies(table, &mut dependencies); + } + if let Some(targets) = manifest.get("target").and_then(toml::Value::as_table) { + for target in targets.values() { + if let Some(table) = target.get("dependencies").and_then(toml::Value::as_table) { + suite_dependencies(table, &mut dependencies); + } + } + } + if let Some(features) = manifest.get("features").and_then(toml::Value::as_table) { + for value in features.values().filter_map(toml::Value::as_array).flatten().filter_map(toml::Value::as_str) { + if let Some(name) = value.strip_suffix("/suite") + && name.starts_with("craft-") + && name != "craft-ui" + { + dependencies.insert(name.to_owned()); + } + } + } + let listed: BTreeSet<_> = include_str!("../../src/lib.rs") + .lines() + .filter_map(|line| line.trim().strip_prefix("crates.push((\"")) + .filter_map(|line| line.split_once('"').map(|(name, _)| name.to_owned())) + .collect(); + assert_eq!(listed, dependencies, "gallery registry and suite dependencies differ"); +} diff --git a/crates/ui-macros/src/command_set.rs b/crates/ui-macros/src/command_set.rs index 9beb0a132..c18fc83b4 100644 --- a/crates/ui-macros/src/command_set.rs +++ b/crates/ui-macros/src/command_set.rs @@ -42,7 +42,7 @@ fn command_attrs(attrs: &[Attribute], mut read: impl FnMut(&syn::meta::ParseNest Ok(()) } -fn snake(name: &str) -> String { +pub(crate) fn snake(name: &str) -> String { let mut out = String::new(); for (i, c) in name.chars().enumerate() { if c.is_ascii_uppercase() { @@ -227,7 +227,26 @@ pub(crate) fn derive(input: TokenStream) -> syn::Result { } Ok(true) })?; - let register = if set.story { quote!(#k::__register_command_set!(#ident, story);) } else { quote!(#k::__register_command_set!(#ident);) }; + let register = if set.story { + let helper = quote::format_ident!("__registry_command_{}", snake(&ident.to_string())); + quote! { + pub(crate) fn #helper() -> #k::runtime::commands::SetEntry { + #k::runtime::commands::SetEntry::new( + ::std::any::type_name::<#ident>, + <#ident as #k::runtime::commands::CommandSet>::defs, + <#ident as #k::runtime::commands::CommandSet>::no_default_on, + <#ident as #k::runtime::commands::CommandSet>::edits, + <#ident as #k::runtime::commands::CommandSet>::holds, + if <#ident as #k::runtime::commands::CommandSet>::TYPING { + Some(<#ident as #k::runtime::commands::CommandSet>::SCOPE) + } else { None }, + <#ident as #k::runtime::commands::CommandSet>::platform_defaults, + ) + } + } + } else { + quote!(#k::__register_command_set!(#ident);) + }; let prefix = set.prefix.ok_or_else(|| syn::Error::new_spanned(ident, "a command set names its id prefix: `#[command(prefix = \"..\")]`"))?; check_prefix(&prefix)?; if let Some(scope) = &set.scope { @@ -346,8 +365,6 @@ pub(crate) fn derive(input: TokenStream) -> syn::Result { } } - const _: () = { - #register - }; + #register }) } diff --git a/crates/ui-macros/src/component.rs b/crates/ui-macros/src/component.rs index 90e66c05b..65c236eed 100644 --- a/crates/ui-macros/src/component.rs +++ b/crates/ui-macros/src/component.rs @@ -22,7 +22,7 @@ struct Declared { exempt: Vec<(LitStr, LitStr)>, /// The function that makes an instance of a leaf for the suite: `sample = path`. sample: Option, - /// The first sentence of the type's doc comment; empty for `register_contract!`. + /// The first sentence of the type's doc comment, or an explicit manual registration purpose. purpose: String, } @@ -61,6 +61,8 @@ impl Declared { (Some(case), Some(reason)) => self.exempt.push((case, reason)), _ => return Err(meta.error("`exempt` needs both `case = \"..\"` and `reason = \"..\"`")), } + } else if path.is_ident("purpose") { + self.purpose = meta.value()?.parse::()?.value(); } else if path.is_ident("sample") { if self.sample.is_some() { return Err(meta.error("`sample` is declared once")); @@ -177,25 +179,38 @@ pub(crate) fn purpose_of(attrs: &[Attribute]) -> String { sentence.trim_end_matches('.').to_owned() } -/// The attributes on a registration block, from the crate being compiled. See `gate_for`. -fn registration_gate() -> TokenStream { +/// Whether the crate being compiled declares its own suite feature. +pub(crate) fn declares_suite() -> bool { let manifest = std::env::var_os("CARGO_MANIFEST_DIR").and_then(|dir| std::fs::read_to_string(std::path::Path::new(&dir).join("Cargo.toml")).ok()); - gate_for(manifest.as_deref().unwrap_or_default()) + declares_suite_in(manifest.as_deref().unwrap_or_default()) } /// The attributes on a registration block. The registration's types can exist only under the defining package's -/// `screen-testing` feature, which may be off while craft-ui's `testing` is on, so the block is gated on it (the cfg +/// `suite` feature, which may be off while craft-ui's `testing` is on, so the block is gated on it (the cfg /// is evaluated in the defining crate) when the package's `manifest` declares that feature, and is not gated otherwise. -pub(crate) fn gate_for(manifest: &str) -> TokenStream { +pub(crate) fn declares_suite_in(manifest: &str) -> bool { let mut in_features = false; - let declares = manifest.lines().map(str::trim).any(|line| { + manifest.lines().map(str::trim).any(|line| { if line.starts_with('[') { in_features = line.trim_end_matches(|c: char| c.is_whitespace()) == "[features]"; return false; } - in_features && line.strip_prefix("screen-testing").is_some_and(|rest| rest.trim_start().starts_with('=')) - }); - if declares { quote!(#[cfg(feature = "screen-testing")]) } else { quote!() } + in_features && line.strip_prefix("suite").is_some_and(|rest| rest.trim_start().starts_with('=')) + }) +} + +pub(crate) fn registration_gate() -> TokenStream { + if declares_suite() { quote!(#[cfg(feature = "suite")]) } else { quote!() } +} + +fn registry_helper(types: &[Type]) -> syn::Result { + let Some(Type::Path(path)) = types.first() else { + return Err(syn::Error::new(proc_macro2::Span::call_site(), "a registration needs a named type")); + }; + let Some(name) = path.path.segments.last() else { + return Err(syn::Error::new_spanned(path, "a registration needs a named type")); + }; + Ok(format_ident!("__registry_component_{}", crate::command_set::snake(&name.ident.to_string()))) } fn registrations(k: &TokenStream, types: &[Type], declared: &Declared, shape: Shape) -> syn::Result { @@ -218,7 +233,13 @@ fn registrations(k: &TokenStream, types: &[Type], declared: &Declared, shape: Sh let purpose = &declared.purpose; let each = types.iter().map(|ty| quote!(#k::__register_contract!(#ty, #shape, #overlay, [#(#exempt),*], [#(#sample)*], #purpose);)); let gate = registration_gate(); + let helper = registry_helper(types)?; Ok(quote! { + #gate + pub(crate) fn #helper(registry: &mut #k::testing::Registry) { + #(registry.add_registration(<#types as #k::testing::Registered>::registration());)* + } + // Outside the gate: the sample exists in every build, so it is never dead code where the registration is absent. #(const _: () = { let _ = #sample; };)* #gate @@ -234,7 +255,15 @@ fn registrations(k: &TokenStream, types: &[Type], declared: &Declared, shape: Sh pub(crate) fn pattern_registrations(k: &TokenStream, types: &[Type], purpose: &str, probe: &TokenStream) -> TokenStream { let each = types.iter().map(|ty| quote!(#k::__register_pattern!(#ty, #purpose, #probe);)); let gate = registration_gate(); + let helper = match registry_helper(types) { + Ok(helper) => helper, + Err(error) => return error.to_compile_error(), + }; quote! { + #gate + pub(crate) fn #helper(registry: &mut #k::testing::Registry) { + #(registry.add_registration(<#types as #k::testing::Registered>::registration());)* + } #gate const _: () = { #(#each)* diff --git a/crates/ui-macros/src/lib.rs b/crates/ui-macros/src/lib.rs index 74e2cb29c..dbb092ee4 100644 --- a/crates/ui-macros/src/lib.rs +++ b/crates/ui-macros/src/lib.rs @@ -9,6 +9,7 @@ mod memo; mod pattern; mod plain; mod props; +mod registry; mod style; mod token_group; mod util; @@ -145,8 +146,7 @@ pub fn words(input: TokenStream) -> TokenStream { /// Registers a function as a trial of its crate's test executable. /// -/// The function takes no arguments and returns `()`; it fails by panicking. The registration lists it in -/// `craft_ui::testing::trials()`, so the runner finds it without a hand-kept list. An `#[ignore]` on the function +/// The function takes no arguments and returns `()`; it fails by panicking. The crate registry includes it in the runner. An `#[ignore]` on the function /// makes it run only under `--ignored`. #[proc_macro_attribute] pub fn trial(attr: TokenStream, item: TokenStream) -> TokenStream { @@ -166,12 +166,17 @@ pub fn trial(attr: TokenStream, item: TokenStream) -> TokenStream { } let ident = &sig.ident; let name = ident.to_string(); + let gate = component::declares_suite().then(|| quote!(#[cfg(any(test, feature = "suite"))])); + let helper = quote::format_ident!("__registry_trial_{}", ident); quote! { + #gate #func - #k::testing::__private::inventory::submit! { + #gate + pub(crate) fn #helper() -> #k::testing::Trial { #k::testing::Trial::#register(module_path!(), #name, #ident) } + } .into() } @@ -234,7 +239,8 @@ impl Parse for StoryArgs { pub fn story(attr: TokenStream, item: TokenStream) -> TokenStream { let k = util::ui_crate(); let args = parse_macro_input!(attr as StoryArgs); - let func = parse_macro_input!(item as ItemFn); + let mut func = parse_macro_input!(item as ItemFn); + func.vis = syn::parse_quote!(pub(crate)); let ident = &func.sig.ident; let name = ident.to_string(); let ty = &args.ty; @@ -244,18 +250,33 @@ pub fn story(attr: TokenStream, item: TokenStream) -> TokenStream { let title = args.title.as_ref().map(|title| quote!(.title(#title))); let group = args.group.as_ref().map(|group| quote!(.group(#group))); let commands = args.commands.as_ref().map(|commands| quote!(.commands(#commands))); + let gate = component::registration_gate(); + let helper = quote::format_ident!("__registry_story_{}", ident); + let registration = quote! { + #k::testing::StoryRegistration::new( + env!("CARGO_PKG_NAME"), + env!("CARGO_CRATE_NAME"), + ::std::any::type_name::<#ty>, + <#ty as #k::testing::Registered>::registration, + #k::testing::Story::new(#name, #ident).covers(&[#(#k::testing::Required::#covers),*]) #drive #disabled_text #title #group #commands, + ).at(file!(), line!()) + }; quote! { + #gate #func - #k::testing::__private::inventory::submit! { - #k::testing::StoryRegistration::new( - env!("CARGO_PKG_NAME"), - env!("CARGO_CRATE_NAME"), - ::std::any::type_name::<#ty>, - #k::testing::Story::new(#name, #ident).covers(&[#(#k::testing::Required::#covers),*]) #drive #disabled_text #title #group #commands, - ) - .at(file!(), line!()) - } + #gate + pub(crate) fn #helper() -> #k::testing::StoryRegistration { #registration } + } .into() } + +/// Generates a crate registration function by reading its source modules. +#[proc_macro] +pub fn registry(input: TokenStream) -> TokenStream { + if !input.is_empty() { + return syn::Error::new(proc_macro2::Span::call_site(), "registry! takes no arguments").to_compile_error().into(); + } + expanded(registry::expand()) +} diff --git a/crates/ui-macros/src/registry.rs b/crates/ui-macros/src/registry.rs new file mode 100644 index 000000000..a265949e2 --- /dev/null +++ b/crates/ui-macros/src/registry.rs @@ -0,0 +1,270 @@ +//! Discovers suite items in a crate's source modules for `registry!()`. + +use proc_macro2::{Ident, Span, TokenStream}; +use quote::{format_ident, quote}; +use std::path::{Path, PathBuf}; +use syn::parse::{Parse, ParseStream}; +use syn::punctuated::Punctuated; +use syn::{Attribute, Item, ItemMod, Meta, Token, Type}; + +struct FirstType(Type); +impl Parse for FirstType { + fn parse(input: ParseStream<'_>) -> syn::Result { + let first = input.parse()?; + let _: TokenStream = input.parse()?; + Ok(Self(first)) + } +} + +fn attrs_cfg(attrs: &[Attribute]) -> Vec { + attrs + .iter() + .filter(|a| a.path().is_ident("cfg") || a.path().is_ident("cfg_attr")) + .cloned() + .map(|mut attr| { + attr.style = syn::AttrStyle::Outer; + attr + }) + .collect() +} + +fn derives(attrs: &[Attribute], wanted: &str) -> bool { + attrs.iter().filter(|a| a.path().is_ident("derive")).any(|a| { + a.parse_args_with(Punctuated::::parse_terminated) + .is_ok_and(|paths| paths.iter().any(|p| p.segments.last().is_some_and(|s| s.ident == wanted))) + }) +} + +fn marker(attrs: &[Attribute], name: &str) -> bool { + attrs.iter().any(|a| a.path().segments.last().is_some_and(|s| s.ident == name)) +} + +fn opt(attrs: &[Attribute], attr: &str, value: &str) -> bool { + attrs.iter().filter(|a| a.path().is_ident(attr)).any(|a| match &a.meta { + Meta::List(list) => list.tokens.to_string().split(|c: char| !c.is_alphanumeric() && c != '_').any(|word| word == value), + _ => false, + }) +} + +fn include_value(expr: &syn::Expr) -> Option { + match expr { + syn::Expr::Lit(expr) => match &expr.lit { + syn::Lit::Str(value) => Some(value.value()), + _ => None, + }, + syn::Expr::Macro(expr) if expr.mac.path.is_ident("env") => { + let name = syn::parse2::(expr.mac.tokens.clone()).ok()?; + (name.value() == "OUT_DIR").then(|| std::env::var("OUT_DIR").ok()).flatten() + } + syn::Expr::Macro(expr) if expr.mac.path.is_ident("concat") => { + let args = expr.mac.parse_body_with(Punctuated::::parse_terminated).ok()?; + args.iter().map(include_value).collect::>>().map(|parts| parts.concat()) + } + _ => None, + } +} + +fn contains_suite_item(items: &[Item]) -> bool { + items.iter().any(|item| match item { + Item::Struct(item) => { + (derives(&item.attrs, "Component") && !opt(&item.attrs, "component", "unregistered")) || derives(&item.attrs, "Pattern") + } + Item::Enum(item) => derives(&item.attrs, "CommandSet") && opt(&item.attrs, "command", "story"), + Item::Fn(item) => marker(&item.attrs, "story") || marker(&item.attrs, "trial"), + Item::Mod(item) => item.content.as_ref().is_some_and(|(_, items)| contains_suite_item(items)), + Item::Macro(item) => { + let name = item.mac.path.segments.last().map(|segment| segment.ident.to_string()).unwrap_or_default(); + let body = item.mac.tokens.to_string(); + name == "register_contract" + || name == "include" + || (name == "macro_rules" + && (body.contains("register_contract") + || body.contains("# [story") + || body.contains("# [trial") + || (body.contains("derive") && (body.contains("Component") || body.contains("Pattern")) && !body.contains("unregistered")) + || (body.contains("CommandSet") && body.contains("story")))) + } + _ => false, + }) +} + +fn explicit_path(path_dir: &Path, module: &ItemMod) -> Option { + for attr in &module.attrs { + if attr.path().is_ident("path") + && let Meta::NameValue(value) = &attr.meta + && let syn::Expr::Lit(expr) = &value.value + && let syn::Lit::Str(path) = &expr.lit + { + return Some(path_dir.join(path.value())); + } + } + None +} + +fn module_file(module_dir: &Path) -> Option { + let plain = module_dir.with_extension("rs"); + if plain.is_file() { + Some(plain) + } else { + let nested = module_dir.join("mod.rs"); + nested.is_file().then_some(nested) + } +} + +#[derive(Default)] +struct Registrations { + trials: Vec, + suite: Vec, +} + +fn walk( + items: &[Item], + file: &Path, + dir: &Path, + path_dir: &Path, + path: &[Ident], + inherited: &[Attribute], + calls: &mut Registrations, +) -> syn::Result<()> { + for item in items { + match item { + Item::Mod(module) => { + let mut cfg = inherited.to_vec(); + cfg.extend(attrs_cfg(&module.attrs)); + let mut child_path = path.to_vec(); + child_path.push(module.ident.clone()); + let module_dir = dir.join(module.ident.to_string()); + let explicit = explicit_path(path_dir, module); + if let Some((_, content)) = &module.content { + let inline_dir = explicit.as_deref().unwrap_or(&module_dir); + walk(content, file, inline_dir, inline_dir, &child_path, &cfg, calls)?; + } else if let Some(file) = explicit.clone().or_else(|| module_file(&module_dir)) { + let text = std::fs::read_to_string(&file) + .map_err(|e| syn::Error::new_spanned(module, format!("cannot read {}: {e}", file.display())))?; + let parsed = + syn::parse_file(&text).map_err(|e| syn::Error::new_spanned(module, format!("cannot parse {}: {e}", file.display())))?; + cfg.extend(attrs_cfg(&parsed.attrs)); + let file_dir = file.parent().unwrap_or(dir); + // Rust looks beside a file selected by #[path] for that file's own modules. + let child_dir = if explicit.is_some() { file_dir } else { &module_dir }; + walk(&parsed.items, &file, child_dir, file_dir, &child_path, &cfg, calls)?; + } + } + Item::Struct(item) + if (derives(&item.attrs, "Component") && !opt(&item.attrs, "component", "unregistered")) || derives(&item.attrs, "Pattern") => + { + let helper = format_ident!("__registry_component_{}", crate::command_set::snake(&item.ident.to_string())); + let mut cfg = inherited.to_vec(); + cfg.extend(attrs_cfg(&item.attrs)); + calls.suite.push(quote! { #(#cfg)* crate::#(#path::)*#helper(registry); }); + } + Item::Fn(item) if marker(&item.attrs, "story") || marker(&item.attrs, "trial") => { + let (prefix, method) = + if marker(&item.attrs, "story") { ("story", format_ident!("add_story")) } else { ("trial", format_ident!("add_trial")) }; + let helper = format_ident!("__registry_{}_{}", prefix, item.sig.ident); + let mut cfg = inherited.to_vec(); + cfg.extend(attrs_cfg(&item.attrs)); + let entries = if marker(&item.attrs, "trial") { &mut calls.trials } else { &mut calls.suite }; + entries.push(quote! { #(#cfg)* registry.#method(crate::#(#path::)*#helper()); }); + } + Item::Enum(item) if derives(&item.attrs, "CommandSet") && opt(&item.attrs, "command", "story") => { + let helper = format_ident!("__registry_command_{}", crate::command_set::snake(&item.ident.to_string())); + let mut cfg = inherited.to_vec(); + cfg.extend(attrs_cfg(&item.attrs)); + calls.suite.push(quote! { #(#cfg)* registry.add_story_set(crate::#(#path::)*#helper()); }); + } + Item::Macro(item) if item.mac.path.is_ident("include") => { + let expression: syn::Expr = syn::parse2(item.mac.tokens.clone())?; + let included = + include_value(&expression).ok_or_else(|| syn::Error::new_spanned(item, "registry! cannot inspect this include! path"))?; + let included = file.parent().unwrap_or(dir).join(included); + let text = std::fs::read_to_string(&included) + .map_err(|e| syn::Error::new_spanned(item, format!("cannot inspect {}: {e}", included.display())))?; + let parsed = + syn::parse_file(&text).map_err(|e| syn::Error::new_spanned(item, format!("cannot inspect {}: {e}", included.display())))?; + if contains_suite_item(&parsed.items) { + return Err(syn::Error::new_spanned(item, "suite registration inside include! is invisible to registry!")); + } + } + Item::Macro(item) if item.mac.path.segments.last().is_some_and(|s| s.ident == "register_contract") => { + let FirstType(ty) = syn::parse2(item.mac.tokens.clone())?; + if let Type::Path(ty) = ty + && let Some(name) = ty.path.segments.last() + { + let helper = format_ident!("__registry_component_{}", crate::command_set::snake(&name.ident.to_string())); + let mut cfg = inherited.to_vec(); + cfg.extend(attrs_cfg(&item.attrs)); + calls.suite.push(quote! { #(#cfg)* crate::#(#path::)*#helper(registry); }); + } + } + _ => {} + } + } + Ok(()) +} + +pub fn expand() -> syn::Result { + let invocation = + proc_macro::Span::call_site().local_file().ok_or_else(|| syn::Error::new(Span::call_site(), "registry! needs a local source file"))?; + let manifest = + std::env::var_os("CARGO_MANIFEST_DIR").map(PathBuf::from).ok_or_else(|| syn::Error::new(Span::call_site(), "missing CARGO_MANIFEST_DIR"))?; + let invocation = std::fs::canonicalize(&invocation).unwrap_or(invocation); + let src = std::fs::canonicalize(manifest.join("src")).unwrap_or_else(|_| manifest.join("src")); + let source = if invocation.starts_with(&src) { src.join("lib.rs") } else { invocation }; + let text = std::fs::read_to_string(&source).map_err(|e| syn::Error::new(Span::call_site(), format!("cannot read {}: {e}", source.display())))?; + let parsed = syn::parse_file(&text)?; + let mut calls = Registrations::default(); + walk(&parsed.items, &source, source.parent().unwrap_or(&manifest), source.parent().unwrap_or(&manifest), &[], &[], &mut calls)?; + let k = crate::util::ui_crate(); + let Registrations { trials, suite } = calls; + let gate = crate::component::registration_gate(); + Ok(quote! { + /// Adds this crate's suite items to the caller's registry. + pub fn register(registry: &mut #k::testing::Registry) { + #(#trials)* + #gate + { #(#suite)* } + } + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn rejects_a_registration_inside_an_include() { + let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/registry/root.rs"); + let parsed = syn::parse_file("include!(\"included.rs\");"); + assert!(parsed.is_ok()); + if let Ok(parsed) = parsed { + let mut calls = Registrations::default(); + let dir = root.parent().unwrap_or(Path::new("")); + assert!(walk(&parsed.items, &root, dir, dir, &[], &[], &mut calls).is_err()); + } + } + + #[test] + fn follows_modules_and_keeps_their_conditions() { + let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/registry/root.rs"); + let source = std::fs::read_to_string(&root).unwrap_or_default(); + let parsed = syn::parse_file(&source); + assert!(parsed.is_ok()); + if let Ok(parsed) = parsed { + let mut calls = Registrations::default(); + let result = + walk(&parsed.items, &root, root.parent().unwrap_or(Path::new("")), root.parent().unwrap_or(Path::new("")), &[], &[], &mut calls); + assert!(result.is_ok()); + let Registrations { trials, suite } = calls; + let generated = quote! { #(#trials)* #(#suite)* }.to_string(); + assert!(generated.contains("feature = \"sample\"")); + assert!(generated.contains("__registry_story_view")); + assert!(generated.contains("__registry_trial_changes")); + assert!(generated.contains("__registry_trial_path_trial")); + assert!(generated.contains("crate :: child :: other :: nested :: __registry_trial_nested_path_trial")); + assert!(generated.contains("crate :: child :: inline_alias :: nested :: __registry_trial_nested_path_trial")); + assert!(generated.contains("cfg (not (target_arch = \"wasm32\"))")); + assert!(!generated.contains("# !")); + } + } +} diff --git a/crates/ui-macros/src/tests.rs b/crates/ui-macros/src/tests.rs index 6ced7341c..ed0ed2c36 100644 --- a/crates/ui-macros/src/tests.rs +++ b/crates/ui-macros/src/tests.rs @@ -1,13 +1,10 @@ //! The registration gate the component derive reads from the package manifest. -use proc_macro2::TokenStream; - #[test] -fn registration_is_gated_only_when_the_package_declares_screen_testing() { - let compact = |tokens: TokenStream| tokens.to_string().split_whitespace().collect::(); - let declared = "[package]\nname = \"app\"\n\n[features]\nscreen-testing = [\"craft-ui/testing\"]\n"; - assert_eq!(compact(crate::component::gate_for(declared)), "#[cfg(feature=\"screen-testing\")]"); - let undeclared = "[package]\nname = \"gallery\"\nscreen-testing = 1\n\n[dependencies]\nscreen-testing = \"1\"\n"; - assert_eq!(compact(crate::component::gate_for(undeclared)), ""); - assert_eq!(compact(crate::component::gate_for("")), ""); +fn registration_is_gated_only_when_the_package_declares_suite() { + let declared = "[package]\nname = \"app\"\n\n[features]\nsuite = [\"craft-ui/testing\"]\n"; + assert!(crate::component::declares_suite_in(declared)); + let undeclared = "[package]\nname = \"gallery\"\nsuite = 1\n\n[dependencies]\nsuite = \"1\"\n"; + assert!(!crate::component::declares_suite_in(undeclared)); + assert!(!crate::component::declares_suite_in("")); } diff --git a/crates/ui-macros/tests/fixtures/registry/child.rs b/crates/ui-macros/tests/fixtures/registry/child.rs new file mode 100644 index 000000000..2e2525059 --- /dev/null +++ b/crates/ui-macros/tests/fixtures/registry/child.rs @@ -0,0 +1,14 @@ +#![cfg(not(target_arch = "wasm32"))] + +#[story(Widget)] +fn view() {} + +#[trial] +fn changes() {} +#[path = "other.rs"] +mod other; + +#[path = "."] +mod inline_alias { + mod nested; +} diff --git a/crates/ui-macros/tests/fixtures/registry/included.rs b/crates/ui-macros/tests/fixtures/registry/included.rs new file mode 100644 index 000000000..d99724797 --- /dev/null +++ b/crates/ui-macros/tests/fixtures/registry/included.rs @@ -0,0 +1,2 @@ +#[trial] +fn hidden() {} diff --git a/crates/ui-macros/tests/fixtures/registry/nested.rs b/crates/ui-macros/tests/fixtures/registry/nested.rs new file mode 100644 index 000000000..5b4dd1385 --- /dev/null +++ b/crates/ui-macros/tests/fixtures/registry/nested.rs @@ -0,0 +1,2 @@ +#[trial] +fn nested_path_trial() {} diff --git a/crates/ui-macros/tests/fixtures/registry/other.rs b/crates/ui-macros/tests/fixtures/registry/other.rs new file mode 100644 index 000000000..5d05daba5 --- /dev/null +++ b/crates/ui-macros/tests/fixtures/registry/other.rs @@ -0,0 +1,4 @@ +#[trial] +fn path_trial() {} + +mod nested; diff --git a/crates/ui-macros/tests/fixtures/registry/root.rs b/crates/ui-macros/tests/fixtures/registry/root.rs new file mode 100644 index 000000000..9a84b5118 --- /dev/null +++ b/crates/ui-macros/tests/fixtures/registry/root.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "sample")] +mod child; diff --git a/crates/ui-panels/Cargo.toml b/crates/ui-panels/Cargo.toml index 2e2703415..44aff9e89 100644 --- a/crates/ui-panels/Cargo.toml +++ b/crates/ui-panels/Cargo.toml @@ -15,6 +15,7 @@ test = false workspace = true [features] +suite = ["testing", "craft-ui-widgets/suite"] default = [] # `craft_ui::testing` with `testing::internals`. testing = ["craft-ui-widgets/testing"] @@ -34,7 +35,7 @@ serde = { workspace = true } serde_json = { workspace = true } [dev-dependencies] -craft-ui-panels = { path = ".", features = ["testing"] } +craft-ui-panels = { path = ".", features = ["suite"] } craft-behavior = { workspace = true } craft-keymap = { workspace = true, features = ["egui"] } egui = { workspace = true } diff --git a/crates/ui-panels/src/dialog/mod.rs b/crates/ui-panels/src/dialog/mod.rs index 3729e8995..52967e875 100644 --- a/crates/ui-panels/src/dialog/mod.rs +++ b/crates/ui-panels/src/dialog/mod.rs @@ -2,24 +2,24 @@ //! configurations (`Alert`, `StandardPrompt`, `UnsavedChangesDialog`, `RecoveryDialog`) and the values an app routes //! its dialogs by (`DialogStack`, `DialogHost`). Form dialogs build on the shells. -mod alert; -mod blocking; +pub(crate) mod alert; +pub(crate) mod blocking; #[doc(hidden)] pub mod frame; mod held; mod host; -mod modal; -mod prompt; -mod prompts; -mod recovery; +pub(crate) mod modal; +pub(crate) mod prompt; +pub(crate) mod prompts; +pub(crate) mod recovery; mod serde_fields; mod stack; -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] #[doc(hidden)] pub mod stories; -#[cfg(feature = "testing")] -mod trials; -mod unsaved; +#[cfg(feature = "suite")] +pub(crate) mod trials; +pub(crate) mod unsaved; mod words; pub use alert::{Alert, AlertOutput, HostedAlert}; diff --git a/crates/ui-panels/src/dialog/prompt.rs b/crates/ui-panels/src/dialog/prompt.rs index 7def4e717..d9e890628 100644 --- a/crates/ui-panels/src/dialog/prompt.rs +++ b/crates/ui-panels/src/dialog/prompt.rs @@ -14,8 +14,8 @@ use craft_keymap::{Chord, mnemonic}; use craft_theme::variant::Tone; use egui::{Response, Ui}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// One answer of a prompt before its button exists: the label, what the button means, whether it has a letter and /// whether it is available. diff --git a/crates/ui-panels/src/docking/dock_column.rs b/crates/ui-panels/src/docking/dock_column.rs index 8cabf2989..d01fa012f 100644 --- a/crates/ui-panels/src/docking/dock_column.rs +++ b/crates/ui-panels/src/docking/dock_column.rs @@ -22,8 +22,8 @@ use egui::{Context, Id, Pos2, Rect, Response, Ui}; use std::fmt::Debug; use std::hash::Hash; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod bar; mod sizing; diff --git a/crates/ui-panels/src/docking/floating.rs b/crates/ui-panels/src/docking/floating.rs index e0e09415e..5c84635a8 100644 --- a/crates/ui-panels/src/docking/floating.rs +++ b/crates/ui-panels/src/docking/floating.rs @@ -31,8 +31,8 @@ use egui::{Id, Pos2, Rect, Response, Ui, Vec2}; use std::cell::RefCell; use std::hash::Hash; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The height of a floating group's title row: a strong `TitleRow`, which is as tall as a panel header. pub(crate) fn title_row(tokens: &UiTokens) -> f32 { diff --git a/crates/ui-panels/src/docking/iconic.rs b/crates/ui-panels/src/docking/iconic.rs index cc8f6cc19..1665e17a0 100644 --- a/crates/ui-panels/src/docking/iconic.rs +++ b/crates/ui-panels/src/docking/iconic.rs @@ -26,10 +26,10 @@ use egui::{Id, Pos2, Rect, Response, Ui, Vec2}; use std::fmt::Debug; use std::hash::Hash; -#[cfg(feature = "testing")] -mod stories; -#[cfg(feature = "testing")] -mod trials; +#[cfg(feature = "suite")] +pub(crate) mod stories; +#[cfg(feature = "suite")] +pub(crate) mod trials; const CELL: PartKey = PartKey::new("cell"); const NAME: PartKey = PartKey::new("name"); diff --git a/crates/ui-panels/src/docking/mod.rs b/crates/ui-panels/src/docking/mod.rs index 6f5c0a214..ee98e4d2d 100644 --- a/crates/ui-panels/src/docking/mod.rs +++ b/crates/ui-panels/src/docking/mod.rs @@ -9,20 +9,20 @@ pub mod divider; mod drop; mod event; pub mod frame; -mod group; +pub(crate) mod group; -mod floating; +pub(crate) mod floating; mod panels; mod placed; -mod root; +pub(crate) mod root; mod spec; -mod splitter; +pub(crate) mod splitter; pub mod stack; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub mod targets; pub mod tree; -mod window_menu; +pub(crate) mod window_menu; mod words; mod commands; @@ -53,9 +53,9 @@ pub use commands::{ dock_states, move_actions, run_workspace, workspace_states, }; -mod dock_column; +pub(crate) mod dock_column; mod flyout; -mod iconic; +pub(crate) mod iconic; pub use dock_column::{ ColumnArrow, ColumnBar, DockColumn, DockColumnOutput, DockColumnStyle, GroupSize, GroupView, column_cells, fit_widths, group_heights, diff --git a/crates/ui-panels/src/docking/root.rs b/crates/ui-panels/src/docking/root.rs index 8b0c59c68..649ca0ce7 100644 --- a/crates/ui-panels/src/docking/root.rs +++ b/crates/ui-panels/src/docking/root.rs @@ -13,8 +13,8 @@ use crate::style::{ComponentStyle, StyleCx}; use craft_behavior::{Metrics, Sense}; use egui::Response; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of a dock root: the docking sizes of its drop bands, columns, groups and floating windows. Colours, /// surfaces and shapes belong to the parts the pattern assembles. diff --git a/crates/ui-panels/src/lib.rs b/crates/ui-panels/src/lib.rs index 8a7337eb4..bcfd0e8df 100644 --- a/crates/ui-panels/src/lib.rs +++ b/crates/ui-panels/src/lib.rs @@ -10,10 +10,10 @@ extern crate self as craft_ui; #[cfg(feature = "testing")] +pub use craft_ui_widgets::registry; +#[cfg(feature = "suite")] #[doc(hidden)] pub use craft_ui_widgets::story_kit; -#[cfg(feature = "testing")] -pub use craft_ui_widgets::testing_registered; #[doc(hidden)] pub use craft_ui_widgets::{__private, __register_command_set, __register_contract, __register_pattern}; pub use craft_ui_widgets::{InstallError, InstallSpec, contract, fonts, install, layout, primitives, runtime, style, words}; @@ -43,5 +43,6 @@ pub mod testing { pub use crate::testing_internals::*; } - crate::testing_registered!(); + #[cfg(feature = "suite")] + crate::registry!(); } diff --git a/crates/ui-panels/src/rails/drawer.rs b/crates/ui-panels/src/rails/drawer.rs index bef693ce6..794b54825 100644 --- a/crates/ui-panels/src/rails/drawer.rs +++ b/crates/ui-panels/src/rails/drawer.rs @@ -24,8 +24,8 @@ use craft_behavior::{DisplayOrder, IconId, ItemSource, Value}; use egui::{Rect, Response, Ui}; use std::borrow::Cow; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// A group of the drawer: a heading over the tools that belong under it. #[derive(Clone, Debug)] diff --git a/crates/ui-panels/src/rails/flyout.rs b/crates/ui-panels/src/rails/flyout.rs index 9bc9aab91..fdcdafaf0 100644 --- a/crates/ui-panels/src/rails/flyout.rs +++ b/crates/ui-panels/src/rails/flyout.rs @@ -15,8 +15,8 @@ use craft_behavior::overlay::{Align, Side}; use craft_behavior::{HitLevel, HitPriority, IconId, Metrics, PartKey, PointerButton, PressPhase, Sense, Value}; use egui::{Rect, Response, Vec2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The face over the whole button. const FACE: PartKey = PartKey::new("face"); diff --git a/crates/ui-panels/src/rails/mod.rs b/crates/ui-panels/src/rails/mod.rs index ec22c322f..200b991b8 100644 --- a/crates/ui-panels/src/rails/mod.rs +++ b/crates/ui-panels/src/rails/mod.rs @@ -3,11 +3,11 @@ mod words; // The Edit Toolbar drawer. -mod drawer; +pub(crate) mod drawer; // The tool rail and its flyout button. -mod flyout; -mod tool; +pub(crate) mod flyout; +pub(crate) mod tool; pub use drawer::{DrawerGroup, ToolbarDrawer, ToolbarDrawerOutput, ToolbarEdit, apply_toolbar_edit, drop_edit}; pub use flyout::{FlyoutButton, FlyoutButtonStyle, FlyoutOutput, SlotEdit}; diff --git a/crates/ui-panels/src/rails/tool.rs b/crates/ui-panels/src/rails/tool.rs index 99e0f0f9a..b59097803 100644 --- a/crates/ui-panels/src/rails/tool.rs +++ b/crates/ui-panels/src/rails/tool.rs @@ -23,10 +23,10 @@ use egui::{Id, Response, Ui, Vec2}; mod data; mod drag; -#[cfg(feature = "testing")] -pub(super) mod stories; -#[cfg(feature = "testing")] -mod trials; +#[cfg(feature = "suite")] +pub(crate) mod stories; +#[cfg(feature = "suite")] +pub(crate) mod trials; use data::row_groups; pub use data::{LastUsed, RailTool, SlotId, ToolSlot, remembered, shown_tool, visible_slots}; diff --git a/crates/ui-panels/src/sections/footer.rs b/crates/ui-panels/src/sections/footer.rs index 31c99abb8..d983d9722 100644 --- a/crates/ui-panels/src/sections/footer.rs +++ b/crates/ui-panels/src/sections/footer.rs @@ -25,8 +25,8 @@ use std::any::Any; use std::fmt; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of a footer bar. A bar of panel actions sits under a divider rule along its top edge, with the control /// padding above and under its buttons; other bars have no look of their own. diff --git a/crates/ui-panels/src/sections/group_box.rs b/crates/ui-panels/src/sections/group_box.rs index a43d3a3d5..16889d707 100644 --- a/crates/ui-panels/src/sections/group_box.rs +++ b/crates/ui-panels/src/sections/group_box.rs @@ -10,8 +10,8 @@ use crate::style::{ComponentStyle, StyleCx, SurfaceKind}; use craft_behavior::{Metrics, Sense}; use egui::Ui; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The heading level AccessKit reports for a section header. pub(super) const SECTION_LEVEL: usize = 3; diff --git a/crates/ui-panels/src/sections/mod.rs b/crates/ui-panels/src/sections/mod.rs index 84760feb1..f133bfb13 100644 --- a/crates/ui-panels/src/sections/mod.rs +++ b/crates/ui-panels/src/sections/mod.rs @@ -1,16 +1,16 @@ //! Sections and title rows: `TitleRow`, `FooterBar`, `Section`, `GroupBox` and `Panel`. pub(crate) mod footer; -mod group_box; -#[cfg(feature = "testing")] +pub(crate) mod group_box; +#[cfg(feature = "suite")] mod sample; -mod section; -mod stack; -mod title_row; +pub(crate) mod section; +pub(crate) mod stack; +pub(crate) mod title_row; mod words; // Panel. -mod panel; +pub(crate) mod panel; pub use footer::{DialogRole, DropAction, DropActionOutput, DropActionStyle, FooterAction, FooterBar, FooterButton, FooterDrop, FooterOutput}; pub use group_box::{GroupBox, GroupBoxStyle}; @@ -25,7 +25,7 @@ pub use panel::{Panel, PanelOutput, PanelStyle}; // Reorderable sections. mod layout; -mod reorderable; +pub(crate) mod reorderable; pub use layout::{SectionEvent, SectionKey, SectionLayout, SectionState}; pub use reorderable::{ReorderableSections, ReorderableSectionsOutput, SectionButton, SectionCommands, SectionSpec}; diff --git a/crates/ui-panels/src/sections/panel.rs b/crates/ui-panels/src/sections/panel.rs index 4d4786d73..5998fd123 100644 --- a/crates/ui-panels/src/sections/panel.rs +++ b/crates/ui-panels/src/sections/panel.rs @@ -18,8 +18,8 @@ use crate::style::{ComponentStyle, StyleColor, StyleCx, SurfaceKind, UiTokens}; use craft_behavior::{Metrics, Sense}; use egui::{CornerRadius, Id, Response, Ui}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of a panel: the surface and padding come from the container. #[derive(Clone, Debug, PartialEq, ComponentStyle)] diff --git a/crates/ui-panels/src/sections/reorderable.rs b/crates/ui-panels/src/sections/reorderable.rs index 2fab48c83..f2690e3ef 100644 --- a/crates/ui-panels/src/sections/reorderable.rs +++ b/crates/ui-panels/src/sections/reorderable.rs @@ -16,8 +16,8 @@ use egui::{Response, Ui}; use std::cell::RefCell; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The commands of a section, run on the section that holds the focus: its header menu rows and any chord the keymap /// binds. Showing a hidden section is a row of the menu, one per section, because a hidden section cannot hold focus. diff --git a/crates/ui-panels/src/sections/section.rs b/crates/ui-panels/src/sections/section.rs index 31e3b09d8..9bb18b6f1 100644 --- a/crates/ui-panels/src/sections/section.rs +++ b/crates/ui-panels/src/sections/section.rs @@ -15,8 +15,8 @@ use crate::style::{ComponentStyle, StyleCx}; use craft_behavior::{Metrics, PointerButton, PressPhase, Sense}; use egui::{Id, Response, Ui}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of a section: no surface or padding of its own; the header and body carry the look. #[derive(Clone, Debug, Default, PartialEq, ComponentStyle)] diff --git a/crates/ui-panels/src/sections/stack.rs b/crates/ui-panels/src/sections/stack.rs index d7ee0de3f..1fbe44a87 100644 --- a/crates/ui-panels/src/sections/stack.rs +++ b/crates/ui-panels/src/sections/stack.rs @@ -15,8 +15,8 @@ use craft_behavior::{Axis, EditEvent, Metrics, Mixed, Sense}; use egui::{Pos2, Rect, Response, Ui}; use std::sync::{Arc, Mutex, PoisonError}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// What a section of a stack is told about its place: `Section::in_stack` reads it. #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/crates/ui-panels/src/sections/title_row.rs b/crates/ui-panels/src/sections/title_row.rs index 9e8764d99..dfbfd4a5a 100644 --- a/crates/ui-panels/src/sections/title_row.rs +++ b/crates/ui-panels/src/sections/title_row.rs @@ -20,8 +20,8 @@ use craft_theme::variant::Tone; use craft_theme::{ControlSize, Stateful, States}; use egui::{Id, Rect, Response, Ui, Vec2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// How much weight a header carries. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] diff --git a/crates/ui-panels/tests/it/access/mod.rs b/crates/ui-panels/tests/it/access/mod.rs index 265795b2d..ff516ed39 100644 --- a/crates/ui-panels/tests/it/access/mod.rs +++ b/crates/ui-panels/tests/it/access/mod.rs @@ -1,3 +1,3 @@ //! The accessibility emitter: the label scope and merge rule, announcements, modal inertness, viewports. -mod modal_inert; +pub(crate) mod modal_inert; diff --git a/crates/ui-panels/tests/it/body/mod.rs b/crates/ui-panels/tests/it/body/mod.rs index b8af0f714..bf7e06cbe 100644 --- a/crates/ui-panels/tests/it/body/mod.rs +++ b/crates/ui-panels/tests/it/body/mod.rs @@ -1,4 +1,4 @@ //! The body step and the mount host: regions, scrolling, move and resize, and viewport mounts. -mod after_label; -mod footer_reserve; +pub(crate) mod after_label; +pub(crate) mod footer_reserve; diff --git a/crates/ui-panels/tests/it/edit/mod.rs b/crates/ui-panels/tests/it/edit/mod.rs index 15c21ab99..fa219de8b 100644 --- a/crates/ui-panels/tests/it/edit/mod.rs +++ b/crates/ui-panels/tests/it/edit/mod.rs @@ -1,3 +1,3 @@ //! The edit mechanism across components: a dialog's outer gesture over its fields. -mod outer; +pub(crate) mod outer; diff --git a/crates/ui-panels/tests/it/focus/mod.rs b/crates/ui-panels/tests/it/focus/mod.rs index 280fca926..fd2552ac9 100644 --- a/crates/ui-panels/tests/it/focus/mod.rs +++ b/crates/ui-panels/tests/it/focus/mod.rs @@ -1,10 +1,10 @@ //! The focus service and the key stage, driven through registered stops over real egui widgets. -mod dialog_tab; -mod keys; -mod press; -mod roving; -mod scopes; +pub(crate) mod dialog_tab; +pub(crate) mod keys; +pub(crate) mod press; +pub(crate) mod roving; +pub(crate) mod scopes; use craft_behavior::Input; use craft_ui::runtime::focus::{FocusTarget, KeyUse, request}; diff --git a/crates/ui-panels/tests/it/list/mod.rs b/crates/ui-panels/tests/it/list/mod.rs index f79e25f25..91f44c194 100644 --- a/crates/ui-panels/tests/it/list/mod.rs +++ b/crates/ui-panels/tests/it/list/mod.rs @@ -1,3 +1,3 @@ //! The `List` component's own settings, over the item step. -mod row_trailing; +pub(crate) mod row_trailing; diff --git a/crates/ui-panels/tests/it/main.rs b/crates/ui-panels/tests/it/main.rs index 1a8ff8e60..70872c8f4 100644 --- a/crates/ui-panels/tests/it/main.rs +++ b/crates/ui-panels/tests/it/main.rs @@ -3,23 +3,23 @@ // The test files name the library as `craft_ui`, as the crates that use it do. extern crate craft_ui_panels as craft_ui; -mod access; +pub(crate) mod access; pub(crate) mod body; -mod dialogs; -mod dock_group; +pub(crate) mod dialogs; +pub(crate) mod dock_group; // outer edit -mod edit; +pub(crate) mod edit; // end of outer edit -mod focus; -mod internals; -mod list; -mod popup_surface; +pub(crate) mod focus; +pub(crate) mod internals; +pub(crate) mod list; +pub(crate) mod popup_surface; -mod rails; -mod sections; +pub(crate) mod rails; +pub(crate) mod sections; -use craft_ui::testing::registered; +craft_ui::registry!(); fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), ®istered()); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register, craft_ui::testing::register])); } diff --git a/crates/ui-panels/tests/it/popup_surface.rs b/crates/ui-panels/tests/it/popup_surface.rs index 74e00aa8e..2e136e6a0 100644 --- a/crates/ui-panels/tests/it/popup_surface.rs +++ b/crates/ui-panels/tests/it/popup_surface.rs @@ -2,7 +2,7 @@ //! a layer or a component shows it from its `overlay` hook, and whatever its body paints itself. Its content sits //! inside the popup padding, and a popup beside its owner does not cover it. -use craft_ui::testing::{Drive, Fixture, stories, trial}; +use craft_ui::testing::{Drive, Fixture, Registry, trial}; use egui::{Rect, Shape}; /// Each story, opened by its drive, with a text only its popup shows. @@ -19,7 +19,8 @@ const OPEN: [(&str, &str); 4] = [ /// The story `name`, opened by its drive, and the shapes of the frame after it settled. fn open(name: &str) -> (Fixture, Vec) { - let entry = stories().into_iter().find(|entry| entry.story.name == name).unwrap_or_else(|| panic!("story {name}")); + let registry = Registry::of(&[craft_ui::testing::register, craft_ui_widgets::testing::register]); + let entry = registry.stories().iter().find(|entry| entry.story.name == name).unwrap_or_else(|| panic!("story {name}")); let mut fixture = Fixture::story(&entry.story); fixture.settle(); if let Drive::Custom(open) = entry.story.drive { diff --git a/crates/ui-panels/tests/it/rails/drawer.rs b/crates/ui-panels/tests/it/rails/drawer.rs index b99eb3629..c5b1a7e5a 100644 --- a/crates/ui-panels/tests/it/rails/drawer.rs +++ b/crates/ui-panels/tests/it/rails/drawer.rs @@ -4,7 +4,7 @@ use craft_ui::rails::{DropAt, RailTool, ToolSlot, ToolbarEdit, apply_toolbar_edit}; use craft_ui::runtime::commands::EditCommands; use craft_ui::runtime::drag; -use craft_ui::testing::{Fixture, stories, trial}; +use craft_ui::testing::{Fixture, Registry, trial}; use egui::Vec2; const UNDO: u8 = 1; @@ -74,7 +74,8 @@ fn closing_the_drawer_returns_the_focus_to_the_rails_edit_toolbar_button() { /// A tool already on the toolbar is dimmed and does not drag; a tool that is not on it drags to the rail. #[trial] fn only_a_tool_off_the_toolbar_drags() { - let entry = stories().into_iter().find(|entry| entry.story.name == "toolbar_drawer").expect("the drawer story"); + let registry = Registry::of(&[craft_ui::testing::register]); + let entry = registry.stories().iter().find(|entry| entry.story.name == "toolbar_drawer").expect("the drawer story"); let mut fixture = Fixture::story(&entry.story); fixture.settle(); let opener = fixture.by_label("Edit Toolbar").expect("the rail's Edit Toolbar button"); diff --git a/crates/ui-panels/tests/it/rails/mod.rs b/crates/ui-panels/tests/it/rails/mod.rs index 0ac0f8473..4c9ba1d0d 100644 --- a/crates/ui-panels/tests/it/rails/mod.rs +++ b/crates/ui-panels/tests/it/rails/mod.rs @@ -1,7 +1,7 @@ //! The rail's own logic: which tool a slot shows, what the rail remembers, where a drop goes, and the flyout's hold //! and click, and a press dragged away. -mod drawer; +pub(crate) mod drawer; use craft_ui::contract::{Role, Show as _}; use craft_ui::rails::{FlyoutButton, RailTool}; diff --git a/crates/ui-panels/tests/it/sections/mod.rs b/crates/ui-panels/tests/it/sections/mod.rs index 60c7053e2..25895f61f 100644 --- a/crates/ui-panels/tests/it/sections/mod.rs +++ b/crates/ui-panels/tests/it/sections/mod.rs @@ -1,8 +1,8 @@ //! Sections: captions, footers, panel headers and reorderable sections. -mod caption; -mod footer_keys; -mod footer_row; -mod layout; -mod panel_header; -mod reorderable; +pub(crate) mod caption; +pub(crate) mod footer_keys; +pub(crate) mod footer_row; +pub(crate) mod layout; +pub(crate) mod panel_header; +pub(crate) mod reorderable; diff --git a/crates/ui-patterns/Cargo.toml b/crates/ui-patterns/Cargo.toml index dc63a22b4..f55ef4892 100644 --- a/crates/ui-patterns/Cargo.toml +++ b/crates/ui-patterns/Cargo.toml @@ -15,6 +15,7 @@ test = false workspace = true [features] +suite = ["testing", "craft-ui-panels/suite"] default = [] # `craft_ui::testing`. testing = ["craft-ui-panels/testing"] @@ -40,10 +41,10 @@ craft-pdf = { path = "../pdf", version = "=0.1.0", default-features = false } zeroize = "1.9" [dev-dependencies] -craft-ui-patterns = { path = ".", features = ["testing"] } +craft-ui-patterns = { path = ".", features = ["suite"] } craft-behavior = { workspace = true } craft-theme = { workspace = true } -craft-ui-test-kit = { workspace = true } +craft-ui-test-kit = { workspace = true, features = ["suite"] } egui = { workspace = true } serde = { workspace = true } diff --git a/crates/ui-patterns/src/lib.rs b/crates/ui-patterns/src/lib.rs index 906d4b154..ca8b46907 100644 --- a/crates/ui-patterns/src/lib.rs +++ b/crates/ui-patterns/src/lib.rs @@ -11,10 +11,10 @@ extern crate self as craft_ui; #[doc(hidden)] pub use craft_ui_panels::canvas_data; #[cfg(feature = "testing")] +pub use craft_ui_panels::registry; +#[cfg(feature = "suite")] #[doc(hidden)] pub use craft_ui_panels::story_kit; -#[cfg(feature = "testing")] -pub use craft_ui_panels::testing_registered; #[doc(hidden)] pub use craft_ui_panels::{__private, __register_command_set, __register_contract, __register_pattern}; pub use craft_ui_panels::{InstallError, InstallSpec, contract, fonts, install, layout, primitives, runtime, style, words}; @@ -31,5 +31,6 @@ pub mod patterns; pub mod testing { pub use craft_ui_panels::testing::*; - crate::testing_registered!(); + #[cfg(feature = "suite")] + crate::registry!(); } diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 4401d77be..fbe9bf9be 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -35,8 +35,8 @@ use std::fmt::Debug; use std::hash::Hash; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// A layout the dock cannot show: the workspace failed `Workspace::validate`. The area draws nothing for it. #[derive(Clone, Debug, PartialEq)] diff --git a/crates/ui-patterns/src/patterns/dock/mod.rs b/crates/ui-patterns/src/patterns/dock/mod.rs index 4ccb311ec..42143c31a 100644 --- a/crates/ui-patterns/src/patterns/dock/mod.rs +++ b/crates/ui-patterns/src/patterns/dock/mod.rs @@ -2,12 +2,12 @@ mod words; -mod area; +pub(crate) mod area; mod hide; -mod switcher; -mod workspace_dialogs; +pub(crate) mod switcher; +pub(crate) mod workspace_dialogs; // Task panes: docked panes as shell panes, floating panes as floating frames. -mod panes; +pub(crate) mod panes; pub use area::{DockArea, DockAreaOutput, InvalidGeometry}; pub use panes::{ diff --git a/crates/ui-patterns/src/patterns/dock/panes.rs b/crates/ui-patterns/src/patterns/dock/panes.rs index 28a51f2d2..fc39e7e36 100644 --- a/crates/ui-patterns/src/patterns/dock/panes.rs +++ b/crates/ui-patterns/src/patterns/dock/panes.rs @@ -29,8 +29,8 @@ use std::cell::{Cell, RefCell}; use std::fmt::Debug; use std::hash::Hash; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// Where a pane is shown. #[derive(Clone, Copy, Debug, PartialEq, Eq)] diff --git a/crates/ui-patterns/src/patterns/dock/switcher.rs b/crates/ui-patterns/src/patterns/dock/switcher.rs index 7a8b94497..f6e067c7d 100644 --- a/crates/ui-patterns/src/patterns/dock/switcher.rs +++ b/crates/ui-patterns/src/patterns/dock/switcher.rs @@ -1,7 +1,7 @@ //! `WorkspaceSwitcher`: a select over the workspace set's names with the workspace commands in its list. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use crate::contract::{Bind, Entry, NoValue, Outcome, Props as _, Show as _, Sizing}; use crate::display::Divider; diff --git a/crates/ui-patterns/src/patterns/dock/workspace_dialogs.rs b/crates/ui-patterns/src/patterns/dock/workspace_dialogs.rs index f711d7e58..fdfa8862b 100644 --- a/crates/ui-patterns/src/patterns/dock/workspace_dialogs.rs +++ b/crates/ui-patterns/src/patterns/dock/workspace_dialogs.rs @@ -1,8 +1,8 @@ //! `NewWorkspaceDialog` and `DeleteWorkspaceDialog`: the questions `run_workspace` returns as `WorkspaceAsk::Name` //! and `WorkspaceAsk::Which`. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::words::WorkspaceDialogWords; use crate::choice::Checkbox; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/about.rs b/crates/ui-patterns/src/patterns/form_dialogs/about.rs index 69106cb61..01d82e842 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/about.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/about.rs @@ -3,8 +3,8 @@ mod contributors; mod credits; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use contributors::{CommitShare, ContributorSort, NameMode}; pub use credits::{AboutInfo, AboutLink, Contributor, Credits, ModelCredit}; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs index 771d8c053..92f838b93 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs @@ -38,8 +38,8 @@ use serde_json::Value; use std::borrow::Cow; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The words of the parameter dialog beside the common OK and Cancel. diff --git a/crates/ui-patterns/src/patterns/form_dialogs/export.rs b/crates/ui-patterns/src/patterns/form_dialogs/export.rs index e589aa5dd..8cb0d5fbd 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/export.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/export.rs @@ -4,12 +4,12 @@ //! //! [`export_file_name`] is the pure file-name rule the export dialogs share. -mod as_dialog; -mod options; -mod path_row; +pub(crate) mod as_dialog; +pub(crate) mod options; +pub(crate) mod path_row; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::PreviewRequest; use crate::contract::SaveKey; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/file_list.rs b/crates/ui-patterns/src/patterns/form_dialogs/file_list.rs index a09eb5b82..65b8a0221 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/file_list.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/file_list.rs @@ -20,8 +20,8 @@ use std::borrow::Cow; use std::cell::RefCell; use std::path::{Path, PathBuf}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The list shows this many rows, then scrolls. const LIST_ROWS: u16 = 6; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/form.rs b/crates/ui-patterns/src/patterns/form_dialogs/form.rs index 884cfe958..bacffc0e2 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/form.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/form.rs @@ -30,8 +30,8 @@ use std::ops::{Deref, DerefMut}; use std::rc::Rc; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The words a form dialog adds beside the common OK and Cancel. diff --git a/crates/ui-patterns/src/patterns/form_dialogs/guides.rs b/crates/ui-patterns/src/patterns/form_dialogs/guides.rs index de5c16e2c..75712a5fa 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/guides.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/guides.rs @@ -8,12 +8,12 @@ //! the same `canvas::Guide`s. mod layout; -mod new_guide; +pub(crate) mod new_guide; -#[cfg(feature = "testing")] -mod stories; -#[cfg(feature = "testing")] -mod trials; +#[cfg(feature = "suite")] +pub(crate) mod stories; +#[cfg(feature = "suite")] +pub(crate) mod trials; pub use layout::{GuideGroup, GuideLayoutError, GuideLayoutOptions, GuideLayoutPreset, GuideLength, GuideRect, GuideTarget, GuideUnits, MAX_COUNT}; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/list_manager.rs b/crates/ui-patterns/src/patterns/form_dialogs/list_manager.rs index a66b70d16..544fd954e 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/list_manager.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/list_manager.rs @@ -24,8 +24,8 @@ use std::sync::Arc; type UnderList<'a> = Box; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The standard words of the list manager; the app's own actions bring their labels. diff --git a/crates/ui-patterns/src/patterns/form_dialogs/mod.rs b/crates/ui-patterns/src/patterns/form_dialogs/mod.rs index 434bbe19b..ee7065327 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/mod.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/mod.rs @@ -4,18 +4,18 @@ mod words; mod fields; mod param; -mod rows; +pub(crate) mod rows; pub use fields::{DialogFields, FieldValue}; pub use param::{CustomContext, CustomRow, NumberUnit, Param, ParamKind, encode, open_fields, set_color_field}; pub use rows::{ParamRows, ParamRowsOutput}; pub use words::ParamWords; -mod dialog; -mod form; +pub(crate) mod dialog; +pub(crate) mod form; mod host_requests; -mod path_row; -mod preview; +pub(crate) mod path_row; +pub(crate) mod preview; pub use dialog::{ BelowRows, HostedParamDialog, ParamDialog, ParamDialogOutput, ParamDialogWords, ParamLayout, ParamResult, ResetFooter, ResetPick, set_param_field, @@ -31,26 +31,26 @@ mod size_model; pub use size_model::{LinkedSize, MAX_DOCUMENT_SIDE, SizeError, resize_from_scale, resize_from_side}; -mod list_manager; -mod password; -mod report; +pub(crate) mod list_manager; +pub(crate) mod password; +pub(crate) mod report; pub use list_manager::{ActionEnabled, ListManager, ListManagerAction, ListManagerChoice, ListManagerEntry, ListManagerOutput, ListManagerWords}; pub use password::{PasswordAnswer, PasswordDialog, PasswordOutput, PasswordPurpose, PasswordStrength, PasswordWords, Secret}; pub use report::{HostedReport, ReportDialog, ReportNote, ReportOutput, ReportWords}; -mod file_list; +pub(crate) mod file_list; pub use file_list::{FileList, FileListMode, FileListPicker, FileListPickerOutput, FileListWords}; -mod sizing; +pub(crate) mod sizing; pub use sizing::{ CanvasExtension, CanvasSize, CanvasSizeOutput, CanvasSizeResult, CanvasSizeValues, HostedCanvasSize, HostedImageSize, ImageSize, ImageSizeOutput, ImageSizeResult, ImageSizeValues, Resample, SizingOutput, SizingWords, }; -mod new_document; +pub(crate) mod new_document; pub use new_document::{ BACKGROUND_COLOR_KEY, BackgroundContents, BitDepth, ColorMode, ColorProfiles, DocumentOptions, DocumentPreset, HostedNewDocument, @@ -58,7 +58,7 @@ pub use new_document::{ SQUARE_PIXELS, }; -mod about; +pub(crate) mod about; pub use about::{ AboutAppTab, AboutDialog, AboutInfo, AboutLayout, AboutLink, AboutOutput, AboutTab, AboutWords, CommitShare, Contributor, ContributorSort, @@ -66,8 +66,8 @@ pub use about::{ }; mod color_choice; -mod guides; -mod properties; +pub(crate) mod guides; +pub(crate) mod properties; pub use guides::{ GUIDE_LAYOUT_COLOR_KEY, GuideDialogWords, GuideGroup, GuideLayoutDialog, GuideLayoutError, GuideLayoutOptions, GuideLayoutOutput, @@ -77,12 +77,12 @@ pub use guides::{ pub use properties::{HostedPropertiesDialog, PropertiesDialog, PropertiesOutput, PropertiesTab, PropertyRow}; // canvas-navigator-a -mod navigator_options; +pub(crate) mod navigator_options; pub use navigator_options::{NAVIGATOR_PROXY_COLOR_KEY, NavigatorOptionsDialog, NavigatorOptionsDialogOutput, NavigatorOptionsWords}; // End of canvas-navigator-a. -mod export; +pub(crate) mod export; pub use export::{ DdsCompression, DdsOptions, ExportAsDialog, ExportAsOutput, ExportAsResult, ExportFormat, ExportFormatDefaults, ExportMetadata, ExportOptions, @@ -92,12 +92,12 @@ pub use export::{ }; // Save PDF. -mod pdf_export; +pub(crate) mod pdf_export; pub use pdf_export::{PdfArtboards, PdfExportDialog, PdfExportOutput, PdfExportResult, PdfExportWords, PdfPresetEvent, PdfSection, RangeError}; -mod save_for_web; -mod watermark; +pub(crate) mod save_for_web; +pub(crate) mod watermark; pub use save_for_web::{ Animation, ColorTable, Dither, HostedSaveForWeb, MATTE_COLOR_KEY, PALETTE_COLOR_KEY, SAVE_PATH_KEY, SaveForWebDialog, SaveForWebOptions, diff --git a/crates/ui-patterns/src/patterns/form_dialogs/navigator_options.rs b/crates/ui-patterns/src/patterns/form_dialogs/navigator_options.rs index 2bd2b187e..0b3ed9294 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/navigator_options.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/navigator_options.rs @@ -14,8 +14,8 @@ use crate::runtime::env::{Env, Label}; use crate::runtime::overlay::CloseReason; use egui::{Response, Ui}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The [`ColorRequest::key`](crate::runtime::requests::ColorRequest::key) of Panel Options' Custom… colour. pub const NAVIGATOR_PROXY_COLOR_KEY: &str = "navigatorOptionsDialog.proxyColor"; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs index 042365588..b446014a5 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs @@ -4,8 +4,8 @@ mod cards; mod details; mod presets; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::form::{read_bind, write_bind}; use super::{FormCx, FormDialog, HostRequests, LinkedSize}; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/password.rs b/crates/ui-patterns/src/patterns/form_dialogs/password.rs index 022792674..cfe0f6f18 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/password.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/password.rs @@ -21,8 +21,8 @@ use std::any::Any; use std::cell::{Cell, RefCell}; use std::fmt; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The words of the password dialog beside the common Cancel. `{name}` is the file's name, `{strength}` one of diff --git a/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs b/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs index c5a1868f5..3e52afc4f 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/path_row.rs @@ -1,7 +1,7 @@ //! `PathRow`: a path typed in a text field, with a Browse button that asks the host to pick one. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use crate::buttons::Button; use crate::contract::{Bind, NoValue, Outcome, Props as _, Remember as _, Show as _, ShowContainer as _, Sizing, TooltipSpec, clicked}; 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 c669b4a87..7b00a3d9f 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/pdf_export.rs @@ -4,8 +4,8 @@ mod sections; mod summary; mod words; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use self::sections::{ArtboardChoice, PasswordSwitches, Sections}; pub use self::summary::RangeError; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/preview.rs b/crates/ui-patterns/src/patterns/form_dialogs/preview.rs index 84fda5c1e..aa9960727 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/preview.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/preview.rs @@ -21,8 +21,8 @@ use egui::load::SizedTexture; use egui::{Pos2, Rect, Response, Ui, Vec2, pos2}; use std::ops::RangeInclusive; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The well: a drag on it pans the picture and a click centres the view on the point clicked. const WELL: PartKey = PartKey::new("well"); diff --git a/crates/ui-patterns/src/patterns/form_dialogs/properties.rs b/crates/ui-patterns/src/patterns/form_dialogs/properties.rs index e4f5e105a..d3471211f 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/properties.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/properties.rs @@ -15,8 +15,8 @@ use egui::{Response, Ui}; use std::borrow::Cow; use std::cell::RefCell; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// One row of a properties tab. #[derive(Clone, Debug, PartialEq)] diff --git a/crates/ui-patterns/src/patterns/form_dialogs/report.rs b/crates/ui-patterns/src/patterns/form_dialogs/report.rs index 1ef83983f..4b34b174b 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/report.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/report.rs @@ -16,8 +16,8 @@ use craft_theme::variant::Tone; use egui::{Response, Ui}; use serde_json::{Value, json}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; craft_ui::words! { /// The words of the report dialog beside the common OK. diff --git a/crates/ui-patterns/src/patterns/form_dialogs/rows.rs b/crates/ui-patterns/src/patterns/form_dialogs/rows.rs index c74eb62e6..bc562b4a5 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/rows.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/rows.rs @@ -39,8 +39,8 @@ use std::ops::RangeInclusive; use std::path::PathBuf; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// Where a grid or point row's numbers go: whole numbers have no decimals. const WHOLE: u32 = 0; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/save_for_web.rs b/crates/ui-patterns/src/patterns/form_dialogs/save_for_web.rs index ece95e4e4..db0f482fc 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/save_for_web.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/save_for_web.rs @@ -36,8 +36,8 @@ use std::path::{Path, PathBuf}; mod options; mod panes; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use panes::WebPane; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/sizing.rs b/crates/ui-patterns/src/patterns/form_dialogs/sizing.rs index 31a0799e2..6de918a89 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/sizing.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/sizing.rs @@ -19,10 +19,10 @@ use egui::{Response, Ui}; use serde::{Deserialize, Serialize}; use std::sync::Arc; -mod canvas; -mod image; -#[cfg(feature = "testing")] -mod stories; +pub(crate) mod canvas; +pub(crate) mod image; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use canvas::{CanvasSize, CanvasSizeOutput, CanvasSizeResult, CanvasSizeValues, HostedCanvasSize}; pub use image::{HostedImageSize, ImageSize, ImageSizeOutput, ImageSizeResult, ImageSizeValues}; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/watermark.rs b/crates/ui-patterns/src/patterns/form_dialogs/watermark.rs index a75dbe1b5..ac4c58185 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/watermark.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/watermark.rs @@ -25,8 +25,8 @@ use serde::{Deserialize, Serialize}; use std::ops::RangeInclusive; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The key of the image request the Choose button files. pub const WATERMARK_IMAGE_KEY: &str = "watermark"; diff --git a/crates/ui-patterns/src/patterns/panels/history.rs b/crates/ui-patterns/src/patterns/panels/history.rs index 1028486df..2fa88b508 100644 --- a/crates/ui-patterns/src/patterns/panels/history.rs +++ b/crates/ui-patterns/src/patterns/panels/history.rs @@ -20,8 +20,8 @@ use std::cell::RefCell; use std::collections::HashSet; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The column of the source marks. const SOURCE: ColumnKey = ColumnKey::new("historySource"); diff --git a/crates/ui-patterns/src/patterns/panels/inspector.rs b/crates/ui-patterns/src/patterns/panels/inspector.rs index aae2c3fe0..d4ede9326 100644 --- a/crates/ui-patterns/src/patterns/panels/inspector.rs +++ b/crates/ui-patterns/src/patterns/panels/inspector.rs @@ -9,8 +9,8 @@ use crate::sections::{HeaderAction, HeaderStrength, MenuRows, Panel, PanelOutput use craft_theme::variant::Tone; use egui::{AsIdSalt, IdSalt, Ui}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// A properties panel: a `Panel` whose header names the target (icon and name, and the kind at the end), and whose body /// the caller fills with the target's controls, labelled as inspector rows (`LabelScheme::Inspector`). diff --git a/crates/ui-patterns/src/patterns/panels/mod.rs b/crates/ui-patterns/src/patterns/panels/mod.rs index 4500fd6c5..195de1a56 100644 --- a/crates/ui-patterns/src/patterns/panels/mod.rs +++ b/crates/ui-patterns/src/patterns/panels/mod.rs @@ -4,20 +4,20 @@ mod words; // Inspector. -mod inspector; +pub(crate) mod inspector; pub use inspector::Inspector; // History and modifier keys. -mod history; -mod modifier_keys; +pub(crate) mod history; +pub(crate) mod modifier_keys; pub use history::{HistoryEvent, HistoryFooter, HistoryKey, HistoryPanel, HistoryPanelOutput, HistoryRow}; pub use modifier_keys::ModifierKeysPanel; // CommandPalette and Tour. -mod palette; -mod tour; +pub(crate) mod palette; +pub(crate) mod tour; pub use palette::{CommandPalette, PaletteFace, PaletteOutput}; pub use tour::{Tour, TourEvent, TourOutput, TourStep}; diff --git a/crates/ui-patterns/src/patterns/panels/modifier_keys.rs b/crates/ui-patterns/src/patterns/panels/modifier_keys.rs index 96e951869..723fc25e3 100644 --- a/crates/ui-patterns/src/patterns/panels/modifier_keys.rs +++ b/crates/ui-patterns/src/patterns/panels/modifier_keys.rs @@ -9,8 +9,8 @@ use craft_keymap::{Mods, Platform}; use egui::{Response, Ui}; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The panel's buttons in their fixed order, each with the one modifier it latches: Shift, the command key (⌘ on /// macOS, Ctrl elsewhere) and Alt (⌥ on macOS). diff --git a/crates/ui-patterns/src/patterns/panels/palette.rs b/crates/ui-patterns/src/patterns/panels/palette.rs index 78928c32a..cc37a7a8a 100644 --- a/crates/ui-patterns/src/patterns/panels/palette.rs +++ b/crates/ui-patterns/src/patterns/panels/palette.rs @@ -25,8 +25,8 @@ use egui::{Id, Response, Ui}; use std::hash::{Hash, Hasher}; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The most commands the empty query lists when the app has run none. const FIRST_ROWS: usize = 12; diff --git a/crates/ui-patterns/src/patterns/panels/tour.rs b/crates/ui-patterns/src/patterns/panels/tour.rs index c782f4343..a1e0c608a 100644 --- a/crates/ui-patterns/src/patterns/panels/tour.rs +++ b/crates/ui-patterns/src/patterns/panels/tour.rs @@ -19,8 +19,8 @@ use craft_theme::variant::Variant; use egui::{Rect, Ui}; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The keys of a tour: Right goes to the next step and Left back (the keymap mirrors them in a right-to-left /// interface). They belong to the tour that holds the focus. diff --git a/crates/ui-patterns/src/patterns/preferences/mod.rs b/crates/ui-patterns/src/patterns/preferences/mod.rs index 748db8edb..85368ae41 100644 --- a/crates/ui-patterns/src/patterns/preferences/mod.rs +++ b/crates/ui-patterns/src/patterns/preferences/mod.rs @@ -27,10 +27,10 @@ pub use search::{Listed, list_pages, matches, row_matches, row_shown, shown_posi pub use words::{PreferencesWords, SettingsDocumentWords}; // The page, the window around it and their rows. -mod page; -mod path_setting; +pub(crate) mod page; +pub(crate) mod path_setting; mod rows; -mod window; +pub(crate) mod window; pub use page::{PreferencesPage, PreferencesPageOutput}; diff --git a/crates/ui-patterns/src/patterns/preferences/page.rs b/crates/ui-patterns/src/patterns/preferences/page.rs index 17583e54e..2417f4fb3 100644 --- a/crates/ui-patterns/src/patterns/preferences/page.rs +++ b/crates/ui-patterns/src/patterns/preferences/page.rs @@ -1,7 +1,7 @@ //! `PreferencesPage`: the preferences body without a window, applying each value at once. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::model::{PageSpec, PreferencesModel}; use super::rows::{RowsOut, ShownRow, reset_button, show_row}; diff --git a/crates/ui-patterns/src/patterns/preferences/path_setting.rs b/crates/ui-patterns/src/patterns/preferences/path_setting.rs index 495eb85f4..4e961a1eb 100644 --- a/crates/ui-patterns/src/patterns/preferences/path_setting.rs +++ b/crates/ui-patterns/src/patterns/preferences/path_setting.rs @@ -1,7 +1,7 @@ //! `PathSetting`: a path setting of Preferences, typed or picked through the host's file service, kept in the draft. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::SettingsDraft; use crate::contract::{Bind, NoValue, Outcome, Props as _, ShowContainer as _}; diff --git a/crates/ui-patterns/src/patterns/preferences/window.rs b/crates/ui-patterns/src/patterns/preferences/window.rs index c056738dc..37293b375 100644 --- a/crates/ui-patterns/src/patterns/preferences/window.rs +++ b/crates/ui-patterns/src/patterns/preferences/window.rs @@ -1,8 +1,8 @@ //! `PreferencesWindow`: the preferences body in an app-modal `Dialog` that opens in its own OS window where windows //! exist. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; #[cfg(doc)] use super::model::PreferencesModel; diff --git a/crates/ui-patterns/src/patterns/presets/browser.rs b/crates/ui-patterns/src/patterns/presets/browser.rs index b8478dd70..c01396567 100644 --- a/crates/ui-patterns/src/patterns/presets/browser.rs +++ b/crates/ui-patterns/src/patterns/presets/browser.rs @@ -7,8 +7,8 @@ //! presets as rows of the same collection in both views: the grid's tail rows, the list's last rows. mod reorder; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use reorder::PresetReorder; diff --git a/crates/ui-patterns/src/patterns/presets/footer.rs b/crates/ui-patterns/src/patterns/presets/footer.rs index 219eabf4f..d5c4c946f 100644 --- a/crates/ui-patterns/src/patterns/presets/footer.rs +++ b/crates/ui-patterns/src/patterns/presets/footer.rs @@ -11,8 +11,8 @@ use egui::{Response, Ui}; use std::marker::PhantomData; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// What a [`PresetFooter`] reports. A browser's footer reports these as `PresetEvent::Footer`, in order with its /// other events. diff --git a/crates/ui-patterns/src/patterns/presets/manager.rs b/crates/ui-patterns/src/patterns/presets/manager.rs index ff588d268..002936293 100644 --- a/crates/ui-patterns/src/patterns/presets/manager.rs +++ b/crates/ui-patterns/src/patterns/presets/manager.rs @@ -1,8 +1,8 @@ //! `PresetManager`: a dialog body for managing the presets of several kinds: a kind select over the presets of that //! kind, with rename and delete, and the host's own action buttons. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::browser::PresetBrowser; use super::event::PresetEvent; diff --git a/crates/ui-patterns/src/patterns/presets/mod.rs b/crates/ui-patterns/src/patterns/presets/mod.rs index 3b480623e..3747307cc 100644 --- a/crates/ui-patterns/src/patterns/presets/mod.rs +++ b/crates/ui-patterns/src/patterns/presets/mod.rs @@ -4,20 +4,20 @@ mod words; // The browser. -mod browser; +pub(crate) mod browser; // Preset data, footer, files and panel menu. mod event; mod files; -mod footer; +pub(crate) mod footer; mod model; mod panel_menu; mod state; // The picker and the named row. -mod manager; -mod named; -mod picker; +pub(crate) mod manager; +pub(crate) mod named; +pub(crate) mod picker; pub use browser::{BrowserTools, PresetBrowser, PresetItemCommands, PresetReorder, ThumbPainter}; pub use event::{PresetEvent, PresetOutput}; diff --git a/crates/ui-patterns/src/patterns/presets/named.rs b/crates/ui-patterns/src/patterns/presets/named.rs index 559d0a743..b12134e0e 100644 --- a/crates/ui-patterns/src/patterns/presets/named.rs +++ b/crates/ui-patterns/src/patterns/presets/named.rs @@ -5,8 +5,8 @@ //! commits the name, Escape or Cancel closes it, and a name the host refuses shows its message under the field and //! keeps the prompt open. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::event::PresetEvent; use super::files::{PresetFileRequest, PresetFiles}; diff --git a/crates/ui-patterns/src/patterns/presets/picker.rs b/crates/ui-patterns/src/patterns/presets/picker.rs index 7aefb3eab..f210f3178 100644 --- a/crates/ui-patterns/src/patterns/presets/picker.rs +++ b/crates/ui-patterns/src/patterns/presets/picker.rs @@ -5,8 +5,8 @@ //! (`keep_open`), give the browser a footer, set how far the thumbnails zoom, open the popover at a point without the //! field (`open_at`) and let the user resize it (`resizable`). -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use std::sync::Arc; diff --git a/crates/ui-patterns/tests/it/docking/mod.rs b/crates/ui-patterns/tests/it/docking/mod.rs index cbdcbb917..d95e562d5 100644 --- a/crates/ui-patterns/tests/it/docking/mod.rs +++ b/crates/ui-patterns/tests/it/docking/mod.rs @@ -4,28 +4,28 @@ use craft_theme::{Contrast, ControlSize, Mode, Variant}; use craft_ui::docking::DockSizes; use craft_ui::testing::style::{tokens, with_cx}; -mod render; +pub(crate) mod render; -mod panel_menu; -mod runs; +pub(crate) mod panel_menu; +pub(crate) mod runs; -mod split; +pub(crate) mod split; -mod drop; -mod drop_preview; -mod drop_session; +pub(crate) mod drop; +pub(crate) mod drop_preview; +pub(crate) mod drop_session; -mod floating; -mod floating_area; -mod hidden; +pub(crate) mod floating; +pub(crate) mod floating_area; +pub(crate) mod hidden; -mod columns; -mod dock_back; -mod group_view; -mod workspace_dialogs; +pub(crate) mod columns; +pub(crate) mod dock_back; +pub(crate) mod group_view; +pub(crate) mod workspace_dialogs; -mod native; -mod panes; +pub(crate) mod native; +pub(crate) mod panes; /// The docking sizes of the default theme with the given divider gap, least pane and strip height. fn sizes(gap: f32, least_pane: f32, strip: f32) -> DockSizes { diff --git a/crates/ui-patterns/tests/it/form_dialogs/mod.rs b/crates/ui-patterns/tests/it/form_dialogs/mod.rs index 49c402eb0..8e2637acc 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/mod.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/mod.rs @@ -1,19 +1,19 @@ //! The form dialogs' own logic: the parameter model, its spec-string parser, the value store, the size model, //! guide layout and the export file name. -mod about; -mod dialog; -mod export; -mod files; -mod hosted; -mod image_unit_order; -mod list_manager; -mod new_document; -mod new_document_orientation; -mod params; -mod password; -mod picker; -mod preview; -mod preview_width; -mod save_for_web; -mod size_model; +pub(crate) mod about; +pub(crate) mod dialog; +pub(crate) mod export; +pub(crate) mod files; +pub(crate) mod hosted; +pub(crate) mod image_unit_order; +pub(crate) mod list_manager; +pub(crate) mod new_document; +pub(crate) mod new_document_orientation; +pub(crate) mod params; +pub(crate) mod password; +pub(crate) mod picker; +pub(crate) mod preview; +pub(crate) mod preview_width; +pub(crate) mod save_for_web; +pub(crate) mod size_model; diff --git a/crates/ui-patterns/tests/it/main.rs b/crates/ui-patterns/tests/it/main.rs index 49919e6b6..a908cb179 100644 --- a/crates/ui-patterns/tests/it/main.rs +++ b/crates/ui-patterns/tests/it/main.rs @@ -3,18 +3,22 @@ // The test files name the library as `craft_ui`, as the crates that use it do. extern crate craft_ui_patterns as craft_ui; -mod blend_keys; -mod docking; -mod form_dialogs; +pub(crate) mod blend_keys; +pub(crate) mod docking; +pub(crate) mod form_dialogs; // Panels family. -mod panels; +pub(crate) mod panels; -mod preferences; -mod presets; +pub(crate) mod preferences; +pub(crate) mod presets; -use craft_ui::testing::registered; +craft_ui::registry!(); fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), ®istered()); + craft_ui::testing::run( + module_path!(), + env!("CARGO_PKG_NAME"), + &craft_ui::testing::Registry::of(&[register, craft_ui::testing::register, craft_ui_test_kit::testing::register]), + ); } diff --git a/crates/ui-patterns/tests/it/panels/mod.rs b/crates/ui-patterns/tests/it/panels/mod.rs index cad91f130..a02a16147 100644 --- a/crates/ui-patterns/tests/it/panels/mod.rs +++ b/crates/ui-patterns/tests/it/panels/mod.rs @@ -1,9 +1,9 @@ //! The rules of the panels family: an inspector keys its controls by the target and shows the empty notice for no //! target. -mod history; -mod palette; -mod tour; +pub(crate) mod history; +pub(crate) mod palette; +pub(crate) mod tour; use craft_ui::choice::Checkbox; use craft_ui::contract::{Bind, Props as _, Show as _}; diff --git a/crates/ui-patterns/tests/it/panels/palette.rs b/crates/ui-patterns/tests/it/panels/palette.rs index 1e3f38a41..601302353 100644 --- a/crates/ui-patterns/tests/it/panels/palette.rs +++ b/crates/ui-patterns/tests/it/panels/palette.rs @@ -9,7 +9,7 @@ use craft_ui::popover::Popover; use craft_ui::runtime::commands::{CommandRef, CommandState, EditCommands, FireSource}; use craft_ui::runtime::env::{Label, WordTemplate}; use craft_ui::runtime::frame::take_output; -use craft_ui::testing::{Fixture, stories, trial}; +use craft_ui::testing::{Fixture, Registry, trial}; use egui::{Key, Modifiers, Pos2, Ui}; use std::cell::{Cell, RefCell}; use std::rc::Rc; @@ -100,7 +100,8 @@ fn a_picked_command_runs_from_the_palette_and_comes_first_when_it_opens_again() /// lists enabled. #[trial] fn the_palette_story_runs_under_its_command_states() { - let entry = stories().into_iter().find(|entry| entry.story.name == "command_palette").expect("the palette story"); + let registry = Registry::of(&[craft_ui::testing::register]); + let entry = registry.stories().iter().find(|entry| entry.story.name == "command_palette").expect("the palette story"); let mut fixture = Fixture::story(&entry.story); fixture.settle(); assert!(disabled(&fixture, "Redo"), "the story's Redo lists disabled"); diff --git a/crates/ui-patterns/tests/it/preferences/mod.rs b/crates/ui-patterns/tests/it/preferences/mod.rs index 5b4f37ab4..6e660ec11 100644 --- a/crates/ui-patterns/tests/it/preferences/mod.rs +++ b/crates/ui-patterns/tests/it/preferences/mod.rs @@ -1,6 +1,6 @@ //! The data and rules of the preferences family: the search over the row model and the settings document, the //! window's answers and the hex codec. -mod model; -mod page; -mod path_setting; +pub(crate) mod model; +pub(crate) mod page; +pub(crate) mod path_setting; diff --git a/crates/ui-patterns/tests/it/presets/mod.rs b/crates/ui-patterns/tests/it/presets/mod.rs index 25a1c8158..33bf20d0d 100644 --- a/crates/ui-patterns/tests/it/presets/mod.rs +++ b/crates/ui-patterns/tests/it/presets/mod.rs @@ -1,6 +1,6 @@ //! The data and rules of the presets family. -mod browser; -mod model; -mod named; -mod picker; +pub(crate) mod browser; +pub(crate) mod model; +pub(crate) mod named; +pub(crate) mod picker; diff --git a/crates/ui-shell/Cargo.toml b/crates/ui-shell/Cargo.toml index d55e80fcb..cef43c27e 100644 --- a/crates/ui-shell/Cargo.toml +++ b/crates/ui-shell/Cargo.toml @@ -15,6 +15,7 @@ test = false workspace = true [features] +suite = ["testing", "craft-ui-panels/suite"] default = [] # `shell::app`: the eframe entry point. app = ["dep:eframe", "craft-window/ui"] @@ -45,11 +46,11 @@ web-time = "1.1" craft-window = { workspace = true, features = ["appkit"] } [dev-dependencies] -craft-ui-shell = { path = ".", features = ["testing"] } +craft-ui-shell = { path = ".", features = ["suite"] } craft-behavior = { workspace = true } craft-host = { workspace = true } craft-theme = { workspace = true } -craft-ui-test-kit = { workspace = true } +craft-ui-test-kit = { workspace = true, features = ["suite"] } craft-window = { workspace = true } egui = { workspace = true } diff --git a/crates/ui-shell/src/lib.rs b/crates/ui-shell/src/lib.rs index c6db34059..dc3c89f5e 100644 --- a/crates/ui-shell/src/lib.rs +++ b/crates/ui-shell/src/lib.rs @@ -11,10 +11,10 @@ extern crate self as craft_ui; #[doc(hidden)] pub use craft_ui_panels::canvas_data; #[cfg(feature = "testing")] +pub use craft_ui_panels::registry; +#[cfg(feature = "suite")] #[doc(hidden)] pub use craft_ui_panels::story_kit; -#[cfg(feature = "testing")] -pub use craft_ui_panels::testing_registered; #[doc(hidden)] pub use craft_ui_panels::{__private, __register_command_set, __register_contract, __register_pattern}; pub use craft_ui_panels::{InstallError, InstallSpec, contract, fonts, install, layout, primitives, runtime, style, words}; @@ -31,5 +31,6 @@ pub mod shell; pub mod testing { pub use craft_ui_panels::testing::*; - crate::testing_registered!(); + #[cfg(feature = "suite")] + crate::registry!(); } diff --git a/crates/ui-shell/src/shell/app_shell.rs b/crates/ui-shell/src/shell/app_shell.rs index ec05a8c8c..12105351e 100644 --- a/crates/ui-shell/src/shell/app_shell.rs +++ b/crates/ui-shell/src/shell/app_shell.rs @@ -3,8 +3,8 @@ //! name of each region come from the pipeline. mod dialogs; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use self::dialogs::{ShellDialogsCx, WindowDialogs}; use super::canvas_shell::slots as keys; diff --git a/crates/ui-shell/src/shell/canvas_shell.rs b/crates/ui-shell/src/shell/canvas_shell.rs index 5167630fc..b8427a4f9 100644 --- a/crates/ui-shell/src/shell/canvas_shell.rs +++ b/crates/ui-shell/src/shell/canvas_shell.rs @@ -18,8 +18,8 @@ //! +----------------------+ //! ``` -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::app_shell::{RegionBody, ShellRegion}; use super::words::ShellWords; diff --git a/crates/ui-shell/src/shell/caption_button.rs b/crates/ui-shell/src/shell/caption_button.rs index ed1a6b6a7..fd7fac19c 100644 --- a/crates/ui-shell/src/shell/caption_button.rs +++ b/crates/ui-shell/src/shell/caption_button.rs @@ -16,8 +16,8 @@ use egui::emath::GuiRounding as _; use egui::{Color32, ColorImage, CornerRadius, Painter, Pos2, Rect, Response, Stroke, StrokeKind, Vec2, pos2, vec2}; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The button's one part: the whole slot. const BUTTON: PartKey = PartKey::new("button"); diff --git a/crates/ui-shell/src/shell/document_window.rs b/crates/ui-shell/src/shell/document_window.rs index 7425692b0..1bc55a73d 100644 --- a/crates/ui-shell/src/shell/document_window.rs +++ b/crates/ui-shell/src/shell/document_window.rs @@ -1,7 +1,7 @@ //! `DocumentWindow`: a document's window, a container in its own OS viewport. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use crate::contract::overlay::OverlayFit; use crate::contract::{ diff --git a/crates/ui-shell/src/shell/mod.rs b/crates/ui-shell/src/shell/mod.rs index bfc8db891..d8e173dcb 100644 --- a/crates/ui-shell/src/shell/mod.rs +++ b/crates/ui-shell/src/shell/mod.rs @@ -17,12 +17,12 @@ mod regions; pub use regions::{Slot, SlotSize}; // App shell, canvas panel, screen modes and reveal. -mod app_shell; -mod canvas_shell; -mod opening; +pub(crate) mod app_shell; +pub(crate) mod canvas_shell; +pub(crate) mod opening; mod reveal; mod screen_mode; -mod screen_mode_button; +pub(crate) mod screen_mode_button; pub use app_shell::{AppShell, AppShellOutput, ShellDialogsCx, ShellRegion, ShellRegionOutput, WindowDialogs}; pub use canvas_shell::{CanvasPanel, CanvasPanelOutput, slots}; @@ -33,9 +33,9 @@ pub use words::ShellWords; // Start screen and app windows. mod recent; -mod recent_list; -mod start; -mod viewport_window; +pub(crate) mod recent_list; +pub(crate) mod start; +pub(crate) mod viewport_window; pub use recent::{RecentFile, RecentSort, RecentView, Template, ThumbKey, sort_recent}; pub use recent_list::RecentList; @@ -43,7 +43,7 @@ pub use start::{StartAction, StartLayout, StartLink, StartLinkTarget, StartOutpu pub use viewport_window::{ViewportWindow, ViewportWindowOutput}; // Caption buttons: the four families' button, its slot layout and the icon-theme glyphs. -mod caption_button; +pub(crate) mod caption_button; mod caption_icons; pub use caption_button::{CaptionButton, CaptionEnd, CaptionPlan, CaptionSlot}; @@ -51,7 +51,7 @@ pub use caption_icons::{CaptionIcon, CaptionIcons, CaptionMask, RenderIconFn}; pub use craft_window::policy::{CaptionFamily, Captions, Frame, MacInset}; // A document's window: a container in its own OS viewport. -mod document_window; +pub(crate) mod document_window; pub use document_window::{DocumentWindow, DocumentWindowOutput, DocumentWindowStyle, Wrapped}; diff --git a/crates/ui-shell/src/shell/opening.rs b/crates/ui-shell/src/shell/opening.rs index d82b31ad3..9764e90e0 100644 --- a/crates/ui-shell/src/shell/opening.rs +++ b/crates/ui-shell/src/shell/opening.rs @@ -10,8 +10,8 @@ use crate::runtime::env::{Env, Label}; use crate::style::{SurfaceKind, TypeRole}; use egui::{Layout, Response, Ui, UiBuilder}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// A centred card: "Opening {name}…" elided on one line with the full text on hover, the muted message, a progress bar /// (indeterminate without a fraction), the percentage at the start and Cancel at the end of the last row. Job UI diff --git a/crates/ui-shell/src/shell/screen_mode_button.rs b/crates/ui-shell/src/shell/screen_mode_button.rs index bde44b5f5..4d1c3ca71 100644 --- a/crates/ui-shell/src/shell/screen_mode_button.rs +++ b/crates/ui-shell/src/shell/screen_mode_button.rs @@ -7,8 +7,8 @@ use crate::rails::{FlyoutButton, RailTool}; use crate::runtime::env::Env; use egui::{Response, Ui}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// A flyout button over the screen modes of the shell's set, with `mode` marked: a click, Enter or Space cycles; a /// hold, a drag away or a right click lists the modes without cycling. The face is the Cycle command's icon and tooltip; disabled diff --git a/crates/ui-shell/src/shell/start.rs b/crates/ui-shell/src/shell/start.rs index fedb69d5f..54e57cfa5 100644 --- a/crates/ui-shell/src/shell/start.rs +++ b/crates/ui-shell/src/shell/start.rs @@ -1,8 +1,8 @@ //! `StartScreen`: the page an app shows with no document open: New and Open, the recent files as a grid or a list, //! pinned folders and templates. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::recent::{RecentFile, RecentSort, RecentView, Template, ThumbKey, sort_recent}; use super::recent_list::{RecentList, recent_body}; diff --git a/crates/ui-shell/src/shell/title_bar.rs b/crates/ui-shell/src/shell/title_bar.rs index b688f25ea..9a58954a9 100644 --- a/crates/ui-shell/src/shell/title_bar.rs +++ b/crates/ui-shell/src/shell/title_bar.rs @@ -21,9 +21,9 @@ pub fn set_window_movable(ctx: &Context, movable: bool) { } // The bar, its title and its two ends. -mod bar; +pub(crate) mod bar; mod measure; -mod page_band; +pub(crate) mod page_band; mod style; mod title; diff --git a/crates/ui-shell/src/shell/title_bar/bar.rs b/crates/ui-shell/src/shell/title_bar/bar.rs index bba60521e..fdd75f67b 100644 --- a/crates/ui-shell/src/shell/title_bar/bar.rs +++ b/crates/ui-shell/src/shell/title_bar/bar.rs @@ -1,7 +1,7 @@ //! `TitleBar`: the app-drawn bar of a window, in the title slot of an `AppShell`. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::measure::{End, Ends, Strip}; use super::style::TitleBarStyle; diff --git a/crates/ui-shell/src/shell/title_bar/page_band.rs b/crates/ui-shell/src/shell/title_bar/page_band.rs index 712baec85..5f4865720 100644 --- a/crates/ui-shell/src/shell/title_bar/page_band.rs +++ b/crates/ui-shell/src/shell/title_bar/page_band.rs @@ -1,7 +1,7 @@ //! `PageBand`: the move band the shell's page shows over the window. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::bar::{Window, act_on_double_click, show_end, window, window_acting}; use super::measure::End; diff --git a/crates/ui-shell/src/shell/viewport_window.rs b/crates/ui-shell/src/shell/viewport_window.rs index 90e8ad5a9..c465c40fe 100644 --- a/crates/ui-shell/src/shell/viewport_window.rs +++ b/crates/ui-shell/src/shell/viewport_window.rs @@ -1,7 +1,7 @@ //! `ViewportWindow`: an app window in its own OS window where windows exist, else a dialog layer over the parent. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use crate::contract::{Bind, BodyCx, NoValue, Outcome, Overlay, Pattern, Props, SaveKey, ShowContainer as _}; use crate::dialog::Dialog; diff --git a/crates/ui-shell/tests/it/body/mod.rs b/crates/ui-shell/tests/it/body/mod.rs index 3f74b2b38..1a957836f 100644 --- a/crates/ui-shell/tests/it/body/mod.rs +++ b/crates/ui-shell/tests/it/body/mod.rs @@ -1,3 +1,3 @@ //! The body step and the mount host: regions, scrolling, move and resize, and viewport mounts. -mod regions; +pub(crate) mod regions; diff --git a/crates/ui-shell/tests/it/commands/mod.rs b/crates/ui-shell/tests/it/commands/mod.rs index 0df0ca31e..50a35dd00 100644 --- a/crates/ui-shell/tests/it/commands/mod.rs +++ b/crates/ui-shell/tests/it/commands/mod.rs @@ -1,7 +1,7 @@ //! The command board: registry, state, the gate, firing and scoped delivery. -mod app_catalog; -mod app_scope; -mod board; -mod kit; -mod resolve; +pub(crate) mod app_catalog; +pub(crate) mod app_scope; +pub(crate) mod board; +pub(crate) mod kit; +pub(crate) mod resolve; diff --git a/crates/ui-shell/tests/it/contract/mod.rs b/crates/ui-shell/tests/it/contract/mod.rs index d40a6a201..a398c82b2 100644 --- a/crates/ui-shell/tests/it/contract/mod.rs +++ b/crates/ui-shell/tests/it/contract/mod.rs @@ -1,3 +1,3 @@ //! The component contract and the show pipeline: the steps each shape runs, and the rules the steps keep. -mod os_window; +pub(crate) mod os_window; diff --git a/crates/ui-shell/tests/it/dialog/mod.rs b/crates/ui-shell/tests/it/dialog/mod.rs index 7f4659df3..df5eeb736 100644 --- a/crates/ui-shell/tests/it/dialog/mod.rs +++ b/crates/ui-shell/tests/it/dialog/mod.rs @@ -1,4 +1,4 @@ //! Dialogs embedded in a region. -mod contained; -mod window; +pub(crate) mod contained; +pub(crate) mod window; diff --git a/crates/ui-shell/tests/it/main.rs b/crates/ui-shell/tests/it/main.rs index 580eb26e0..041a34efe 100644 --- a/crates/ui-shell/tests/it/main.rs +++ b/crates/ui-shell/tests/it/main.rs @@ -4,16 +4,20 @@ extern crate craft_ui_shell as craft_ui; pub(crate) mod body; -mod commands; -mod contract; -mod dialog; -mod measure; -mod notices; +pub(crate) mod commands; +pub(crate) mod contract; +pub(crate) mod dialog; +pub(crate) mod measure; +pub(crate) mod notices; -mod shell; +pub(crate) mod shell; -use craft_ui::testing::registered; +craft_ui::registry!(); fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), ®istered()); + craft_ui::testing::run( + module_path!(), + env!("CARGO_PKG_NAME"), + &craft_ui::testing::Registry::of(&[register, craft_ui::testing::register, craft_ui_test_kit::testing::register]), + ); } diff --git a/crates/ui-shell/tests/it/measure/mod.rs b/crates/ui-shell/tests/it/measure/mod.rs index 5817c5814..259a6a210 100644 --- a/crates/ui-shell/tests/it/measure/mod.rs +++ b/crates/ui-shell/tests/it/measure/mod.rs @@ -1,6 +1,6 @@ //! A measuring run delivers nothing and consumes nothing: what the real run after it needs is still there. -mod record; +pub(crate) mod record; use craft_ui::contract::{Bind, Politeness, Show as _}; use craft_ui::runtime::commands::{FireSource, fire}; diff --git a/crates/ui-shell/tests/it/shell/mod.rs b/crates/ui-shell/tests/it/shell/mod.rs index 77b127448..86e73aa6d 100644 --- a/crates/ui-shell/tests/it/shell/mod.rs +++ b/crates/ui-shell/tests/it/shell/mod.rs @@ -1,14 +1,14 @@ //! The window skeleton's interface: what `ShellCx` answers by mode and reveal, and how a body reads it. -mod app_shell; -mod canvas_panel; -mod caption_button; -mod document_window; -mod embed; -mod f6; -mod opening; -mod reveal; -mod screen_mode; -mod start; -mod title_bar; -mod window_parts; +pub(crate) mod app_shell; +pub(crate) mod canvas_panel; +pub(crate) mod caption_button; +pub(crate) mod document_window; +pub(crate) mod embed; +pub(crate) mod f6; +pub(crate) mod opening; +pub(crate) mod reveal; +pub(crate) mod screen_mode; +pub(crate) mod start; +pub(crate) mod title_bar; +pub(crate) mod window_parts; diff --git a/crates/ui-test-kit/Cargo.toml b/crates/ui-test-kit/Cargo.toml index 7b3673484..1e003a89b 100644 --- a/crates/ui-test-kit/Cargo.toml +++ b/crates/ui-test-kit/Cargo.toml @@ -15,6 +15,9 @@ workspace = true test = false doctest = false +[features] +suite = ["craft-ui-contract/suite"] + [dependencies] craft-ui-contract = { workspace = true, features = ["testing"] } egui = { workspace = true } diff --git a/crates/ui-test-kit/src/lib.rs b/crates/ui-test-kit/src/lib.rs index bde456318..12006a6f3 100644 --- a/crates/ui-test-kit/src/lib.rs +++ b/crates/ui-test-kit/src/lib.rs @@ -8,3 +8,9 @@ extern crate craft_ui_contract as craft_ui; pub mod body; pub mod contract; pub mod windows; + +/// Registrations of the shared test components. +#[cfg(feature = "suite")] +pub mod testing { + craft_ui::registry!(); +} diff --git a/crates/ui-widgets/Cargo.toml b/crates/ui-widgets/Cargo.toml index 1be428234..9afe30081 100644 --- a/crates/ui-widgets/Cargo.toml +++ b/crates/ui-widgets/Cargo.toml @@ -15,6 +15,7 @@ test = false workspace = true [features] +suite = ["testing", "craft-ui-contract/suite"] default = [] # `craft_ui::testing` with the story helpers that show components. testing = ["craft-ui-contract/testing"] @@ -32,13 +33,13 @@ smallvec = { workspace = true } serde = { workspace = true } [dev-dependencies] -craft-ui-widgets = { path = ".", features = ["testing"] } +craft-ui-widgets = { path = ".", features = ["suite"] } craft-behavior = { workspace = true } craft-host = { workspace = true } craft-i18n = { workspace = true, features = ["collate"] } craft-keymap = { workspace = true, features = ["egui"] } craft-theme = { workspace = true } -craft-ui-test-kit = { workspace = true } +craft-ui-test-kit = { workspace = true, features = ["suite"] } egui = { workspace = true } [[test]] diff --git a/crates/ui-widgets/src/bars/align.rs b/crates/ui-widgets/src/bars/align.rs index 8f915e9eb..d2f4b4ba9 100644 --- a/crates/ui-widgets/src/bars/align.rs +++ b/crates/ui-widgets/src/bars/align.rs @@ -10,8 +10,8 @@ use crate::style::GlyphRole; use craft_behavior::fit::FitKeep; use egui::{Response, Ui}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// One align or distribute command. The commands are app commands: the app gates them with command state and takes /// them when they run, from a button, the menu or a chord. diff --git a/crates/ui-widgets/src/bars/breadcrumb.rs b/crates/ui-widgets/src/bars/breadcrumb.rs index 6e993e622..cdc6323c1 100644 --- a/crates/ui-widgets/src/bars/breadcrumb.rs +++ b/crates/ui-widgets/src/bars/breadcrumb.rs @@ -17,8 +17,8 @@ use craft_behavior::fit::{FitItem, FitKeep, fit_items}; use craft_behavior::{Axis, CursorIcon, Flow, IconId, Metrics, NavShape, PartKey, PartRef, Roving, Sense, Value}; use egui::{Rect, Response, Vec2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; const HIDDEN: PartKey = PartKey::new("hidden"); const CRUMB: PartKey = PartKey::new("crumb"); diff --git a/crates/ui-widgets/src/bars/constraint_fields.rs b/crates/ui-widgets/src/bars/constraint_fields.rs index c0dffc57e..ce3bbd166 100644 --- a/crates/ui-widgets/src/bars/constraint_fields.rs +++ b/crates/ui-widgets/src/bars/constraint_fields.rs @@ -16,8 +16,8 @@ use egui::{Response, Ui}; use std::ops::RangeInclusive; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The three kinds of [`Constraint`], as the Style select lists them. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] diff --git a/crates/ui-widgets/src/bars/mod.rs b/crates/ui-widgets/src/bars/mod.rs index c9dc5bb6e..f7ab811e6 100644 --- a/crates/ui-widgets/src/bars/mod.rs +++ b/crates/ui-widgets/src/bars/mod.rs @@ -1,15 +1,15 @@ //! `Bar` and `BarItems`: the bar container and its strip of command items, and the members of a status bar. -mod align; -mod bar; -mod breadcrumb; -mod constraint_fields; -mod items; -mod lead; -mod status; -mod status_readout; -#[cfg(feature = "testing")] -mod stories; +pub(crate) mod align; +pub(crate) mod bar; +pub(crate) mod breadcrumb; +pub(crate) mod constraint_fields; +pub(crate) mod items; +pub(crate) mod lead; +pub(crate) mod status; +pub(crate) mod status_readout; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod words; pub use align::{AlignAction, AlignBar, AlignBarOutput}; diff --git a/crates/ui-widgets/src/bars/status_readout.rs b/crates/ui-widgets/src/bars/status_readout.rs index 2c631e7ef..8cd78bbff 100644 --- a/crates/ui-widgets/src/bars/status_readout.rs +++ b/crates/ui-widgets/src/bars/status_readout.rs @@ -15,8 +15,8 @@ use craft_behavior::{CanvasView, EditEvents, IconId, Mixed, PixelSize}; use egui::{Response, Ui}; use std::time::Duration; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// Shown for an item whose value the host does not know. const MISSING: &str = "\u{2014}"; diff --git a/crates/ui-widgets/src/buttons/mod.rs b/crates/ui-widgets/src/buttons/mod.rs index 344551be0..7f4c81570 100644 --- a/crates/ui-widgets/src/buttons/mod.rs +++ b/crates/ui-widgets/src/buttons/mod.rs @@ -5,8 +5,8 @@ pub(crate) mod face; pub mod icon_button; pub mod link; pub mod split_button; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub mod toggle_button; mod words; diff --git a/crates/ui-widgets/src/choice/check.rs b/crates/ui-widgets/src/choice/check.rs index be9bec8f0..d2d0ef9b6 100644 --- a/crates/ui-widgets/src/choice/check.rs +++ b/crates/ui-widgets/src/choice/check.rs @@ -93,5 +93,5 @@ impl Component for Checkbox<'_> { } } -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; diff --git a/crates/ui-widgets/src/choice/mod.rs b/crates/ui-widgets/src/choice/mod.rs index 517520e01..a40b8c04a 100644 --- a/crates/ui-widgets/src/choice/mod.rs +++ b/crates/ui-widgets/src/choice/mod.rs @@ -2,13 +2,13 @@ pub mod check; pub mod radio; -mod rating; -mod segmented; -mod switch; +pub(crate) mod rating; +pub(crate) mod segmented; +pub(crate) mod switch; mod words; -mod swatch; -mod swatch_table; +pub(crate) mod swatch; +pub(crate) mod swatch_table; pub use check::{Checkbox, CheckboxStyle}; pub use radio::{GroupStyle, Radio, RadioGroup, RadioKind, RadioStyle}; diff --git a/crates/ui-widgets/src/choice/radio.rs b/crates/ui-widgets/src/choice/radio.rs index 0b9af26ae..a39f7cd7f 100644 --- a/crates/ui-widgets/src/choice/radio.rs +++ b/crates/ui-widgets/src/choice/radio.rs @@ -223,5 +223,5 @@ impl Component for Radio { } } -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; diff --git a/crates/ui-widgets/src/choice/rating.rs b/crates/ui-widgets/src/choice/rating.rs index 77202885e..8c07612a1 100644 --- a/crates/ui-widgets/src/choice/rating.rs +++ b/crates/ui-widgets/src/choice/rating.rs @@ -203,5 +203,5 @@ impl Component for Rating<'_> { } } -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; diff --git a/crates/ui-widgets/src/choice/segmented.rs b/crates/ui-widgets/src/choice/segmented.rs index c982d7402..fdd73b2ed 100644 --- a/crates/ui-widgets/src/choice/segmented.rs +++ b/crates/ui-widgets/src/choice/segmented.rs @@ -252,5 +252,5 @@ impl Component for Segment { } } -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; diff --git a/crates/ui-widgets/src/choice/swatch.rs b/crates/ui-widgets/src/choice/swatch.rs index 7cc3920fe..d9f39ad5c 100644 --- a/crates/ui-widgets/src/choice/swatch.rs +++ b/crates/ui-widgets/src/choice/swatch.rs @@ -14,8 +14,8 @@ use craft_behavior::{Metrics, Mixed, Sense, Value}; use craft_theme::{Rgba, Srgba, Stateful, States, over}; use egui::{Color32, CornerRadius, Pos2, Rect, Response, Vec2, pos2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// Opacity of the black or white ring that stands out from a well's colour. const INNER_EDGE_ALPHA: u8 = 0x80; diff --git a/crates/ui-widgets/src/choice/swatch_table.rs b/crates/ui-widgets/src/choice/swatch_table.rs index 8e03d6a66..6c9b5e87b 100644 --- a/crates/ui-widgets/src/choice/swatch_table.rs +++ b/crates/ui-widgets/src/choice/swatch_table.rs @@ -13,8 +13,8 @@ use craft_behavior::{DisplayOrder, ItemLayout, ItemSource, Metrics, NavShape, Pr use craft_theme::Srgba; use egui::{Pos2, Rect, Response, Ui, Vec2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The entries of a colour table as an item source: keyed by index, named for type-ahead. #[derive(Clone, Copy, Debug)] diff --git a/crates/ui-widgets/src/choice/switch.rs b/crates/ui-widgets/src/choice/switch.rs index 9bd4a6e20..98464a6f5 100644 --- a/crates/ui-widgets/src/choice/switch.rs +++ b/crates/ui-widgets/src/choice/switch.rs @@ -113,5 +113,5 @@ impl Component for Switch<'_> { } } -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; diff --git a/crates/ui-widgets/src/controls/mod.rs b/crates/ui-widgets/src/controls/mod.rs index 5fedaf35f..8bc1dfc59 100644 --- a/crates/ui-widgets/src/controls/mod.rs +++ b/crates/ui-widgets/src/controls/mod.rs @@ -1,5 +1,5 @@ //! Value controls: `Disclosure`. pub mod disclosure; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; diff --git a/crates/ui-widgets/src/display/badge.rs b/crates/ui-widgets/src/display/badge.rs index 40deb2149..5ab3719ed 100644 --- a/crates/ui-widgets/src/display/badge.rs +++ b/crates/ui-widgets/src/display/badge.rs @@ -12,8 +12,8 @@ use craft_theme::{ use egui::{Response, Vec2}; use std::borrow::Cow; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The largest count a count badge shows; more reads `99+`. pub const MAX_COUNT: u32 = 99; diff --git a/crates/ui-widgets/src/display/divider.rs b/crates/ui-widgets/src/display/divider.rs index 0840b119f..e96bfd3f2 100644 --- a/crates/ui-widgets/src/display/divider.rs +++ b/crates/ui-widgets/src/display/divider.rs @@ -5,8 +5,8 @@ use crate::style::{ComponentStyle, RuleWidth, StyleCx}; use craft_behavior::{Metrics, Sense}; use egui::{Response, Vec2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of a divider. #[derive(Clone, Debug, PartialEq, ComponentStyle)] diff --git a/crates/ui-widgets/src/display/icon.rs b/crates/ui-widgets/src/display/icon.rs index 390af10d1..ca8d531de 100644 --- a/crates/ui-widgets/src/display/icon.rs +++ b/crates/ui-widgets/src/display/icon.rs @@ -8,8 +8,8 @@ use craft_theme::variant::Tone; use craft_theme::{Stateful, States}; use egui::{Response, Vec2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of an icon. #[derive(Clone, Debug, PartialEq, ComponentStyle)] diff --git a/crates/ui-widgets/src/display/inspect_overlay.rs b/crates/ui-widgets/src/display/inspect_overlay.rs index 8717f8d79..73f9e24ab 100644 --- a/crates/ui-widgets/src/display/inspect_overlay.rs +++ b/crates/ui-widgets/src/display/inspect_overlay.rs @@ -10,8 +10,8 @@ use craft_theme::Opacity; use egui::{CornerRadius, Pos2, Rect, Response, Vec2}; use std::sync::Arc; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// Which drawings an [`InspectOverlay`] shows. #[derive(Clone, Copy, Debug, PartialEq, Eq, crate::contract::MemoProps, crate::contract::PlainData)] diff --git a/crates/ui-widgets/src/display/kbd.rs b/crates/ui-widgets/src/display/kbd.rs index 8649c36da..dc3f36dce 100644 --- a/crates/ui-widgets/src/display/kbd.rs +++ b/crates/ui-widgets/src/display/kbd.rs @@ -12,8 +12,8 @@ use craft_keymap::{Chord, Layout, ReturnGlyph, Trigger}; use craft_theme::Stateful; use egui::{Rect, Response, Vec2, pos2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of a chord. #[derive(Clone, Debug, PartialEq, ComponentStyle)] diff --git a/crates/ui-widgets/src/display/mod.rs b/crates/ui-widgets/src/display/mod.rs index 860385fdd..5b1e0e582 100644 --- a/crates/ui-widgets/src/display/mod.rs +++ b/crates/ui-widgets/src/display/mod.rs @@ -3,16 +3,16 @@ //! None of them takes input or a Tab stop. A tooltip, or a label no text paints, gives the root a hover sense so the //! tooltip can show. -mod badge; -mod divider; -mod icon; -mod inspect_overlay; -mod kbd; -mod picture; -mod progress; -mod spinner; -mod target_mark; -mod text; +pub(crate) mod badge; +pub(crate) mod divider; +pub(crate) mod icon; +pub(crate) mod inspect_overlay; +pub(crate) mod kbd; +pub(crate) mod picture; +pub(crate) mod progress; +pub(crate) mod spinner; +pub(crate) mod target_mark; +pub(crate) mod text; mod words; pub use badge::{Badge, BadgeStyle}; diff --git a/crates/ui-widgets/src/display/picture.rs b/crates/ui-widgets/src/display/picture.rs index 9e0ad4cfb..e01f65f5c 100644 --- a/crates/ui-widgets/src/display/picture.rs +++ b/crates/ui-widgets/src/display/picture.rs @@ -11,8 +11,8 @@ use crate::style::{ComponentStyle, StyleCx}; use craft_behavior::{Metrics, Sense}; use egui::{ColorImage, Id, Rect, Response, Vec2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// How large a picture is: its height, from a token. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] diff --git a/crates/ui-widgets/src/display/progress.rs b/crates/ui-widgets/src/display/progress.rs index 0d80c770e..ac6adb1c0 100644 --- a/crates/ui-widgets/src/display/progress.rs +++ b/crates/ui-widgets/src/display/progress.rs @@ -8,8 +8,8 @@ use craft_theme::variant::{Emphasis, Tone}; use craft_theme::{Stateful, Variant}; use egui::{CornerRadius, Rect, Response, Vec2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// Seconds for the unknown-extent segment to cross the track. const SWEEP: f64 = 1.25; diff --git a/crates/ui-widgets/src/display/spinner.rs b/crates/ui-widgets/src/display/spinner.rs index ad3b34b35..53949bdbb 100644 --- a/crates/ui-widgets/src/display/spinner.rs +++ b/crates/ui-widgets/src/display/spinner.rs @@ -10,8 +10,8 @@ use craft_theme::Stateful; use egui::{Pos2, Response, Vec2, vec2}; use std::f32::consts::{PI, TAU}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// How long the spinner takes for a turn, in seconds. const PERIOD: f64 = 1.0; diff --git a/crates/ui-widgets/src/display/target_mark.rs b/crates/ui-widgets/src/display/target_mark.rs index 3f192b9cb..40b200b4e 100644 --- a/crates/ui-widgets/src/display/target_mark.rs +++ b/crates/ui-widgets/src/display/target_mark.rs @@ -13,8 +13,8 @@ use craft_theme::Mix as _; use egui::{CornerRadius, Rect, Response, Ui}; use std::f32::consts::TAU; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The period of the pulse in seconds: a sine of four radians per second. const PULSE_PERIOD: f64 = std::f64::consts::FRAC_PI_2; diff --git a/crates/ui-widgets/src/display/text.rs b/crates/ui-widgets/src/display/text.rs index 49221e051..aa75a0e99 100644 --- a/crates/ui-widgets/src/display/text.rs +++ b/crates/ui-widgets/src/display/text.rs @@ -10,8 +10,8 @@ use craft_behavior::{Metrics, Proposal, Sense}; use craft_theme::{Stateful, States, variant::Tone}; use egui::{Response, Vec2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// How strongly the text reads against its surface. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)] diff --git a/crates/ui-widgets/src/form/mod.rs b/crates/ui-widgets/src/form/mod.rs index da36f14f9..71a31be6f 100644 --- a/crates/ui-widgets/src/form/mod.rs +++ b/crates/ui-widgets/src/form/mod.rs @@ -1,10 +1,10 @@ //! Form rows: `Field`, `FieldGroup` and `SliderField`. -mod field; -mod group; -mod slider_field; -#[cfg(feature = "testing")] -mod stories; +pub(crate) mod field; +pub(crate) mod group; +pub(crate) mod slider_field; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod words; pub use field::{Field, FieldRowStyle, Help}; diff --git a/crates/ui-widgets/src/form/slider_field.rs b/crates/ui-widgets/src/form/slider_field.rs index 07a764b1d..0d1e0ddf0 100644 --- a/crates/ui-widgets/src/form/slider_field.rs +++ b/crates/ui-widgets/src/form/slider_field.rs @@ -1,7 +1,7 @@ //! `SliderField`: a slider and a number field over one value. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use crate::contract::{ Bind, BindCheck, BindMut, Common, Component, Cx, Edit as _, EditResponse, FieldLayout, MeasureCx, Outcome, PaintUi, Props as _, Role, SideLabel, diff --git a/crates/ui-widgets/src/graph/mod.rs b/crates/ui-widgets/src/graph/mod.rs index ee9273e19..e11d633d5 100644 --- a/crates/ui-widgets/src/graph/mod.rs +++ b/crates/ui-widgets/src/graph/mod.rs @@ -5,9 +5,9 @@ //! `NodeKind`. mod kind; -mod node; -#[cfg(feature = "testing")] -mod stories; +pub(crate) mod node; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use kind::{NodeEvent, NodeId, NodeKind, PortRef, Wire, WireDrag}; pub use node::{Node, NodeOutput, NodeStyle}; diff --git a/crates/ui-widgets/src/layout_components/mod.rs b/crates/ui-widgets/src/layout_components/mod.rs index 0c164bfa5..e5c1c8e73 100644 --- a/crates/ui-widgets/src/layout_components/mod.rs +++ b/crates/ui-widgets/src/layout_components/mod.rs @@ -10,8 +10,8 @@ use crate::style::{ComponentStyle, StyleCx}; use craft_behavior::{ColumnWidth, Insets, Metrics, Sense}; use egui::{Response, Ui}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of the layout components: no minimum size, and padding only at the start edge, one /// `space.pad.regular` per level of indent. @@ -59,7 +59,7 @@ macro_rules! layout_component { ($(#[$doc:meta])* $name:ident, $key:ident, [$($fwd:ident),*] $(, <$life:lifetime> { $($field:ident: $ty:ty),* })?) => { $(#[$doc])* #[derive(crate::contract::Component, crate::contract::Props)] - #[component(container)] + #[component(container, unregistered)] pub struct $name $(<$life>)? { #[common] common: Common, @@ -189,6 +189,13 @@ macro_rules! layout_component { }; } +#[cfg(feature = "suite")] +crate::contract::register_contract!(Stack<'static>; container, purpose = "Children one under another"); +#[cfg(feature = "suite")] +crate::contract::register_contract!(Row; container, purpose = "Children side by side"); +#[cfg(feature = "suite")] +crate::contract::register_contract!(Grid; container, purpose = "Children row-major over a column list: a child in flow takes the next cell"); + layout_component!( /// Children one under another. A header and a footer sit outside the body: the footer stays in the room under /// a collection that fills it. diff --git a/crates/ui-widgets/src/lib.rs b/crates/ui-widgets/src/lib.rs index 3ec71b0ef..fbb6cf38c 100644 --- a/crates/ui-widgets/src/lib.rs +++ b/crates/ui-widgets/src/lib.rs @@ -11,7 +11,7 @@ extern crate self as craft_ui; #[cfg(feature = "testing")] -pub use craft_ui_contract::testing_registered; +pub use craft_ui_contract::registry; #[doc(hidden)] pub use craft_ui_contract::{__private, __register_command_set, __register_contract, __register_pattern}; pub use craft_ui_contract::{InstallError, InstallSpec, contract, fonts, install, layout, primitives, runtime, style, words}; @@ -30,7 +30,7 @@ pub mod menu; pub mod notices; pub mod pickers; pub mod popover; -#[cfg(feature = "testing")] +#[cfg(feature = "suite")] #[doc(hidden)] pub mod story_kit; pub mod table; @@ -43,8 +43,10 @@ pub mod value_drag; /// `story_props`. #[cfg(feature = "testing")] pub mod testing { + #[cfg(feature = "suite")] pub use crate::story_kit::{props, story_props}; pub use craft_ui_contract::testing::*; - crate::testing_registered!(); + #[cfg(feature = "suite")] + crate::registry!(); } diff --git a/crates/ui-widgets/src/list/mod.rs b/crates/ui-widgets/src/list/mod.rs index 1f7c2930b..4176bcba8 100644 --- a/crates/ui-widgets/src/list/mod.rs +++ b/crates/ui-widgets/src/list/mod.rs @@ -1,18 +1,18 @@ //! `List` and its rows: `ListRow`, `FindingsList`, `EventList` and `UndoList`. -mod events; -mod findings; +pub(crate) mod events; +pub(crate) mod findings; mod predicate; #[doc(hidden)] pub mod row; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod toggle; mod tree; -mod undo; -mod view; -#[cfg(feature = "testing")] -mod view_stories; +pub(crate) mod undo; +pub(crate) mod view; +#[cfg(feature = "suite")] +pub(crate) mod view_stories; mod view_words; mod words; diff --git a/crates/ui-widgets/src/list/row.rs b/crates/ui-widgets/src/list/row.rs index 64365ae6b..9252296a6 100644 --- a/crates/ui-widgets/src/list/row.rs +++ b/crates/ui-widgets/src/list/row.rs @@ -23,7 +23,7 @@ mod paint; mod placement; mod show; mod style; -mod thumb; +pub(crate) mod thumb; mod trailing; use crate::contract::Hosting; diff --git a/crates/ui-widgets/src/menu/bar.rs b/crates/ui-widgets/src/menu/bar.rs index e0459d70f..50e060a8f 100644 --- a/crates/ui-widgets/src/menu/bar.rs +++ b/crates/ui-widgets/src/menu/bar.rs @@ -15,8 +15,8 @@ //! The Help menu can start with a search field over a list of `HelpEntry` commands: typing lists up to `search::MAX_RESULTS` //! matches by label, English label, menu path or command id, each as a command row with its path as detail. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::search::{HelpEntry, search_order}; use super::words::MenuWords; diff --git a/crates/ui-widgets/src/menu/mod.rs b/crates/ui-widgets/src/menu/mod.rs index ce19aecb6..16ea5cfd3 100644 --- a/crates/ui-widgets/src/menu/mod.rs +++ b/crates/ui-widgets/src/menu/mod.rs @@ -1,15 +1,15 @@ //! Menu presets with `MenuItem` rows, menu-bar keys and mnemonics. pub mod bar; -mod edit; +pub(crate) mod edit; pub(crate) mod item; #[doc(hidden)] pub mod level; -mod panel; -mod popup; +pub(crate) mod panel; +pub(crate) mod popup; pub mod search; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; mod words; pub use bar::{MenuBar, MenuBarOutput, MenuBarStyle, MenuHelp, MenuTitle}; diff --git a/crates/ui-widgets/src/notices/mod.rs b/crates/ui-widgets/src/notices/mod.rs index cdfb18bc3..6c430edec 100644 --- a/crates/ui-widgets/src/notices/mod.rs +++ b/crates/ui-widgets/src/notices/mod.rs @@ -1,14 +1,14 @@ //! `Notice` (inline, card and centred layouts), the settings notices and the notice center. The toast queue is //! `runtime::toast`, drawn by `ToastStack` through the contract's `ToastHost`. -mod center; -mod notice; -mod settings; -mod toasts; +pub(crate) mod center; +pub(crate) mod notice; +pub(crate) mod settings; +pub(crate) mod toasts; mod words; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use center::{NoticeCenter, NoticeCenterOutput, NoticeEnd, PostedNotice}; pub use notice::{Notice, NoticeAction, NoticeIcon, NoticeLayout, NoticeOutput, NoticeStyle}; diff --git a/crates/ui-widgets/src/pickers/combo_box.rs b/crates/ui-widgets/src/pickers/combo_box.rs index 65963e37b..3b52582d9 100644 --- a/crates/ui-widgets/src/pickers/combo_box.rs +++ b/crates/ui-widgets/src/pickers/combo_box.rs @@ -4,8 +4,8 @@ //! component's own popup on the dropdown preset, so focus stays in the text part and the host hands the list keys to //! the list. The option the keys make active puts its text in the field; the list's Escape puts back what was typed. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::dress::RowDress; use super::rows::EntryRows; diff --git a/crates/ui-widgets/src/pickers/date.rs b/crates/ui-widgets/src/pickers/date.rs index eb4e282f8..d8819c941 100644 --- a/crates/ui-widgets/src/pickers/date.rs +++ b/crates/ui-widgets/src/pickers/date.rs @@ -5,10 +5,10 @@ //! button opens the calendar; the day under the pointer is proposed while it is open and a pick commits it. Escape //! or a press outside closes it and restores the value. -mod calendar; +pub(crate) mod calendar; mod codec; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use calendar::{Calendar, CalendarOutput, CalendarStyle, CalendarView, local_month_grid, month_grid}; pub use codec::DateCodec; diff --git a/crates/ui-widgets/src/pickers/face.rs b/crates/ui-widgets/src/pickers/face.rs index 998f8222b..4ae005ecd 100644 --- a/crates/ui-widgets/src/pickers/face.rs +++ b/crates/ui-widgets/src/pickers/face.rs @@ -256,8 +256,8 @@ impl Component for SelectFace<'_> { } } -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// Opens the popup of a picker whose face part toggles it, from the keyboard: Enter and Space (an activation by key) /// toggle it. A click on the face reaches the popup through the part's `toggles`, so the pointer is not read here. diff --git a/crates/ui-widgets/src/pickers/icon_picker.rs b/crates/ui-widgets/src/pickers/icon_picker.rs index 218cc2bc0..2dc967ed8 100644 --- a/crates/ui-widgets/src/pickers/icon_picker.rs +++ b/crates/ui-widgets/src/pickers/icon_picker.rs @@ -3,8 +3,8 @@ //! The pattern puts a `TextField::search` over a `TileGrid`. The field drives the grid: Up and Down move into the //! tiles, Enter picks the active tile, and focus stays in the field. A click on a tile picks it. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::words::PickerWords; use crate::contract::{ diff --git a/crates/ui-widgets/src/pickers/mod.rs b/crates/ui-widgets/src/pickers/mod.rs index 4c890b800..f4361dafd 100644 --- a/crates/ui-widgets/src/pickers/mod.rs +++ b/crates/ui-widgets/src/pickers/mod.rs @@ -1,18 +1,18 @@ //! Dropdown pickers: `Select`, `ComboBox`, `TreePicker`, `Autocomplete`, `DatePicker` and `IconPicker`. -mod combo_box; -mod date; +pub(crate) mod combo_box; +pub(crate) mod date; mod dress; -mod face; -mod icon_picker; +pub(crate) mod face; +pub(crate) mod icon_picker; mod rows; mod search; -mod select; -mod tree_picker; -mod unit_select; +pub(crate) mod select; +pub(crate) mod tree_picker; +pub(crate) mod unit_select; mod words; -mod reference_point; +pub(crate) mod reference_point; pub use combo_box::{ComboBox, ComboBoxOutput}; pub use date::{ diff --git a/crates/ui-widgets/src/pickers/reference_point.rs b/crates/ui-widgets/src/pickers/reference_point.rs index f0ebd4632..aa7aea113 100644 --- a/crates/ui-widgets/src/pickers/reference_point.rs +++ b/crates/ui-widgets/src/pickers/reference_point.rs @@ -14,8 +14,8 @@ use crate::style::{ComponentStyle, Flags, FocusLook, Stateful, States, StyleColo use craft_behavior::{Anchor9, Metrics, NavShape, PartKey, PartRef, Roving, Sense}; use egui::{Pos2, Rect, Vec2, vec2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; const CELL: PartKey = PartKey::new("cell"); diff --git a/crates/ui-widgets/src/pickers/select.rs b/crates/ui-widgets/src/pickers/select.rs index b6ebb1f1e..8aec2a378 100644 --- a/crates/ui-widgets/src/pickers/select.rs +++ b/crates/ui-widgets/src/pickers/select.rs @@ -31,8 +31,8 @@ use craft_theme::{Stateful, States}; use egui::{Rect, Ui, Vec2}; use std::borrow::Cow; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The part that shows the face over the whole field and opens the list on a click. const FACE: PartKey = PartKey::new("face"); diff --git a/crates/ui-widgets/src/pickers/tree_picker.rs b/crates/ui-widgets/src/pickers/tree_picker.rs index 30b6fc81d..3d6d0fb97 100644 --- a/crates/ui-widgets/src/pickers/tree_picker.rs +++ b/crates/ui-widgets/src/pickers/tree_picker.rs @@ -4,8 +4,8 @@ //! list: folders open and close with Left, Right, Enter and a click, and an item is picked with Enter or a click. //! Typing lists the items whose path holds every typed word instead of the tree. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::SelectFace; use super::face::toggle_on_key; diff --git a/crates/ui-widgets/src/pickers/unit_select.rs b/crates/ui-widgets/src/pickers/unit_select.rs index e303f3374..7afe8fd2e 100644 --- a/crates/ui-widgets/src/pickers/unit_select.rs +++ b/crates/ui-widgets/src/pickers/unit_select.rs @@ -11,8 +11,8 @@ use craft_behavior::{EditEvents, Flow, Metrics, Mixed, NumberCodec, Proposal, Se use egui::{Rect, Response, Vec2, pos2}; use std::ops::{Deref, RangeInclusive}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of a unit select: the gap between the field and the select, and the number field's width. #[derive(Clone, Debug, PartialEq, ComponentStyle)] diff --git a/crates/ui-widgets/src/popover/anchored.rs b/crates/ui-widgets/src/popover/anchored.rs index a9cf220b6..835daae44 100644 --- a/crates/ui-widgets/src/popover/anchored.rs +++ b/crates/ui-widgets/src/popover/anchored.rs @@ -207,5 +207,5 @@ impl Container for Popover<'_> { } } -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; diff --git a/crates/ui-widgets/src/popover/drop_veil.rs b/crates/ui-widgets/src/popover/drop_veil.rs index b27b9dbe9..1e003857e 100644 --- a/crates/ui-widgets/src/popover/drop_veil.rs +++ b/crates/ui-widgets/src/popover/drop_veil.rs @@ -12,8 +12,8 @@ use crate::style::{ComponentStyle, Corners, Insets, Stateful, StyleCx, SurfaceKi use craft_behavior::{Metrics, Proposal, Sense}; use egui::{Rect, Response}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of a drop veil: the scrim comes from the surface kind; the card is a child. #[derive(Clone, Debug, PartialEq, ComponentStyle)] diff --git a/crates/ui-widgets/src/popover/mod.rs b/crates/ui-widgets/src/popover/mod.rs index aefa94fb9..66d19ea72 100644 --- a/crates/ui-widgets/src/popover/mod.rs +++ b/crates/ui-widgets/src/popover/mod.rs @@ -1,8 +1,8 @@ //! Overlay components: `Popover`, `PopupList`, `Tooltip` and `DropVeil`. -mod anchored; -mod drop_veil; -mod popup_list; +pub(crate) mod anchored; +pub(crate) mod drop_veil; +pub(crate) mod popup_list; mod words; pub use anchored::{Popover, PopoverOutput, PopoverStyle}; diff --git a/crates/ui-widgets/src/popover/popup_list.rs b/crates/ui-widgets/src/popover/popup_list.rs index 38465aa75..4fcf84c16 100644 --- a/crates/ui-widgets/src/popover/popup_list.rs +++ b/crates/ui-widgets/src/popover/popup_list.rs @@ -8,8 +8,8 @@ use crate::style::{ComponentStyle, StyleCx, SurfaceKind}; use craft_behavior::{Metrics, Sense}; use egui::Response; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The style of a popup list: the surface comes from the container. #[derive(Clone, Debug, Default, PartialEq, ComponentStyle)] diff --git a/crates/ui-widgets/src/table/metadata.rs b/crates/ui-widgets/src/table/metadata.rs index 861b7a99c..659855d13 100644 --- a/crates/ui-widgets/src/table/metadata.rs +++ b/crates/ui-widgets/src/table/metadata.rs @@ -325,8 +325,8 @@ impl<'a> MetadataTable<'a> { } } -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The rows stamp of a filter query: the same query keeps the layout, another one rebuilds it. fn query_stamp(query: &str) -> u64 { diff --git a/crates/ui-widgets/src/table/mod.rs b/crates/ui-widgets/src/table/mod.rs index 392a02dcf..a0e7b77e1 100644 --- a/crates/ui-widgets/src/table/mod.rs +++ b/crates/ui-widgets/src/table/mod.rs @@ -1,10 +1,10 @@ //! `Table` and `MetadataTable`, as `List` with columns. -mod metadata; +pub(crate) mod metadata; mod sort; -#[cfg(feature = "testing")] -mod stories; -mod view; +#[cfg(feature = "suite")] +pub(crate) mod stories; +pub(crate) mod view; mod words; pub use metadata::{Checked, FieldKey, MetadataGroup, MetadataRow, MetadataTable, MetadataTableOutput}; diff --git a/crates/ui-widgets/src/tabs/document.rs b/crates/ui-widgets/src/tabs/document.rs index 340dc95b7..c8f0da436 100644 --- a/crates/ui-widgets/src/tabs/document.rs +++ b/crates/ui-widgets/src/tabs/document.rs @@ -2,8 +2,8 @@ //! strip through the drag session, and tear off when released over no strip; the host areas at both ends of the strip //! are the caller's closures. Files from the OS drop between the tabs when the host takes them. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::{Tab, TabStrip}; use crate::contract::{ diff --git a/crates/ui-widgets/src/tabs/mod.rs b/crates/ui-widgets/src/tabs/mod.rs index 321017554..9949119f5 100644 --- a/crates/ui-widgets/src/tabs/mod.rs +++ b/crates/ui-widgets/src/tabs/mod.rs @@ -4,15 +4,15 @@ mod words; // Tab and the strip rules. mod rules; -mod tab; +pub(crate) mod tab; pub use rules::{CloseSide, FitMode, OverflowMenu, OverflowPlace, TabKind, close_side}; pub use tab::{Tab, TabOutput, TabPartEvent, TabRole, TabStyle}; pub use words::TabWords; // The strip and the document tabs. -mod document; -mod strip; +pub(crate) mod document; +pub(crate) mod strip; pub use document::{DocumentTab, DocumentTabs, DocumentTabsEvent, DocumentTabsOutput}; pub use strip::{StripEnd, StripLayout, TabRoles, TabStrip, TabStripOutput, TabStripStyle, TornOff}; diff --git a/crates/ui-widgets/src/tabs/strip.rs b/crates/ui-widgets/src/tabs/strip.rs index eb86e0ce5..455e5eebf 100644 --- a/crates/ui-widgets/src/tabs/strip.rs +++ b/crates/ui-widgets/src/tabs/strip.rs @@ -9,8 +9,8 @@ //! carries panels reads the same payload with the panel key as `K`. mod end; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; pub use end::StripEnd; diff --git a/crates/ui-widgets/src/tabs/tab.rs b/crates/ui-widgets/src/tabs/tab.rs index 7e10f8a8b..eb757ad87 100644 --- a/crates/ui-widgets/src/tabs/tab.rs +++ b/crates/ui-widgets/src/tabs/tab.rs @@ -20,8 +20,8 @@ use craft_behavior::{Flow, IconId, Insets, Metrics, PartKey, PointerButton, Pres use craft_theme::{Contrast, Rgba, Stateful, States, TypeRole}; use egui::{Pos2, Rect, Response, Vec2}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The role of a tab in its strip. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] diff --git a/crates/ui-widgets/src/text/alt_text.rs b/crates/ui-widgets/src/text/alt_text.rs index a93a82aa1..644e2ce1c 100644 --- a/crates/ui-widgets/src/text/alt_text.rs +++ b/crates/ui-widgets/src/text/alt_text.rs @@ -1,7 +1,7 @@ //! `AltTextField`: an object's description for people who cannot see it, with a Mark as decorative check. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::{FieldStyle, text_part}; use crate::choice::Checkbox; diff --git a/crates/ui-widgets/src/text/chips.rs b/crates/ui-widgets/src/text/chips.rs index 9aeaae597..15cb0beb8 100644 --- a/crates/ui-widgets/src/text/chips.rs +++ b/crates/ui-widgets/src/text/chips.rs @@ -1,8 +1,8 @@ //! `ChipField`: a list of text chips in lines, each removable, with a draft text part after the last chip, "+N more" //! where a line limit stops the list, and Clear All. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::{FieldStyle, text_part}; use crate::buttons::IconButton; diff --git a/crates/ui-widgets/src/text/hex.rs b/crates/ui-widgets/src/text/hex.rs index 08d6fbb6a..7d8974b8b 100644 --- a/crates/ui-widgets/src/text/hex.rs +++ b/crates/ui-widgets/src/text/hex.rs @@ -1,8 +1,8 @@ //! `HexField`: a text field over a colour's hex digits, the `#` side label its row shows before it, and `HexCodec`, //! the codec behind it. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::TextField; use crate::contract::{Bind, GlyphLabel, LabelKind, SideLabel}; diff --git a/crates/ui-widgets/src/text/linked.rs b/crates/ui-widgets/src/text/linked.rs index 930533ba2..6964e0b82 100644 --- a/crates/ui-widgets/src/text/linked.rs +++ b/crates/ui-widgets/src/text/linked.rs @@ -1,8 +1,8 @@ //! `LinkedFields`: number fields joined by a link toggle that keeps their values in proportion (width and height) or //! equal (four sides). -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::NumberField; use crate::buttons::ToggleButton; diff --git a/crates/ui-widgets/src/text/mod.rs b/crates/ui-widgets/src/text/mod.rs index f44baf575..4b125e7a7 100644 --- a/crates/ui-widgets/src/text/mod.rs +++ b/crates/ui-widgets/src/text/mod.rs @@ -1,16 +1,16 @@ //! Text and number fields: `TextField` and `NumberField` on the text part (18.3). mod adorn; -mod alt_text; -mod chips; +pub(crate) mod alt_text; +pub(crate) mod chips; mod completions; -mod hex; -mod linked; -mod number; -mod selectable_text; -mod text_field; +pub(crate) mod hex; +pub(crate) mod linked; +pub(crate) mod number; +pub(crate) mod selectable_text; +pub(crate) mod text_field; mod words; -mod zoom_field; +pub(crate) mod zoom_field; pub use adorn::{Adornment, Placed, place, reserve}; pub use alt_text::{AltText, AltTextField, AltTextFieldStyle, AltTextWords}; diff --git a/crates/ui-widgets/src/text/number.rs b/crates/ui-widgets/src/text/number.rs index 777b14cd7..262f26501 100644 --- a/crates/ui-widgets/src/text/number.rs +++ b/crates/ui-widgets/src/text/number.rs @@ -4,8 +4,8 @@ //! range every written value stays in and the step that arrows, the wheel and a scrub move by. A drag on a field that //! is not in edit scrubs it; a click enters edit, where a drag selects text. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::adorn::{Adornment, Placed, place, reserve}; use super::words::TextWords; diff --git a/crates/ui-widgets/src/text/selectable_text.rs b/crates/ui-widgets/src/text/selectable_text.rs index e802598b6..41e64a745 100644 --- a/crates/ui-widgets/src/text/selectable_text.rs +++ b/crates/ui-widgets/src/text/selectable_text.rs @@ -1,7 +1,7 @@ //! `SelectableText`: read-only text the user can focus, select and copy. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use crate::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, PartsCx, Props as _, Role, Styled as _}; use crate::primitives::{Span, TextRun, Wrap}; diff --git a/crates/ui-widgets/src/text/text_field.rs b/crates/ui-widgets/src/text/text_field.rs index cb2f458c8..89a3edc1f 100644 --- a/crates/ui-widgets/src/text/text_field.rs +++ b/crates/ui-widgets/src/text/text_field.rs @@ -1,7 +1,7 @@ //! `TextField`: a text field over a codec, with the search form and the adornment layout. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::adorn::{self, Adornment}; use super::{FieldStyle, completions, text_part, words}; diff --git a/crates/ui-widgets/src/text/zoom_field.rs b/crates/ui-widgets/src/text/zoom_field.rs index cccbc1fea..e8d7c93f0 100644 --- a/crates/ui-widgets/src/text/zoom_field.rs +++ b/crates/ui-widgets/src/text/zoom_field.rs @@ -9,8 +9,8 @@ use craft_behavior::kurbo::Size; use craft_behavior::{CanvasView, EditEvents, ZoomLadder}; use egui::{Response, Ui}; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The decimals the zoom range's ends are written with in the message, as the field shows a zoom. const MESSAGE_DECIMALS: usize = 2; diff --git a/crates/ui-widgets/src/tile_grid/grid.rs b/crates/ui-widgets/src/tile_grid/grid.rs index 15e92d9e0..d086f5474 100644 --- a/crates/ui-widgets/src/tile_grid/grid.rs +++ b/crates/ui-widgets/src/tile_grid/grid.rs @@ -5,8 +5,8 @@ //! the item step that hold the lead), and the rating keys. It owns what its cards have in common: where the //! caption goes, whether a detail line is reserved, and the zoom. -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; use super::headers::Outline; use super::layout::{Around, ArrangeSpacing, GridLayout, Recipe, Slot, TailRow, TileGroup, Tiling, arrange, aspects_of, slot_at}; diff --git a/crates/ui-widgets/src/tile_grid/mod.rs b/crates/ui-widgets/src/tile_grid/mod.rs index 19322017a..8eba110b6 100644 --- a/crates/ui-widgets/src/tile_grid/mod.rs +++ b/crates/ui-widgets/src/tile_grid/mod.rs @@ -3,13 +3,13 @@ //! The data types of a tile (badges, status, marks, the caption's place) live here; `TileGrid` shows tiles in //! rows and columns and reads the tile size from the value a `ThumbnailSlider` edits. -mod grid; +pub(crate) mod grid; mod headers; mod layout; -mod slider; -#[cfg(feature = "testing")] -mod stories; -mod tile; +pub(crate) mod slider; +#[cfg(feature = "suite")] +pub(crate) mod stories; +pub(crate) mod tile; mod words; use crate::runtime::env::Label; diff --git a/crates/ui-widgets/src/value_drag/angle_dial.rs b/crates/ui-widgets/src/value_drag/angle_dial.rs index a0518a233..db02d76f5 100644 --- a/crates/ui-widgets/src/value_drag/angle_dial.rs +++ b/crates/ui-widgets/src/value_drag/angle_dial.rs @@ -17,8 +17,8 @@ use craft_theme::{Stateful, States}; use egui::{CornerRadius, Pos2, Rect, Vec2}; use std::ops::RangeInclusive; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The face: the circle the pointer points at. const FACE: PartKey = PartKey::new("face"); diff --git a/crates/ui-widgets/src/value_drag/mod.rs b/crates/ui-widgets/src/value_drag/mod.rs index fec2aba73..12d65961e 100644 --- a/crates/ui-widgets/src/value_drag/mod.rs +++ b/crates/ui-widgets/src/value_drag/mod.rs @@ -1,10 +1,10 @@ //! `Slider`, `RangeSlider`, `AngleDial`, `PointPicker` and `ThumbRow`, built on `ValueDrag`. -mod angle_dial; -mod point_picker; -mod range_slider; -mod slider; -mod thumb_row; +pub(crate) mod angle_dial; +pub(crate) mod point_picker; +pub(crate) mod range_slider; +pub(crate) mod slider; +pub(crate) mod thumb_row; pub(crate) mod track; mod words; diff --git a/crates/ui-widgets/src/value_drag/point_picker.rs b/crates/ui-widgets/src/value_drag/point_picker.rs index 6f877c725..8417bdd3a 100644 --- a/crates/ui-widgets/src/value_drag/point_picker.rs +++ b/crates/ui-widgets/src/value_drag/point_picker.rs @@ -19,8 +19,8 @@ use craft_behavior::{ use egui::{Pos2, Rect, Vec2, pos2}; use std::ops::RangeInclusive; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The point: a drag on it follows the pointer. const THUMB: PartKey = PartKey::new("thumb"); diff --git a/crates/ui-widgets/src/value_drag/range_slider.rs b/crates/ui-widgets/src/value_drag/range_slider.rs index 5ecce7e4b..00fd5547a 100644 --- a/crates/ui-widgets/src/value_drag/range_slider.rs +++ b/crates/ui-widgets/src/value_drag/range_slider.rs @@ -16,8 +16,8 @@ use craft_theme::Stateful; use egui::{Pos2, Rect, Vec2}; use std::ops::RangeInclusive; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The track both thumbs ride on. pub(crate) const TRACK: PartKey = PartKey::new("track"); diff --git a/crates/ui-widgets/src/value_drag/slider.rs b/crates/ui-widgets/src/value_drag/slider.rs index e63553c07..88a3b8f7f 100644 --- a/crates/ui-widgets/src/value_drag/slider.rs +++ b/crates/ui-widgets/src/value_drag/slider.rs @@ -17,8 +17,8 @@ use craft_theme::Stateful; use egui::{Pos2, Rect, Vec2}; use std::ops::RangeInclusive; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The track the thumb rides on. pub(crate) const TRACK: PartKey = PartKey::new("track"); diff --git a/crates/ui-widgets/src/value_drag/thumb_row.rs b/crates/ui-widgets/src/value_drag/thumb_row.rs index f11da91d0..bf2ba60e8 100644 --- a/crates/ui-widgets/src/value_drag/thumb_row.rs +++ b/crates/ui-widgets/src/value_drag/thumb_row.rs @@ -32,8 +32,8 @@ use std::ops::RangeInclusive; /// How far a thumb's width runs past the standard handle side, in small handle sides (the old levels thumb: 8 + 6 / 2). const THUMB_WIDTH_IN_SMALL_HANDLES: f32 = 0.5; -#[cfg(feature = "testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; /// The row-wide part: a press off the thumbs lands here. pub(crate) const ROW: PartKey = PartKey::new("row"); diff --git a/crates/ui-widgets/tests/it/access/mod.rs b/crates/ui-widgets/tests/it/access/mod.rs index 1f8f33f8b..48bc3bb72 100644 --- a/crates/ui-widgets/tests/it/access/mod.rs +++ b/crates/ui-widgets/tests/it/access/mod.rs @@ -1,4 +1,4 @@ //! The accessibility emitter: the label scope and merge rule, announcements, modal inertness, viewports. -mod scroll_into_view; -mod step_ends; +pub(crate) mod scroll_into_view; +pub(crate) mod step_ends; diff --git a/crates/ui-widgets/tests/it/bars/mod.rs b/crates/ui-widgets/tests/it/bars/mod.rs index a77f9502c..7fe285259 100644 --- a/crates/ui-widgets/tests/it/bars/mod.rs +++ b/crates/ui-widgets/tests/it/bars/mod.rs @@ -1,9 +1,9 @@ //! `Bar` and `BarItems`, and a toolbar's edit commands over a focused text field. -mod bar; -mod breadcrumb; -mod constraint_fields; -mod edit_focus; -mod items; -mod memo; -mod overflow; +pub(crate) mod bar; +pub(crate) mod breadcrumb; +pub(crate) mod constraint_fields; +pub(crate) mod edit_focus; +pub(crate) mod items; +pub(crate) mod memo; +pub(crate) mod overflow; diff --git a/crates/ui-widgets/tests/it/body/mod.rs b/crates/ui-widgets/tests/it/body/mod.rs index 297ca5886..b95a6002f 100644 --- a/crates/ui-widgets/tests/it/body/mod.rs +++ b/crates/ui-widgets/tests/it/body/mod.rs @@ -1,7 +1,7 @@ //! The body step and the mount host: regions, scrolling, move and resize, and viewport mounts. -mod memo_audit; -mod memo_reads; -mod memo_settled; -mod memo_view; -mod scroll; +pub(crate) mod memo_audit; +pub(crate) mod memo_reads; +pub(crate) mod memo_settled; +pub(crate) mod memo_view; +pub(crate) mod scroll; diff --git a/crates/ui-widgets/tests/it/commands/mod.rs b/crates/ui-widgets/tests/it/commands/mod.rs index c3bed565b..701124194 100644 --- a/crates/ui-widgets/tests/it/commands/mod.rs +++ b/crates/ui-widgets/tests/it/commands/mod.rs @@ -1,3 +1,3 @@ //! The command board: registry, state, the gate, firing and scoped delivery. -mod panel_scope; +pub(crate) mod panel_scope; diff --git a/crates/ui-widgets/tests/it/contract/mod.rs b/crates/ui-widgets/tests/it/contract/mod.rs index b30861de3..62e206552 100644 --- a/crates/ui-widgets/tests/it/contract/mod.rs +++ b/crates/ui-widgets/tests/it/contract/mod.rs @@ -1,7 +1,7 @@ //! The component contract and the show pipeline: the steps each shape runs, and the rules the steps keep. -mod elide; -mod faces; -mod levelled; -mod measure; -mod state_looks; +pub(crate) mod elide; +pub(crate) mod faces; +pub(crate) mod levelled; +pub(crate) mod measure; +pub(crate) mod state_looks; diff --git a/crates/ui-widgets/tests/it/label/mod.rs b/crates/ui-widgets/tests/it/label/mod.rs index 1c36ecfdf..6facfa093 100644 --- a/crates/ui-widgets/tests/it/label/mod.rs +++ b/crates/ui-widgets/tests/it/label/mod.rs @@ -1,17 +1,17 @@ //! The label step: scrub across a pointer warp and the label beside or above a fill-width control. -mod align; -mod baseline; -mod caption; +pub(crate) mod align; +pub(crate) mod baseline; +pub(crate) mod caption; pub mod group; -mod hit; -mod inside; +pub(crate) mod hit; +pub(crate) mod inside; pub mod kit; -mod reach; -mod reset; -mod scheme; -mod short; -mod tooltip; +pub(crate) mod reach; +pub(crate) mod reset; +pub(crate) mod scheme; +pub(crate) mod short; +pub(crate) mod tooltip; use self::kit::{Dial, Field, Seen, Wide}; use craft_host::target::ShellInfo; diff --git a/crates/ui-widgets/tests/it/layer/mod.rs b/crates/ui-widgets/tests/it/layer/mod.rs index f840ad829..29e4970b8 100644 --- a/crates/ui-widgets/tests/it/layer/mod.rs +++ b/crates/ui-widgets/tests/it/layer/mod.rs @@ -1,3 +1,3 @@ //! Layers: what a layer starts with when it opens again. -mod reopen; +pub(crate) mod reopen; diff --git a/crates/ui-widgets/tests/it/layout/mod.rs b/crates/ui-widgets/tests/it/layout/mod.rs index 345f8b837..580f62713 100644 --- a/crates/ui-widgets/tests/it/layout/mod.rs +++ b/crates/ui-widgets/tests/it/layout/mod.rs @@ -1,17 +1,17 @@ -mod cross_fill; -mod fill_column; -mod fill_height; -mod fill_share; -mod fonts; -mod grid_labels; -mod grid_least; -mod nested; -mod room_height; -mod row_line; -mod row_room; -mod rtl_scroll; -mod scroll_region; -mod shrink_order; -mod stack_header; -mod stack_widths; -mod zero_width; +pub(crate) mod cross_fill; +pub(crate) mod fill_column; +pub(crate) mod fill_height; +pub(crate) mod fill_share; +pub(crate) mod fonts; +pub(crate) mod grid_labels; +pub(crate) mod grid_least; +pub(crate) mod nested; +pub(crate) mod room_height; +pub(crate) mod row_line; +pub(crate) mod row_room; +pub(crate) mod rtl_scroll; +pub(crate) mod scroll_region; +pub(crate) mod shrink_order; +pub(crate) mod stack_header; +pub(crate) mod stack_widths; +pub(crate) mod zero_width; diff --git a/crates/ui-widgets/tests/it/main.rs b/crates/ui-widgets/tests/it/main.rs index 66d13ee1f..c419ef04f 100644 --- a/crates/ui-widgets/tests/it/main.rs +++ b/crates/ui-widgets/tests/it/main.rs @@ -3,41 +3,45 @@ // The test files name the library as `craft_ui`, as the crates that use it do. extern crate craft_ui_widgets as craft_ui; -mod access; -mod bars; +pub(crate) mod access; +pub(crate) mod bars; pub(crate) mod body; -mod buttons; -mod commands; -mod contract; -mod disabled_fade; -mod field_text_centred; -mod keys; -mod label; -mod layer; -mod layout; -mod link; -mod list; -mod menu; -mod notices; -mod overlay; +pub(crate) mod buttons; +pub(crate) mod commands; +pub(crate) mod contract; +pub(crate) mod disabled_fade; +pub(crate) mod field_text_centred; +pub(crate) mod keys; +pub(crate) mod label; +pub(crate) mod layer; +pub(crate) mod layout; +pub(crate) mod link; +pub(crate) mod list; +pub(crate) mod menu; +pub(crate) mod notices; +pub(crate) mod overlay; -mod pickers; -mod picture; -mod popover; -mod runtime; +pub(crate) mod pickers; +pub(crate) mod picture; +pub(crate) mod popover; +pub(crate) mod runtime; -mod suite_rtl; -mod suite_rules; -mod suite_title; -mod table; -mod tabs; -mod text; -mod tile_grid; -mod value_drag; -mod values; +pub(crate) mod suite_rtl; +pub(crate) mod suite_rules; +pub(crate) mod suite_title; +pub(crate) mod table; +pub(crate) mod tabs; +pub(crate) mod text; +pub(crate) mod tile_grid; +pub(crate) mod value_drag; +pub(crate) mod values; -use craft_ui::testing::registered; +craft_ui::registry!(); fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), ®istered()); + craft_ui::testing::run( + module_path!(), + env!("CARGO_PKG_NAME"), + &craft_ui::testing::Registry::of(&[register, craft_ui::testing::register, craft_ui_test_kit::testing::register]), + ); } diff --git a/crates/ui-widgets/tests/it/menu/mod.rs b/crates/ui-widgets/tests/it/menu/mod.rs index c23c138a0..8a164d05f 100644 --- a/crates/ui-widgets/tests/it/menu/mod.rs +++ b/crates/ui-widgets/tests/it/menu/mod.rs @@ -1,24 +1,24 @@ //! `Menu` and `MenuItem`: the columns of an inline menu's rows. -mod bar; +pub(crate) mod bar; -mod closed; +pub(crate) mod closed; -mod companion; +pub(crate) mod companion; -mod native; +pub(crate) mod native; -mod openers; +pub(crate) mod openers; -mod overflow; +pub(crate) mod overflow; -mod pick_focus; +pub(crate) mod pick_focus; -mod rows; +pub(crate) mod rows; -mod search; +pub(crate) mod search; -mod submenus; +pub(crate) mod submenus; use craft_behavior::IconId; use craft_ui::contract::{Show as _, ShowContainer as _}; diff --git a/crates/ui-widgets/tests/it/overlay/mod.rs b/crates/ui-widgets/tests/it/overlay/mod.rs index f2ad8e89c..582d9da48 100644 --- a/crates/ui-widgets/tests/it/overlay/mod.rs +++ b/crates/ui-widgets/tests/it/overlay/mod.rs @@ -1,7 +1,7 @@ //! The overlay host (15): popups, modals and menu picking. -mod hosting; +pub(crate) mod hosting; pub(crate) mod kit; -mod modal; -mod pages; -mod sampler; +pub(crate) mod modal; +pub(crate) mod pages; +pub(crate) mod sampler; diff --git a/crates/ui-widgets/tests/it/pickers/mod.rs b/crates/ui-widgets/tests/it/pickers/mod.rs index e96846356..6985b7f5d 100644 --- a/crates/ui-widgets/tests/it/pickers/mod.rs +++ b/crates/ui-widgets/tests/it/pickers/mod.rs @@ -1,11 +1,11 @@ //! Dropdown pickers. -mod combo_list; -mod date; -mod icon_picker; -mod select_list; -mod select_measure; -mod select_steps; -mod select_width; -mod swatch_table; -mod tree_list; +pub(crate) mod combo_list; +pub(crate) mod date; +pub(crate) mod icon_picker; +pub(crate) mod select_list; +pub(crate) mod select_measure; +pub(crate) mod select_steps; +pub(crate) mod select_width; +pub(crate) mod swatch_table; +pub(crate) mod tree_list; diff --git a/crates/ui-widgets/tests/it/popover/mod.rs b/crates/ui-widgets/tests/it/popover/mod.rs index d25856671..5e0ea49ba 100644 --- a/crates/ui-widgets/tests/it/popover/mod.rs +++ b/crates/ui-widgets/tests/it/popover/mod.rs @@ -1,5 +1,5 @@ //! The popover family (15.5): popup lists and their dismissal. -mod commands; -mod one_at_a_time; -mod popup; +pub(crate) mod commands; +pub(crate) mod one_at_a_time; +pub(crate) mod popup; diff --git a/crates/ui-widgets/tests/it/runtime/mod.rs b/crates/ui-widgets/tests/it/runtime/mod.rs index 66faeeb6a..3063263e7 100644 --- a/crates/ui-widgets/tests/it/runtime/mod.rs +++ b/crates/ui-widgets/tests/it/runtime/mod.rs @@ -1,2 +1,2 @@ -mod bypass; -mod inspect; +pub(crate) mod bypass; +pub(crate) mod inspect; diff --git a/crates/ui-widgets/tests/it/suite_rules.rs b/crates/ui-widgets/tests/it/suite_rules.rs index f9564c751..39b25b945 100644 --- a/crates/ui-widgets/tests/it/suite_rules.rs +++ b/crates/ui-widgets/tests/it/suite_rules.rs @@ -11,8 +11,11 @@ use egui::{Ui, vec2}; fn probe_of() -> &'static Probe { let name = std::any::type_name::(); - craft_ui::contract::registrations() - .into_iter() + static REGISTRY: std::sync::OnceLock = std::sync::OnceLock::new(); + REGISTRY + .get_or_init(|| craft_ui::testing::Registry::of(&[crate::register, craft_ui::testing::register])) + .registrations() + .iter() .filter_map(Registration::probe) .find(|probe| probe.type_name() == name) .expect("the type is registered") diff --git a/crates/ui-widgets/tests/it/text/chips.rs b/crates/ui-widgets/tests/it/text/chips.rs index ff5a5ba02..fa45945c4 100644 --- a/crates/ui-widgets/tests/it/text/chips.rs +++ b/crates/ui-widgets/tests/it/text/chips.rs @@ -20,7 +20,7 @@ fn a_draft_adds_its_pieces_after_the_existing_chips() { assert_eq!(codec.parse("two words", &Vec::new()), Ok(chips(&["two words"])), "a space does not end a chip"); } -mod field { +pub(crate) mod field { use craft_ui::contract::{Role, Show as _}; use craft_ui::testing::access::name; use craft_ui::testing::{Fixture, Story, StoryData, StoryOutput, pointer, trial}; diff --git a/crates/ui-widgets/tests/it/text/mod.rs b/crates/ui-widgets/tests/it/text/mod.rs index 8932b32bd..42f14bd0e 100644 --- a/crates/ui-widgets/tests/it/text/mod.rs +++ b/crates/ui-widgets/tests/it/text/mod.rs @@ -1,16 +1,16 @@ -mod access; -mod alt_text; -mod chips; -mod edit_menu; -mod fields; -mod hex; +pub(crate) mod access; +pub(crate) mod alt_text; +pub(crate) mod chips; +pub(crate) mod edit_menu; +pub(crate) mod fields; +pub(crate) mod hex; mod kit; -mod linked; -mod mixed_blank; -mod number; -mod number_length; -mod number_scrub_step; -mod selectable; -mod text_field; -mod widths; -mod zoom_field; +pub(crate) mod linked; +pub(crate) mod mixed_blank; +pub(crate) mod number; +pub(crate) mod number_length; +pub(crate) mod number_scrub_step; +pub(crate) mod selectable; +pub(crate) mod text_field; +pub(crate) mod widths; +pub(crate) mod zoom_field; diff --git a/crates/ui-widgets/tests/it/tile_grid/mod.rs b/crates/ui-widgets/tests/it/tile_grid/mod.rs index be6ff4d7f..e3c99a8a8 100644 --- a/crates/ui-widgets/tests/it/tile_grid/mod.rs +++ b/crates/ui-widgets/tests/it/tile_grid/mod.rs @@ -1,6 +1,6 @@ //! The tile grid family's own logic. -mod cells; -mod grid; -mod keys; -mod tile; +pub(crate) mod cells; +pub(crate) mod grid; +pub(crate) mod keys; +pub(crate) mod tile; diff --git a/crates/ui-widgets/tests/it/value_drag.rs b/crates/ui-widgets/tests/it/value_drag.rs index 862ed342a..507caf2eb 100644 --- a/crates/ui-widgets/tests/it/value_drag.rs +++ b/crates/ui-widgets/tests/it/value_drag.rs @@ -1,9 +1,9 @@ //! `Slider` and `RangeSlider`: the value maths that is the family's own: stepping in the reading direction, the scales //! that spread a range over a track, and thumbs that never cross. -mod dials; +pub(crate) mod dials; -mod thumb_row; +pub(crate) mod thumb_row; use craft_behavior::{EditEvent, MotionMode}; use craft_ui::contract::{Bind, Props as _, Show as _}; diff --git a/crates/ui-widgets/tests/it/values/mod.rs b/crates/ui-widgets/tests/it/values/mod.rs index f121dc92d..8dd255105 100644 --- a/crates/ui-widgets/tests/it/values/mod.rs +++ b/crates/ui-widgets/tests/it/values/mod.rs @@ -1,13 +1,13 @@ //! Values and edits: the binding sources, gestures, cancels, mixed values, checks and the undo adapter. -mod bindings; +pub(crate) mod bindings; -mod gestures; +pub(crate) mod gestures; -mod history; +pub(crate) mod history; pub(crate) mod kit; -mod reads; +pub(crate) mod reads; -mod write_back; +pub(crate) mod write_back; diff --git a/crates/ui/Cargo.toml b/crates/ui/Cargo.toml index 4bf541158..5b8644d4e 100644 --- a/crates/ui/Cargo.toml +++ b/crates/ui/Cargo.toml @@ -16,6 +16,7 @@ test = false workspace = true [features] +suite = ["testing", "craft-ui-contract/suite", "craft-ui-widgets/suite", "craft-ui-panels/suite", "craft-ui-canvas/suite", "craft-ui-patterns/suite", "craft-ui-shell/suite"] default = [] # `shell::app`: the eframe entry point. app = ["craft-ui-shell/app"] @@ -51,7 +52,7 @@ craft-ui-shell = { workspace = true } craft-cloud-ui = { workspace = true } [dev-dependencies] -craft-ui = { path = ".", features = ["testing"] } +craft-ui = { path = ".", features = ["suite"] } craft-behavior = { workspace = true } craft-i18n = { workspace = true, features = ["collate"] } egui = { workspace = true } diff --git a/crates/ui/src/lib.rs b/crates/ui/src/lib.rs index bd7618f67..b66112c99 100644 --- a/crates/ui/src/lib.rs +++ b/crates/ui/src/lib.rs @@ -10,6 +10,8 @@ //! `presence`) from craft-cloud-ui, which is still raw egui. #![warn(missing_docs)] +extern crate self as craft_ui; + #[cfg(feature = "cloud")] pub use craft_cloud_ui::cloud; #[cfg(feature = "esign")] @@ -19,7 +21,7 @@ pub use craft_cloud_ui::presence; pub use craft_cloud_ui::{account, share}; pub use craft_ui_canvas::{canvas, canvas_controls, dialog}; #[cfg(feature = "testing")] -pub use craft_ui_contract::testing_registered; +pub use craft_ui_contract::registry; #[doc(hidden)] pub use craft_ui_contract::{__private, __register_command_set, __register_contract, __register_pattern}; pub use craft_ui_contract::{InstallError, InstallSpec, contract, fonts, install, layout, primitives, runtime, style, words}; @@ -46,34 +48,32 @@ pub mod patterns { pub mod testing { pub use craft_ui_canvas::testing::*; - crate::testing_registered!(); + #[cfg(feature = "suite")] + crate::registry!(); - /// A crate's `registered`. - type Registered = fn() -> Vec<&'static Registration>; - - /// The crates of the library, each with its `registered`. - const LIBRARY: [(&str, Registered); 7] = [ - ("craft-ui", registered), - ("craft-ui-contract", craft_ui_contract::testing::registered), - ("craft-ui-widgets", craft_ui_widgets::testing::registered), - ("craft-ui-panels", craft_ui_panels::testing::registered), - ("craft-ui-canvas", craft_ui_canvas::testing::registered), - ("craft-ui-patterns", craft_ui_patterns::testing::registered), - ("craft-ui-shell", craft_ui_shell::testing::registered), + /// The framework crates whose suite items form the library. + #[cfg(feature = "suite")] + const LIBRARY: [fn(&mut Registry); 7] = [ + register, + craft_ui_contract::testing::register, + craft_ui_widgets::testing::register, + craft_ui_panels::testing::register, + craft_ui_canvas::testing::register, + craft_ui_patterns::testing::register, + craft_ui_shell::testing::register, ]; - /// Every registration declared in the library crates of the library: this crate and the six it re-exports. - /// Types declared in integration binaries are fixtures and are left out. - pub fn library_registrations() -> Vec<&'static Registration> { - // A crate's registrations run only in a binary that links the crate; naming each crate's `registered` - // links them all. - let library = std::hint::black_box(LIBRARY); - crate::contract::registrations() - .into_iter() - .filter(|registration| { - library.iter().any(|(name, _)| *name == registration.crate_name()) - && registration.crate_target() == registration.crate_name().replace('-', "_") - }) - .collect() + /// Adds the framework library crates to a registry. + #[cfg(feature = "suite")] + pub fn register_library(registry: &mut Registry) { + for register in LIBRARY { + register(registry); + } + } + + /// The suite items declared by the framework library crates. + #[cfg(feature = "suite")] + pub fn library_registrations() -> Registry { + Registry::of(&LIBRARY) } } diff --git a/crates/ui/tests/it/canvas/mod.rs b/crates/ui/tests/it/canvas/mod.rs index af1480537..6a3f1c9d2 100644 --- a/crates/ui/tests/it/canvas/mod.rs +++ b/crates/ui/tests/it/canvas/mod.rs @@ -1,3 +1,3 @@ //! `Canvas` (20.6): a press away from every canvas control's parts reaches the tool. -mod document_canvas; +pub(crate) mod document_canvas; diff --git a/crates/ui/tests/it/components_index.rs b/crates/ui/tests/it/components_index.rs index e932828e1..637a71dd0 100644 --- a/crates/ui/tests/it/components_index.rs +++ b/crates/ui/tests/it/components_index.rs @@ -11,8 +11,10 @@ use std::path::Path; fn the_committed_components_index_is_what_the_registrations_give() { let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); let committed = std::fs::read_to_string(root.join("docs/components-index.md")).unwrap_or_default(); + let registry = library_registrations(); + let registrations: Vec<_> = registry.registrations().iter().collect(); assert!( - committed == components_index(&root, &library_registrations()), + committed == components_index(&root, ®istrations), "docs/components-index.md is stale; run `cargo run -p craft-ui-gallery --bin components-index`" ); } @@ -21,6 +23,7 @@ fn the_committed_components_index_is_what_the_registrations_give() { /// together only here. #[trial] fn the_level_tables_name_only_registered_types_and_story_groups() { - let stale = stale_table_rows(&library_registrations()); + let registry = library_registrations(); + let stale = stale_table_rows(®istry); assert!(stale.is_empty(), "stale level table rows: {stale:#?}"); } diff --git a/crates/ui/tests/it/form_dialogs/mod.rs b/crates/ui/tests/it/form_dialogs/mod.rs index d0f4f035a..a07f22d6d 100644 --- a/crates/ui/tests/it/form_dialogs/mod.rs +++ b/crates/ui/tests/it/form_dialogs/mod.rs @@ -1,4 +1,4 @@ //! The form dialogs' own logic: the parameter model, its spec-string parser, the value store, the size model, //! guide layout and the export file name. -mod guides; +pub(crate) mod guides; diff --git a/crates/ui/tests/it/main.rs b/crates/ui/tests/it/main.rs index 5e341b9a8..afe462985 100644 --- a/crates/ui/tests/it/main.rs +++ b/crates/ui/tests/it/main.rs @@ -1,14 +1,18 @@ //! The integration binary of craft-ui: every test is a registered trial. -mod api_map; -mod canvas; -mod components_index; -mod form_dialogs; +pub(crate) mod api_map; +pub(crate) mod canvas; +pub(crate) mod components_index; +pub(crate) mod form_dialogs; -mod shell; +pub(crate) mod shell; -use craft_ui::testing::registered; +craft_ui::registry!(); fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), ®istered()); + craft_ui::testing::run( + module_path!(), + env!("CARGO_PKG_NAME"), + &craft_ui::testing::Registry::of(&[register, craft_ui::testing::register_library]), + ); } diff --git a/crates/ui/tests/it/shell/mod.rs b/crates/ui/tests/it/shell/mod.rs index 2b08cbe45..696f10ab6 100644 --- a/crates/ui/tests/it/shell/mod.rs +++ b/crates/ui/tests/it/shell/mod.rs @@ -1,3 +1,3 @@ //! The window skeleton's interface: what `ShellCx` answers by mode and reveal, and how a body reads it. -mod app_shell; +pub(crate) mod app_shell; diff --git a/crates/update/Cargo.toml b/crates/update/Cargo.toml index db6a8d872..0325ea8f9 100644 --- a/crates/update/Cargo.toml +++ b/crates/update/Cargo.toml @@ -17,6 +17,7 @@ harness = false workspace = true [features] +suite = ["screen-testing", "craft-ui/suite"] # Opt-in migration of first party Flatpak bundles to the ArtCraft OCI remote. oci_migration = [] default = [] @@ -43,7 +44,7 @@ chrono = { workspace = true } semver = { version = "1", features = ["serde"] } [dev-dependencies] -craft-ui = { workspace = true, features = ["testing"] } +craft-ui = { workspace = true, features = ["suite"] } flate2 = "1" [target.'cfg(unix)'.dependencies] diff --git a/crates/update/src/app.rs b/crates/update/src/app.rs index 3d47f8d6d..c4d0d34f7 100644 --- a/crates/update/src/app.rs +++ b/crates/update/src/app.rs @@ -84,7 +84,7 @@ impl App { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/desktop_entry.rs b/crates/update/src/desktop_entry.rs index 95e327425..fa13e5ebf 100644 --- a/crates/update/src/desktop_entry.rs +++ b/crates/update/src/desktop_entry.rs @@ -132,7 +132,7 @@ pub fn exec_program(text: &str) -> Option { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use craft_ui::testing::trial; use super::*; diff --git a/crates/update/src/detect.rs b/crates/update/src/detect.rs index 21fcc1317..4011fbef7 100644 --- a/crates/update/src/detect.rs +++ b/crates/update/src/detect.rs @@ -155,4 +155,4 @@ pub mod linux; pub mod freebsd; #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/update/src/install.rs b/crates/update/src/install.rs index 3a2e883e1..2b1235a09 100644 --- a/crates/update/src/install.rs +++ b/crates/update/src/install.rs @@ -916,4 +916,4 @@ pub(crate) fn msi_path(msi: &Path) -> Result { pub mod windows; #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/update/src/install/tests.rs b/crates/update/src/install/tests.rs index 1b6e71b13..ceb59b238 100644 --- a/crates/update/src/install/tests.rs +++ b/crates/update/src/install/tests.rs @@ -702,7 +702,7 @@ fn hdiutil_busy_replies_are_recognized() { } #[cfg(target_os = "macos")] -mod macos_checks { +pub(crate) mod macos_checks { use craft_ui::testing::trial; use super::macos::{CheckTurn, Expect, Signature, TEAM_ID, signed_by}; diff --git a/crates/update/src/lib.rs b/crates/update/src/lib.rs index 97ff5e342..06897fd1d 100644 --- a/crates/update/src/lib.rs +++ b/crates/update/src/lib.rs @@ -11,8 +11,8 @@ pub mod http; pub mod install; pub mod manifest; pub mod msi_context; -mod msi_copy; -mod msi_migrate; +pub(crate) mod msi_copy; +pub(crate) mod msi_migrate; pub mod packages; pub mod paths; pub mod pins; @@ -51,7 +51,9 @@ pub use version::{Version, is_newer, parse as parse_version}; #[cfg(feature = "screen-testing")] /// The registrations of this package for the integration binary. pub mod testing { - craft_ui::testing_registered!(); + + #[cfg(feature = "suite")] + craft_ui::registry!(); } /// Checks for an update against GitHub releases for the given app. @@ -88,12 +90,13 @@ pub(crate) const TEST_AGENT: &str = "ArtCraft-Launcher-Test/0.0"; extern crate self as craft_update; #[cfg(test)] #[path = "../tests/https_only.rs"] -mod https_only; +pub(crate) mod https_only; #[cfg(all(test, feature = "screen-testing"))] #[path = "../tests/it/main.rs"] -mod integration; +pub(crate) mod integration; #[cfg(test)] fn main() { - craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::registered_in(env!("CARGO_PKG_NAME"))); + craft_ui::registry!(); + craft_ui::testing::run(module_path!(), env!("CARGO_PKG_NAME"), &craft_ui::testing::Registry::of(&[register])); } diff --git a/crates/update/src/manifest.rs b/crates/update/src/manifest.rs index 8aa02bf10..87e40b337 100644 --- a/crates/update/src/manifest.rs +++ b/crates/update/src/manifest.rs @@ -46,7 +46,7 @@ impl Manifest { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/msi_context.rs b/crates/update/src/msi_context.rs index 414ac4aa8..c1813ea56 100644 --- a/crates/update/src/msi_context.rs +++ b/crates/update/src/msi_context.rs @@ -174,7 +174,7 @@ fn current_user_sid() -> Result { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/msi_copy.rs b/crates/update/src/msi_copy.rs index ea846c704..a29e9776a 100644 --- a/crates/update/src/msi_copy.rs +++ b/crates/update/src/msi_copy.rs @@ -218,7 +218,7 @@ pub(crate) mod windows { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/msi_migrate.rs b/crates/update/src/msi_migrate.rs index 7d8a86226..a80068484 100644 --- a/crates/update/src/msi_migrate.rs +++ b/crates/update/src/msi_migrate.rs @@ -169,7 +169,7 @@ pub(crate) mod windows { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/packages.rs b/crates/update/src/packages.rs index b76cca4b2..9eb80884b 100644 --- a/crates/update/src/packages.rs +++ b/crates/update/src/packages.rs @@ -119,7 +119,7 @@ pub fn version_of(p: &Package) -> Option { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; @@ -183,7 +183,7 @@ pub fn is_artcraft_remote(origin: &str, remotes: &str) -> bool { } #[cfg(test)] -mod remote_url_tests { +pub(crate) mod remote_url_tests { use super::*; use craft_ui::testing::trial; @@ -224,7 +224,7 @@ pub(crate) fn oci_ref_available(reference: &str, expected: &version::Version, li #[cfg(test)] #[cfg(all(target_os = "linux", feature = "oci_migration"))] -mod migration_tests { +pub(crate) mod migration_tests { use super::{oci_ref_available, version}; use craft_ui::testing::trial; @@ -256,7 +256,7 @@ pub fn remote_manages_flatpak(origin: &str, remotes: &str) -> bool { } #[cfg(test)] -mod remote_ownership_tests { +pub(crate) mod remote_ownership_tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/paths.rs b/crates/update/src/paths.rs index 3238610d1..e1d6ad8ef 100644 --- a/crates/update/src/paths.rs +++ b/crates/update/src/paths.rs @@ -87,7 +87,7 @@ pub fn write_atomic(path: &std::path::Path, bytes: &[u8]) -> Result<(), String> #[cfg(test)] #[cfg(unix)] -mod tests { +pub(crate) mod tests { use super::*; #[craft_ui::testing::trial] diff --git a/crates/update/src/pins.rs b/crates/update/src/pins.rs index 1dc1c3a3a..e82fb5702 100644 --- a/crates/update/src/pins.rs +++ b/crates/update/src/pins.rs @@ -151,7 +151,7 @@ impl Pins { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/platform.rs b/crates/update/src/platform.rs index addb21902..07beed1bd 100644 --- a/crates/update/src/platform.rs +++ b/crates/update/src/platform.rs @@ -299,7 +299,7 @@ pub fn pick_asset<'a>(release: &'a Release, stems: &[&str], platform: Platform, } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/portable.rs b/crates/update/src/portable.rs index e6f951f12..8f057e42f 100644 --- a/crates/update/src/portable.rs +++ b/crates/update/src/portable.rs @@ -472,4 +472,4 @@ fn single_top_folder(files: &[PathBuf]) -> Option { } #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/update/src/process.rs b/crates/update/src/process.rs index cd34af85c..29e584187 100644 --- a/crates/update/src/process.rs +++ b/crates/update/src/process.rs @@ -560,7 +560,7 @@ pub(crate) mod tests { } #[cfg(test)] -mod run_tests { +pub(crate) mod run_tests { use super::*; #[cfg(unix)] @@ -630,7 +630,7 @@ mod run_tests { } #[cfg(test)] -mod inherited_pipe_tests { +pub(crate) mod inherited_pipe_tests { use super::*; use craft_ui::testing::trial; use std::io::{BufRead, BufReader, Read, Write}; @@ -768,7 +768,7 @@ pub(crate) fn cancellable_output(mut cmd: Command, check: impl Fn() -> Result<() #[cfg(test)] #[cfg(target_os = "linux")] -mod update_cancel_tests { +pub(crate) mod update_cancel_tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/proxy.rs b/crates/update/src/proxy.rs index b4e039f61..aee2cc09e 100644 --- a/crates/update/src/proxy.rs +++ b/crates/update/src/proxy.rs @@ -191,7 +191,7 @@ pub fn parse_scutil(out: &str) -> Option { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/queue.rs b/crates/update/src/queue.rs index 59292f01a..2bf756c87 100644 --- a/crates/update/src/queue.rs +++ b/crates/update/src/queue.rs @@ -168,4 +168,4 @@ impl Queue { } #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/update/src/release.rs b/crates/update/src/release.rs index 370d4d92b..eb4ccc41c 100644 --- a/crates/update/src/release.rs +++ b/crates/update/src/release.rs @@ -365,7 +365,7 @@ pub(crate) fn truncate(s: &str, max: usize) -> String { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/self_update.rs b/crates/update/src/self_update.rs index e71c93e52..9f4ac9d95 100644 --- a/crates/update/src/self_update.rs +++ b/crates/update/src/self_update.rs @@ -321,4 +321,4 @@ pub fn prepare_update_with_options( } #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/update/src/source.rs b/crates/update/src/source.rs index 9d24788ca..715624f2a 100644 --- a/crates/update/src/source.rs +++ b/crates/update/src/source.rs @@ -214,7 +214,7 @@ impl ReleaseSource for GitHubSource { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/src/stack_dialogs.rs b/crates/update/src/stack_dialogs.rs index cd577ba8e..619adc1e2 100644 --- a/crates/update/src/stack_dialogs.rs +++ b/crates/update/src/stack_dialogs.rs @@ -23,8 +23,8 @@ use crate::release::{Release, safe_web_link}; use crate::self_update; use crate::updater::Status; -#[cfg(feature = "screen-testing")] -mod stories; +#[cfg(feature = "suite")] +pub(crate) mod stories; const PROMPT_KEY: &str = "updateDialog.prompt"; const CHECK_KEY: &str = "updateDialog.check"; diff --git a/crates/update/src/updater.rs b/crates/update/src/updater.rs index 21ec360aa..8f43e73d8 100644 --- a/crates/update/src/updater.rs +++ b/crates/update/src/updater.rs @@ -1139,4 +1139,4 @@ pub fn download_action(app: &App, release: &Release) -> Action { } #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/update/src/version.rs b/crates/update/src/version.rs index 502afc4ad..d8b68069e 100644 --- a/crates/update/src/version.rs +++ b/crates/update/src/version.rs @@ -148,7 +148,7 @@ pub fn is_update(latest: &Version, installed: &Version) -> bool { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use craft_ui::testing::trial; diff --git a/crates/update/tests/it/main.rs b/crates/update/tests/it/main.rs index 1cd188529..71718ba34 100644 --- a/crates/update/tests/it/main.rs +++ b/crates/update/tests/it/main.rs @@ -2,4 +2,4 @@ // Unwrapping, expecting and panicking on failure is fine in tests, unlike in shipped code. #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] -mod update; +pub(crate) mod update; diff --git a/docs/development.md b/docs/development.md index 0a5ec0911..0cf6e7a25 100644 --- a/docs/development.md +++ b/docs/development.md @@ -28,10 +28,12 @@ A fix to one gallery component, from the edit to its old/new picture on a page: cargo compiles a crate once per distinct feature set, and every crate above it once more, and it unifies features only over the packages a command selects. A framework crate's tests have no eframe in their graph; a domain crate's tests do; the gallery adds every domain crate, whose dependencies turn on more features of egui, wgpu, craft-window, image and others below the framework. Each kind of command would build its own copy of the framework, and wgpu with it. -`cl` selects the `feature-root` package beside the package of every command (`-p -p feature-root`). Its dependencies are the gallery's, with every domain crate's `screen-testing`, so every local build resolves features as the gallery does, and a target directory holds one build of each crate. Nothing of `feature-root` is compiled: its one target is a bin no `cl` command selects (`cl` names the crate's own targets), and only the targets a command names are built, so a render still links one domain crate and a framework crate's tests still link no app. On top, `cl` adds the crate's own test feature (`screen-testing`, else `testing`). The Mac's and CI's commands never select `feature-root` and are unaffected. +`cl` selects the `feature-root` package beside the package of every command (`-p -p feature-root`). Its dependencies are the gallery's, with every domain crate's `suite`, so every local build resolves features as the gallery does, and a target directory holds one build of each crate. Nothing of `feature-root` is compiled: its one target is a bin no `cl` command selects (`cl` names the crate's own targets), and only the targets a command names are built, so a render still links one domain crate and a framework crate's tests still link no app. On top, `cl` adds the crate's own test feature (`suite`, else `screen-testing`, else `testing`). The Mac's and CI's commands never select `feature-root` and are unaffected. Four manifest facts keep this true, and `cl doctor` checks them: `feature-root` lists every optional domain crate of the gallery with the gallery's features, and depends on the gallery without its default features (so the gallery lib's own features stay each command's: `apps` for the gallery, one crate for a render); the story renderer asks its shared dependencies for no feature the gallery's lines lack; dev-dependency lines ask egui for no features (a feature there differs between a crate's tests and everything else); the proc-macro crate pins syn's and proc-macro2's features to everything other derive crates may add, so the one syn every proc macro shares is the same with or without design-lint in the graph. `cl` names any new build of a framework crate in the target directory after each command; after a manifest change one is expected, otherwise run `cl doctor`. +The `testing` feature (or `screen-testing` on domain crates) supplies fixtures and helpers for app tests. The `suite` feature implies that kit and adds framework stories, registrations, trials, snapshots, and the suite runner. Framework and gallery tests enable `suite`; apps should use the kit without it. + ## App workspaces `tools/cl` finds its workspace with `git rev-parse --show-toplevel` from the current directory, so `/path/to/craft-libs/tools/cl` run inside an app's tree builds and tests that tree. An app workspace is one whose root `Cargo.toml` has a `[workspace.metadata.cl]` table. There every command selects the same packages (`selection`), in test mode, without `--features` (the test features come from the dev-dependencies). Each package brings features the others lack, so a command that drops one builds a second copy of the shared crates below it (in PhotoCraft egui, photocraft-io and craft-affinity) and of everything above them. The craft-libs workspace has no such table and keeps the commands above. diff --git a/tools/cl b/tools/cl index 7d0a63648..da8489603 100755 --- a/tools/cl +++ b/tools/cl @@ -31,7 +31,7 @@ the story renderer each pull in different crates, which turn on different featur others below the framework, so each would build its own copy of the framework (minutes, and wgpu again). cl selects the `feature-root` package beside every command's package: its dependencies are the gallery's, with every domain crate, so every command resolves features as the gallery does and builds only the targets it names. The crate's own -test feature (`screen-testing`, else `testing`) is added on top. Builds that take other features (CI's +test feature (`suite`, else `screen-testing`, else `testing`) is added on top. Builds that take other features (CI's `--all-features`, wasm checks) belong on GitHub. docs/development.md has the whole picture. Records: every build cl composes passes cargo's --timings (a report per build in /cargo-timings/, the newest @@ -183,6 +183,8 @@ def package(packages, name): def canonical(packages, name): """The package's name and the features cl adds for it, qualified: its own test feature.""" p = package(packages, name) + if "suite" in p["features"]: + return p["name"], [p["name"] + "/suite"] if "screen-testing" in p["features"]: return p["name"], [p["name"] + "/screen-testing"] if "testing" in p["features"] and p["name"] != "craft-ui-test-kit": @@ -219,7 +221,7 @@ def doctor(top, packages, quiet=False): gallery = packages.get("craft-ui-gallery") if gallery: for d in gallery["dependencies"]: - if d["name"].startswith("craft-") and "screen-testing" in d["features"] and not d["optional"]: + if d["name"].startswith("craft-") and "suite" in d["features"] and not d["optional"]: problems.append(f"crates/ui-gallery/Cargo.toml: {d['name']} must be optional (one feature per domain crate), or the story renderer links every crate") root = packages.get(ROOT) if not root: