Lints: gate test-only items, simplify types, struct literals, doc link

This commit is contained in:
aiongg
2026-11-14 01:25:10 +00:00
parent d08c97c8c5
commit 8378864db3
22 changed files with 54 additions and 43 deletions
+5 -2
View File
@@ -70,6 +70,9 @@ struct Slot<K> {
stack: Option<u32>,
}
/// The test for whether a card takes a drop.
type Takes<'a, K> = Rc<dyn Fn(&K) -> 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<FreeBinMove<K>>,
/// Which cards take a drop of a foreign drag.
drop_into: Option<Rc<dyn Fn(&K) -> bool + 'a>>,
drop_into: Option<Takes<'a, K>>,
/// The drop onto the cards `drop_into` takes.
drops: Vec<DropKind<'a, K>>,
cards: &'a [FreeformCard<K>],
@@ -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<dyn Fn(&K) -> 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<K>, at: &DropAt<K>| matches!(at, DropAt::Onto(card) if onto(card)))];
self.drop_into = Some(takes);
-1
View File
@@ -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<P: Send + Sync + 'static>(mut self, accepts: impl Fn(&Path, &P) -> bool + 'a) -> Self {
let onto = move |payload: &P, at: &DropAt<RowKey>| matches!(at, DropAt::Onto(RowKey::Folder(folder)) if accepts(&folder.path, payload));
self.drop = Some(DropKind::new(DropPlace::Onto, onto));
+2 -1
View File
@@ -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(|| {
+1 -4
View File
@@ -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() }
}
}
+1 -3
View File
@@ -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.
+1 -1
View File
@@ -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),
@@ -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.
+1 -3
View File
@@ -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)) {
@@ -108,16 +108,18 @@ fn transform_phase(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
None => (Vec::new(), false, false),
};
let edits: Vec<TransformEdit<()>> = 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<TransformRequest<()>> = edits.into_iter().filter_map(|edit| kept.session.apply(edit, frame.time)).collect();
if apply || bar.apply || key_apply {
requests.push(kept.session.commit());
+1 -3
View File
@@ -207,9 +207,7 @@ fn preview_pane(ui: &mut Ui, data: &mut StoryData, status: &Pending<PreviewDone,
let window = StorySource::new(image, Preview::Loading).window;
let state = data.value("pane", PaneState { view: FullWindowView::new(), framing: PreviewFraming::default() });
let shown = FillPreviewPane::new(&mut state.view, &mut state.framing, status, &image).frame(Some(window)).show(ui);
let mut output = StoryOutput::default();
output.id = Some(shown.id);
output
StoryOutput { id: Some(shown.id), ..StoryOutput::default() }
}
#[story(FillPreviewPane<'static>, covers = [Default], drive = Drive::Never)]
+1 -1
View File
@@ -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};
+4 -2
View File
@@ -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<Cell<CanvasView>>, Rc<Cell<Option<f64>>>, Rc<Cell<egui::Rect>>);
/// 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<Cell<CanvasView>>, Rc<Cell<Option<f64>>>, Rc<Cell<egui::Rect>>) {
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));
});
+3 -1
View File
@@ -157,9 +157,11 @@ impl CanvasTool for Band {
}
}
type BandCanvas = (Fixture, Rc<RefCell<Band>>, Rc<Cell<Option<CanvasView>>>);
/// 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<RefCell<Band>>, Rc<Cell<Option<CanvasView>>>) {
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::<CanvasView>));
+2 -1
View File
@@ -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),
+1
View File
@@ -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<R>(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
}
+4 -2
View File
@@ -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,
};
@@ -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};
@@ -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<Event> {
(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<Frame> {
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<Frame> {
let mut frames = vec![announced(modifiers).into_iter().chain([pointer_moved(pos)]).collect()];
for _ in 0..count {
+3 -2
View File
@@ -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;
@@ -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)
}
+3 -1
View File
@@ -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)]
@@ -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;