mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 18:32:23 +00:00
Merge pull request #8719 from Hassan1305/feat-8363-trim-view-guides
View: Trim View hides the guides and the grid while it is on (#8363)
This commit is contained in:
@@ -856,6 +856,12 @@ impl Session {
|
||||
self.ruler_origin = None;
|
||||
}
|
||||
|
||||
/// A guide is being dragged out of a ruler ([`Session::ruler_guide`]): its first event came
|
||||
/// and its release has not.
|
||||
pub fn ruler_guide_dragging(&self) -> bool {
|
||||
self.ruler_guide.is_some()
|
||||
}
|
||||
|
||||
/// Time passed while the pointer button is held (`dt` seconds; see [`Tool::tick`]): the
|
||||
/// desktop app ticks every frame of a press, agents with `holdMs` on a pointer event.
|
||||
pub fn tool_tick(&mut self, dt: f64, view: ViewInfo) -> Result<Vec<UiRequest>> {
|
||||
|
||||
@@ -1657,7 +1657,7 @@ impl DirectSelectionTool {
|
||||
// The grabbed anchor snaps and the others follow it. Shift keeps the move at its
|
||||
// angle, and the anchor slides along it onto what Smart Guides find there (#886).
|
||||
self.guides.clear();
|
||||
if segment && let Some(grid) = &self.partial_grid {
|
||||
if segment && let Some(grid) = &mut self.partial_grid {
|
||||
(d, self.guides) = if ev.mods.shift { grid.snap_along(cx, grab, d, false) } else { grid.snap(cx, grab, d, false) };
|
||||
} else if let Some(snap) = &self.anchor_snap {
|
||||
let shift = ev.mods.shift.then(|| Leave::segment(cx, grab, true));
|
||||
@@ -1710,7 +1710,7 @@ impl DirectSelectionTool {
|
||||
&& let Some(snap) = &self.partial_snap
|
||||
{
|
||||
let held = grab.unwrap_or(hold);
|
||||
if let Some(grid) = &self.partial_grid {
|
||||
if let Some(grid) = &mut self.partial_grid {
|
||||
(d, self.guides) = if ev.mods.shift { grid.snap_along(cx, held, d, false) } else { grid.snap(cx, held, d, false) };
|
||||
} else {
|
||||
let shift = ev.mods.shift.then(|| Leave::segment(cx, held, true));
|
||||
@@ -1730,7 +1730,7 @@ impl DirectSelectionTool {
|
||||
let shift = ev.mods.shift.then(|| Leave::segment(cx, grab, true));
|
||||
let (q, guides) = snap.snap_from(cx, grab + (p - start), shift.as_ref());
|
||||
(d, self.guides) = (q - grab, guides);
|
||||
} else if let Some(snap) = &self.move_snap {
|
||||
} else if let Some(snap) = &mut self.move_snap {
|
||||
(d, self.guides) = if ev.mods.shift { snap.snap_along(cx, hold, d, ev.mods.alt) } else { snap.snap(cx, hold, d, ev.mods.alt) };
|
||||
}
|
||||
self.snapped = snapped(d, unsnapped, ev.mods.shift, &self.guides);
|
||||
|
||||
@@ -707,6 +707,12 @@ impl Targets {
|
||||
self
|
||||
}
|
||||
|
||||
/// These targets without the ruler guides, once they stop showing during the drag they were
|
||||
/// gathered for (#8363).
|
||||
pub(crate) fn forget_rulers(&mut self) {
|
||||
self.rulers.clear();
|
||||
}
|
||||
|
||||
/// The ruler guides alone ([`Self::with_rulers`]): what a dragged selection's grabbed point
|
||||
/// still snaps to with View → Snap to Point when Smart Guides line the selection up.
|
||||
pub(crate) fn rulers(cx: &ToolContext) -> Self {
|
||||
|
||||
@@ -309,10 +309,24 @@ impl MoveSnap {
|
||||
Self { bounds, targets: None, points: None, copy_targets: None, copy_points: None, rulers: None, by_edge: false }
|
||||
}
|
||||
|
||||
/// The ruler guides stopped showing since the move began (View › Hide Guides, or Trim View,
|
||||
/// #8363): the move no longer snaps to them, for the rest of it, while its other targets stay.
|
||||
/// They were gathered when it began, and nothing pulls toward a guide the canvas does not draw.
|
||||
fn forget_hidden_rulers(&mut self, cx: &ToolContext) {
|
||||
if cx.guides {
|
||||
return;
|
||||
}
|
||||
self.rulers = None;
|
||||
for t in [&mut self.points, &mut self.copy_points].into_iter().flatten() {
|
||||
t.forget_rulers();
|
||||
}
|
||||
}
|
||||
|
||||
/// The move (`copy`: the copy) by `d` of the selection grabbed at `start`, snapped, and its
|
||||
/// guides. With Smart Guides › Snap to Last Location, a move within Snapping Tolerance of where
|
||||
/// it began goes back there before anything else snaps ([`Targets::snap_back`]).
|
||||
pub(crate) fn snap(&self, cx: &ToolContext, start: Point, mut d: Vec2, copy: bool) -> (Vec2, Vec<Overlay>) {
|
||||
pub(crate) fn snap(&mut self, cx: &ToolContext, start: Point, mut d: Vec2, copy: bool) -> (Vec2, Vec<Overlay>) {
|
||||
self.forget_hidden_rulers(cx);
|
||||
let (targets, points) = if copy { (&self.copy_targets, &self.copy_points) } else { (&self.targets, &self.points) };
|
||||
if let Some(ov) = targets.as_ref().and_then(|t| t.snap_back(self.bounds, d, cx.snap_tol())) {
|
||||
return (Vec2::ZERO, ov);
|
||||
@@ -391,7 +405,8 @@ impl MoveSnap {
|
||||
/// passes an anchor or crosses a ruler guide ([`Targets::snap_point_along`]). A move of zero
|
||||
/// length does not snap, and Snap to Last Location goes back to where the move began first, as
|
||||
/// in [`Self::snap`].
|
||||
pub(crate) fn snap_along(&self, cx: &ToolContext, start: Point, mut d: Vec2, copy: bool) -> (Vec2, Vec<Overlay>) {
|
||||
pub(crate) fn snap_along(&mut self, cx: &ToolContext, start: Point, mut d: Vec2, copy: bool) -> (Vec2, Vec<Overlay>) {
|
||||
self.forget_hidden_rulers(cx);
|
||||
let len = d.hypot();
|
||||
if !len.is_finite() || len <= 1e-9 {
|
||||
return (d, vec![]);
|
||||
@@ -1957,7 +1972,7 @@ impl SelectionTool {
|
||||
}
|
||||
let mut d = move_delta(start, p, m.shift, cx.constrain_angle);
|
||||
let unsnapped = d;
|
||||
if let Some(snap) = &self.moving {
|
||||
if let Some(snap) = &mut self.moving {
|
||||
(d, self.guides) = if m.shift { snap.snap_along(cx, hold, d, m.alt) } else { snap.snap(cx, hold, d, m.alt) };
|
||||
}
|
||||
// Shift has already constrained `d`: any change is a snap.
|
||||
|
||||
@@ -2198,7 +2198,7 @@ fn move_follows_the_while_moving_option() {
|
||||
let p = paint();
|
||||
let pixel_snap = PixelSnap { moving: false, ..PixelSnap::default() };
|
||||
let c = ToolContext { snap_to_pixel: true, pixel_snap, smart_guides: false, snap_to_point: false, ..cx(&d, &s, &p) };
|
||||
let snap = MoveSnap::new(&c);
|
||||
let mut snap = MoveSnap::new(&c);
|
||||
let (dv, _) = snap.snap(&c, Point::new(150.0, 150.0), Vec2::new(3.3, 4.6), false);
|
||||
assert!((dv - Vec2::new(3.3, 4.6)).hypot() < 1e-9, "{dv:?}");
|
||||
let on = ToolContext { pixel_snap: PixelSnap::default(), ..c };
|
||||
|
||||
@@ -122,7 +122,7 @@ impl VectorcraftApp {
|
||||
zoom: self.view().map_or(1.0, |v| v.screen_zoom(self.canvas_ui_zoom)),
|
||||
outline: self.outline_view(),
|
||||
smart_guides: self.ui.view.smart_guides,
|
||||
guides: self.ui.view.guides,
|
||||
guides: self.ui.view.guides_shown(),
|
||||
snap_to_grid: self.ui.view.snap_to_grid,
|
||||
pixel_preview: self.ui.view.pixel_preview,
|
||||
snap_to_pixel: self.ui.view.snap_to_pixel,
|
||||
|
||||
@@ -326,7 +326,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
|
||||
paint_paper(app, st, ui, &painter, &xf, rect, (&t, app.outline_view()));
|
||||
// The grid behind the art (Guides & Grid › Grids In Back), else over it below.
|
||||
let grid_look = (app.ui.view.grid && !presenting).then(|| LineLook::grid(&app.session.prefs));
|
||||
let grid_look = (app.ui.view.grid_shown() && !presenting).then(|| LineLook::grid(&app.session.prefs));
|
||||
let grids_in_back = app.session.prefs.grids_in_back;
|
||||
if let Some(look) = grid_look.filter(|_| grids_in_back) {
|
||||
grid(&painter, &xf, doc.grid.spacing, doc.grid.subdivisions, look);
|
||||
@@ -416,7 +416,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
grid(&painter, &xf, 1.0, 1, LineLook { color: PIXEL_GRID, dots: false });
|
||||
}
|
||||
artboard_outlines(app, ui, &painter, &xf, &t);
|
||||
if app.ui.view.guides {
|
||||
if app.ui.view.guides_shown() {
|
||||
guide_lines(app, &painter, &xf, rect, &t);
|
||||
}
|
||||
nine_slice_overlay(app, &painter, &xf);
|
||||
@@ -899,7 +899,7 @@ fn cache_key(
|
||||
outline: app.outline_view(),
|
||||
trim: app.ui.view.trim_view,
|
||||
templates: app.ui.view.templates,
|
||||
guides: app.ui.view.guides,
|
||||
guides: app.ui.view.guides_shown(),
|
||||
ppp,
|
||||
hidden: vec![],
|
||||
rot: v.rotation,
|
||||
@@ -1098,7 +1098,7 @@ fn frame_options(
|
||||
overprint_preview: vectorcraft_render::proof::overprint_preview_on(),
|
||||
trim: app.ui.view.trim_view,
|
||||
hide_templates: !app.ui.view.templates,
|
||||
hide_guides: !app.ui.view.guides,
|
||||
hide_guides: !app.ui.view.guides_shown(),
|
||||
tile_edge: vectorcraft_color::Color::from_hex(&app.session.prefs.pattern_tile_edge_color).map_or(opts.tile_edge, |c| {
|
||||
let [r, g, b, _] = c.to_rgba8(1.0);
|
||||
[r, g, b]
|
||||
|
||||
@@ -222,7 +222,14 @@ pub(super) fn ruler_input(app: &mut VectorcraftApp, ui: &Ui, full: egui::Rect, c
|
||||
if resp.clicked_by(egui::PointerButton::Primary) {
|
||||
ui.data_mut(|d| d.insert_temp(last_click, now));
|
||||
}
|
||||
if resp.double_clicked_by(egui::PointerButton::Primary)
|
||||
// Trim View hides the guides (#8363): a guide made now could not be seen, so none is.
|
||||
let trim_view = app.ui.view.trim_view;
|
||||
let refuse = |app: &mut VectorcraftApp| app.status(crate::menus::TRIM_VIEW_HIDES.to_string());
|
||||
if trim_view && first_here && resp.double_clicked_by(egui::PointerButton::Primary) {
|
||||
refuse(app);
|
||||
}
|
||||
if !trim_view
|
||||
&& resp.double_clicked_by(egui::PointerButton::Primary)
|
||||
&& first_here
|
||||
&& let Some(p) = resp.interact_pointer_pos().or_else(|| ui.input(|i| i.pointer.latest_pos()))
|
||||
{
|
||||
@@ -253,12 +260,22 @@ pub(super) fn ruler_input(app: &mut VectorcraftApp, ui: &Ui, full: egui::Rect, c
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
let p = resp.interact_pointer_pos().or_else(|| ui.input(|i| i.pointer.latest_pos()));
|
||||
let on_canvas = p.is_some_and(|p| canvas.contains(p));
|
||||
if on_canvas {
|
||||
// The new guide shows even if guides were hidden.
|
||||
app.ui.view.guides = true;
|
||||
// A drag Trim View is on for at any point makes no guide, so none previews, even when
|
||||
// Trim View is turned off again before the release: the whole gesture is cancelled and
|
||||
// stays so until the button is released.
|
||||
let cancel = egui::Id::unique(if vertical { "ruler-left-trim-cancel" } else { "ruler-top-trim-cancel" });
|
||||
if resp.drag_started() {
|
||||
ui.data_mut(|d| d.remove::<bool>(cancel));
|
||||
}
|
||||
if trim_view && ui.data(|d| d.get_temp::<bool>(cancel).is_none()) {
|
||||
refuse(app);
|
||||
ui.data_mut(|d| d.insert_temp(cancel, true));
|
||||
}
|
||||
let cancelled = ui.data(|d| d.get_temp::<bool>(cancel).is_some());
|
||||
if cancelled && kind == PointerKind::Up {
|
||||
ui.data_mut(|d| d.remove::<bool>(cancel));
|
||||
}
|
||||
let p = resp.interact_pointer_pos().or_else(|| ui.input(|i| i.pointer.latest_pos()));
|
||||
let ev = PointerEvent {
|
||||
kind,
|
||||
pos: p.map_or(Point::ZERO, |p| xf.to_doc(p)),
|
||||
@@ -267,6 +284,21 @@ pub(super) fn ruler_input(app: &mut VectorcraftApp, ui: &Ui, full: egui::Rect, c
|
||||
pressure: 1.0,
|
||||
pen: None,
|
||||
};
|
||||
if cancelled {
|
||||
// A guide already dragged when Trim View turned on ends as a release off the canvas
|
||||
// does: no guide, no undo step.
|
||||
if app.session.ruler_guide_dragging()
|
||||
&& let Err(e) = app.session.ruler_guide(vertical, &PointerEvent { kind: PointerKind::Up, ..ev }, false, app.view_info())
|
||||
{
|
||||
app.status(e.to_string());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let on_canvas = p.is_some_and(|p| canvas.contains(p));
|
||||
if on_canvas {
|
||||
// The new guide shows even if guides were hidden.
|
||||
app.ui.view.guides = true;
|
||||
}
|
||||
if let Err(e) = app.session.ruler_guide(vertical, &ev, on_canvas, app.view_info()) {
|
||||
app.status(e.to_string());
|
||||
}
|
||||
@@ -288,11 +320,14 @@ pub(super) fn ruler_input(app: &mut VectorcraftApp, ui: &Ui, full: egui::Rect, c
|
||||
let drag_id = ruler_origin_drag_id();
|
||||
let uid = app.session.active().map(|d| d.uid);
|
||||
if corner.drag_started_by(egui::PointerButton::Primary) {
|
||||
ui.data_mut(|d| d.insert_temp(drag_id, (uid, false)));
|
||||
ui.data_mut(|d| d.insert_temp(drag_id, OriginDrag { doc: uid, cancelled: false, trim_view: app.ui.view.trim_view }));
|
||||
}
|
||||
let mut preview = None;
|
||||
if let Some((started_in, mut cancelled)) = ui.data(|d| d.get_temp::<(Option<u64>, bool)>(drag_id)) {
|
||||
cancelled |= started_in != uid || ui.input(|i| !i.focused || i.key_pressed(egui::Key::Escape));
|
||||
if let Some(OriginDrag { doc: started_in, mut cancelled, trim_view }) = ui.data(|d| d.get_temp::<OriginDrag>(drag_id)) {
|
||||
// Trim View turned on or off during the drag: the snap targets gathered at its start
|
||||
// hold the ruler guides, or leave them out, as they no longer show (#8363), so the origin
|
||||
// could snap to a guide nobody sees. The drag is cancelled as for hidden rulers.
|
||||
cancelled |= started_in != uid || trim_view != app.ui.view.trim_view || ui.input(|i| !i.focused || i.key_pressed(egui::Key::Escape));
|
||||
let pointer =
|
||||
corner.interact_pointer_pos().or_else(|| ui.input(|i| i.pointer.latest_pos())).filter(|p| canvas.contains(*p)).map(|p| xf.to_doc(p));
|
||||
// The origin snaps as a drawn point does (Smart Guides, Snap to Point, pixels, the grid).
|
||||
@@ -313,7 +348,7 @@ pub(super) fn ruler_input(app: &mut VectorcraftApp, ui: &Ui, full: egui::Rect, c
|
||||
} else if !ui.input(|i| i.pointer.primary_down()) {
|
||||
end_ruler_origin_drag(app, ui);
|
||||
} else {
|
||||
ui.data_mut(|d| d.insert_temp(drag_id, (started_in, cancelled)));
|
||||
ui.data_mut(|d| d.insert_temp(drag_id, OriginDrag { doc: started_in, cancelled, trim_view }));
|
||||
if !cancelled {
|
||||
preview = at;
|
||||
}
|
||||
@@ -333,10 +368,21 @@ pub(super) fn rulers_hidden(app: &mut VectorcraftApp, ui: &Ui) -> Option<Point>
|
||||
|
||||
/// Ends a drag from the rulers' corner, released or cancelled: its state and its snapping guides go.
|
||||
fn end_ruler_origin_drag(app: &mut VectorcraftApp, ui: &Ui) {
|
||||
ui.data_mut(|d| d.remove::<(Option<u64>, bool)>(ruler_origin_drag_id()));
|
||||
ui.data_mut(|d| d.remove::<OriginDrag>(ruler_origin_drag_id()));
|
||||
app.session.end_ruler_origin_drag();
|
||||
}
|
||||
|
||||
/// A drag of the rulers' origin out of their corner, kept between frames.
|
||||
#[derive(Clone, Copy)]
|
||||
struct OriginDrag {
|
||||
/// The document it started in (`Document::uid`): another one active cancels it.
|
||||
doc: Option<u64>,
|
||||
/// Cancelled (Escape, focus lost, another document, Trim View toggled): it sets nothing.
|
||||
cancelled: bool,
|
||||
/// View › Trim View was on when it started.
|
||||
trim_view: bool,
|
||||
}
|
||||
|
||||
/// The key of the ruler origin drag's state in egui's temporary data.
|
||||
fn ruler_origin_drag_id() -> egui::Id {
|
||||
egui::Id::unique("ruler-origin-drag")
|
||||
@@ -345,7 +391,7 @@ fn ruler_origin_drag_id() -> egui::Id {
|
||||
/// Is a drag from the rulers' corner in progress? It stays true after Escape cancels the move, until
|
||||
/// the button is released.
|
||||
pub(crate) fn ruler_origin_dragging(ctx: &egui::Context) -> bool {
|
||||
ctx.data(|d| d.get_temp::<(Option<u64>, bool)>(ruler_origin_drag_id()).is_some())
|
||||
ctx.data(|d| d.get_temp::<OriginDrag>(ruler_origin_drag_id()).is_some())
|
||||
}
|
||||
|
||||
/// What the rulers count, and from where: `unit`, from `origin` (document points), with each
|
||||
|
||||
@@ -188,7 +188,7 @@ pub(super) fn hit_with<T>(
|
||||
path_only: prefs.object_selection_by_path_only,
|
||||
type_path_only: prefs.type_selection_by_path_only,
|
||||
scope: app.session.active().and_then(|st| st.isolation),
|
||||
skip_guides: !app.ui.view.guides,
|
||||
skip_guides: !app.ui.view.guides_shown(),
|
||||
..Default::default()
|
||||
};
|
||||
test(&app.session.active()?.doc, p, opt)
|
||||
|
||||
@@ -554,7 +554,7 @@ fn draw_pane(app: &mut VectorcraftApp, ui: &Ui, w: Win, cell: egui::Rect) -> boo
|
||||
let xf = Xf::at(rect, &v, ui_zoom);
|
||||
let painter = ui.painter_at(rect);
|
||||
paint_paper(app, st, ui, &painter, &xf, rect, (&t, v.outline));
|
||||
let grid_look = app.ui.view.grid.then(|| LineLook::grid(&app.session.prefs));
|
||||
let grid_look = app.ui.view.grid_shown().then(|| LineLook::grid(&app.session.prefs));
|
||||
let grids_in_back = app.session.prefs.grids_in_back;
|
||||
if let Some(look) = grid_look.filter(|_| grids_in_back) {
|
||||
grid(&painter, &xf, st.doc.grid.spacing, st.doc.grid.subdivisions, look);
|
||||
@@ -587,7 +587,7 @@ fn draw_pane(app: &mut VectorcraftApp, ui: &Ui, w: Win, cell: egui::Rect) -> boo
|
||||
if shows_artboards(app) {
|
||||
artboard_edges(app, &st.doc, (&painter, &xf, &t), (v.artboard, dim_on_canvas(&t, v.outline)), |_| false);
|
||||
}
|
||||
if app.ui.view.guides {
|
||||
if app.ui.view.guides_shown() {
|
||||
guides_of(app, st, (&painter, &xf, &t), rect);
|
||||
}
|
||||
if app.ui.view.edges {
|
||||
|
||||
@@ -15357,3 +15357,250 @@ fn auto_spell_check_is_a_toggle_of_the_canvas_lines() {
|
||||
assert_eq!(count(&mut app), 0, "off");
|
||||
assert!(app.canvas.spelling.lines.is_empty(), "no node is kept");
|
||||
}
|
||||
|
||||
/// #8363: Trim View hides the ruler guides, the guide paths and the grid while it is on, and they
|
||||
/// are neither snapped to nor picked, as hidden guides are; turned off, they come back as they
|
||||
/// were. The rulers stay.
|
||||
#[test]
|
||||
fn trim_view_hides_the_guides_and_the_grid() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.session.execute("guide.add", &json!({"vertical": true, "pos": 100})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 150, "y": 100, "width": 100, "height": 100})).unwrap();
|
||||
app.run("view.guides.make", json!({})).unwrap();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
(app.ui.view.grid, app.ui.view.guides, app.ui.view.rulers) = (true, true, true);
|
||||
let (red, green) = (Color32::from_rgb(255, 0, 0), Color32::from_rgb(0, 255, 0));
|
||||
app.session.execute("prefs.set", &json!({"values": {"gridColor": "#ff0000", "guideColor": "#00ff00"}})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
// → (a gridline, a ruler guide, guide paths in the art, guides snapped to and picked).
|
||||
let drawn = |app: &mut VectorcraftApp| {
|
||||
let s = shapes(app, &ctx);
|
||||
let line = |c: Color32| s.iter().any(|s| matches!(s, Shape::LineSegment { stroke, .. } if stroke.color == c));
|
||||
let guide_paths = !app.canvas.shown.as_ref().unwrap().1.hide_guides;
|
||||
(line(red), line(green), guide_paths, app.view_info().guides)
|
||||
};
|
||||
assert_eq!(drawn(&mut app), (true, true, true, true), "Trim View off: all of them");
|
||||
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
assert_eq!(drawn(&mut app), (false, false, false, false), "Trim View on: none of them");
|
||||
assert!(app.ui.view.grid && app.ui.view.guides && app.ui.view.rulers, "the choices stay, and so do the rulers");
|
||||
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
assert_eq!(drawn(&mut app), (true, true, true, true), "Trim View off: back as they were");
|
||||
|
||||
// Hidden before, they stay hidden after.
|
||||
app.run("view.guides", json!({})).unwrap();
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
assert_eq!(drawn(&mut app), (true, false, false, false), "guides hidden before Trim View stay hidden");
|
||||
}
|
||||
|
||||
/// #8363: a selected guide path is deselected when Trim View hides it, as Hide Guides does (#3219).
|
||||
#[test]
|
||||
fn trim_view_deselects_selected_guide_paths() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
let id = app.run("shape.rectangle", json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("view.guides.make", json!({})).unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, vec![vectorcraft_doc::NodeId(id)]);
|
||||
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
|
||||
assert!(app.session.active().unwrap().selection.objects.is_empty());
|
||||
}
|
||||
|
||||
/// #8363: Trim View hides the guides, so a guide dragged or double-clicked out of a ruler while it
|
||||
/// is on would be made but never seen. None is: no preview line, no guide, no undo step, the
|
||||
/// stored Show/Hide Guides choice is left alone, and the status line says why. A drag already
|
||||
/// going when Trim View turns on ends as a release off the canvas does.
|
||||
#[test]
|
||||
fn trim_view_makes_no_guide_from_the_rulers() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.ui.view.rulers = true;
|
||||
app.ui.view.guides = false;
|
||||
app.ui.view.smart_guides = false;
|
||||
app.ui.view.snap_to_point = false;
|
||||
app.ui.view.trim_view = true;
|
||||
let ctx = egui::Context::default();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let rect = app.canvas_rect.unwrap();
|
||||
let from = pos2(rect.center().x, rect.top() - RULER / 2.0);
|
||||
let at = pos2(rect.center().x, rect.top() + 120.0);
|
||||
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
let across = |s: &Shape| {
|
||||
matches!(s, Shape::LineSegment { points, .. }
|
||||
if (points[0].y - at.y).abs() <= 2.0 && points[0].y == points[1].y && (points[1].x - points[0].x).abs() >= rect.width() - 0.5)
|
||||
};
|
||||
let count = |app: &VectorcraftApp| app.session.active().unwrap().doc.ruler_guides().len();
|
||||
let steps = |app: &VectorcraftApp| app.session.active().unwrap().history.undo.len();
|
||||
let before = steps(&app);
|
||||
|
||||
// A drag: nothing previews and nothing is made.
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(from)]);
|
||||
frame(&mut app, &ctx, vec![button(from, true)]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]);
|
||||
assert!(!shapes(&mut app, &ctx).iter().any(across), "no guide previews");
|
||||
assert!(!app.session.ruler_guide_dragging());
|
||||
frame(&mut app, &ctx, vec![button(at, false)]);
|
||||
assert_eq!(count(&app), 0, "no guide from a drag");
|
||||
assert!(!app.ui.view.guides, "the stored choice is left alone");
|
||||
assert_eq!(app.ui.status, crate::menus::TRIM_VIEW_HIDES);
|
||||
|
||||
// A double-click: nothing either.
|
||||
app.ui.status.clear();
|
||||
let click = |app: &mut VectorcraftApp| {
|
||||
frame(app, &ctx, vec![egui::Event::PointerMoved(from)]);
|
||||
frame(app, &ctx, vec![button(from, true)]);
|
||||
frame(app, &ctx, vec![button(from, false)]);
|
||||
};
|
||||
click(&mut app);
|
||||
click(&mut app);
|
||||
assert_eq!(count(&app), 0, "no guide from a double-click");
|
||||
assert!(!app.ui.view.guides);
|
||||
assert_eq!(app.ui.status, crate::menus::TRIM_VIEW_HIDES);
|
||||
assert_eq!(steps(&app), before, "no undo step");
|
||||
|
||||
// Trim View turned on during a drag: the drag ends without a guide.
|
||||
app.ui.view.trim_view = false;
|
||||
let from2 = pos2(rect.center().x + 30.0, rect.top() - RULER / 2.0);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(from2)]);
|
||||
frame(&mut app, &ctx, vec![button(from2, true)]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]);
|
||||
assert!(app.session.ruler_guide_dragging(), "the drag started with Trim View off");
|
||||
app.ui.view.trim_view = true;
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(pos2(at.x + 5.0, at.y))]);
|
||||
assert!(!app.session.ruler_guide_dragging(), "ended");
|
||||
assert!(!shapes(&mut app, &ctx).iter().any(across), "no guide previews");
|
||||
frame(&mut app, &ctx, vec![button(at, false)]);
|
||||
assert_eq!(count(&app), 0, "no guide from the drag Trim View interrupted");
|
||||
assert_eq!(steps(&app), before, "no undo step");
|
||||
|
||||
// With Trim View off again, a drag makes a guide as before.
|
||||
app.ui.view.trim_view = false;
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(from)]);
|
||||
frame(&mut app, &ctx, vec![button(from, true)]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]);
|
||||
frame(&mut app, &ctx, vec![button(at, false)]);
|
||||
assert_eq!(count(&app), 1);
|
||||
assert!(app.ui.view.guides, "the new guide shows");
|
||||
}
|
||||
|
||||
/// #8363: a guide drag Trim View cancelled stays cancelled until the button is released. Trim
|
||||
/// View turned off again before the release does not start a new guide: the release makes none
|
||||
/// and adds no undo step. The next drag works as before.
|
||||
#[test]
|
||||
fn a_ruler_drag_trim_view_cancelled_stays_cancelled_until_released() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.ui.view.rulers = true;
|
||||
app.ui.view.smart_guides = false;
|
||||
app.ui.view.snap_to_point = false;
|
||||
let ctx = egui::Context::default();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let rect = app.canvas_rect.unwrap();
|
||||
let from = pos2(rect.center().x, rect.top() - RULER / 2.0);
|
||||
let at = pos2(rect.center().x, rect.top() + 120.0);
|
||||
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
let count = |app: &VectorcraftApp| app.session.active().unwrap().doc.ruler_guides().len();
|
||||
let steps = |app: &VectorcraftApp| app.session.active().unwrap().history.undo.len();
|
||||
let before = steps(&app);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(from)]);
|
||||
frame(&mut app, &ctx, vec![button(from, true)]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]);
|
||||
assert!(app.session.ruler_guide_dragging());
|
||||
app.ui.view.trim_view = true;
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(pos2(at.x, at.y + 5.0))]);
|
||||
assert!(!app.session.ruler_guide_dragging(), "Trim View ends the drag");
|
||||
app.ui.view.trim_view = false;
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(pos2(at.x, at.y + 10.0))]);
|
||||
assert!(!app.session.ruler_guide_dragging(), "turned off again, no new guide starts");
|
||||
frame(&mut app, &ctx, vec![button(pos2(at.x, at.y + 10.0), false)]);
|
||||
assert_eq!(count(&app), 0, "the release makes no guide");
|
||||
assert_eq!(steps(&app), before, "no undo step");
|
||||
// The next drag makes a guide.
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(from)]);
|
||||
frame(&mut app, &ctx, vec![button(from, true)]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]);
|
||||
frame(&mut app, &ctx, vec![button(at, false)]);
|
||||
assert_eq!(count(&app), 1);
|
||||
}
|
||||
|
||||
/// #8363: Trim View turned on or off during a drag of the rulers' origin out of their corner
|
||||
/// cancels it, as hiding the rulers does: the snap targets gathered at its start would hold
|
||||
/// guides Trim View hides. The origin is left where it was. A drag wholly with Trim View on, or
|
||||
/// wholly off, sets it.
|
||||
#[test]
|
||||
fn trim_view_toggled_during_a_ruler_origin_drag_cancels_it() {
|
||||
for (start, end, sets) in [(false, true, false), (true, false, false), (true, true, true), (false, false, true)] {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.session.execute("guide.add", &json!({"vertical": true, "pos": 150})).unwrap();
|
||||
app.ui.view.rulers = true;
|
||||
app.ui.view.trim_view = start;
|
||||
let ctx = egui::Context::default();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let rect = app.canvas_rect.unwrap();
|
||||
let xf = Xf::new(rect, app.view().unwrap());
|
||||
let origin = |app: &VectorcraftApp| {
|
||||
let d = &app.session.active().unwrap().doc;
|
||||
format!("{:?} {:?}", d.ruler_origin, d.artboard_ruler_origins)
|
||||
};
|
||||
let was = origin(&app);
|
||||
let from = pos2(rect.left() - RULER / 2.0, rect.top() - RULER / 2.0);
|
||||
let at = xf.to_screen(Point::new(151.0, 100.0));
|
||||
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(from)]);
|
||||
frame(&mut app, &ctx, vec![button(from, true)]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]);
|
||||
assert!(crate::canvas::ruler_origin_dragging(&ctx), "{start} {end}: dragging");
|
||||
app.ui.view.trim_view = end;
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at + vec2(1.0, 0.0))]);
|
||||
frame(&mut app, &ctx, vec![button(at + vec2(1.0, 0.0), false)]);
|
||||
assert_eq!(origin(&app) != was, sets, "Trim View {start} then {end}: origin set {sets}");
|
||||
}
|
||||
}
|
||||
|
||||
/// #8363: a Selection move begun with the guides shown gathers the ruler guides to snap to. When
|
||||
/// they stop showing during the move (Trim View or Hide Guides turned on), it no longer snaps to
|
||||
/// them; with them shown throughout, it does.
|
||||
#[test]
|
||||
fn a_move_stops_snapping_to_guides_hidden_during_it() {
|
||||
// What hides the guides mid-move (none: they stay shown), and whether the move then snaps.
|
||||
for (hide, snaps) in [(None, true), (Some("trim"), false), (Some("guides"), false)] {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 50, "y": 50, "width": 50, "height": 50})).unwrap();
|
||||
app.session.execute("guide.add", &json!({"vertical": true, "pos": 200})).unwrap();
|
||||
app.select_tool("selection");
|
||||
app.ui.view.smart_guides = false;
|
||||
app.ui.view.snap_to_point = true;
|
||||
app.ui.view.guides = true;
|
||||
let ctx = egui::Context::default();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let rect = app.canvas_rect.unwrap();
|
||||
let xf = Xf::new(rect, app.view().unwrap());
|
||||
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
// Grabbed at its centre, moved first well away from the guide, then 1.5 px short of it.
|
||||
let grab = xf.to_screen(Point::new(75.0, 75.0));
|
||||
let away = xf.to_screen(Point::new(120.0, 75.0));
|
||||
let near = xf.to_screen(Point::new(200.0, 75.0)) - vec2(1.5, 0.0);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(grab)]);
|
||||
frame(&mut app, &ctx, vec![button(grab, true)]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(away)]);
|
||||
match hide {
|
||||
Some("trim") => app.ui.view.trim_view = true,
|
||||
Some(_) => app.ui.view.guides = false,
|
||||
None => {}
|
||||
}
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(near)]);
|
||||
frame(&mut app, &ctx, vec![button(near, false)]);
|
||||
let b = app.session.active().unwrap().doc.art_bounds().unwrap();
|
||||
let centre = (b.x0 + b.x1) / 2.0;
|
||||
assert_eq!((centre - 200.0).abs() < 1e-6, snaps, "{hide:?}: the grabbed centre at {centre}");
|
||||
assert!((centre - xf.to_doc(near).x).abs() < 1e-6 || snaps, "{hide:?}: unsnapped, it follows the pointer: {centre}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ mod invoke;
|
||||
mod keyboard;
|
||||
mod labels;
|
||||
mod run;
|
||||
pub(crate) use run::TRIM_VIEW_HIDES;
|
||||
mod slots;
|
||||
mod state;
|
||||
mod submenus;
|
||||
|
||||
@@ -270,8 +270,9 @@ fn isolatable(app: &VectorcraftApp, doc: &vectorcraft_doc::Document, n: &vectorc
|
||||
&& doc.symbol_edit.as_ref().is_none_or(|e| doc.ancestry(target).is_some_and(|a| a.contains(&e.layer)))
|
||||
}
|
||||
|
||||
/// `items` without the commands that can't run now (Undo and Redo stay, greyed out), submenus
|
||||
/// left empty, and separators that no longer separate anything.
|
||||
/// `items` without the commands that can't run now (Undo and Redo stay, greyed out, and so do Show
|
||||
/// Grid and Hide Guides while Trim View holds them off: #8363), submenus left empty, and separators
|
||||
/// that no longer separate anything.
|
||||
fn prune(app: &VectorcraftApp, items: Vec<Item>) -> Vec<Item> {
|
||||
let mut out: Vec<Item> = Vec::with_capacity(items.len());
|
||||
for it in items {
|
||||
@@ -280,7 +281,7 @@ fn prune(app: &VectorcraftApp, items: Vec<Item>) -> Vec<Item> {
|
||||
it => it,
|
||||
};
|
||||
let keep = match &it {
|
||||
Item::Cmd(_, id, _) => matches!(*id, "edit.undo" | "edit.redo") || enabled(app, id),
|
||||
Item::Cmd(_, id, _) => matches!(*id, "edit.undo" | "edit.redo" | "view.guides" | "view.grid") || enabled(app, id),
|
||||
Item::Sub(_, children) => !children.is_empty(),
|
||||
Item::Sep => out.last().is_some_and(|l| !matches!(l, Item::Sep)),
|
||||
_ => true,
|
||||
|
||||
@@ -135,6 +135,26 @@ pub fn run_ui_command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
|
||||
.or_else(|| run_ui_part13(app, id, p))
|
||||
}
|
||||
|
||||
/// Why Show/Hide Guides and Show/Hide Grid refuse to run while Trim View is on.
|
||||
pub(crate) const TRIM_VIEW_HIDES: &str = "Trim View hides the guides and the grid; turn it off first";
|
||||
|
||||
/// Drops the selection when it holds ruler guides or guide paths that no longer draw (Hide Guides,
|
||||
/// Trim View): their selection overlay would otherwise reveal the geometry just hidden.
|
||||
fn deselect_hidden_guides(app: &mut VectorcraftApp) {
|
||||
let hidden_selection = !app.ui.view.guides_shown()
|
||||
&& app.session.active().is_some_and(|d| {
|
||||
!d.selection.guides.is_empty()
|
||||
|| d.selection
|
||||
.objects
|
||||
.iter()
|
||||
.any(|id| matches!(d.doc.node(*id).map(|n| &n.kind), Some(vectorcraft_doc::NodeKind::Path { guide: true, .. })))
|
||||
});
|
||||
if hidden_selection {
|
||||
// Deselecting a document that is open cannot fail.
|
||||
let _ = app.run("select.none", json!({}));
|
||||
}
|
||||
}
|
||||
|
||||
/// UI commands, part 1.
|
||||
fn run_ui_part1(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<Value, String>> {
|
||||
let s = |k: &str| p.get(k).and_then(Value::as_str).map(str::to_string);
|
||||
@@ -292,7 +312,12 @@ fn run_ui_part3(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<
|
||||
};
|
||||
let r = match id {
|
||||
"view.pixelPreview" => flag(&mut app.ui.view.pixel_preview),
|
||||
"view.trimView" => flag(&mut app.ui.view.trim_view),
|
||||
// Trim View hides the guides while it is on (#8363), and hidden guides cannot stay selected.
|
||||
"view.trimView" => {
|
||||
let r = flag(&mut app.ui.view.trim_view);
|
||||
deselect_hidden_guides(app);
|
||||
r
|
||||
}
|
||||
"view.cornerWidget" => flag(&mut app.ui.view.corner_widgets),
|
||||
// Hide/Show Shape Widgets: `on` sets the state, and without it the state flips.
|
||||
"view.shapeWidgets" => opt_bool(p, "on").map(|on| {
|
||||
@@ -403,22 +428,12 @@ fn run_ui_part4(app: &mut VectorcraftApp, id: &str, _p: &Value) -> Option<Result
|
||||
Ok(json!(show))
|
||||
}
|
||||
"view.boundingBox" => flag(&mut app.ui.view.bounding_box),
|
||||
// Trim View hides the guides and the grid while it is on, and their Show/Hide items wait
|
||||
// until it is off (#8363).
|
||||
"view.guides" | "view.grid" if app.ui.view.trim_view => Err(TRIM_VIEW_HIDES.into()),
|
||||
"view.guides" => {
|
||||
let r = flag(&mut app.ui.view.guides);
|
||||
// Hidden ruler guides and guide paths cannot stay selected: their selection overlay
|
||||
// would otherwise reveal geometry that Hide Guides just hid.
|
||||
let hidden_selection = !app.ui.view.guides
|
||||
&& app.session.active().is_some_and(|d| {
|
||||
!d.selection.guides.is_empty()
|
||||
|| d.selection
|
||||
.objects
|
||||
.iter()
|
||||
.any(|id| matches!(d.doc.node(*id).map(|n| &n.kind), Some(vectorcraft_doc::NodeKind::Path { guide: true, .. })))
|
||||
});
|
||||
if hidden_selection {
|
||||
// Deselecting a document that is open cannot fail.
|
||||
let _ = app.run("select.none", json!({}));
|
||||
}
|
||||
deselect_hidden_guides(app);
|
||||
r
|
||||
}
|
||||
"view.smartGuides" => flag(&mut app.ui.view.smart_guides),
|
||||
|
||||
@@ -369,6 +369,9 @@ fn ui_enabled(app: &VectorcraftApp, id: &str) -> bool {
|
||||
"file.exportSelection" => app.session.active().is_some_and(|d| !d.selection.is_empty()),
|
||||
"css.copy" | "css.exportFile" => app.session.active().is_some(),
|
||||
"print.printerSetup" => app.services.print.as_ref().is_some_and(|s| s.has_setup()),
|
||||
// Trim View hides the guides and the grid while it is on, so their Show/Hide items wait
|
||||
// until it is off (#8363).
|
||||
"view.guides" | "view.grid" => !app.ui.view.trim_view,
|
||||
"view.refreshMonitorProfile" => app.session.prefs.monitor_profile_display && app.display_profile.has_reader(),
|
||||
"plugin.dialog" => app.session.active().is_some(),
|
||||
"ui.perspectiveGridDialog" | "ui.savePerspectivePreset" => app.session.active().is_some(),
|
||||
|
||||
@@ -1745,3 +1745,43 @@ fn selection_tools_toggle_propagates_a_failed_valid_choice() {
|
||||
}
|
||||
assert_eq!(failures, vec![Err(failure.to_string()), Err(failure.to_string())], "both failed valid choices must reach the command caller");
|
||||
}
|
||||
|
||||
/// #8363: while Trim View is on, View › Guides › Show/Hide Guides and View › Show/Hide Grid are
|
||||
/// greyed out (in the menu bar, on their keys and in the canvas context menu, where they stay
|
||||
/// listed), refuse to run and leave the choices they keep alone; turning it off brings them back.
|
||||
#[test]
|
||||
fn trim_view_greys_out_show_guides_and_show_grid() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.ui.view.grid = true;
|
||||
let listed = |app: &VectorcraftApp, id: &str| {
|
||||
fn find(items: &[Item], id: &str) -> bool {
|
||||
items.iter().any(|it| match it {
|
||||
Item::Cmd(_, c, _) => *c == id,
|
||||
Item::Sub(_, children) => find(children, id),
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
find(&context_items(app), id)
|
||||
};
|
||||
for id in ["view.guides", "view.grid"] {
|
||||
assert!(enabled(&app, id), "{id} runs with Trim View off");
|
||||
assert!(listed(&app, id), "{id} is in the canvas context menu");
|
||||
}
|
||||
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
for id in ["view.guides", "view.grid"] {
|
||||
assert!(!enabled(&app, id), "{id} is greyed out while Trim View is on");
|
||||
assert!(listed(&app, id), "{id} stays in the canvas context menu, greyed out");
|
||||
assert!(app.run(id, json!({})).is_err(), "{id} does not run while Trim View is on");
|
||||
}
|
||||
assert!(app.ui.view.guides && app.ui.view.grid, "the choices stay as they were");
|
||||
assert_eq!((checked(&app, "view.grid", &Value::Null), dynamic_label(&app, "view.guides", "Show Guides").as_str()), (Some(true), "Hide Guides"));
|
||||
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
for id in ["view.guides", "view.grid"] {
|
||||
assert!(enabled(&app, id), "{id} runs again with Trim View off");
|
||||
}
|
||||
app.run("view.guides", json!({})).unwrap();
|
||||
assert!(!app.ui.view.guides);
|
||||
}
|
||||
|
||||
@@ -767,7 +767,9 @@ fn document_sections(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
if widgets::icon_button(ui, "ruler", tl!("Show Rulers (⌘R)"), v.rulers, 26.0).clicked() {
|
||||
app.run("view.rulers", json!({})).ok();
|
||||
}
|
||||
if widgets::icon_button(ui, "grid-3x3", tl!("Show Grid (⌘')"), v.grid, 26.0).clicked() {
|
||||
// Trim View holds the grid and the guides off while it is on (#8363).
|
||||
let shows = crate::menus::enabled(app, "view.grid");
|
||||
if widgets::icon_button_enabled(ui, "grid-3x3", tl!("Show Grid (⌘')"), v.grid, shows, 26.0).clicked() {
|
||||
app.run("view.grid", json!({})).ok();
|
||||
}
|
||||
let transparency_grid = app.session.active().is_some_and(|d| d.transparency_grid);
|
||||
@@ -779,7 +781,8 @@ fn document_sections(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
section_header(ui, tl!("Guides"));
|
||||
ui.horizontal(|ui| {
|
||||
let v = app.ui.view.clone();
|
||||
if widgets::icon_button(ui, "layout-grid", tl!("Show Guides"), v.guides, 26.0).clicked() {
|
||||
let shows = crate::menus::enabled(app, "view.guides");
|
||||
if widgets::icon_button_enabled(ui, "layout-grid", tl!("Show Guides"), v.guides, shows, 26.0).clicked() {
|
||||
app.run("view.guides", json!({})).ok();
|
||||
}
|
||||
if widgets::icon_button(ui, "sparkles", tl!("Smart Guides (⌘U)"), v.smart_guides, 26.0).clicked() {
|
||||
|
||||
@@ -349,6 +349,19 @@ impl Default for ViewFlags {
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewFlags {
|
||||
/// Whether the ruler guides and guide paths draw: View › Show Guides, unless Trim View hides
|
||||
/// them while it is on (#8363). `guides` keeps the choice, so they come back as they were.
|
||||
pub fn guides_shown(&self) -> bool {
|
||||
self.guides && !self.trim_view
|
||||
}
|
||||
|
||||
/// Whether the grid draws: View › Show Grid, unless Trim View hides it while it is on (#8363).
|
||||
pub fn grid_shown(&self) -> bool {
|
||||
self.grid && !self.trim_view
|
||||
}
|
||||
}
|
||||
|
||||
/// An open modal dialog. `fields` are string-valued so agents can set them uniformly.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Dialog {
|
||||
|
||||
+3
-2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+3
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user