mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-30 18:27:00 +01:00
Clippy: port test code and the cancel response of upstream callers
ToolHost::cancel returns the port's ToolHostResponse (must_use); the fill, liquify, raw develop and vanishing point cancels take it as wide_angle and select_mask do, as their tools request no URLs. Port tests: unused Props import, Id::unique for a fixed id, a one-range Vec from once, as_chunks, Result::inspect, and the dropper trial's hover and sample phases as helpers under the complexity cap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3562f506fe
commit
b2a4cfc26f
10 files changed
+72
-53
No files matched your search
@@ -12,10 +12,9 @@ fn a_failed_accept_waits_before_the_next() {
|
||||
let failed = || Err(std::io::Error::other("no file descriptors left"));
|
||||
let waits = Cell::new(0);
|
||||
let incoming = [failed(), Ok(1), failed(), failed(), Ok(2)].into_iter().map(|result| {
|
||||
result.map(|connection| {
|
||||
let preceding_failures = if connection == 1 { 1 } else { 3 };
|
||||
result.inspect(|connection| {
|
||||
let preceding_failures = if *connection == 1 { 1 } else { 3 };
|
||||
assert_eq!(waits.get(), preceding_failures, "every failure waits before the next accept");
|
||||
connection
|
||||
})
|
||||
});
|
||||
let connections: Vec<_> = accepted(incoming, || waits.set(waits.get() + 1)).collect();
|
||||
|
||||
@@ -135,29 +135,35 @@ impl CaptureSource for Late {
|
||||
|
||||
const PICKED: Srgba = Srgba { r: 0.25, g: 0.5, b: 0.75, a: 1.0 };
|
||||
|
||||
#[trial]
|
||||
fn a_pick_dropper_picks_once_and_ends_on_escape_a_secondary_press_or_a_press_off_the_document() {
|
||||
let make = |mode| {
|
||||
let reads = Rc::new(Cell::new(0));
|
||||
let sampled = Rc::clone(&reads);
|
||||
let dropper = DropperTool::new(move |at| {
|
||||
sampled.set(sampled.get() + 1);
|
||||
(at[0] >= 0.0 && at[1] >= 0.0 && at[0] < f64::from(SIZE[0]) && at[1] < f64::from(SIZE[1])).then_some(PICKED)
|
||||
})
|
||||
.mode(mode);
|
||||
let rerun = Rc::new(Cell::new(false));
|
||||
let discard = Rc::clone(&rerun);
|
||||
let mut tool = ToolFixture::with_view("Dropper", dropper, sampler_view, move |ui, _| {
|
||||
if frame::discardable(ui.ctx()) && discard.replace(false) {
|
||||
frame::discard_pass(ui.ctx(), "rerun a dropper pass");
|
||||
}
|
||||
});
|
||||
tool.fixture().room(vec2(800.0, 600.0)).settle();
|
||||
(tool, rerun, reads)
|
||||
};
|
||||
let inside = |tool: &ToolFixture<DropperTool<'static>>| tool.canvas().rect.min + vec2(100.5, 50.5);
|
||||
/// A dropper in `mode` over the sampled document, the flag that discards its next pass, and its count of samples read.
|
||||
fn dropper_rig(mode: DropperMode) -> (ToolFixture<DropperTool<'static>>, Rc<Cell<bool>>, Rc<Cell<usize>>) {
|
||||
let reads = Rc::new(Cell::new(0));
|
||||
let sampled = Rc::clone(&reads);
|
||||
let dropper = DropperTool::new(move |at| {
|
||||
sampled.set(sampled.get() + 1);
|
||||
(at[0] >= 0.0 && at[1] >= 0.0 && at[0] < f64::from(SIZE[0]) && at[1] < f64::from(SIZE[1])).then_some(PICKED)
|
||||
})
|
||||
.mode(mode);
|
||||
let rerun = Rc::new(Cell::new(false));
|
||||
let discard = Rc::clone(&rerun);
|
||||
let mut tool = ToolFixture::with_view("Dropper", dropper, sampler_view, move |ui, _| {
|
||||
if frame::discardable(ui.ctx()) && discard.replace(false) {
|
||||
frame::discard_pass(ui.ctx(), "rerun a dropper pass");
|
||||
}
|
||||
});
|
||||
tool.fixture().room(vec2(800.0, 600.0)).settle();
|
||||
(tool, rerun, reads)
|
||||
}
|
||||
|
||||
let (mut tool, rerun, reads) = make(DropperMode::Pick);
|
||||
/// A point inside the sampled document.
|
||||
fn inside(tool: &ToolFixture<DropperTool<'static>>) -> Pos2 {
|
||||
tool.canvas().rect.min + vec2(100.5, 50.5)
|
||||
}
|
||||
|
||||
/// A pick dropper's hover: its loupe stays while the pointer rests and through a rerun, leaves with the pointer, and
|
||||
/// neither samples again nor picks.
|
||||
fn a_pick_droppers_hover_keeps_its_loupe_and_never_picks() {
|
||||
let (mut tool, rerun, reads) = dropper_rig(DropperMode::Pick);
|
||||
let at = inside(&tool);
|
||||
let without_loupe = tool.fixture().texts().to_vec();
|
||||
tool.move_to(at);
|
||||
@@ -184,6 +190,34 @@ fn a_pick_dropper_picks_once_and_ends_on_escape_a_secondary_press_or_a_press_off
|
||||
let mut dropper = tool.tool_mut();
|
||||
assert!(dropper.take_at().is_none() && !dropper.ended(), "hover never picks or disarms");
|
||||
}
|
||||
}
|
||||
|
||||
/// A sample dropper samples on press, through a drag and once on release, stays armed, and a cancel never ends it.
|
||||
fn a_sample_dropper_samples_while_pressed_and_stays_armed() {
|
||||
let (mut tool, rerun, reads) = dropper_rig(DropperMode::Sample);
|
||||
let at = inside(&tool);
|
||||
tool.press_at(at);
|
||||
assert_eq!(tool.tool_mut().take(), Some(PICKED), "sample mode samples on press");
|
||||
tool.move_to(at + vec2(60.0, 20.0));
|
||||
assert_eq!(tool.tool_mut().take(), Some(PICKED), "sample mode samples during a drag");
|
||||
let before_release = reads.get();
|
||||
rerun.set(true);
|
||||
tool.release_at(at + vec2(60.0, 20.0));
|
||||
assert_eq!(reads.get(), before_release + 1, "a second pass in one frame does not repeat the release sample");
|
||||
assert_eq!(tool.tool_mut().take(), Some(PICKED));
|
||||
assert!(!tool.tool().ended(), "sample mode stays armed after release");
|
||||
tool.escape();
|
||||
{
|
||||
let mut dropper = tool.tool_mut();
|
||||
assert!(dropper.cancelled() && !dropper.ended(), "sample cancellation never becomes a pick ending");
|
||||
}
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_pick_dropper_picks_once_and_ends_on_escape_a_secondary_press_or_a_press_off_the_document() {
|
||||
let make = dropper_rig;
|
||||
a_pick_droppers_hover_keeps_its_loupe_and_never_picks();
|
||||
a_sample_dropper_samples_while_pressed_and_stays_armed();
|
||||
|
||||
let (mut tool, rerun, reads) = make(DropperMode::Pick);
|
||||
let at = inside(&tool);
|
||||
@@ -262,24 +296,6 @@ fn a_pick_dropper_picks_once_and_ends_on_escape_a_secondary_press_or_a_press_off
|
||||
let mut dropper = tool.tool_mut();
|
||||
assert!(dropper.ended() && dropper.take().is_some(), "a later click still picks after a discarded pass");
|
||||
}
|
||||
|
||||
let (mut tool, rerun, reads) = make(DropperMode::Sample);
|
||||
let at = inside(&tool);
|
||||
tool.press_at(at);
|
||||
assert_eq!(tool.tool_mut().take(), Some(PICKED), "sample mode samples on press");
|
||||
tool.move_to(at + vec2(60.0, 20.0));
|
||||
assert_eq!(tool.tool_mut().take(), Some(PICKED), "sample mode samples during a drag");
|
||||
let before_release = reads.get();
|
||||
rerun.set(true);
|
||||
tool.release_at(at + vec2(60.0, 20.0));
|
||||
assert_eq!(reads.get(), before_release + 1, "a second pass in one frame does not repeat the release sample");
|
||||
assert_eq!(tool.tool_mut().take(), Some(PICKED));
|
||||
assert!(!tool.tool().ended(), "sample mode stays armed after release");
|
||||
tool.escape();
|
||||
{
|
||||
let mut dropper = tool.tool_mut();
|
||||
assert!(dropper.cancelled() && !dropper.ended(), "sample cancellation never becomes a pick ending");
|
||||
}
|
||||
}
|
||||
|
||||
#[trial]
|
||||
|
||||
@@ -841,7 +841,8 @@ impl ContentAwareFillWorkspace {
|
||||
/// passes) only the canvas's own state is dropped.
|
||||
fn cancel_gesture(&mut self, ctx: Option<&Context>, reason: CancelReason) {
|
||||
if let (Some(ctx), Some(id)) = (ctx, self.canvas_id) {
|
||||
match self.tool {
|
||||
// These tools request no URLs, so the cancel response has nothing to open.
|
||||
let _ = match self.tool {
|
||||
FillTool::Hand => ToolHost::new().cancel(ctx, id, &mut self.hand, reason),
|
||||
FillTool::Zoom => ToolHost::new().cancel(ctx, id, &mut self.zoom, reason),
|
||||
FillTool::SamplingBrush | FillTool::Lasso => {
|
||||
|
||||
@@ -698,7 +698,8 @@ impl Edit {
|
||||
let cursor = self.cursor_options;
|
||||
let LiquifyView { canvas, canvas_id, .. } = state;
|
||||
if let (Some(ctx), Some(id)) = (ctx, *canvas_id) {
|
||||
match self.settings.tool {
|
||||
// These tools request no URLs, so the cancel response has nothing to open.
|
||||
let _ = match self.settings.tool {
|
||||
LiquifyTool::Hand => ToolHost::new().cancel(ctx, id, &mut canvas.hand, reason),
|
||||
LiquifyTool::Zoom => ToolHost::new().cancel(ctx, id, &mut canvas.zoom, reason),
|
||||
_ => ToolHost::new().cancel(ctx, id, &mut canvas.tool(&mut self.settings, &cursor), reason),
|
||||
|
||||
@@ -419,16 +419,17 @@ impl RawDevelopWorkspace {
|
||||
fn end_gesture(&mut self, ctx: &Context, reason: CancelReason) {
|
||||
let Some(canvas) = self.canvas else { return };
|
||||
let size = [self.size.width, self.size.height];
|
||||
// These tools request no URLs, so the cancel response has nothing to open.
|
||||
match self.tool {
|
||||
RawTool::Hand => {}
|
||||
RawTool::Zoom => {
|
||||
if let Some(zoom) = self.zoom_tool.as_mut() {
|
||||
ToolHost::new().cancel(ctx, canvas, zoom, reason);
|
||||
let _ = ToolHost::new().cancel(ctx, canvas, zoom, reason);
|
||||
}
|
||||
}
|
||||
RawTool::Sampler => {
|
||||
let mut pass = self.sampler_tool.pass(&self.samplers, size);
|
||||
ToolHost::new().cancel(ctx, canvas, &mut pass, reason);
|
||||
let _ = ToolHost::new().cancel(ctx, canvas, &mut pass, reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -639,12 +639,13 @@ impl VanishingPointWorkspace {
|
||||
/// Cancels the gesture the strip's tool holds with `reason`: the editor puts back what the press found (the
|
||||
/// Hand's and Zoom's drags go through the host).
|
||||
fn cancel_gesture(&mut self, ctx: &egui::Context, state: &VanishingView, reason: CancelReason, out: &mut Vec<VanishingPointEvent>) {
|
||||
// The Hand and Zoom request no URLs, so the cancel response has nothing to open.
|
||||
match (self.strip, state.canvas) {
|
||||
(VanishingPointStripTool::Hand, Some(canvas)) => {
|
||||
ToolHost::new().cancel(ctx, canvas, &mut self.hand, reason);
|
||||
let _ = ToolHost::new().cancel(ctx, canvas, &mut self.hand, reason);
|
||||
}
|
||||
(VanishingPointStripTool::Zoom, Some(canvas)) => {
|
||||
ToolHost::new().cancel(ctx, canvas, &mut self.zoom, reason);
|
||||
let _ = ToolHost::new().cancel(ctx, canvas, &mut self.zoom, reason);
|
||||
}
|
||||
_ => self.editor.cancel(&mut self.session, reason),
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::rc::Rc;
|
||||
use craft_behavior::IconId;
|
||||
use craft_menu::ribbon::{BackLook, BackstageCommands, BackstageEntry, BackstageEvent, BackstageView};
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{Bind, Props as _, Role, Show as _};
|
||||
use craft_ui::contract::{Bind, Role, Show as _};
|
||||
use craft_ui::runtime::commands::CommandSet as _;
|
||||
use craft_ui::runtime::egui::access::NodeKey;
|
||||
use craft_ui::runtime::env::WindowKey;
|
||||
|
||||
@@ -566,7 +566,7 @@ fn a_tab_keeps_its_own_group_row_scroll_offset_when_it_is_picked_again() {
|
||||
let discard = rerun.clone();
|
||||
let forward_name = Rc::new(RefCell::new(Label::Empty));
|
||||
let name = forward_name.clone();
|
||||
let id = Id::new("ribbon.scroll_trial");
|
||||
let id = Id::unique("ribbon.scroll_trial");
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
if discard.take() {
|
||||
ui.ctx().request_discard("the ribbon input frame runs twice");
|
||||
|
||||
@@ -63,7 +63,7 @@ const LINE: usize = 4;
|
||||
|
||||
impl Host {
|
||||
fn rows(&self) -> Vec<Range<usize>> {
|
||||
let Some(columns) = self.columns else { return vec![0..self.text.chars().count()] };
|
||||
let Some(columns) = self.columns else { return std::iter::once(0..self.text.chars().count()).collect() };
|
||||
let chars: Vec<char> = self.text.chars().collect();
|
||||
let mut rows = Vec::new();
|
||||
let mut start = 0;
|
||||
|
||||
@@ -139,7 +139,7 @@ fn mark_segments(shapes: &[Shape], ink: Color32) -> Vec<[Pos2; 2]> {
|
||||
segments.extend(path.points.windows(2).map(|pair| [pair[0], pair[1]]));
|
||||
}
|
||||
Shape::Mesh(mesh) => {
|
||||
for triangle in mesh.indices.chunks_exact(3) {
|
||||
for triangle in mesh.indices.as_chunks::<3>().0 {
|
||||
for (a, b) in [(0, 1), (1, 2), (2, 0)] {
|
||||
let (a, b) = (mesh.vertices[triangle[a] as usize], mesh.vertices[triangle[b] as usize]);
|
||||
if a.color == ink && b.color == ink {
|
||||
|
||||
Reference in new issue
Block a user