Use a magnet icon for snapping tools

This commit is contained in:
Dandaedre 2026-11-14 15:31:33 +01:00
parent 5f9a704fe0
commit a5f6391606
2 changed files with 33 additions and 12 deletions

View File

@ -2114,12 +2114,7 @@ impl Editor {
.layout(egui::Layout::left_to_right(egui::Align::Center)),
|ui| {
ui.spacing_mut().interact_size.y = 32.0;
let title = match self.effective_grid(modifiers) {
Some(10) => "10 px ▾",
Some(100) => "100 px ▾",
_ => "Snap ▾",
};
toolbar_menu(ui, title, |ui| {
let response = toolbar_menu(ui, SNAP_MENU_TITLE, |ui| {
ui.label("Grid tools");
for (spacing, label, shortcut) in [(10, "10 px", "Shift"), (100, "100 px", "Ctrl+Shift")] {
ui.horizontal(|ui| {
@ -2145,6 +2140,33 @@ impl Editor {
ui.colored_label(ui.visuals().error_fg_color, error);
}
}).response.on_hover_text("Snapping tools and options. Shift: 10 px · Ctrl+Shift: 100 px · Alt: invert snapping.");
response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, "Snapping"));
let center = response.rect.left_center() + Vec2::new(17.0, 0.0);
let color = if self.snapping.enabled || self.effective_grid(modifiers).is_some() {
palette.cyan
} else {
palette.muted
};
let point = |x, y| center + Vec2::new(x, y);
// Horseshoe magnet, with distinct pole caps and a rounded lower bend.
let mut arc = vec![point(-7.0, -8.0), point(-7.0, 1.0)];
for step in 1..=16 {
let angle = std::f32::consts::PI * (1.0 - step as f32 / 16.0);
arc.push(point(7.0 * angle.cos(), 1.0 + 7.0 * angle.sin()));
}
arc.push(point(7.0, -8.0));
ui.painter().add(egui::Shape::line(arc, Stroke::new(4.0_f32, color)));
for x in [-7.0, 7.0] {
ui.painter().line_segment([point(x, -8.0), point(x, -4.0)], Stroke::new(4.0_f32, palette.text));
}
if names || self.effective_grid(modifiers).is_some() {
let caption = match self.effective_grid(modifiers) {
Some(10) => "10 px",
Some(100) => "100 px",
_ => "Snap",
};
ui.painter().text(response.rect.center_bottom() + Vec2::new(0.0, 3.0), Align2::CENTER_TOP, caption, FontId::proportional(10.0), palette.muted);
}
},
);
let pivot_rect = Rect::from_min_size(ink.point(tools_x + 76.0, tools_y), Vec2::splat(32.0));
@ -3440,6 +3462,8 @@ enum ToolbarIcon {
Redo,
}
const SNAP_MENU_TITLE: &str = " ▾";
// Match the original toolbar's dark surfaces without changing popup controls.
fn toolbar_menu<R>(
ui: &mut egui::Ui,
@ -4455,12 +4479,7 @@ mod tests {
("Pivot", None, false),
] {
if label != "Pivot" {
let title = match app.grid_tool {
Some(10) => "10 px ▾",
Some(100) => "100 px ▾",
_ => "Snap ▾",
};
click_text(&mut app, &ctx, title);
click_text(&mut app, &ctx, SNAP_MENU_TITLE);
}
frame(&mut app, &ctx, vec![]);
let pos = ctx

View File

@ -4,6 +4,8 @@
## Unreleased
- Use a crisp, theme-aware magnet icon for the snapping dropdown; preserve snapping controls and active grid indicators.
- Unify file exchange around shared geometry preparation, byte-oriented codecs and one Export layers window. Add optional native PPTX/FIG import/export with slide/frame selection and embedded artwork, plus local VectorCraft AI conversion. File conversions run off the UI thread. Document and test `--no-default-features --features no_proprietary`; CI covers both configurations and production coverage includes the codecs.
- Add versioned geometry JSON, RFC-style CSV, DXF and HTML/CSS import/export alongside SVG and draw.io. All six formats have two-layer Full HD/UHD templates and round-trip tests; artwork support is explicit per format.