diff --git a/crates/browse/src/ui/freebin/mod.rs b/crates/browse/src/ui/freebin/mod.rs index b431265a8..9f922f85e 100644 --- a/crates/browse/src/ui/freebin/mod.rs +++ b/crates/browse/src/ui/freebin/mod.rs @@ -70,6 +70,9 @@ struct Slot { stack: Option, } +/// The test for whether a card takes a drop. +type Takes<'a, K> = Rc bool + 'a>; + /// The sizes of a card and the space between cards. #[derive(Clone, Debug, PartialEq, ComponentStyle)] #[non_exhaustive] @@ -137,7 +140,7 @@ pub struct FreeBin<'a, K: TextureKey + 'static> { #[prop] moving: Option>, /// Which cards take a drop of a foreign drag. - drop_into: Option bool + 'a>>, + drop_into: Option>, /// The drop onto the cards `drop_into` takes. drops: Vec>, cards: &'a [FreeformCard], @@ -177,7 +180,7 @@ impl<'a, K: TextureKey> FreeBin<'a, K> { /// background. #[must_use] pub fn drop_into(mut self, takes: impl Fn(&K) -> bool + 'a) -> Self { - let takes: Rc bool + 'a> = Rc::new(takes); + let takes: Takes<'a, K> = Rc::new(takes); let onto = Rc::clone(&takes); self.drops = vec![DropKind::new(DropPlace::Onto, move |_: &ListDrag, at: &DropAt| matches!(at, DropAt::Onto(card) if onto(card)))]; self.drop_into = Some(takes); diff --git a/crates/browse/src/ui/places/mod.rs b/crates/browse/src/ui/places/mod.rs index 75e2cf4b7..b129fd351 100644 --- a/crates/browse/src/ui/places/mod.rs +++ b/crates/browse/src/ui/places/mod.rs @@ -197,7 +197,6 @@ impl<'a> PlacesTree<'a> { /// A drag carrying a `P` drops onto a folder row where `accepts` passes for the folder and the payload: the row is /// outlined while the drag is over it, and the release reports [`PlacesEvent::Dropped`]. - #[must_use] pub fn accepts(mut self, accepts: impl Fn(&Path, &P) -> bool + 'a) -> Self { let onto = move |payload: &P, at: &DropAt| matches!(at, DropAt::Onto(RowKey::Folder(folder)) if accepts(&folder.path, payload)); self.drop = Some(DropKind::new(DropPlace::Onto, onto)); diff --git a/crates/dialogs/src/probe.rs b/crates/dialogs/src/probe.rs index ada771bba..1da8fb20e 100644 --- a/crates/dialogs/src/probe.rs +++ b/crates/dialogs/src/probe.rs @@ -13,7 +13,7 @@ // Only Linux probes; the types and helpers stay testable on every platform. #![cfg_attr(not(target_os = "linux"), allow(dead_code))] -use std::sync::{Once, OnceLock}; +use std::sync::OnceLock; /// What the probe found. `None` means it couldn't tell, which counts as present. #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -57,6 +57,7 @@ fn on_path(program: &str, path: &std::ffi::OsStr) -> bool { pub(crate) fn start() { #[cfg(target_os = "linux")] { + use std::sync::Once; static STARTED: Once = Once::new(); STARTED.call_once(|| { let spawned = std::thread::Builder::new().name("file dialog probe".into()).spawn(|| { diff --git a/crates/draw/src/ui/add_beside/mod.rs b/crates/draw/src/ui/add_beside/mod.rs index 34513faa3..fb1856c79 100644 --- a/crates/draw/src/ui/add_beside/mod.rs +++ b/crates/draw/src/ui/add_beside/mod.rs @@ -123,10 +123,7 @@ impl Outcome for AddBesideOutput { #[cfg(feature = "screen-testing")] fn story_facts(&self) -> craft_ui::testing::StoryOutput { - let mut facts = craft_ui::testing::StoryOutput::default(); - facts.id = Some(self.response.id); - facts.clicked = self.added.is_some(); - facts + craft_ui::testing::StoryOutput { id: Some(self.response.id), clicked: self.added.is_some(), ..craft_ui::testing::StoryOutput::default() } } } diff --git a/crates/draw/src/ui/artboard/stories.rs b/crates/draw/src/ui/artboard/stories.rs index 5278f9ea4..6cac751e1 100644 --- a/crates/draw/src/ui/artboard/stories.rs +++ b/crates/draw/src/ui/artboard/stories.rs @@ -71,9 +71,7 @@ fn two_artboards(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { named }); // A board's name is a button: its click is a click of the story. - let mut output = StoryOutput::default(); - output.clicked = shown.inner.unwrap_or_default(); - output + StoryOutput { clicked: shown.inner.unwrap_or_default(), ..StoryOutput::default() } } /// The bar for one board, whose size the story keeps: a preset, Make Portrait or Landscape, or W and H resize it. diff --git a/crates/draw/src/ui/corner/stories.rs b/crates/draw/src/ui/corner/stories.rs index 1329985d7..6b9541ada 100644 --- a/crates/draw/src/ui/corner/stories.rs +++ b/crates/draw/src/ui/corner/stories.rs @@ -148,7 +148,7 @@ fn edit(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { } let output = on_canvas(ui, targets, |ui, at, targets| { let shown = CornerWidgets::new("Corner radius", Bind::bound(&mut *targets)).kinds(kinds).hide_above(hide_above).show_at(ui, at); - let kind = shown.edit.events.iter().filter_map(EditKind::of).last().and_then(|kind| match kind { + let kind = shown.edit.events.iter().filter_map(EditKind::of).next_back().and_then(|kind| match kind { EditKind::Begin => Some(&words.began), EditKind::Update => Some(&words.updated), EditKind::Commit => Some(&words.committed), diff --git a/crates/draw/src/ui/gradient/swatch/stories.rs b/crates/draw/src/ui/gradient/swatch/stories.rs index 7b0409693..73911f69c 100644 --- a/crates/draw/src/ui/gradient/swatch/stories.rs +++ b/crates/draw/src/ui/gradient/swatch/stories.rs @@ -56,9 +56,7 @@ fn gradient_swatch(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { if clicked { *clicks += 1; } - let mut output = StoryOutput::default(); - output.clicked = clicked; - output.readout(craft_i18n::fmt(words.clicked.as_str(), &[("count", clicks.to_string().as_str())])) + StoryOutput { clicked, ..StoryOutput::default() }.readout(craft_i18n::fmt(words.clicked.as_str(), &[("count", clicks.to_string().as_str())])) } /// A gradient fading in, enabled and disabled, each with its name. diff --git a/crates/draw/src/ui/slice/stories.rs b/crates/draw/src/ui/slice/stories.rs index 75effdcfa..7d630169a 100644 --- a/crates/draw/src/ui/slice/stories.rs +++ b/crates/draw/src/ui/slice/stories.rs @@ -243,9 +243,7 @@ fn slice_tool(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let _ = run.host.run(&mut kept.tool); let mut events = run.shown.unwrap_or_default(); events.extend(kept.tool.take_events()); - let mut output = StoryOutput::default(); - output.edits = events.iter().filter_map(edit_kind).collect(); - output.clicked = run.pressed.is_some(); + let output = StoryOutput { edits: events.iter().filter_map(edit_kind).collect(), clicked: run.pressed.is_some(), ..StoryOutput::default() }; if run.pressed == Some(HIDE_AUTO) { settings.hide_auto = !settings.hide_auto; } else if let Some((_, command)) = run.pressed.and_then(|label| COMMANDS.iter().find(|(name, _)| *name == label)) { diff --git a/crates/draw/src/ui/transform/session_overlay/stories.rs b/crates/draw/src/ui/transform/session_overlay/stories.rs index 1495b8a87..5e20e4f3c 100644 --- a/crates/draw/src/ui/transform/session_overlay/stories.rs +++ b/crates/draw/src/ui/transform/session_overlay/stories.rs @@ -108,16 +108,18 @@ fn transform_phase(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { None => (Vec::new(), false, false), }; let edits: Vec> = edits.into_iter().chain(bar.edits).collect(); - let mut output = StoryOutput::default(); - output.edits = edits - .iter() - .filter_map(|edit| match edit { - TransformEdit::Box(event) => EditKind::of(event), - TransformEdit::Fields(event) => EditKind::of(event), - _ => None, - }) - .collect(); - output.clicked = bar.apply || bar.discard; + let output = StoryOutput { + edits: edits + .iter() + .filter_map(|edit| match edit { + TransformEdit::Box(event) => EditKind::of(event), + TransformEdit::Fields(event) => EditKind::of(event), + _ => None, + }) + .collect(), + clicked: bar.apply || bar.discard, + ..StoryOutput::default() + }; let mut requests: Vec> = edits.into_iter().filter_map(|edit| kept.session.apply(edit, frame.time)).collect(); if apply || bar.apply || key_apply { requests.push(kept.session.commit()); diff --git a/crates/imaging/src/ui/fill/stories.rs b/crates/imaging/src/ui/fill/stories.rs index 6f2736738..f65994a98 100644 --- a/crates/imaging/src/ui/fill/stories.rs +++ b/crates/imaging/src/ui/fill/stories.rs @@ -207,9 +207,7 @@ fn preview_pane(ui: &mut Ui, data: &mut StoryData, status: &Pending, covers = [Default], drive = Drive::Never)] diff --git a/crates/indd/src/lib.rs b/crates/indd/src/lib.rs index 657b417fc..7afbac5c9 100644 --- a/crates/indd/src/lib.rs +++ b/crates/indd/src/lib.rs @@ -1,7 +1,7 @@ //! Shared InDesign document conversion boundary. //! //! InDesign's binary document model is converted to IDML here. Applications can import the -//! resulting package through [`craft_idml`] while retaining only their own model and UI mapping. +//! resulting package through `craft_idml` while retaining only their own model and UI mapping. pub use indd::header::SIGNATURE; pub use indd::{Conversion, Error, Preview, Warning}; diff --git a/crates/ui-canvas/tests/it/canvas/navigate.rs b/crates/ui-canvas/tests/it/canvas/navigate.rs index 508ae6081..8f669a051 100644 --- a/crates/ui-canvas/tests/it/canvas/navigate.rs +++ b/crates/ui-canvas/tests/it/canvas/navigate.rs @@ -167,9 +167,11 @@ fn at_a_whole_device_zoom_with_no_rotation_the_shown_view_puts_document_pixels_o assert!((p.x - p.x.round()).abs() < 1e-3 && (p.y - p.y.round()).abs() < 1e-3, "a view set at a whole zoom is shown aligned: {p:?}"); } +type WheelRig = (Fixture, Rc>, Rc>>, Rc>); + /// A canvas over a large document at zoom 1 below a framework number field and an app's own text field, on `os`: the /// fixture, the view it shows, the number and where the app's field is. -fn wheel_rig(os: Platform) -> (Fixture, Rc>, Rc>>, Rc>) { +fn wheel_rig(os: Platform) -> WheelRig { let view = Rc::new(Cell::new(CanvasView::new(egui::Rect::ZERO, Point::new(2000.0, 2000.0), 1.0))); let number = Rc::new(Cell::new(Some(10.0))); let app_field = Rc::new(Cell::new(egui::Rect::NOTHING)); @@ -312,7 +314,7 @@ fn a_wheel_zoom_keeps_the_point_under_the_pointer_where_an_app_widget_covers_the given.rect = ui.available_rect_before_wrap(); let canvas = Canvas::new("Document").document(Size::new(4000.0, 4000.0)).view(given).show(ui, |ui, body| { // An app's own tool widget over the whole body, as an app that runs its tools itself places one. - ui.interact(body.rect, egui::Id::new("app tools"), egui::Sense::click_and_drag()); + ui.interact(body.rect, egui::Id::unique("app tools"), egui::Sense::click_and_drag()); }); shown.set(canvas.output.view.unwrap_or(given)); }); diff --git a/crates/ui-canvas/tests/it/canvas/tool.rs b/crates/ui-canvas/tests/it/canvas/tool.rs index 625434b21..935da3627 100644 --- a/crates/ui-canvas/tests/it/canvas/tool.rs +++ b/crates/ui-canvas/tests/it/canvas/tool.rs @@ -157,9 +157,11 @@ impl CanvasTool for Band { } } +type BandCanvas = (Fixture, Rc>, Rc>>); + /// The hover autoscroll as an app runs it: the canvas shows a document zoomed in past the room, and the app moves its /// view by the host's `scroll`. Returns the fixture, the tool and the app's view. -fn band_canvas(scrolls: bool) -> (Fixture, Rc>, Rc>>) { +fn band_canvas(scrolls: bool) -> BandCanvas { const DOCUMENT: Size = Size::new(1200.0, 900.0); let tool = Rc::new(RefCell::new(Band { scrolls, hovers: 0 })); let view = Rc::new(Cell::new(None::)); diff --git a/crates/ui-canvas/tests/it/canvas/tools.rs b/crates/ui-canvas/tests/it/canvas/tools.rs index 493e8584b..b539016d7 100644 --- a/crates/ui-canvas/tests/it/canvas/tools.rs +++ b/crates/ui-canvas/tests/it/canvas/tools.rs @@ -29,7 +29,8 @@ fn view_commands_run_with_their_facts_and_are_disabled_without() { [rect.origin(), Point::new(rect.x1, rect.y1)].iter().all(|corner| view.rect.expand(0.5).contains(view.to_screen(*corner))) }; // What each command owes the view it changed. - let rows: [(ViewCommands, &dyn Fn(&CanvasView) -> bool); 4] = [ + type Owed<'a> = &'a dyn Fn(&CanvasView) -> bool; + let rows: [(ViewCommands, Owed<'_>); 4] = [ (ViewCommands::TwoHundredPercent, &|view| (device(view) - 2.0).abs() < 1e-9 && view.center == start.center), // Print Size: the screen's 72 ppi over the document's 300. (ViewCommands::PrintSize, &|view| (device(view) - 72.0 / 300.0).abs() < 1e-9 && view.center == start.center), diff --git a/crates/ui-contract/src/layout/body.rs b/crates/ui-contract/src/layout/body.rs index 4d477405e..eb02b5bbe 100644 --- a/crates/ui-contract/src/layout/body.rs +++ b/crates/ui-contract/src/layout/body.rs @@ -1019,6 +1019,7 @@ fn found(ctx: &egui::Context, sizing: bool, id: Id, room: Vec2, took: Vec2) { /// run found, `SpaceBetween` shares the room its children left there between them, and `Grid` places its cells from /// the widest child per column and tallest per row there. Without a measuring run they place as `Start`, spread at /// the gap and size columns from the cells as they come. +#[cfg(feature = "testing")] pub(crate) fn run_body(ui: &mut Ui, env: &Env, id: Id, layout: &BodyLayout, gap: Vec2, body: impl FnMut(&mut Ui) -> R) -> R { run_body_measured(ui, env, id, layout, gap, None, body).0 } diff --git a/crates/ui-contract/src/layout/mod.rs b/crates/ui-contract/src/layout/mod.rs index 5386274bf..baf0a8b31 100644 --- a/crates/ui-contract/src/layout/mod.rs +++ b/crates/ui-contract/src/layout/mod.rs @@ -21,8 +21,10 @@ pub(crate) use crate::runtime::env::Shrink; #[doc(hidden)] pub use body::place_in_flow; +#[cfg(feature = "testing")] +pub(crate) use body::run_body; pub(crate) use body::{ InFlow, MainFill, close_first_line, counting_fills, fill_share, flow_fill_room, flow_region, flow_room, in_grid_content_column, leaf_fill_room, - main_fill, open_first_lines, place_in_cell, report_least, report_shrink, row_alone_room, run_body, run_body_measured, shares_y, shrink_cap, - take_in_flow, view_room, + main_fill, open_first_lines, place_in_cell, report_least, report_shrink, row_alone_room, run_body_measured, shares_y, shrink_cap, take_in_flow, + view_room, }; diff --git a/crates/ui-contract/src/runtime/egui/access.rs b/crates/ui-contract/src/runtime/egui/access.rs index a0420f06a..ef40f3516 100644 --- a/crates/ui-contract/src/runtime/egui/access.rs +++ b/crates/ui-contract/src/runtime/egui/access.rs @@ -10,6 +10,7 @@ mod text; mod tree; use crate::runtime::pass_state; +#[cfg(feature = "testing")] use egui::FullOutput; use egui::{Context, Id, ViewportId}; use std::collections::{HashMap, HashSet}; diff --git a/crates/ui-contract/src/runtime/egui/injected.rs b/crates/ui-contract/src/runtime/egui/injected.rs index 50d682663..32cf14ea4 100644 --- a/crates/ui-contract/src/runtime/egui/injected.rs +++ b/crates/ui-contract/src/runtime/egui/injected.rs @@ -25,6 +25,7 @@ pub(crate) fn pointer_moved(pos: Pos2) -> Event { } /// `button` going down or up at `pos` with `modifiers`. +#[cfg(feature = "testing")] pub(crate) fn button(pos: Pos2, button: egui::PointerButton, pressed: bool, modifiers: Modifiers) -> Event { Event::PointerButton { pos, button, pressed, modifiers } } @@ -57,17 +58,20 @@ pub(crate) fn text_event(text: &str) -> Event { } /// The announcement of `modifiers`, none when no modifier is held. +#[cfg(feature = "testing")] fn announced(modifiers: Modifiers) -> Option { (modifiers != Modifiers::NONE).then(|| modifiers_changed(modifiers)) } /// The frame that clears `modifiers`, none when none was held. +#[cfg(feature = "testing")] fn cleared(modifiers: Modifiers) -> Option { announced(modifiers).map(|_| vec![modifiers_changed(Modifiers::NONE)]) } /// A move to `pos` (with `modifiers` announced first), then `count` times a press and a release of `button`, one /// frame each; `modifiers` are cleared in a last frame when they were set. +#[cfg(feature = "testing")] pub(crate) fn click_frames(pos: Pos2, pressed_button: egui::PointerButton, count: u32, modifiers: Modifiers) -> Vec { let mut frames = vec![announced(modifiers).into_iter().chain([pointer_moved(pos)]).collect()]; for _ in 0..count { diff --git a/crates/ui-contract/src/runtime/keys.rs b/crates/ui-contract/src/runtime/keys.rs index 09bf53c39..052ab8a39 100644 --- a/crates/ui-contract/src/runtime/keys.rs +++ b/crates/ui-contract/src/runtime/keys.rs @@ -32,14 +32,15 @@ pub(crate) use input::{input_hook, queue_nav, take_menu_keys, take_nav}; pub use intents::Intents; #[doc(hidden)] pub use intents::intents_of; +#[cfg(feature = "testing")] +pub(crate) use intents::lent_taken; #[doc(hidden)] pub use intents::settle; #[doc(hidden)] pub use intents::take_submit; pub use intents::with_window_intents; pub(crate) use intents::{ - Lent, context_part, context_request, give_back, lend, lent_taken, request_context, route_whole_reset, scope_escape, take_cancel, - take_window_cancel, + Lent, context_part, context_request, give_back, lend, request_context, route_whole_reset, scope_escape, take_cancel, take_window_cancel, }; pub(crate) use nodes::{redirect_node, register_expanded, register_node}; pub use route::focus_holds; diff --git a/crates/ui-contract/src/runtime/keys/intents.rs b/crates/ui-contract/src/runtime/keys/intents.rs index 78936e9c7..704aba64a 100644 --- a/crates/ui-contract/src/runtime/keys/intents.rs +++ b/crates/ui-contract/src/runtime/keys/intents.rs @@ -356,6 +356,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")] pub(crate) fn lent_taken(ctx: &Context) -> u64 { current(ctx, |stage| stage.lent_taken) } diff --git a/crates/ui-contract/src/runtime/measure.rs b/crates/ui-contract/src/runtime/measure.rs index 7d73c5e8d..c281c04a5 100644 --- a/crates/ui-contract/src/runtime/measure.rs +++ b/crates/ui-contract/src/runtime/measure.rs @@ -4,7 +4,9 @@ use super::egui::memory as store; use super::pass_state; -use egui::{Context, Id}; +use egui::Context; +#[cfg(feature = "testing")] +use egui::Id; /// The widths per column the items measured inside `cell_widths` report, innermost call last. #[derive(Default)] diff --git a/crates/ui-contract/src/runtime/windows/shell.rs b/crates/ui-contract/src/runtime/windows/shell.rs index ce8f92ac2..5e9251d43 100644 --- a/crates/ui-contract/src/runtime/windows/shell.rs +++ b/crates/ui-contract/src/runtime/windows/shell.rs @@ -6,8 +6,8 @@ use super::{Record, shared}; use crate::runtime::egui::viewports; use crate::runtime::frame::PerViewport; #[cfg(feature = "testing")] -use craft_host::target::Runtime; -use craft_host::target::{Caps, EdgeInsets, Os, ShellInfo, WindowChrome, WindowInfo, WindowKind, WindowState}; +use craft_host::target::{Caps, Runtime}; +use craft_host::target::{EdgeInsets, Os, ShellInfo, WindowChrome, WindowInfo, WindowKind, WindowState}; use egui::{Context, ViewportId}; use std::sync::Arc;