mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Merge main into fix/new-document-layout
This commit is contained in:
commit
4e7d97224a
20 files changed
+536
-51
No files matched your search
@@ -7,11 +7,17 @@
|
||||
//! fails in a Flatpak sandbox (`XCURSOR_PATH` unset, no cursor theme in the runtime) and where the
|
||||
//! `default` theme is a dangling symlink; the desktop's own setting names a theme that loads.
|
||||
//!
|
||||
//! Where no cursor theme can be found at all (KDE or sway without gsettings), the env fix does
|
||||
//! nothing: [`shell_caps`] leaves out [`Caps::SYSTEM_CURSOR`], and the framework keeps the system
|
||||
//! pointer and paints no tool cursor beside it (#5311).
|
||||
//!
|
||||
//! This reads the desktop's cursor theme and size and sets what the user left unset, once, before
|
||||
//! any thread starts and before the window opens.
|
||||
#![cfg_attr(not(target_os = "linux"), allow(dead_code))]
|
||||
|
||||
use craft::host::target::Caps;
|
||||
use std::ffi::OsString;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Where a Flatpak sandbox mounts the host's cursor themes (user and system).
|
||||
const FLATPAK_HOST_ICONS: [&str; 2] = ["/run/host/user-share/icons", "/run/host/share/icons"];
|
||||
@@ -48,6 +54,74 @@ pub fn plan(var: impl Fn(&str) -> Option<OsString>, host_icons: &[&str], desktop
|
||||
out
|
||||
}
|
||||
|
||||
/// Xcursor's default search path when `XCURSOR_PATH` is unset (relative entries are in `$HOME`).
|
||||
const DEFAULT_ICON_DIRS: [&str; 5] = ["~/.local/share/icons", "~/.icons", "/usr/share/icons", "/usr/share/pixmaps", "/usr/X11R6/lib/X11/icons"];
|
||||
|
||||
/// The themes `index.theme` lists after `Inherits=`.
|
||||
fn inherits(index: &str) -> Vec<String> {
|
||||
index
|
||||
.lines()
|
||||
.find_map(|l| l.trim().strip_prefix("Inherits="))
|
||||
.map(|v| v.split([',', ';']).map(|t| t.trim().to_owned()).filter(|t| !t.is_empty()).collect())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Can Xcursor load a pointer for the environment's theme (`XCURSOR_THEME`, else `default`)? It does
|
||||
/// when the theme, or one it inherits from, has a `default` or `left_ptr` cursor file in a folder of
|
||||
/// `XCURSOR_PATH` (else Xcursor's default folders). `read` returns a file's text, `exists` tells
|
||||
/// whether a file is there.
|
||||
pub fn theme_usable(
|
||||
var: impl Fn(&str) -> Option<OsString>,
|
||||
home: Option<&Path>,
|
||||
read: impl Fn(&Path) -> Option<String>,
|
||||
exists: impl Fn(&Path) -> bool,
|
||||
) -> bool {
|
||||
let dirs: Vec<PathBuf> = match var("XCURSOR_PATH").filter(|v| !v.is_empty()) {
|
||||
Some(v) => std::env::split_paths(&v).collect(),
|
||||
None => DEFAULT_ICON_DIRS
|
||||
.iter()
|
||||
.filter_map(|d| match d.strip_prefix("~/") {
|
||||
Some(rest) => home.map(|h| h.join(rest)),
|
||||
None => Some(PathBuf::from(d)),
|
||||
})
|
||||
.collect(),
|
||||
};
|
||||
let first = var("XCURSOR_THEME").and_then(|v| v.into_string().ok()).filter(|t| !t.is_empty()).unwrap_or_else(|| "default".into());
|
||||
let mut todo = vec![first];
|
||||
let mut seen: Vec<String> = Vec::new();
|
||||
while let Some(theme) = todo.pop() {
|
||||
// Bounded: themes inherit in short chains, and a cycle must end.
|
||||
if seen.contains(&theme) || seen.len() >= 16 {
|
||||
continue;
|
||||
}
|
||||
for dir in &dirs {
|
||||
let base = dir.join(&theme);
|
||||
if ["default", "left_ptr"].iter().any(|c| exists(&base.join("cursors").join(c))) {
|
||||
return true;
|
||||
}
|
||||
if let Some(index) = read(&base.join("index.theme")) {
|
||||
todo.extend(inherits(&index));
|
||||
}
|
||||
}
|
||||
seen.push(theme);
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// On this machine, after [`apply`]: is there no cursor theme Xcursor can load? Then winit never
|
||||
/// sets a pointer, and a hidden system pointer does not come back (#2450).
|
||||
pub fn theme_missing() -> bool {
|
||||
let home = std::env::var_os("HOME").filter(|h| !h.is_empty()).map(PathBuf::from);
|
||||
!theme_usable(|n| std::env::var_os(n), home.as_deref(), |p| std::fs::read_to_string(p).ok(), |p| p.exists())
|
||||
}
|
||||
|
||||
/// The shell's capabilities `caps`, without [`Caps::SYSTEM_CURSOR`] when the window opens on
|
||||
/// Wayland and `theme_missing` finds no cursor theme. The framework then keeps the system pointer
|
||||
/// and paints no tool cursor beside it (#5311). `theme_missing` runs only on Wayland.
|
||||
pub fn shell_caps(caps: Caps, wayland: bool, theme_missing: impl FnOnce() -> bool) -> Caps {
|
||||
if wayland && theme_missing() { caps.difference(Caps::SYSTEM_CURSOR) } else { caps }
|
||||
}
|
||||
|
||||
/// The value of a `gsettings get` line: `'Adwaita'` becomes `Adwaita`, `24` stays `24`.
|
||||
fn gsettings_value(output: &str) -> &str {
|
||||
output.trim().trim_matches('\'')
|
||||
@@ -113,6 +187,43 @@ mod tests {
|
||||
assert!(plan(env(&[("WAYLAND_DISPLAY", "wayland-0")]), &[], odd).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_theme_is_usable_directly_or_through_inherits_and_missing_otherwise() {
|
||||
let files = ["/i/Bibata/cursors/left_ptr", "/i/Breeze/index.theme", "/i/Loop/index.theme"];
|
||||
// Compared as paths, so the joins match on Windows too, where they use `\`.
|
||||
let exists = |p: &Path| files.iter().any(|f| Path::new(f) == p);
|
||||
let read = |p: &Path| {
|
||||
if p == Path::new("/i/Breeze/index.theme") {
|
||||
Some("[Icon Theme]\nInherits=Other, Bibata\n".to_owned())
|
||||
} else if p == Path::new("/i/Loop/index.theme") {
|
||||
Some("Inherits=Loop\n".to_owned())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
let with = |theme: &'static str| {
|
||||
move |n: &str| (n == "XCURSOR_PATH").then(|| OsString::from("/i")).or((n == "XCURSOR_THEME").then(|| OsString::from(theme)))
|
||||
};
|
||||
assert!(theme_usable(with("Bibata"), None, read, exists));
|
||||
assert!(theme_usable(with("Breeze"), None, read, exists));
|
||||
// No such theme, a theme without cursors, an inheritance loop: nothing to load.
|
||||
assert!(!theme_usable(with("Nope"), None, read, exists));
|
||||
assert!(!theme_usable(with("Loop"), None, read, exists));
|
||||
// Unset: Xcursor's default folders and the `default` theme.
|
||||
assert!(!theme_usable(|_| None, Some(Path::new("/home/u")), read, exists));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_a_cursor_theme_on_wayland_the_system_pointer_stays_alone() {
|
||||
let native = Caps::native(craft::host::target::Os::Linux);
|
||||
assert!(native.contains(Caps::SYSTEM_CURSOR));
|
||||
let without = shell_caps(native, true, || true);
|
||||
assert!(!without.contains(Caps::SYSTEM_CURSOR), "Wayland with no cursor theme: no painted cursor beside the system pointer");
|
||||
assert_eq!(without.union(Caps::SYSTEM_CURSOR), native, "only the system cursor is left out");
|
||||
assert_eq!(shell_caps(native, true, || false), native, "Wayland with a theme");
|
||||
assert_eq!(shell_caps(native, false, || panic!("the theme is looked up only on Wayland")), native, "X11 and XWayland");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gsettings_output_is_unquoted() {
|
||||
assert_eq!(gsettings_value("'Adwaita'\n"), "Adwaita");
|
||||
|
||||
@@ -667,6 +667,11 @@ fn main() -> std::process::ExitCode {
|
||||
// framework decides the frame for that backend, from the platform, `VECTORCRAFT_TITLEBAR` and
|
||||
// Preferences › User Interface › System Title Bar.
|
||||
let shell_info = if forced_to_x11 { ShellInfo::current().backend(Backend::X11) } else { ShellInfo::current() };
|
||||
// On Wayland with no cursor theme, the system pointer stays and no tool cursor is painted
|
||||
// beside it (#2450, #5311).
|
||||
let wayland = !forced_to_x11 && Backend::from_env() == Backend::Wayland;
|
||||
let caps = cursor_theme::shell_caps(shell_info.caps, wayland, cursor_theme::theme_missing);
|
||||
let shell_info = shell_info.caps(caps);
|
||||
let titlebar_pref =
|
||||
if engine_pref("systemTitleBar").and_then(|v| v.as_bool()).unwrap_or(false) { TitleBarPref::System } else { TitleBarPref::Integrated };
|
||||
let decision = decide_for(Prefix::new("VECTORCRAFT"), shell_info.backend, titlebar_pref);
|
||||
|
||||
@@ -262,6 +262,9 @@ fn distance_overlays(cx: &ToolContext, to: DistanceTo) -> Vec<Overlay> {
|
||||
/// it snaps to the original too.
|
||||
pub(crate) struct MoveSnap {
|
||||
bounds: Option<Rect>,
|
||||
/// The selection's geometric bounds, which Smart Guides line up with the other art's geometric
|
||||
/// bounds and space evenly between them, whether Use Preview Bounds is on or off (#6436).
|
||||
edges: Option<Rect>,
|
||||
targets: Option<Targets>,
|
||||
points: Option<Targets>,
|
||||
/// The targets and points for a copy, gathered with the others before the previews move the
|
||||
@@ -300,6 +303,7 @@ impl MoveSnap {
|
||||
let points = |exclude: &[NodeId]| if cx.snap_to_grid { None } else { Targets::snap_to_point(cx, exclude) };
|
||||
Self {
|
||||
bounds: selection_bounds(cx),
|
||||
edges: guides.then(|| cx.doc.bounds_of(&cx.selection.objects, false)).flatten(),
|
||||
targets: guides.then(|| for_move(cx, &cx.selection.objects)),
|
||||
points: points(&cx.selection.objects),
|
||||
copy_targets: guides.then(|| for_move(cx, &[])),
|
||||
@@ -312,7 +316,7 @@ impl MoveSnap {
|
||||
/// Snap to Grid and Snap to Pixel alone, for a move whose box is `bounds`: the grid lands an
|
||||
/// edge of the box on a gridline, and pixels put its top-left on whole pixels.
|
||||
pub(crate) fn grid_only(bounds: Option<Rect>) -> Self {
|
||||
Self { bounds, targets: None, points: None, copy_targets: None, copy_points: None, rulers: None, by_edge: false }
|
||||
Self { bounds, edges: None, 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,
|
||||
@@ -353,7 +357,7 @@ impl MoveSnap {
|
||||
// The grabbed anchor landed on a path or a crossing, which a ruler guide does not pull
|
||||
// it off.
|
||||
let mut on_path = false;
|
||||
if let (Some(t), Some(b)) = (targets, self.bounds) {
|
||||
if let (Some(t), Some(b)) = (targets, self.edges) {
|
||||
// The point the selection was grabbed by, near another object's anchor or centre,
|
||||
// lands on it, rather than the bounds lining up a little beside it (#955).
|
||||
if t.has_point_near(start + d, cx.snap_tol()) {
|
||||
@@ -434,7 +438,7 @@ impl MoveSnap {
|
||||
d = q - start;
|
||||
guides = ov;
|
||||
}
|
||||
if let (Some(t), Some(b)) = (targets, self.bounds) {
|
||||
if let (Some(t), Some(b)) = (targets, self.edges) {
|
||||
if t.has_point_near(start + d, cx.snap_tol()) {
|
||||
let (q, ov) = t.snap_point_along(start + d, u, cx.snap_tol());
|
||||
d = q - start;
|
||||
|
||||
@@ -1255,6 +1255,42 @@ fn an_alt_copy_snaps_to_the_original_left_behind() {
|
||||
assert_eq!(dx(&t.pointer(&c, &ev(PointerKind::Drag, 253.0, 150.0))), 103.0);
|
||||
}
|
||||
|
||||
/// With Use Preview Bounds on, Smart Guides line up the moved selection's geometric bounds with
|
||||
/// the other art's, as they do with it off: an edge lands exactly on the other path's edge, and the
|
||||
/// edge of a stroke does not pull it there (#6436).
|
||||
#[test]
|
||||
fn a_move_lines_up_geometric_edges_with_use_preview_bounds_on() {
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_doc::{Appearance, Node};
|
||||
// An artboard whose edges and center are out of reach, and two rectangles stroked 20 pt.
|
||||
let mut d = Document::new(1000.0, 1000.0);
|
||||
let l = d.layers[0].id;
|
||||
let mut add = |r: Rect| {
|
||||
let id = d.alloc_id();
|
||||
let wide = Appearance::basic(Paint::solid(Color::WHITE), Paint::solid(Color::BLACK), 20.0);
|
||||
d.insert(Some(l), 0, Node::path(id, vectorcraft_geom::shapes::rectangle(r), wide)).unwrap();
|
||||
id
|
||||
};
|
||||
let a = add(Rect::new(100.0, 100.0, 200.0, 200.0));
|
||||
add(Rect::new(300.0, 100.0, 400.0, 200.0));
|
||||
let s = Selection { objects: vec![a], ..Default::default() };
|
||||
let p = paint();
|
||||
for preview in [false, true] {
|
||||
let c = ToolContext { preview_bounds: preview, ..cx(&d, &s, &p) };
|
||||
let dragged = |to: f64| {
|
||||
let mut t = SelectionTool::default();
|
||||
t.pointer(&c, &ev(PointerKind::Down, 150.0, 150.0));
|
||||
let a = t.pointer(&c, &ev(PointerKind::Drag, to, 150.0));
|
||||
let Some(Action::Preview(_, v)) = a.last() else { panic!("{a:?}") };
|
||||
(v["matrix"][4].as_f64().unwrap(), v["matrix"][5].as_f64().unwrap())
|
||||
};
|
||||
// The right edge, 1 pt short of the other rectangle's left edge (x = 300), lands on it.
|
||||
assert_eq!(dragged(249.0), (100.0, 0.0), "preview {preview}");
|
||||
// 9 pt short, it stays where it is dragged, though the edge of its stroke is 1 pt past there.
|
||||
assert_eq!(dragged(241.0), (91.0, 0.0), "preview {preview}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Smart Guides › Snap to Last Location: a move that comes within Snapping Tolerance of where it
|
||||
/// began goes back there, labeled "last location", a Shift move too; farther out, with the option
|
||||
/// or Smart Guides off, it stays where it is dragged, and an Alt copy snaps as it does with the
|
||||
|
||||
@@ -395,7 +395,7 @@ fn compass(app: &VectorcraftApp, ui: &mut Ui, space: &CanvasSpace) -> Option<Can
|
||||
return None;
|
||||
}
|
||||
let mut turn = space.view.rotation;
|
||||
let rect = RotateView::compass_rect(ui, space.view.rect);
|
||||
let rect = RotateView::compass_rect(ui, clear_of_scroll_bars(app, ui, space.view.rect));
|
||||
RotateView::new(tl!("Rotate View"), Bind::bound(&mut turn), false).show_at(ui, rect);
|
||||
(turn != space.view.rotation).then(|| {
|
||||
let mut view = space.view;
|
||||
@@ -404,6 +404,17 @@ fn compass(app: &VectorcraftApp, ui: &mut Ui, space: &CanvasSpace) -> Option<Can
|
||||
})
|
||||
}
|
||||
|
||||
/// `rect` without the strip the vertical scroll bar takes along its right edge (the bar's thickness and its margin,
|
||||
/// the sizes `CanvasScrollbars` draws with), in the screen modes that show the scroll bars.
|
||||
fn clear_of_scroll_bars(app: &VectorcraftApp, ui: &Ui, rect: egui::Rect) -> egui::Rect {
|
||||
if app.ui.screen_mode >= 2 {
|
||||
return rect;
|
||||
}
|
||||
let env = Env::of(ui);
|
||||
let strip = env.tokens.size.icon.md + env.tokens.space.gap.tight;
|
||||
egui::Rect::from_min_max(rect.min, egui::pos2((rect.right() - strip).max(rect.left()), rect.bottom()))
|
||||
}
|
||||
|
||||
/// The scroll bars along the right and bottom edges (Normal and Full Screen with Menu Bar): the view
|
||||
/// a thumb drag or page press moved.
|
||||
fn scroll_bars(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpace) -> Option<CanvasView> {
|
||||
|
||||
@@ -19,7 +19,7 @@ use serde_json::json;
|
||||
use vectorcraft_geom::{Affine, Point};
|
||||
|
||||
use super::BodyKind;
|
||||
use super::raster::{backdrop, cache_key, frame_options, frame_ppp, frame_view, pixel_region, placed_key, plugin_key};
|
||||
use super::raster::{backdrop, cache_key, frame_options, frame_ppp, frame_view, pixel_region, placed_key, plugin_key, snapped_rect};
|
||||
use crate::doc_windows::Win;
|
||||
use crate::state::View;
|
||||
use crate::{CacheKey, VectorcraftApp};
|
||||
@@ -141,6 +141,7 @@ impl PaneSource {
|
||||
pub(super) fn new(app: &mut VectorcraftApp, ctx: &egui::Context, w: Win, cv: &CanvasView) -> Option<PaneSource> {
|
||||
let env = Env::of_root(ctx);
|
||||
let ppp = ctx.pixels_per_point();
|
||||
let device_ppp = ppp;
|
||||
let space = cv.rect;
|
||||
let v = crate::doc_windows::view(app, w).copied()?;
|
||||
let st = app.session.documents().get(w.0)?;
|
||||
@@ -165,7 +166,12 @@ impl PaneSource {
|
||||
Some([x0, y0, x1, y1]) => {
|
||||
egui::Rect::from_two_pos(cv.to_screen(Point::new(x0 as f64, y0 as f64)), cv.to_screen(Point::new(x1 as f64, y1 as f64)))
|
||||
}
|
||||
None => space,
|
||||
// The frame's own pixel size, centered on the pane and on whole device pixels, so each
|
||||
// of its pixels covers one device pixel.
|
||||
None => {
|
||||
let size = egui::vec2(pw as f32 / ppp, ph as f32 / ppp);
|
||||
snapped_rect(space.center() - size / 2.0, size, device_ppp)
|
||||
}
|
||||
};
|
||||
let frame = PaneFrame {
|
||||
key: PaneKey { slot: (st.uid, w.1) },
|
||||
|
||||
@@ -313,6 +313,18 @@ pub(super) fn frame_ppp(size: egui::Vec2, ppp: f32, max_side: usize) -> f32 {
|
||||
if longest.round() <= max { ppp } else { ppp * (max / longest) }
|
||||
}
|
||||
|
||||
/// Where a frame drawn `size` points across from `min` goes on a display of `device_ppp` pixels a
|
||||
/// point: `min` moved to the nearest device pixel, the size unchanged. A canvas whose corner falls
|
||||
/// between device pixels would otherwise draw every pixel of the frame across two device pixels,
|
||||
/// and each edge in the art would show as a soft double line.
|
||||
pub(super) fn snapped_rect(min: egui::Pos2, size: egui::Vec2, device_ppp: f32) -> egui::Rect {
|
||||
if !(device_ppp.is_finite() && device_ppp > 0.0) {
|
||||
return egui::Rect::from_min_size(min, size);
|
||||
}
|
||||
let snap = |c: f32| (c * device_ppp).round() / device_ppp;
|
||||
egui::Rect::from_min_size(pos2(snap(min.x), snap(min.y)), size)
|
||||
}
|
||||
|
||||
/// Pixel Preview: the whole document pixels (x0, y0, x1, y1) under the canvas, rotated view
|
||||
/// included. None when the view is degenerate, or when a side of the region is more than
|
||||
/// `max_side` pixels, the largest texture side the display supports.
|
||||
@@ -975,7 +987,8 @@ fn reproject_frame(app: &VectorcraftApp, painter: &egui::Painter, view: &CanvasV
|
||||
let old = CanvasView::new(old_rect, Point::new(k.cx, k.cy), k.zoom).rotation(rotation);
|
||||
let a = view.to_screen(old.to_doc(old_rect.min));
|
||||
let b = view.to_screen(old.to_doc(old_rect.max));
|
||||
painter.image(tex.id(), egui::Rect::from_min_max(a, b), egui::Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE);
|
||||
let placed = snapped_rect(a, b - a, painter.pixels_per_point());
|
||||
painter.image(tex.id(), placed, egui::Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE);
|
||||
}
|
||||
// The view turned after the last frame was rendered, and the worker renders the frame at
|
||||
// the new angle. Until it arrives, the last frame is drawn turned into this view: each
|
||||
|
||||
@@ -1191,6 +1191,45 @@ fn the_art_renders_within_the_largest_texture_side() {
|
||||
assert_eq!(pixel_region(&view, 1024), None, "more than the display's largest texture");
|
||||
}
|
||||
|
||||
/// On a display of 2 pixels a point, a canvas whose corner falls between device pixels still draws
|
||||
/// its art's frame on whole device pixels at its own size, so each frame pixel covers one device
|
||||
/// pixel and a stroke's edges stay sharp instead of spreading over two device pixels.
|
||||
#[test]
|
||||
fn the_art_lands_on_whole_device_pixels() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width":400,"height":300})).unwrap();
|
||||
app.canvas.worker_started = true; // every frame on this thread
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.set_pixels_per_point(2.0);
|
||||
let mut shapes = vec![];
|
||||
// The first frame sets the pixels a point, the second draws at them.
|
||||
for _ in 0..2 {
|
||||
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(pos2(31.3, 19.7), vec2(800.3, 600.35))), ..Default::default() };
|
||||
let mut out = ctx.run_ui(raw, |ui| show(&mut app, ui));
|
||||
out.textures_delta.clear();
|
||||
shapes = flat_shapes(out.shapes);
|
||||
}
|
||||
let ppp = ctx.pixels_per_point();
|
||||
assert_eq!(ppp, 2.0);
|
||||
let rect = app.canvas_view().unwrap().rect;
|
||||
let off_grid = |c: f32| ((c * ppp) - (c * ppp).round()).abs() > 0.01;
|
||||
assert!(off_grid(rect.min.x) || off_grid(rect.min.y), "the canvas {rect:?} starts between device pixels");
|
||||
let tex = app.canvas.texture.as_ref().expect("a rendered frame");
|
||||
let (tid, size) = (tex.id(), tex.size());
|
||||
let drawn = shapes
|
||||
.iter()
|
||||
.find_map(|s| match s {
|
||||
Shape::Mesh(m) if m.texture_id == tid => Some(m.calc_bounds()),
|
||||
_ => None,
|
||||
})
|
||||
.expect("the frame is drawn");
|
||||
for (c, what) in [(drawn.min.x, "left"), (drawn.min.y, "top")] {
|
||||
assert!(!off_grid(c), "the frame's {what} edge {c} is not on a device pixel");
|
||||
}
|
||||
assert!((drawn.width() * ppp - size[0] as f32).abs() < 0.01, "{} device pixels across for {} frame pixels", drawn.width() * ppp, size[0]);
|
||||
assert!((drawn.height() * ppp - size[1] as f32).abs() < 0.01, "{} device pixels down for {} frame pixels", drawn.height() * ppp, size[1]);
|
||||
}
|
||||
|
||||
/// `rgb` as the display transform `t` shows it.
|
||||
fn convert8(t: &craft::color_ui::display::DisplayTransform, rgb: [u8; 3]) -> [u8; 3] {
|
||||
let mut px = [rgb[0], rgb[1], rgb[2], 255];
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::cell::RefCell;
|
||||
use craft::behavior::IconId;
|
||||
use craft::menu::MenuBarUi;
|
||||
use craft::ui::buttons::{Button, IconButton, ToggleButton};
|
||||
use craft::ui::contract::{Bind, BodyCx, Props, Show, ShowContainer};
|
||||
use craft::ui::contract::{Bind, BodyCx, Gap, Props, Show, ShowContainer};
|
||||
use craft::ui::display::Picture;
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::primitives::IconSpec;
|
||||
@@ -114,17 +114,20 @@ fn leading(ui: &mut Ui, app: &mut VectorcraftApp) {
|
||||
}
|
||||
|
||||
/// The end of the bar: each ranked control in a row of its own, which the fitted title bar gives up whole, lowest rank
|
||||
/// first, before the menus narrow.
|
||||
/// first, before the menus narrow. The controls are `space.gap.item` apart, the gap between neighboring controls in a
|
||||
/// bar.
|
||||
fn trailing(ui: &mut Ui, app: &mut VectorcraftApp) {
|
||||
let safe = vectorcraft_plugins::safe_mode::active();
|
||||
for t in Trailing::SHOWN.into_iter().filter(|t| safe || *t != Trailing::Safe) {
|
||||
match t.rank() {
|
||||
Some(rank) => {
|
||||
Row::new().fit_rank(rank).show(ui, |ui, _| t.show(app, ui));
|
||||
Row::new().gap(Gap::Item).show(ui, |ui, _| {
|
||||
for t in Trailing::SHOWN.into_iter().filter(|t| safe || *t != Trailing::Safe) {
|
||||
match t.rank() {
|
||||
Some(rank) => {
|
||||
Row::new().fit_rank(rank).show(ui, |ui, _| t.show(app, ui));
|
||||
}
|
||||
None => t.show(app, ui),
|
||||
}
|
||||
None => t.show(app, ui),
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// The application bar, the body of the shell's title bar: brand mark, Home and menus, then Discord,
|
||||
|
||||
@@ -120,8 +120,15 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
}
|
||||
}
|
||||
Field::new(tl!("Artboard")).side(SideLabel::new().kind(LabelKind::Hidden)).show(ui, |ui, _| {
|
||||
if let Some(i) =
|
||||
Select::new(tl!("Artboard"), Bind::given(cur), &boards).look(SelectLook::Filled).enabled(nab > 0).show(ui).events.committed().copied()
|
||||
// With no document the navigator shows a dash, as the info readout does.
|
||||
if let Some(i) = Select::new(tl!("Artboard"), Bind::given(cur), &boards)
|
||||
.placeholder("\u{2013}")
|
||||
.look(SelectLook::Filled)
|
||||
.enabled(nab > 0)
|
||||
.show(ui)
|
||||
.events
|
||||
.committed()
|
||||
.copied()
|
||||
{
|
||||
go = Some(json!(i));
|
||||
}
|
||||
@@ -264,6 +271,15 @@ mod tests {
|
||||
assert_eq!(app.session.active().unwrap().history.undo.len(), undo);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_no_document_the_artboard_navigator_shows_a_dash() {
|
||||
let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
let mut panel = Panel::new(app, status_bar);
|
||||
panel.room(egui::vec2(1200.0, 300.0));
|
||||
panel.frame();
|
||||
assert_eq!(panel.value_role("Artboard", Role::COMBO_BOX).as_deref(), Some("\u{2013}"), "the empty navigator reads as a dash");
|
||||
}
|
||||
}
|
||||
|
||||
/// What the bar shows as work in progress: the running script, then background jobs, opens and places. The first
|
||||
|
||||
@@ -473,6 +473,28 @@ fn the_app_bar_gives_up_its_right_hand_controls_in_order() {
|
||||
assert!(widest.zip(narrowest).is_some_and(|(w, n)| n >= w - 0.5), "the search keeps its width until it goes: {search_widths:?}");
|
||||
}
|
||||
|
||||
/// The app bar's right-hand controls stand at least `space.gap.item` apart, the gap between neighboring controls in a
|
||||
/// bar, so a hovered control's highlight does not touch the one beside it.
|
||||
#[test]
|
||||
fn the_app_bar_keeps_its_right_hand_controls_an_item_gap_apart() {
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
let app = crate::VectorcraftApp::new(Session::new(), Default::default());
|
||||
let gap = Rc::new(std::cell::Cell::new(0.0_f32));
|
||||
let read = Rc::clone(&gap);
|
||||
let mut bar = Shown::new(app, egui::vec2(1600.0, 600.0), move |app, ui| {
|
||||
read.set(craft::ui::runtime::env::Env::of(ui).tokens.space.gap.item);
|
||||
app.ui(ui);
|
||||
});
|
||||
bar.frame(Vec::new()).frame(Vec::new());
|
||||
assert!(gap.get() > 0.0, "the item gap is read from the theme");
|
||||
let controls = ["Discord", "Search commands", "Choose a workspace"];
|
||||
let rects: Vec<egui::Rect> = controls.iter().map(|c| bar.starting(c).unwrap_or_else(|| panic!("{c} shows")).rect).collect();
|
||||
for pair in rects.windows(2) {
|
||||
let between = pair[1].left() - pair[0].right();
|
||||
assert!(between >= gap.get() - 0.5, "neighboring controls {pair:?} are {between} apart, under the item gap {}", gap.get());
|
||||
}
|
||||
}
|
||||
|
||||
/// A text the status bar painted, with where it lies.
|
||||
#[derive(Debug)]
|
||||
struct StatusText {
|
||||
|
||||
@@ -87,8 +87,11 @@ fn dialog<'a>(relative: bool, lengths: LengthUnits) -> ParamDialog<'a> {
|
||||
Param::number("radius", tl!("Radius:"), 0.0, 1.0, 3).length(lengths).bounds(Some(0.0), None)
|
||||
};
|
||||
let radii = vec![("relative".to_owned(), tl!("Relative").into()), ("absolute".to_owned(), tl!("Absolute").into())];
|
||||
let params =
|
||||
vec![Param::new("kind", tl!("Corner:"), ParamKind::radio(kinds, None)), Param::new("radii", "", ParamKind::radio(radii, None)), radius];
|
||||
let params = vec![
|
||||
Param::new("kind", tl!("Corner:"), ParamKind::radio(kinds, None)),
|
||||
Param::new("radii", "", ParamKind::radio(radii, None)).options_in_row(),
|
||||
radius,
|
||||
];
|
||||
ParamDialog::new(KIND, tl!("Corners"), params)
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ fn sized_row(key: &str, label: Label, default: f64, relative: bool, lengths: Len
|
||||
/// the flag's JSON values, which `form::json_of` writes back as a bool.
|
||||
pub(super) fn relative_radio(label: impl Into<Label>, default: bool) -> Param {
|
||||
let options = vec![("true".to_owned(), lbl!("Relative")), ("false".to_owned(), lbl!("Absolute"))];
|
||||
Param::new("relative", label, ParamKind::radio(options, Some(default.to_string())))
|
||||
Param::new("relative", label, ParamKind::radio(options, Some(default.to_string()))).options_in_row()
|
||||
}
|
||||
|
||||
/// Whether the pair's rows are shares of the object's size.
|
||||
@@ -71,14 +71,16 @@ pub(super) fn transform(cx: &EffectCx, _fields: &DialogFields) -> Vec<Param> {
|
||||
let lengths = cx.lengths;
|
||||
vec![
|
||||
Param::custom("transform", lbl!("Transform"), move |ui, fields, _| transform_each::rows(ui, fields, lengths, ScaleLink::None))
|
||||
.companions(["scaleH", "scaleV", "moveH", "moveV", "rotate"]),
|
||||
.companions(["scaleH", "scaleV", "moveH", "moveV", "rotate"])
|
||||
.full_width(),
|
||||
Param::section(lbl!("Options")),
|
||||
Param::new("objects", lbl!("Transform Objects"), ParamKind::bool(true)),
|
||||
Param::new("patterns", lbl!("Transform Patterns"), ParamKind::bool(false)),
|
||||
Param::new("strokes", lbl!("Scale Strokes & Effects"), ParamKind::bool(false)),
|
||||
Param::new("copies", lbl!("Copies:"), ParamKind::int(Some(0), Some(1000), 0)),
|
||||
Param::custom("__reflect", lbl!("Reflect"), |ui, fields, _| transform_each::reflect_checks(ui, fields))
|
||||
.companions(["reflectX", "reflectY", "random"]),
|
||||
Param::new("reflectX", lbl!("Reflect X"), ParamKind::bool(false)),
|
||||
Param::new("reflectY", lbl!("Reflect Y"), ParamKind::bool(false)),
|
||||
Param::new("random", lbl!("Random"), ParamKind::bool(false)),
|
||||
Param::custom("__reference", lbl!("Reference Point"), |ui, fields, _| transform_each::reference_point(ui, fields)).companions(["reference"]),
|
||||
]
|
||||
}
|
||||
@@ -102,7 +104,8 @@ pub(super) fn distort(cx: &EffectCx, fields: &DialogFields) -> Vec<Param> {
|
||||
"points",
|
||||
Label::from(crate::i18n::tr_ctx(crate::i18n::current(), "effect", "Points").to_string()),
|
||||
ParamKind::radio(points, None),
|
||||
),
|
||||
)
|
||||
.options_in_row(),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -185,12 +188,13 @@ pub(super) fn drop_shadow(cx: &EffectCx, fields: &DialogFields) -> Vec<Param> {
|
||||
.map(|p| if matches!(p.key.as_str(), "opacity" | "x" | "y" | "blur") { p.step_arrows(StepArrows::Leading) } else { p });
|
||||
rows.chain([
|
||||
Param::new("shade", Label::Empty, ParamKind::radio(shades, None)),
|
||||
Param::new("color", lbl!("Color"), ParamKind::color(None)).enabled_when("shade", "color"),
|
||||
Param::new("color", lbl!("Color"), ParamKind::color(None)).enabled_when("shade", "color").under_option("color"),
|
||||
Param::number("darkness", lbl!("Darkness"), 100.0, 1.0, 0)
|
||||
.bounds(Some(0.0), Some(100.0))
|
||||
.unit(UnitKind::Percent)
|
||||
.step_arrows(StepArrows::Leading)
|
||||
.enabled_when("shade", "darkness"),
|
||||
.enabled_when("shade", "darkness")
|
||||
.under_option("darkness"),
|
||||
])
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -706,7 +706,10 @@ fn sections(lists: &Lists) -> Vec<PrintSection> {
|
||||
flag("collate", tl!("Collate")).enabled_when_in("copies", counts),
|
||||
flag("reverse", tl!("Reverse Order")),
|
||||
Param::new("artboards", tl!("Artboards"), ParamKind::radio(artboards, None)),
|
||||
Param::new("range", tl!("Range:"), ParamKind::text("")).hint("1-3, 5").enabled_when("artboards", PrintArtboards::Range.id()),
|
||||
Param::new("range", tl!("Range:"), ParamKind::text(""))
|
||||
.hint("1-3, 5")
|
||||
.enabled_when("artboards", PrintArtboards::Range.id())
|
||||
.under_option(PrintArtboards::Range.id()),
|
||||
flag("skipBlank", tl!("Skip Blank Artboards")).enabled_when_in("artboards", [PrintArtboards::All.id(), PrintArtboards::Range.id()]),
|
||||
Param::section(tl!("Media")),
|
||||
pick::<Media>("media", tl!("Size:")),
|
||||
|
||||
@@ -445,6 +445,15 @@ pub(crate) fn reference_point(ui: &mut Ui, fields: &mut DialogFields) -> Respons
|
||||
shown.response
|
||||
}
|
||||
|
||||
/// The reference point picker with its name beside it, for a full-width row that draws no label of its own.
|
||||
fn labelled_reference_point(ui: &mut Ui, fields: &mut DialogFields) -> Response {
|
||||
let shown = Row::new().show(ui, |ui, _| {
|
||||
reference_point(ui, fields);
|
||||
Text::new(tl!("Reference Point")).show(ui);
|
||||
});
|
||||
shown.output
|
||||
}
|
||||
|
||||
/// The dialog's rows: Scale, Move and Rotate in one row, then the options.
|
||||
fn dialog_params(lengths: LengthUnits) -> Vec<Param> {
|
||||
vec![
|
||||
@@ -464,7 +473,7 @@ fn dialog_params(lengths: LengthUnits) -> Vec<Param> {
|
||||
Ok(())
|
||||
})
|
||||
.full_width(),
|
||||
Param::custom("reference", tl!("Reference Point"), |ui, f, _| reference_point(ui, f))
|
||||
Param::custom("reference", tl!("Reference Point"), |ui, f, _| labelled_reference_point(ui, f))
|
||||
.on_set(|f, key, value| {
|
||||
let at = value.as_i64().filter(|at| (0..=8).contains(at)).ok_or_else(|| FieldRefusal::Rejects(&value).message(key))?;
|
||||
f.set(key, at);
|
||||
|
||||
@@ -5,10 +5,10 @@ use craft::behavior::IconId;
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::ui::buttons::{Button, IconButton};
|
||||
use craft::ui::choice::Checkbox;
|
||||
use craft::ui::contract::{Bind, LabelScheme, Props as _, Show as _, ShowContainer as _, Sizing, Trigger, clicked};
|
||||
use craft::ui::contract::{Bind, Gap, LabelScheme, Props as _, Show as _, ShowContainer as _, Sizing, Trigger, clicked};
|
||||
use craft::ui::display::{Elide, Shade, Text};
|
||||
use craft::ui::form::Field;
|
||||
use craft::ui::layout_components::Row;
|
||||
use craft::ui::form::{Field, FieldGroup};
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::menu::Menu;
|
||||
use craft::ui::popover::Popover;
|
||||
use craft::ui::style::TypeRole;
|
||||
@@ -194,27 +194,40 @@ pub(crate) fn global_edit_options(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let caption = |ui: &mut Ui, text: &'static str| {
|
||||
Text::new(text).role(TypeRole::Caption).shade(Shade::Muted).show(ui);
|
||||
};
|
||||
caption(ui, tl!("Match"));
|
||||
if let Some(on) = option_check(ui, tl!("Appearance"), o.appearance) {
|
||||
set(app, json!({ "appearance": on }));
|
||||
let results = global_edit_results(global_edit_count(app));
|
||||
// Each group is its caption over its options a row gap apart; the groups and the Results line are a stack gap
|
||||
// apart. A click is kept and run after the stack returns.
|
||||
let mut changes = Vec::new();
|
||||
Stack::new().gap(Gap::Stack).show(ui, |ui, _| {
|
||||
FieldGroup::new(tl!("Match")).show(ui, |ui, _| {
|
||||
caption(ui, tl!("Match"));
|
||||
if let Some(on) = option_check(ui, tl!("Appearance"), o.appearance) {
|
||||
changes.push(json!({ "appearance": on }));
|
||||
}
|
||||
if let Some(on) = option_check(ui, tl!("Size"), o.size) {
|
||||
changes.push(json!({ "size": on }));
|
||||
}
|
||||
});
|
||||
FieldGroup::new(tl!("On Artboards")).show(ui, |ui, _| {
|
||||
caption(ui, tl!("On Artboards"));
|
||||
if let Some(all) = option_check(ui, tl!("All Artboards"), o.artboards.is_none()) {
|
||||
changes.push(json!({ "artboards": if all { "all" } else { "1" } }));
|
||||
}
|
||||
if let Some(range) = &o.artboards {
|
||||
let typed = Field::new(tl!("Range:")).show(ui, |ui, _| TextField::new(tl!("Range:"), Bind::given(range.clone())).show(ui)).inner;
|
||||
if let Some(range) = typed.and_then(|t| t.events.committed().cloned()) {
|
||||
changes.push(json!({ "artboards": range }));
|
||||
}
|
||||
}
|
||||
if let Some(on) = option_check(ui, tl!("Include Objects On Canvas"), o.include_canvas) {
|
||||
changes.push(json!({ "includeCanvas": on }));
|
||||
}
|
||||
});
|
||||
Text::new(results.clone()).shade(Shade::Muted).show(ui);
|
||||
});
|
||||
for p in changes {
|
||||
set(app, p);
|
||||
}
|
||||
if let Some(on) = option_check(ui, tl!("Size"), o.size) {
|
||||
set(app, json!({ "size": on }));
|
||||
}
|
||||
caption(ui, tl!("On Artboards"));
|
||||
if let Some(all) = option_check(ui, tl!("All Artboards"), o.artboards.is_none()) {
|
||||
set(app, json!({ "artboards": if all { "all" } else { "1" } }));
|
||||
}
|
||||
if let Some(range) = &o.artboards {
|
||||
let typed = Field::new(tl!("Range:")).show(ui, |ui, _| TextField::new(tl!("Range:"), Bind::given(range.clone())).show(ui)).inner;
|
||||
if let Some(range) = typed.and_then(|t| t.events.committed().cloned()) {
|
||||
set(app, json!({ "artboards": range }));
|
||||
}
|
||||
}
|
||||
if let Some(on) = option_check(ui, tl!("Include Objects On Canvas"), o.include_canvas) {
|
||||
set(app, json!({ "includeCanvas": on }));
|
||||
}
|
||||
Text::new(global_edit_results(global_edit_count(app))).shade(Shade::Muted).show(ui);
|
||||
}
|
||||
|
||||
/// The options' line with how many objects Start Global Edit would take, in the interface language.
|
||||
|
||||
@@ -181,6 +181,34 @@ fn global_edit_starting_closes_the_quick_action_options() {
|
||||
assert!(!panel.app().ui.properties_panel.global_edit_open && !panel.shows(&results), "the options stay closed once Global Edit stops");
|
||||
}
|
||||
|
||||
/// The Global Edit Options are two groups, Match and On Artboards, and the Results line: the On Artboards caption is a
|
||||
/// stack gap below the Size option, and the Results line a stack gap below Include Objects On Canvas.
|
||||
#[test]
|
||||
fn global_edit_options_groups_are_a_stack_gap_apart() {
|
||||
use craft::ui::contract::Role;
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
let stack = std::rc::Rc::new(std::cell::Cell::new(0.0));
|
||||
let seen = std::rc::Rc::clone(&stack);
|
||||
craft::ui::testing::Fixture::new(move |ui| seen.set(craft::ui::runtime::env::Env::of(ui).tokens.space.gap.stack)).frame(vec![]);
|
||||
let stack = stack.get();
|
||||
assert!(stack > 0.0, "the interface resolved its stack gap");
|
||||
let mut app = new_app();
|
||||
let a = rect(&mut app, 20.0, 20.0, 40.0, 40.0);
|
||||
rect(&mut app, 200.0, 20.0, 40.0, 40.0);
|
||||
app.run("select.set", json!({"ids": [a]})).unwrap();
|
||||
let mut panel = Panel::new(app, super::appearance_section::global_edit_row);
|
||||
panel.click("Global Edit Options");
|
||||
let results = global_edit_results(2);
|
||||
assert!(panel.shows(&results), "the options open");
|
||||
let size = panel.rect_role("Size", Role::CHECK_BOX);
|
||||
let caption = panel.rect_role("On Artboards", Role::LABEL);
|
||||
let canvas = panel.rect_role("Include Objects On Canvas", Role::CHECK_BOX);
|
||||
let line = panel.rect(&results);
|
||||
let (above, below) = (caption.top() - size.bottom(), line.top() - canvas.bottom());
|
||||
assert!(above >= stack - 0.5, "On Artboards is {above} below Size, under the stack gap {stack}");
|
||||
assert!(below >= stack - 0.5, "Results is {below} below the last option, under the stack gap {stack}");
|
||||
}
|
||||
|
||||
/// The options' Results count is found once per document revision, options and selected
|
||||
/// object, not every frame; another selected object or other options find it again.
|
||||
#[test]
|
||||
|
||||
@@ -5,6 +5,7 @@ pub(super) mod background;
|
||||
mod clipboard;
|
||||
mod contextmenu;
|
||||
mod cut;
|
||||
mod dialog_layout;
|
||||
mod distortkeys;
|
||||
mod document_drag;
|
||||
mod drag_commands;
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
//! Where the parameter dialogs draw their rows: option rows stand beside or under the choice they belong to, and
|
||||
//! every check box and picker shows its name.
|
||||
|
||||
use egui::{Pos2, Rect};
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
type Window = egui_kittest::Harness<'static, VectorcraftApp>;
|
||||
|
||||
/// A document with one selected rectangle, in a window that runs whole app frames.
|
||||
fn window() -> Window {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 120, "height": 90})).unwrap();
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
let mut fonts = false;
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 900.0)).build_ui_state(
|
||||
move |ui, app: &mut VectorcraftApp| {
|
||||
if !std::mem::replace(&mut fonts, true) {
|
||||
crate::testing::install(ui.ctx());
|
||||
return;
|
||||
}
|
||||
app.tick(ui.ctx());
|
||||
app.ui(ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
let root = h.input_mut().viewports.entry(egui::ViewportId::ROOT).or_default();
|
||||
root.inner_rect = Some(Rect::from_min_size(Pos2::ZERO, egui::vec2(1200.0, 900.0)));
|
||||
root.focused = Some(true);
|
||||
for _ in 0..2 {
|
||||
step(&mut h);
|
||||
}
|
||||
h
|
||||
}
|
||||
|
||||
/// One frame as the hosts run the window's; the commands it fired run as the next frame begins.
|
||||
fn step(h: &mut Window) {
|
||||
let ctx = h.ctx.clone();
|
||||
let app = h.state_mut();
|
||||
app.adopt_context(&ctx);
|
||||
craft::ui::shell::embed::before_input(&ctx, |out| app.frame_input(out));
|
||||
h.step();
|
||||
crate::testing::run_fired(h.state_mut(), &ctx);
|
||||
}
|
||||
|
||||
/// The texts the window paints with `command` run, each with where it was drawn, a field label's colon left off.
|
||||
fn texts(command: &str, params: Value) -> Vec<(String, Rect)> {
|
||||
fn collect(s: &egui::Shape, out: &mut Vec<(String, Rect)>) {
|
||||
match s {
|
||||
egui::Shape::Text(t) => out.push((t.galley.text().trim().trim_end_matches(':').to_owned(), t.visual_bounding_rect())),
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| collect(s, out)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut h = window();
|
||||
crate::menus::invoke(h.state_mut(), command, params);
|
||||
for _ in 0..6 {
|
||||
step(&mut h);
|
||||
}
|
||||
let mut out = vec![];
|
||||
h.output().shapes.iter().for_each(|c| collect(&c.shape, &mut out));
|
||||
out
|
||||
}
|
||||
|
||||
/// Where each painted `label` was drawn, top to bottom.
|
||||
fn all(texts: &[(String, Rect)], label: &str) -> Vec<Rect> {
|
||||
let mut found: Vec<Rect> = texts.iter().filter(|(t, _)| t == label).map(|(_, r)| *r).collect();
|
||||
found.sort_by(|a, b| a.top().total_cmp(&b.top()));
|
||||
found
|
||||
}
|
||||
|
||||
/// The one painted `label`.
|
||||
fn one(texts: &[(String, Rect)], label: &str) -> Rect {
|
||||
let found = all(texts, label);
|
||||
assert_eq!(found.len(), 1, "`{label}` drawn {} times in {:?}", found.len(), texts.iter().map(|t| &t.0).collect::<Vec<_>>());
|
||||
found[0]
|
||||
}
|
||||
|
||||
/// `b` stands on `a`'s line, to its right.
|
||||
fn beside(a: Rect, b: Rect) -> bool {
|
||||
(a.center().y - b.center().y).abs() < a.height() / 2.0 && b.left() > a.right()
|
||||
}
|
||||
|
||||
/// The Transform effect names its Reflect X, Reflect Y and Random check boxes.
|
||||
#[test]
|
||||
fn the_transform_effect_names_its_reflect_options() {
|
||||
let shown = texts("effect.dialog", json!({"effect": "distort.transform"}));
|
||||
for label in ["Reflect X", "Reflect Y", "Random"] {
|
||||
one(&shown, label);
|
||||
}
|
||||
}
|
||||
|
||||
/// Transform Each names its reference point picker.
|
||||
#[test]
|
||||
fn transform_each_names_its_reference_point() {
|
||||
let shown = texts("object.transformEach", json!({}));
|
||||
one(&shown, "Reference Point");
|
||||
}
|
||||
|
||||
/// Roughen's Relative and Absolute stand on one line, and so do Smooth and Corner.
|
||||
#[test]
|
||||
fn roughen_puts_each_choice_on_one_line() {
|
||||
let shown = texts("effect.dialog", json!({"effect": "distort.roughen"}));
|
||||
assert!(beside(one(&shown, "Relative"), one(&shown, "Absolute")), "Relative, then Absolute on its line");
|
||||
// The Properties panel also shows a Corner row; the dialog's Corner is the one on Smooth's line.
|
||||
let smooth = one(&shown, "Smooth");
|
||||
assert!(all(&shown, "Corner").into_iter().any(|corner| beside(smooth, corner)), "Smooth, then Corner on its line");
|
||||
}
|
||||
|
||||
/// The Corners dialog's Relative and Absolute stand on one line.
|
||||
#[test]
|
||||
fn corners_puts_relative_and_absolute_on_one_line() {
|
||||
let shown = texts("ui.corners", json!({}));
|
||||
assert!(beside(one(&shown, "Relative"), one(&shown, "Absolute")), "Relative, then Absolute on its line");
|
||||
}
|
||||
|
||||
/// Drop Shadow's color row stands under the Color choice, before Darkness, and the Darkness row under Darkness.
|
||||
#[test]
|
||||
fn drop_shadow_rows_stand_under_their_choice() {
|
||||
let shown = texts("effect.dialog", json!({"effect": "stylize.dropShadow"}));
|
||||
let mut order: Vec<(f32, &str)> = ["Color", "Darkness"].iter().flat_map(|l| all(&shown, l).into_iter().map(move |r| (r.top(), *l))).collect();
|
||||
order.sort_by(|a, b| a.0.total_cmp(&b.0));
|
||||
let labels: Vec<&str> = order.iter().map(|(_, l)| *l).collect();
|
||||
assert_eq!(labels, ["Color", "Color", "Darkness", "Darkness"], "each choice, then its row");
|
||||
}
|
||||
|
||||
/// Print's Range field stands under the Range choice, before Ignore Artboards.
|
||||
#[test]
|
||||
fn print_range_stands_under_its_choice() {
|
||||
let shown = texts("file.print", json!({}));
|
||||
let ignore = one(&shown, "Ignore Artboards (all the art as one page)");
|
||||
let ranges = all(&shown, "Range");
|
||||
assert_eq!(ranges.len(), 2, "the choice and the field");
|
||||
assert!(ranges.iter().all(|r| r.bottom() <= ignore.top()), "the Range field before Ignore Artboards");
|
||||
}
|
||||
@@ -318,6 +318,26 @@ fn rotate_view_to_selection_squares_the_view_to_the_selected_object() {
|
||||
assert!(square_on_screen(&app));
|
||||
}
|
||||
|
||||
/// The Rotate View compass of a turned view sits clear of the vertical scroll bar, so the bar does not cover it.
|
||||
#[test]
|
||||
fn the_rotate_view_compass_is_clear_of_the_vertical_scroll_bar() {
|
||||
let mut w = Window::new();
|
||||
w.ctx.enable_accesskit();
|
||||
w.after(0.0, vec![]);
|
||||
let out = w.after(0.0, vec![]);
|
||||
let nodes = out.platform_output.accesskit_update.as_ref().map_or(&[][..], |u| &u.nodes[..]);
|
||||
let bounds = |label: &str| {
|
||||
nodes
|
||||
.iter()
|
||||
.find(|(_, n)| n.label() == Some(label))
|
||||
.and_then(|(_, n)| n.bounds())
|
||||
.map(|b| egui::Rect::from_min_max(egui::pos2(b.x0 as f32, b.y0 as f32), egui::pos2(b.x1 as f32, b.y1 as f32)))
|
||||
.unwrap_or_else(|| panic!("no {label} in the access tree"))
|
||||
};
|
||||
let (compass, bar) = (bounds("Rotation compass"), bounds("Vertical scroll bar"));
|
||||
assert!(compass.right() <= bar.left(), "the compass {compass:?} reaches under the scroll bar {bar:?}");
|
||||
}
|
||||
|
||||
/// The window, with a 400 × 300 document whose view is turned to 30°, and the Selection tool. Each
|
||||
/// frame comes the given number of seconds, zero or more, after the one before it.
|
||||
struct Window {
|
||||
|
||||
Reference in new issue
Block a user