VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Format: rustfmt after the batch
bflatasticc895f640632f
diff --git a/crates/doc/src/corners.rs b/crates/doc/src/corners.rsindex e69b528e5..24228604a 100644--- a/crates/doc/src/corners.rs+++ b/crates/doc/src/corners.rs@@ -60,7 +60,9 @@ pub fn convert_radii_relative(live: &mut LiveShape, relative: bool) {}}match live {- LiveShape::Rectangle { radii_relative: rel, .. } | LiveShape::Polygon { radii_relative: rel, .. } | LiveShape::Path { radii_relative: rel, .. } => {+ LiveShape::Rectangle { radii_relative: rel, .. }+ | LiveShape::Polygon { radii_relative: rel, .. }+ | LiveShape::Path { radii_relative: rel, .. } => {*rel = relative;}LiveShape::Ellipse { .. } | LiveShape::Line { .. } => {}@@ -290,7 +292,14 @@ mod tests {#[test]fn rectangle_corners_map_to_their_anchors() {- let l = LiveShape::Rectangle { w: 100.0, h: 50.0, radii: [0.0, 10.0, 0.0, 0.0], kinds: Default::default(), radii_relative: false, xf: Affine::IDENTITY };+ let l = LiveShape::Rectangle {+ w: 100.0,+ h: 50.0,+ radii: [0.0, 10.0, 0.0, 0.0],+ kinds: Default::default(),+ radii_relative: false,+ xf: Affine::IDENTITY,+ };let path = l.to_path();let c = LiveCorners::new(&path, Some(&l)).unwrap();// Anchors: top-left, the top-right corner's two, bottom-right, bottom-left.@@ -333,7 +342,8 @@ mod tests {/// A polygon's corners are cut in the document and survive a change of sides when shared.#[test]fn polygon_corners_follow_their_sides() {- let mut l = LiveShape::Polygon { radius: 50.0, sides: 6, xf: Affine::translate((100.0, 100.0)), radii: vec![], kinds: vec![], radii_relative: false };+ let mut l =+ LiveShape::Polygon { radius: 50.0, sides: 6, xf: Affine::translate((100.0, 100.0)), radii: vec![], kinds: vec![], radii_relative: false };let (mut path, mut live) = (l.to_path(), Some(Box::new(l.clone())));set_corners(&mut path, &mut live, &set(&[0, 1, 2, 3, 4, 5]), Some(8.0), None);assert_eq!(path.anchor_count(), 12);@@ -355,11 +365,25 @@ mod tests {#[test]fn relative_radii_scale_with_rectangle_size() {- let l = LiveShape::Rectangle { w: 100.0, h: 100.0, radii: [0.25, 0.25, 0.25, 0.25], kinds: Default::default(), radii_relative: true, xf: Affine::IDENTITY };+ let l = LiveShape::Rectangle {+ w: 100.0,+ h: 100.0,+ radii: [0.25, 0.25, 0.25, 0.25],+ kinds: Default::default(),+ radii_relative: true,+ xf: Affine::IDENTITY,+ };let path = l.to_path();let c = LiveCorners::new(&path, Some(&l)).unwrap();let r0 = c.drawn_radius(0);- let l2 = LiveShape::Rectangle { w: 200.0, h: 200.0, radii: [0.25, 0.25, 0.25, 0.25], kinds: Default::default(), radii_relative: true, xf: Affine::IDENTITY };+ let l2 = LiveShape::Rectangle {+ w: 200.0,+ h: 200.0,+ radii: [0.25, 0.25, 0.25, 0.25],+ kinds: Default::default(),+ radii_relative: true,+ xf: Affine::IDENTITY,+ };let path2 = l2.to_path();let c2 = LiveCorners::new(&path2, Some(&l2)).unwrap();assert!((c2.drawn_radius(0) / r0 - 2.0).abs() < 0.05, "{r0} → {}", c2.drawn_radius(0));@@ -367,7 +391,14 @@ mod tests {#[test]fn convert_between_relative_and_absolute_radii() {- let mut l = LiveShape::Rectangle { w: 100.0, h: 50.0, radii: [10.0, 0.0, 0.0, 0.0], kinds: Default::default(), radii_relative: false, xf: Affine::IDENTITY };+ let mut l = LiveShape::Rectangle {+ w: 100.0,+ h: 50.0,+ radii: [10.0, 0.0, 0.0, 0.0],+ kinds: Default::default(),+ radii_relative: false,+ xf: Affine::IDENTITY,+ };let before = LiveCorners::new(&l.to_path(), Some(&l)).unwrap().drawn_radius(0);convert_radii_relative(&mut l, true);assert!(l.radii_relative());diff --git a/crates/doc/src/node.rs b/crates/doc/src/node.rsindex 2a649ec85..ad2d76b19 100644--- a/crates/doc/src/node.rs+++ b/crates/doc/src/node.rs@@ -146,7 +146,9 @@ fn is_false(b: &bool) -> bool {impl LiveShape {pub fn radii_relative(&self) -> bool {match self {- LiveShape::Rectangle { radii_relative, .. } | LiveShape::Polygon { radii_relative, .. } | LiveShape::Path { radii_relative, .. } => *radii_relative,+ LiveShape::Rectangle { radii_relative, .. } | LiveShape::Polygon { radii_relative, .. } | LiveShape::Path { radii_relative, .. } => {+ *radii_relative+ }LiveShape::Ellipse { .. } | LiveShape::Line { .. } => false,}}@@ -2205,14 +2207,28 @@ mod tests {#[test]fn rect_live_shape_roundtrip() {- let l = LiveShape::Rectangle { w: 10.0, h: 20.0, radii: [0.0; 4], kinds: Default::default(), radii_relative: false, xf: Affine::translate((5.0, 5.0)) };+ let l = LiveShape::Rectangle {+ w: 10.0,+ h: 20.0,+ radii: [0.0; 4],+ kinds: Default::default(),+ radii_relative: false,+ xf: Affine::translate((5.0, 5.0)),+ };assert_eq!(l.to_path().bounds(), Some(Rect::new(5.0, 5.0, 15.0, 25.0)));assert_eq!(l.label(), "Rectangle");}#[test]fn corner_kinds_save_only_when_some_corner_isnt_round() {- let mut l = LiveShape::Rectangle { w: 100.0, h: 50.0, radii: [0.0, 10.0, 0.0, 0.0], kinds: Default::default(), radii_relative: false, xf: Affine::IDENTITY };+ let mut l = LiveShape::Rectangle {+ w: 100.0,+ h: 50.0,+ radii: [0.0, 10.0, 0.0, 0.0],+ kinds: Default::default(),+ radii_relative: false,+ xf: Affine::IDENTITY,+ };// Older files read as round.let json = serde_json::to_value(&l).unwrap();assert!(json.get("kinds").is_none(), "{json}");diff --git a/crates/effects/src/group.rs b/crates/effects/src/group.rsindex 72dfb3274..4b08295d8 100644--- a/crates/effects/src/group.rs+++ b/crates/effects/src/group.rs@@ -176,11 +176,7 @@ fn hard_mix_face(path: PathData, covering: &[usize], shapes: &[po::Shape], sourcpainted = true;}}- let fill = if painted {- Paint::solid(Color::cmyk(cmyk[0], cmyk[1], cmyk[2], cmyk[3]))- } else {- Paint::None- };+ let fill = if painted { Paint::solid(Color::cmyk(cmyk[0], cmyk[1], cmyk[2], cmyk[3])) } else { Paint::None };let top = covering.last().and_then(|&si| sources.get(shapes[si].key as usize));let mut n = Node::path(top.map_or(NodeId(0), |s| s.id), path, Appearance::basic(fill, Paint::None, 0.0));if let Some(src) = top {diff --git a/crates/effects/src/pixel/artistic.rs b/crates/effects/src/pixel/artistic.rsindex adcbaccea..edd5b9342 100644--- a/crates/effects/src/pixel/artistic.rs+++ b/crates/effects/src/pixel/artistic.rs@@ -463,11 +463,7 @@ pub(super) fn dry_brush(px: &mut [[u8; 4]], w: usize, h: usize, space: &PixelSpa*a /= SAMPLES as f32;}let a = acc[3].clamp(0.0, 1.0);- let c = if a > 1e-6 {- [0, 1, 2].map(|i| (acc[i] / a).clamp(0.0, 1.0))- } else {- straight(*p)- };+ let c = if a > 1e-6 { [0, 1, 2].map(|i| (acc[i] / a).clamp(0.0, 1.0)) } else { straight(*p) };let edge = edges[k].min(1.0);let dark = (edge_gain * edge).clamp(0.0, 0.75);let grain = bristle * (2.0 * value_noise(SALT_DRY, q.x / (5.0 * space.px), q.y / (5.0 * space.px)) - 1.0) as f32;diff --git a/crates/effects/src/pixel/tests.rs b/crates/effects/src/pixel/tests.rsindex c053bcd47..28f07e380 100644--- a/crates/effects/src/pixel/tests.rs+++ b/crates/effects/src/pixel/tests.rs@@ -1446,10 +1446,7 @@ fn texturizer_draws_a_loaded_texture_as_relief() {assert_ne!(relief, run(json!({"texture": builtin, "relief": 20})), "{builtin}");}assert_eq!(run(json!({"texture": "loaded", "textureImage": rings, "relief": 0})), flat(w, mid));- assert_eq!(- fx("texture.texturizer", json!({"texture": "LOADED", "textureImage": "not a texture"})),- fx("texture.texturizer", json!({}))- );+ assert_eq!(fx("texture.texturizer", json!({"texture": "LOADED", "textureImage": "not a texture"})), fx("texture.texturizer", json!({})));}/// The Texture filters' patterns lie in document space around the object's centre: the same atdiff --git a/crates/engine/src/cmd/menucmds.rs b/crates/engine/src/cmd/menucmds.rsindex acd9a9b28..518c7c59d 100644--- a/crates/engine/src/cmd/menucmds.rs+++ b/crates/engine/src/cmd/menucmds.rs@@ -899,7 +899,14 @@ pub(crate) fn detect_shape(path: &PathData) -> Option<LiveShape> {}let rot = Affine::rotate(e0.y.atan2(e0.x));let flip = if e0.cross(e1) < 0.0 { Affine::scale_non_uniform(1.0, -1.0) } else { Affine::IDENTITY };- return Some(LiveShape::Rectangle { w, h, radii: [0.0; 4], kinds: Default::default(), radii_relative: false, xf: Affine::translate(a[0].p.to_vec2()) * rot * flip });+ return Some(LiveShape::Rectangle {+ w,+ h,+ radii: [0.0; 4],+ kinds: Default::default(),+ radii_relative: false,+ xf: Affine::translate(a[0].p.to_vec2()) * rot * flip,+ });}let b = path.bounds()?;let c = b.center();diff --git a/crates/svg/tests/css_rules.rs b/crates/svg/tests/css_rules.rsindex 70962b559..48e0747ca 100644--- a/crates/svg/tests/css_rules.rs+++ b/crates/svg/tests/css_rules.rs@@ -30,7 +30,14 @@ fn rect(d: &mut Document, (x, y, w, h): (f64, f64, f64, f64), radius: f64) -> NoAppearance::basic(fill, Paint::solid(Color::rgb8(0, 0, 255)), 2.0),);if let NodeKind::Path { live, .. } = &mut n.kind {- *live = Some(Box::new(LiveShape::Rectangle { w, h, radii: [radius; 4], kinds: Default::default(), radii_relative: false, xf: Affine::translate((x, y)) }));+ *live = Some(Box::new(LiveShape::Rectangle {+ w,+ h,+ radii: [radius; 4],+ kinds: Default::default(),+ radii_relative: false,+ xf: Affine::translate((x, y)),+ }));}n}diff --git a/crates/tools/src/corners.rs b/crates/tools/src/corners.rsindex 0183f69dd..c9281fade 100644--- a/crates/tools/src/corners.rs+++ b/crates/tools/src/corners.rs@@ -485,7 +485,14 @@ mod tests {#[test]fn widgets_of_several_selected_paths_drag_together() {let (mut d, a) = live_rect(0.0, Affine::translate((100.0, 100.0)));- let live = LiveShape::Rectangle { w: 100.0, h: 100.0, radii: [0.0; 4], kinds: Default::default(), radii_relative: false, xf: Affine::translate((300.0, 100.0)) };+ let live = LiveShape::Rectangle {+ w: 100.0,+ h: 100.0,+ radii: [0.0; 4],+ kinds: Default::default(),+ radii_relative: false,+ xf: Affine::translate((300.0, 100.0)),+ };let b = d.alloc_id();let mut n = Node::path(b, live.to_path(), Appearance::default_art());if let NodeKind::Path { live: slot, .. } = &mut n.kind {@@ -792,7 +799,8 @@ mod tests {/// cuts outline in red.#[test]fn a_live_polygon_rounds_with_either_tool() {- let live = LiveShape::Polygon { radius: 80.0, sides: 6, xf: Affine::translate((200.0, 200.0)), radii: vec![], kinds: vec![], radii_relative: false };+ let live =+ LiveShape::Polygon { radius: 80.0, sides: 6, xf: Affine::translate((200.0, 200.0)), radii: vec![], kinds: vec![], radii_relative: false };let (d, id) = doc_with(live.to_path(), Some(live));let s = selected(id);let p = paint();diff --git a/crates/ui-egui/src/dialogs/effect.rs b/crates/ui-egui/src/dialogs/effect.rsindex c50777892..e535e4c1f 100644--- a/crates/ui-egui/src/dialogs/effect.rs+++ b/crates/ui-egui/src/dialogs/effect.rs@@ -231,11 +231,7 @@ fn glass_fields(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog, id:// The stored texture is shown as its size, not as a text field.let stored = d.fields.remove(TEXTURE_IMAGE);let size = stored.as_ref().and_then(Value::as_str).and_then(texture).map(|t| t.size());- let menu = if id == TEXTURIZER {- texturizer_textures(size.is_some())- } else {- glass_textures(size.is_some())- };+ let menu = if id == TEXTURIZER { texturizer_textures(size.is_some()) } else { glass_textures(size.is_some()) };let doc = vectorcraft_effects::effect_info(id).map(|e| e.params).unwrap_or_default();let unit = app.session.general_unit();let pick = |k: &str| if k == "texture" { Some(menu) } else { choices(id, k) };diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rsindex 321cef6a0..450ef2bc0 100644--- a/crates/ui-egui/src/dock.rs+++ b/crates/ui-egui/src/dock.rs@@ -725,7 +725,6 @@ mod tests {fn arrow(&self) -> egui::Pos2 {egui::pos2(SCREEN.x - 10.0, HEADER / 2.0)}-}fn icon_panel_count() -> usize {@@ -842,11 +841,7 @@ mod tests {let mut app = VectorcraftApp::new(Session::new(), Default::default());app.run("file.new", json!({"width": 300, "height": 300})).unwrap();assert!(app.ui.docking.is_none());- app.run(- "window.panel.move",- json!({ "panel": "libraries", "anchor": "properties", "before": "properties" }),- )- .unwrap();+ app.run("window.panel.move", json!({ "panel": "libraries", "anchor": "properties", "before": "properties" })).unwrap();let order: Vec<_> = floating::docked_tabs(&app.ui).map(|t| t.info().0).collect();assert_eq!(order, ["libraries", "properties", "layers"]);let saved: crate::state::UiState = serde_json::from_slice(&serde_json::to_vec(&app.ui).unwrap()).unwrap();@@ -855,11 +850,8 @@ mod tests {#[test]fn partial_dock_tab_order_appends_tabs_missing_from_preferences() {- let ui = crate::state::UiState {- dock_tab: DockTab::Layers,- dock_tab_order: vec![DockTab::Layers, DockTab::Properties],- ..Default::default()- };+ let ui =+ crate::state::UiState { dock_tab: DockTab::Layers, dock_tab_order: vec![DockTab::Layers, DockTab::Properties], ..Default::default() };let order = floating::resolved_dock_tab_order(&ui);assert_eq!(order.len(), DockTab::ALL.len());assert_eq!(order[..2], [DockTab::Layers, DockTab::Properties]);diff --git a/crates/ui-egui/src/floating.rs b/crates/ui-egui/src/floating.rsindex 72098d1a5..2a4b87e6d 100644--- a/crates/ui-egui/src/floating.rs+++ b/crates/ui-egui/src/floating.rs@@ -1295,9 +1295,7 @@ mod tests {h.drag(h.icons()[2].center(), pos2(500.0, 250.0));h.drag(h.icons()[0].center(), h.shared_tab("swatches").center());assert_eq!(h.groups(), [["swatches", "color"]]);- h.app- .run("window.panel.move", json!({ "panel": "color", "anchor": "swatches", "before": "swatches" }))- .unwrap();+ h.app.run("window.panel.move", json!({ "panel": "color", "anchor": "swatches", "before": "swatches" })).unwrap();assert_eq!(h.groups(), [["color", "swatches"]]);}diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rsindex e051b904f..a61089997 100644--- a/crates/ui-egui/src/panel_docking.rs+++ b/crates/ui-egui/src/panel_docking.rs@@ -167,12 +167,7 @@ fn legacy_strip_reorder_target(/// Legacy workspaces (no saved `docking` layout): reorder tabs in the dock strip or a floating/// group without promoting to a shared layout.-fn legacy_same_strip_reorder(- app: &mut VectorcraftApp,- panel: &str,- before: &str,- target: LegacyStripReorder,-) -> Result<Value, String> {+fn legacy_same_strip_reorder(app: &mut VectorcraftApp, panel: &str, before: &str, target: LegacyStripReorder) -> Result<Value, String> {use crate::state::DockTab;match target {LegacyStripReorder::DockStrip => {@@ -852,8 +847,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) -> bool {return app.ui.docking.is_some();}craft_ui::docking::cancel_drag::<String>(ui.ctx(), egui::Id::new("vectorcraft-panel-docking"));- ui.ctx()- .data_mut(|data| data.remove::<LegacyDrag>(egui::Id::new("vectorcraft-panel-docking").with("legacy-origin")));+ ui.ctx().data_mut(|data| data.remove::<LegacyDrag>(egui::Id::new("vectorcraft-panel-docking").with("legacy-origin")));}for action in output.actions {if tab_drop@@ -947,13 +941,7 @@ pub(crate) fn legacy_tab(app: &mut VectorcraftApp, ui: &mut egui::Ui, panel: &stlegacy_tab_in_strip(app, ui, panel, response, None);}-pub(crate) fn legacy_tab_in_strip(- app: &mut VectorcraftApp,- ui: &mut egui::Ui,- panel: &str,- response: &egui::Response,- strip: Option<egui::Rect>,-) {+pub(crate) fn legacy_tab_in_strip(app: &mut VectorcraftApp, ui: &mut egui::Ui, panel: &str, response: &egui::Response, strip: Option<egui::Rect>) {let Some(panel) = normalize(panel) else { return };response.context_menu(|ui| {if ui.button(tl!("Float Panel")).clicked() {@@ -977,19 +965,11 @@ pub(crate) fn legacy_tab_in_strip(}});});- let inside_strip = strip.is_some_and(|strip| {- ui.input(|i| i.pointer.interact_pos()).is_some_and(|p| strip.expand(4.0).contains(p))- });+ let inside_strip = strip.is_some_and(|strip| ui.input(|i| i.pointer.interact_pos()).is_some_and(|p| strip.expand(4.0).contains(p)));let area = egui::Id::new("vectorcraft-panel-docking");let begun = ui.ctx().data(|d| d.get_temp::<LegacyDrag>(area.with("legacy-origin")).is_some());- let begin = if strip.is_some() {- !begun && (response.drag_started() || (!inside_strip && response.dragged()))- } else {- response.drag_started()- };- if begin- && let Some(id) = normalize(panel)- {+ let begin = if strip.is_some() { !begun && (response.drag_started() || (!inside_strip && response.dragged())) } else { response.drag_started() };+ if begin && let Some(id) = normalize(panel) {let mut layout = app.ui.docking.clone().unwrap_or_else(|| legacy(app));let bounds = ui.max_rect();let source = egui::Rect::from_min_size(diff --git a/crates/ui-egui/src/tests_labels.rs b/crates/ui-egui/src/tests_labels.rsindex 02f4c2587..1a2c3dc2c 100644--- a/crates/ui-egui/src/tests_labels.rs+++ b/crates/ui-egui/src/tests_labels.rs@@ -88,17 +88,7 @@ fn effect_menu_lists_the_artistic_filters_before_blur() {let labels: Vec<&str> = artistic.iter().map(|e| e.label.as_str()).collect();assert_eq!(labels,- [- "Cutout…",- "Dry Brush…",- "Film Grain…",- "Neon Glow…",- "Plastic Wrap…",- "Poster Edges…",- "Smudge Stick…",- "Sponge…",- "Watercolor…"- ]+ ["Cutout…", "Dry Brush…", "Film Grain…", "Neon Glow…", "Plastic Wrap…", "Poster Edges…", "Smudge Stick…", "Sponge…", "Watercolor…"]);assert!(artistic.iter().all(|e| e.command.as_deref() == Some("effect.dialog")));assert_eq!(artistic[1].params, json!({"effect": "artistic.dryBrush"}));diff --git a/crates/ui-egui/src/workspaces.rs b/crates/ui-egui/src/workspaces.rsindex dfca5bb31..824ccb934 100644--- a/crates/ui-egui/src/workspaces.rs+++ b/crates/ui-egui/src/workspaces.rs@@ -142,12 +142,7 @@ pub fn sync_touch_workspace(app: &mut VectorcraftApp, touch_screen: bool) {}}} else if app.ui.touch_workspace_restore.is_some() && app.ui.workspace == TOUCH {- let back = app- .ui- .touch_workspace_restore- .take()- .filter(|n| find(&app.ui, n).is_some())- .unwrap_or_else(|| ESSENTIALS.to_string());+ let back = app.ui.touch_workspace_restore.take().filter(|n| find(&app.ui, n).is_some()).unwrap_or_else(|| ESSENTIALS.to_string());if let Some(w) = find(&app.ui, &back) {apply(&mut app.ui, &w);}