Format: rustfmt after the batch

This commit is contained in:
bflatastic
2026-10-21 23:38:03 +07:00
parent e5471be4d9
commit c895f64063
14 changed files with 98 additions and 89 deletions
+37 -6
View File
@@ -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());
+19 -3
View File
@@ -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}");
+1 -5
View File
@@ -176,11 +176,7 @@ fn hard_mix_face(path: PathData, covering: &[usize], shapes: &[po::Shape], sourc
painted = 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 {
+1 -5
View File
@@ -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;
+1 -4
View File
@@ -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 at
+8 -1
View File
@@ -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();
+8 -1
View File
@@ -30,7 +30,14 @@ fn rect(d: &mut Document, (x, y, w, h): (f64, f64, f64, f64), radius: f64) -> No
Appearance::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
}
+10 -2
View File
@@ -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();
+1 -5
View File
@@ -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) };
+3 -11
View File
@@ -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]);
+1 -3
View File
@@ -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"]]);
}
+6 -26
View File
@@ -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: &st
legacy_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(
+1 -11
View File
@@ -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"}));
+1 -6
View File
@@ -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);
}