Merge main into fix/new-document-recent-units

This commit is contained in:
dotCooCoo
2026-12-04 01:59:15 -08:00
15 changed files with 491 additions and 40 deletions
+5 -2
View File
@@ -409,11 +409,14 @@ impl Session {
/// The selection tool a press at `p` with `mods` borrows ([`Self::lent_tool`]): none when
/// the Selection tool keeps a Cmd press on a selected object to select the object behind it
/// (Selection & Anchor Display › Command Click to Select Objects Behind), which an earlier Cmd
/// press armed ([`Self::behind_armed`]).
/// press armed ([`Self::behind_armed`]); none either when the active tool keeps the press
/// ([`vectorcraft_tools::Tool::keeps_cmd_press`]), as Direct Selection keeps one on a shown
/// direction handle to mirror the opposite handle.
fn lent_tool_at(&mut self, p: Point, mods: &Mods, view: ViewInfo) -> Option<&'static str> {
let id = self.lent_tool(self.tool.id(), mods)?;
let behind = self.tool.id() == "selection" && self.with_tool_cx(view, |_, cx| vectorcraft_tools::select::selects_behind_at(cx, p));
(!behind).then_some(id)
let kept = !behind && self.with_tool_cx(view, |t, cx| t.keeps_cmd_press(cx, p, *mods));
(!behind && !kept).then_some(id)
}
/// Is the press `ev` lent a selection tool ([`Self::lend_selection_tool`])? The frontend asks
@@ -332,6 +332,70 @@ fn direct_handle_cmd_before_press_still_lends_selection_and_returns_direct() {
assert_eq!(s.doc().unwrap().history.undo.len(), before.undo);
}
#[test]
fn direct_handle_cmd_held_before_pressing_a_handle_mirrors_instead_of_moving_the_path() {
let mut s = session();
let id = curve(&mut s, Point::new(50.0, 100.0));
let before = node(&s, id);
let undo = s.doc().unwrap().history.undo.len();
let end = Point::new(180.0, 100.0);
pointer(&mut s, PointerKind::Down, end, cmd());
assert_eq!(s.tool_id(), "directSelection", "a Cmd press on a shown handle is not lent to the Selection tool");
let q = Point::new(180.0, 160.0);
pointer(&mut s, PointerKind::Drag, q, cmd());
assert_mirrored(anchor(&s, id), q, AnchorKind::Smooth);
assert_other_geometry(&s, id, &before);
pointer(&mut s, PointerKind::Up, q, cmd());
assert_mirrored(anchor(&s, id), q, AnchorKind::Smooth);
assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1);
assert_eq!(s.tool_id(), "directSelection");
}
#[test]
fn direct_handle_cmd_shift_held_before_pressing_a_handle_constrains_and_mirrors() {
let mut s = session();
let id = curve(&mut s, Point::new(50.0, 100.0));
let before = node(&s, id);
let p = anchor(&s, id).p;
let shifted = Mods { shift: true, ..cmd() };
pointer(&mut s, PointerKind::Down, Point::new(180.0, 100.0), shifted);
assert_eq!(s.tool_id(), "directSelection");
let raw = Point::new(180.0, 150.0);
pointer(&mut s, PointerKind::Drag, raw, shifted);
assert_mirrored(anchor(&s, id), constrained(p, raw), AnchorKind::Smooth);
assert_other_geometry(&s, id, &before);
pointer(&mut s, PointerKind::Up, raw, shifted);
}
#[test]
fn direct_handle_cmd_press_on_a_handle_under_a_bounding_box_handle_still_lends_selection() {
let mut s = session();
let id = curve(&mut s, Point::new(50.0, 100.0));
// A second object widens the selection's bounding box so its top-middle handle lands on the
// curve's outgoing handle end at (180, 100).
let rect = run(&mut s, "path.create", json!({"anchors": [{"x": 330, "y": 150}, {"x": 340, "y": 150}, {"x": 340, "y": 200}], "closed": true}));
run(&mut s, "select.set", json!({"ids": [id.0, rect["id"]]}));
let boxed = ViewInfo { show_bbox: true, ..view() };
let end = Point::new(180.0, 100.0);
s.pointer(&PointerEvent::new(PointerKind::Down, end.x, end.y).with_mods(cmd()), boxed).unwrap();
assert_eq!(s.tool_id(), "selection", "the bounding box handle keeps the press for the lent Selection tool");
s.pointer(&PointerEvent::new(PointerKind::Up, end.x, end.y).with_mods(cmd()), boxed).unwrap();
assert_eq!(s.tool_id(), "directSelection");
}
#[test]
fn direct_handle_cmd_alt_before_pressing_a_handle_still_lends_group_selection() {
let mut s = session();
let id = curve(&mut s, Point::new(50.0, 100.0));
let a = anchor(&s, id);
let both = Mods { alt: true, ..cmd() };
pointer(&mut s, PointerKind::Down, Point::new(180.0, 100.0), both);
assert_eq!(s.tool_id(), "groupSelection", "Cmd+Alt keeps its Group Selection loan on a handle");
pointer(&mut s, PointerKind::Up, Point::new(180.0, 100.0), both);
assert_eq!(s.tool_id(), "directSelection");
assert_eq!(anchor(&s, id), a);
}
#[test]
fn direct_handle_cmd_that_lends_direct_selection_from_the_pen_does_not_mirror() {
let mut s = session();
@@ -490,6 +554,22 @@ fn direct_handle_pinned_blend_spine_cmd_shift_preserves_keys_and_mapping() {
assert_content(&s, &after);
}
#[test]
fn direct_handle_cmd_held_before_pressing_a_blend_spine_handle_mirrors() {
let mut s = session();
let id = blend(&mut s);
let (a, keys, _) = blend_state(&s, id);
pointer(&mut s, PointerKind::Down, a.h_out, cmd());
assert_eq!(s.tool_id(), "directSelection", "a Cmd press on a spine handle is not lent to the Selection tool");
let q = Point::new(180.0, 160.0);
pointer(&mut s, PointerKind::Drag, q, cmd());
pointer(&mut s, PointerKind::Up, q, cmd());
let (after, after_keys, _) = blend_state(&s, id);
near(after.p, a.p);
assert_mirrored(after, q, AnchorKind::Smooth);
assert_eq!(after_keys, keys, "the key objects did not move");
}
#[test]
fn direct_handle_incoming_drag_mirrors_outgoing_and_release_restores_ordinary_length() {
let mut s = session();
+72
View File
@@ -119,6 +119,78 @@ fn picked_handles_stay_picked_after_they_are_dragged() {
near(anchor(&s, id, 2).h_in, Point::new(310.0, 170.0));
}
/// With two handles picked, Cmd/Ctrl held before the press on one of them drags that handle alone
/// and mirrors its opposite handle; the other picked handle stays where it is.
#[test]
fn a_cmd_drag_of_one_of_two_picked_handles_mirrors_its_opposite_handle() {
let (mut s, id) = session();
click(&mut s, Point::new(180.0, 100.0), Mods::default());
click(&mut s, Point::new(300.0, 140.0), shift());
let cmd = Mods { cmd: true, ..Mods::default() };
drag(&mut s, Point::new(180.0, 100.0), Point::new(180.0, 160.0), cmd);
assert_eq!(s.tool_id(), "directSelection");
let a = anchor(&s, id, 1);
near(a.h_out, Point::new(180.0, 160.0));
near(a.h_in, Point::new(20.0, 40.0));
assert_eq!(a.kind, AnchorKind::Smooth);
near(anchor(&s, id, 2).h_in, Point::new(300.0, 140.0));
}
/// Both handles stay picked after a Cmd/Ctrl drag of one of them: a drag of the other without
/// Cmd/Ctrl then moves both.
#[test]
fn picked_handles_stay_picked_after_a_cmd_drag_of_one_of_them() {
let (mut s, id) = session();
click(&mut s, Point::new(180.0, 100.0), Mods::default());
click(&mut s, Point::new(300.0, 140.0), shift());
let cmd = Mods { cmd: true, ..Mods::default() };
drag(&mut s, Point::new(180.0, 100.0), Point::new(180.0, 160.0), cmd);
drag(&mut s, Point::new(300.0, 140.0), Point::new(310.0, 140.0), Mods::default());
near(anchor(&s, id, 1).h_out, Point::new(190.0, 160.0));
near(anchor(&s, id, 2).h_in, Point::new(310.0, 140.0));
}
/// Both handles stay picked after a Cmd/Ctrl+Shift drag of one of them, and after Escape during
/// one.
#[test]
fn picked_handles_stay_picked_after_a_cmd_shift_drag_of_one_of_them() {
for escape in [false, true] {
let (mut s, id) = session();
click(&mut s, Point::new(180.0, 100.0), Mods::default());
click(&mut s, Point::new(300.0, 140.0), shift());
let cmd_shift = Mods { cmd: true, shift: true, ..Mods::default() };
pointer(&mut s, PointerKind::Down, Point::new(180.0, 100.0), cmd_shift);
pointer(&mut s, PointerKind::Drag, Point::new(220.0, 100.0), cmd_shift);
if escape {
s.tool_key(ToolKey::Escape, Mods::default(), view()).unwrap();
}
pointer(&mut s, PointerKind::Up, Point::new(220.0, 100.0), cmd_shift);
let x = if escape { 180.0 } else { 220.0 };
near(anchor(&s, id, 1).h_out, Point::new(x, 100.0));
drag(&mut s, Point::new(300.0, 140.0), Point::new(310.0, 140.0), Mods::default());
near(anchor(&s, id, 1).h_out, Point::new(x + 10.0, 100.0));
near(anchor(&s, id, 2).h_in, Point::new(310.0, 140.0));
}
}
/// Escape during a Cmd/Ctrl drag of one of two picked handles puts the handle back and leaves both
/// picked.
#[test]
fn escape_during_a_cmd_drag_of_a_picked_handle_keeps_both_picked() {
let (mut s, id) = session();
click(&mut s, Point::new(180.0, 100.0), Mods::default());
click(&mut s, Point::new(300.0, 140.0), shift());
let cmd = Mods { cmd: true, ..Mods::default() };
pointer(&mut s, PointerKind::Down, Point::new(180.0, 100.0), cmd);
pointer(&mut s, PointerKind::Drag, Point::new(180.0, 160.0), cmd);
s.tool_key(ToolKey::Escape, Mods::default(), view()).unwrap();
pointer(&mut s, PointerKind::Up, Point::new(180.0, 160.0), cmd);
near(anchor(&s, id, 1).h_out, Point::new(180.0, 100.0));
drag(&mut s, Point::new(300.0, 140.0), Point::new(310.0, 140.0), Mods::default());
near(anchor(&s, id, 1).h_out, Point::new(190.0, 100.0));
near(anchor(&s, id, 2).h_in, Point::new(310.0, 140.0));
}
/// A Shift-click on a picked handle takes it away, and Escape lets every picked handle go: a drag
/// then moves only the handle pressed.
#[test]
+56 -11
View File
@@ -110,6 +110,8 @@ struct HandlePress {
moved: bool,
/// The picked handles when the press began.
picked: PickedHandles,
/// A mirroring Cmd/Ctrl press on one of several picked handles: they stay picked after its drag.
keeps_picks: bool,
}
#[derive(Clone, Debug)]
@@ -1046,6 +1048,33 @@ impl Tool for DirectSelectionTool {
self.lent_cmd = value.as_bool().unwrap_or(false);
}
}
/// A Cmd/Ctrl press without Alt on the end of a shown direction handle (a path's, type on a
/// path's or a selected blend spine anchor's) stays with Direct Selection, so the drag mirrors
/// the opposite handle ([`DirectSelectionTool::mirrors`]). A press on a handle of the bounding
/// box the lent Selection tool shows still goes to that tool, and so does a press anywhere else,
/// including one that a press of the tool gives to something it checks before the handles (a
/// corner widget, a bracket of type on a path, a gradient mesh point).
fn keeps_cmd_press(&self, cx: &ToolContext, p: Point, mods: Mods) -> bool {
if self.group || mods.alt || crate::select::bbox_handle_at(cx, p) {
return false;
}
let point = cx.point_tol();
// The order of the checks is the order `pointer` tries them in on a press.
let ev = PointerEvent::new(PointerKind::Down, p.x, p.y).with_mods(mods);
if CornerDrag::hit(cx, &ev, true).is_some_and(|c| !(c.on_unpicked() && c.widget_center().is_some_and(|w| yields_to_point(cx, p, w)))) {
return false;
}
if !over_path_type_anchor(cx, p) && BracketDrag::hit_any(cx, &ev).is_some() {
return false;
}
if self.spine.filter(|(id, _)| cx.selection.contains(*id)).and_then(|sel| hit_spine_handle(cx, sel, p, point)).is_some() {
return true;
}
if self.mesh.hit(cx, &cx.selection.objects, p).is_some() {
return false;
}
hit_handle(cx, p, point).is_some()
}
/// Escape during a drag (anchors, handles, segments, objects, type areas, blend spines, mesh
/// points, corner widgets, the brackets of type on a path, a marquee) cancels it: what it moved
/// goes back and the tool waits for the next press (#1743).
@@ -1087,13 +1116,16 @@ impl Tool for DirectSelectionTool {
self.mesh.cancel();
// The frame anchors or handles a cancelled drag held stay selected.
let frame = matches!(self.state, State::TypeArea { .. }) && !self.frame.is_empty();
let handles = matches!(self.state, State::Handles { .. });
let kept = self.handle_press.take().filter(|press| press.keeps_picks && matches!(self.state, State::Handle { .. }));
let handles = matches!(self.state, State::Handles { .. }) || kept.is_some();
if let Some(press) = kept {
self.handles = press.picked;
}
self.state = State::Idle;
self.guides.clear();
(self.anchor_snap, self.copy_snap, self.move_snap) = (None, None, None);
self.last_location = None;
(self.click, self.click_segment, self.click_group, self.frame_click) = (None, None, None, None);
self.handle_press = None;
match (frame, handles) {
(true, _) => vec![Action::Cancel, Action::Notify(FRAME_PICKED.into())],
(_, true) => vec![Action::Cancel, Action::Notify(HANDLES_PICKED.into())],
@@ -1896,9 +1928,11 @@ impl DirectSelectionTool {
self.state = State::Handle { id, si, ai, out, drag: Some(drag) };
vec![Action::Preview("path.setHandle".into(), params)]
}
/// A press on the end of the direction handle `(id, si, ai, out)`. Without Shift on one of two or
/// more picked handles (`picks`, as they were before the press), a drag moves them all; any
/// other press drags that handle alone, as before handles could be picked.
/// A press on the end of the direction handle `(id, si, ai, out)`. Without Shift or a mirroring
/// Cmd/Ctrl ([`Self::mirrors`]) on one of two or more picked handles (`picks`, as they were
/// before the press), a drag moves them all; any other press drags that handle alone, as before
/// handles could be picked, so a Cmd/Ctrl drag mirrors its opposite handle. The picked handles
/// stay picked after such a Cmd/Ctrl or Cmd/Ctrl+Shift drag of one of them.
fn press_handle(
&mut self,
cx: &ToolContext,
@@ -1931,8 +1965,11 @@ impl DirectSelectionTool {
};
let handle = (id, (si, ai, out));
let on = picks.get(&id).is_some_and(|set| set.contains(&handle.1));
let several = on && !ev.mods.shift && picks.values().map(BTreeSet::len).sum::<usize>() > 1;
let begin = if several {
let one_of_several = on && picks.values().map(BTreeSet::len).sum::<usize>() > 1;
let among_several = one_of_several && !ev.mods.shift;
// A mirroring drag keeps the picks with Shift held too.
let keeps_picks = one_of_several && self.mirrors(ev);
let begin = if among_several && !keeps_picks {
let items = picks.iter().flat_map(|(id, set)| set.iter().map(|h| (*id, *h))).collect();
self.state = State::Handles { handle, from, start: p, items, began: false };
self.handles = picks.clone();
@@ -1942,7 +1979,7 @@ impl DirectSelectionTool {
self.state = State::Handle { id, si, ai, out, drag };
vec![Action::Begin("Reshape".into())]
};
self.handle_press = Some(HandlePress { handle, at: p, shift: ev.mods.shift, moved: false, picked: picks });
self.handle_press = Some(HandlePress { handle, at: p, shift: ev.mods.shift, moved: false, picked: picks, keeps_picks });
begin
}
/// The release of a press on one of several picked handles: a drag commits, and the picked
@@ -1957,10 +1994,18 @@ impl DirectSelectionTool {
self.handles = BTreeMap::from([(handle.0, BTreeSet::from([handle.1]))]);
vec![Action::Notify(HANDLES_PICKED.into())]
}
/// After the release of a press on a handle that did not drag: a click picks the handle alone,
/// and a Shift-click adds it to the picked handles or takes it away.
/// After the release of a press on a handle: a click picks the handle alone, and a Shift-click
/// adds it to the picked handles or takes it away. A mirroring drag of one of several picked
/// handles leaves them all picked.
fn pick_clicked_handle(&mut self) -> Option<Action> {
let press = self.handle_press.take().filter(|press| !press.moved)?;
let press = self.handle_press.take()?;
if press.moved {
if !press.keeps_picks {
return None;
}
self.handles = press.picked;
return Some(Action::Notify(HANDLES_PICKED.into()));
}
let (id, h) = press.handle;
let mut picked = if press.shift { press.picked } else { BTreeMap::new() };
let set = picked.entry(id).or_default();
+6
View File
@@ -279,6 +279,12 @@ pub trait Tool: Send {
fn hover_object(&self, _cx: &ToolContext, _p: Point, _mods: Mods) -> Option<NodeId> {
None
}
/// Does a press at `p` with Cmd/Ctrl and `mods` held stay with the tool, instead of going to
/// the selection tool the session lends for Cmd/Ctrl? Direct Selection keeps a press on a shown
/// direction handle, where Cmd/Ctrl mirrors the opposite handle.
fn keeps_cmd_press(&self, _cx: &ToolContext, _p: Point, _mods: Mods) -> bool {
false
}
/// What the Info panel shows for the tool as it is now: the drag in progress (a move of the
/// selection, a gradient vector, a handle the Pen pulls out, a Scale, Rotate, Reflect or Shear
/// tool drag), or the Paintbrush's brush. None for a tool with nothing of its own to show.
+7 -4
View File
@@ -11,7 +11,7 @@ use craft::ui::docking::IconGroupSeparator;
use craft::ui::list::{CommandHighlight, ThumbRows};
use craft::ui::menu::{MenuTitleLook, MenuTitlePad};
use craft::ui::patterns::form_dialogs::PresetCardLook;
use craft::ui::runtime::env::{AltCodeKeys, RootEnv, Scale, ScrubDrags, WindowKey};
use craft::ui::runtime::env::{AltCodeKeys, RootEnv, Scale, ScrubDrags, WindowKey, WordsOverride, with_env};
use craft::ui::runtime::frame::{FrameInput, FrameOutput};
use craft::ui::runtime::toast::{self, Toast};
use craft::ui::runtime::windows::WindowHost;
@@ -771,7 +771,7 @@ impl VectorcraftApp {
let mut control_bar_place = chrome::control_bar_place(&self.ui);
// PLAN: assumed `chrome::window_title(&VectorcraftApp) -> String` (shell-01 A1 names the call, no row gives its signature; shell-w9).
let window_title = chrome::window_title(self);
let shown = AppShell::new(WindowKey::main())
let shell = AppShell::new(WindowKey::main())
.title_bar_if(true, |_| None, chrome::app_bar)
.options_bar(
self.ui.control_bar,
@@ -801,8 +801,11 @@ impl VectorcraftApp {
.body(|ui, cx, app: &mut VectorcraftApp| {
panel_docking::show(app, ui, cx.shell().is_some_and(|shell| shell.panels_hidden()));
crate::place::window_files(app, ui);
})
.show(ui, self);
});
// The shell shows the window's dialogs under these words. Temporary: removed once the craft-libs pin includes
// storytold/craft-libs#4891 (`dialogs::print::title_words`).
let words = dialogs::print::title_words(self).map(WordsOverride::Overlay);
let shown = with_env(ui, |env| env.words = words, |ui| shell.show(ui, self));
chrome::set_control_bar_place(&mut self.ui, control_bar_place);
if shown.screen_mode != given {
self.ui.follow_screen_mode(shown.screen_mode);
+22 -5
View File
@@ -1,12 +1,13 @@
use craft::behavior::{ColumnWidth, IconId};
use craft::i18n::WordSet as _;
use craft::ui::buttons::{Link, LinkLook};
use craft::ui::contract::{Bind, Gap, Pad, Props as _, Show as _, ShowContainer as _, clicked};
use craft::ui::display::Text;
use craft::ui::layout::CellAlign;
use craft::ui::layout_components::{Grid, Stack};
use craft::ui::runtime::env::{Env, Overrides, with_env};
use craft::ui::runtime::env::{Env, Overrides, WordRows, WordsOverride, with_env};
use craft::ui::sections::Section;
use craft::ui::shell::{RecentFile, StartAction, StartLayout, StartLink, StartPlace, StartScreen, Template};
use craft::ui::shell::{RecentFile, ShellWords, StartAction, StartLayout, StartLink, StartPlace, StartScreen, Template};
use craft::ui::style::{SurfaceKind, TypeRole};
use super::{Ui, VectorcraftApp, json};
@@ -45,9 +46,14 @@ pub(super) fn home(app: &mut VectorcraftApp, ui: &mut Ui, rect: egui::Rect) {
}
let mut pressed = None;
let mut child = ui.new_child(egui::UiBuilder::new().max_rect(rect).layout(egui::Layout::top_down(egui::Align::Min)));
// Production's community links read in the accent alone, with no underline.
let plain_links = |overrides: &mut Overrides| {
let words = recent_words(app.ui_language());
// Production's community links read in the accent alone, with no underline, and the recent files are headed
// "Recent Files".
let set_env = |overrides: &mut Overrides| {
overrides.values.set(LinkLook::Plain);
if let Some(words) = words {
overrides.words = Some(WordsOverride::Overlay(words));
}
};
// Learn follows the presets, which stand right under New and Open as in production 0.24.1.
let start = StartScreen::new(Bind::bound(&mut app.ui.home_view), Bind::bound(&mut app.ui.home_sort), &recent)
@@ -62,7 +68,7 @@ pub(super) fn home(app: &mut VectorcraftApp, ui: &mut Ui, rect: egui::Rect) {
.links(&links)
.links_title(tl!("Community"))
.section(StartPlace::AfterSections, |ui, _| learn(ui, &mut pressed));
let out = with_env(&mut child, plain_links, |ui| start.show(ui));
let out = with_env(&mut child, set_env, |ui| start.show(ui));
for action in out.actions {
run_action(app, action);
}
@@ -73,6 +79,17 @@ pub(super) fn home(app: &mut VectorcraftApp, ui: &mut Ui, rect: egui::Rect) {
}
}
/// VectorCraft's heading for the Home screen's recent files, "Recent Files", over the framework's "Recent". Outside
/// English, a language whose catalog does not translate it keeps the framework's translation.
// Workaround for craft-libs#4890: once the craft-libs pin includes it, the start screen's `recent_title` heads the
// list, and this word row is removed.
fn recent_words(lang: crate::i18n::Lang) -> Option<WordRows> {
const ENGLISH: &str = "Recent Files";
let shown = crate::i18n::tr(lang, ENGLISH);
let word = ShellWords::word("startScreen.recent")?;
(lang == crate::i18n::Lang::EN || shown != ENGLISH).then(|| WordRows::new().row(word, shown))
}
/// What the start screen's user did. A command that fails says why in the status bar (#6160).
fn run_action(app: &mut VectorcraftApp, action: StartAction) {
fn run(app: &mut VectorcraftApp, id: &str, params: serde_json::Value) {
+10 -1
View File
@@ -33,7 +33,7 @@ use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, Param, ParamKi
use craft::ui::patterns::presets::{NamedPresetEvent, PresetError, PresetRow};
use craft::ui::pickers::{Anchor9, ReferencePoint, ReferencePointLook};
use craft::ui::primitives::IconSpec;
use craft::ui::runtime::env::{LengthUnits, UnitKind};
use craft::ui::runtime::env::{LengthUnits, UnitKind, WordRows};
use craft::ui::shell::WindowDialogs;
use craft::ui::text::{LinkMode, LinkedFields, NumberField, SelectableText};
use serde_json::{Map, Value, json};
@@ -518,6 +518,15 @@ pub(super) fn settings(fields: &DialogFields) -> Value {
Value::Object(nested(p))
}
/// The words that title File › Print "Print" while the Print dialog is open in Print mode, for the window's shell to
/// show its dialogs under. The framework titles a dialog in sections "Print Settings". Temporary: this is removed, and
/// the dialog is titled with `HostedPrint::title`, once the craft-libs pin includes storytold/craft-libs#4891.
pub(crate) fn title_words(app: &VectorcraftApp) -> Option<WordRows> {
app.print_dialog.open.as_ref().filter(|open| open.mode == PrintMode::Print)?;
let title = craft::i18n::Word::keyed("printDialog.title", "Print Settings");
Some(WordRows::new().row(title, tl!("Print")))
}
/// The work of the open dialog, once per frame: the printer list, Setup…, the preview, the placement the preview was
/// dragged to, the presets and OK.
pub(crate) fn pump(app: &mut VectorcraftApp, ctx: &egui::Context) {
+36
View File
@@ -143,6 +143,42 @@ fn pages(pdf: &[u8]) -> usize {
vectorcraft_pdf::info(pdf, None).unwrap().pages.len()
}
/// The texts the whole window paints, with where each is drawn, once the open dialog has faded in (each frame is a
/// quarter second on).
fn window_texts(app: &mut VectorcraftApp) -> Vec<(String, egui::Rect)> {
let ctx = ctx(app);
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1400.0, 1000.0));
let mut texts = vec![];
for k in 0..4 {
let raw = egui::RawInput { screen_rect: Some(screen), time: Some(f64::from(k) * 0.25), ..Default::default() };
let out = crate::testing::app_frame(app, &ctx, raw);
texts = crate::tests_labels::text_shapes(&out)
.into_iter()
.map(|(t, transform)| (t.galley.text().to_string(), transform * t.galley.rect.translate(t.pos.to_vec2())))
.collect();
}
texts
}
#[test]
fn the_print_dialog_is_titled_print_and_the_preset_editor_keeps_its_title() {
let (mut printing, _) = app();
printing.run("file.print", json!({})).unwrap();
let texts = window_texts(&mut printing);
let painted = |texts: &[(String, egui::Rect)], text: &str| texts.iter().filter(|(t, _)| t == text).map(|(_, r)| *r).collect::<Vec<_>>();
assert!(painted(&texts, "Print Settings").is_empty(), "the Print dialog is not titled Print Settings: {texts:?}");
let preset_row = painted(&texts, "Print Preset");
let preset_row = preset_row.first().expect("the Print Preset row is shown");
// The title sits above the dialog's first row; the Print button sits below it.
assert!(painted(&texts, "Print").iter().any(|title| title.bottom() <= preset_row.top()), "the dialog is titled Print: {texts:?}");
// The preset editor keeps the framework's title.
let (mut editing, _) = app();
editing.run("ui.printPresetDialog", json!({"preset": vectorcraft_engine::cmd::printpresets::DEFAULT_PRESET})).unwrap();
let texts = window_texts(&mut editing);
assert!(!painted(&texts, "Print Settings").is_empty(), "the preset editor is titled Print Settings: {texts:?}");
}
#[test]
fn print_sends_every_page_to_the_chosen_printer_and_keeps_the_settings() {
let (mut app, jobs) = app();
+40 -12
View File
@@ -7,15 +7,17 @@
//! list stays after the selection changes, so choosing a font in it sets that font on the live text
//! selected then, as the font menus do. The sample field sets the text the samples show, and the
//! panel menu sets their size; Reset Retype Panel clears the list. `retype.find`, `retype.list`,
//! `retype.preview` and `retype.reset` do the same.
//! `retype.preview` and `retype.reset` do the same. A font's menu (a secondary click on its row, or
//! Shift+F10 on the focused row) selects the row and holds Apply Font, which sets that font as a
//! click does, then the panel menu's sample sizes and Reset Retype Panel.
use craft::behavior::{EditEvent, Mixed, keyed};
use craft::keymap::CommandRef;
use craft::ui::buttons::{Button, Link};
use craft::ui::contract::{ActivateOn, Bind, CollectionEvent, Props as _, SelectMode, Show as _, ShowCollection as _};
use craft::ui::contract::{ActivateOn, Bind, CollectionEvent, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _};
use craft::ui::display::{Divider, Shade, Text};
use craft::ui::list::{List, ListRow, ThumbAspect, ThumbSize};
use craft::ui::menu::PanelRow;
use craft::ui::menu::{Menu, MenuItem, PanelRow};
use craft::ui::primitives::ContentPainterCx;
use craft::ui::runtime::commands::{CommandState, CommandStates};
use craft::ui::style::Variant;
@@ -50,7 +52,7 @@ const SIZES: [(Size, &str, ThumbSize); 3] =
[(Size::Small, "small", ThumbSize::Small), (Size::Medium, "medium", ThumbSize::Medium), (Size::Large, "large", ThumbSize::Large)];
/// One font in the list.
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Found {
pub family: String,
pub style: String,
@@ -114,21 +116,47 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let on_white = app.session.prefs.font_samples_on_white;
let indexed: Vec<(usize, &Found)> = view.fonts.iter().enumerate().collect();
let source = keyed(&indexed, |(at, _)| *at);
// A click activates a row, so the same row chosen again sets its font again.
let list = List::<usize>::new(tl!("Matching fonts")).select(SelectMode::Single).activate(ActivateOn::Click).show_items(
ui,
&source,
&mut |key, _| {
// The rows are keyed by place, so a list with other fonts, or another document, is another
// list: a row's menu closes rather than act on the font that took its place.
let document = app.session.active().map(|st| st.uid);
// A click activates a row, so the same row chosen again sets its font again. A secondary
// click selects its row and asks for the row's menu; it does not activate the row.
let list = List::<usize>::new(tl!("Matching fonts"))
.id(ui.scope_id().with(("matching-fonts", document, &view.fonts)))
.select(SelectMode::Single)
.activate(ActivateOn::Click)
.row_menu()
.show_items(ui, &source, &mut |key, _| {
let (family, style) = indexed.get(*key).map_or(("", ""), |(_, f)| (f.family.as_str(), f.style.as_str()));
ListRow::new(format!("{family} {style}")).thumb_aspect(size, ThumbAspect::new(8, 1), move |cx: &ContentPainterCx, rect: Rect| {
crate::font_menu::paint_family_sample(cx, rect, family, style, sample, on_white);
})
},
);
let chosen = list.events.iter().find_map(|e| match e {
});
let mut chosen = list.events.iter().find_map(|e| match e {
CollectionEvent::Activate(at) => view.fonts.get(*at),
_ => None,
});
if let Some(request) = list.menu
&& let Some(f) = view.fonts.get(request.key)
{
// Apply Font is off while choosing the font would set it on nothing.
let live = live_text_selected(app);
Menu::context(format!("{} {}", f.family, f.style), &list.response).show(ui, |ui, _| {
if MenuItem::new(tl!("Apply Font")).enabled(live).show(ui).ran {
chosen = Some(f);
}
Divider::horizontal().show(ui);
for (size, name, _) in SIZES {
if MenuItem::new(size_label(size)).check(view.size == size).show(ui).ran {
run = Some(("retype.preview", json!({ "size": name })));
}
}
Divider::horizontal().show(ui);
if MenuItem::new(tl!("Reset Retype Panel")).show(ui).ran {
run = Some(("retype.reset", json!({})));
}
});
}
if let Some(f) = chosen
&& live_text_selected(app)
{
+122
View File
@@ -232,3 +232,125 @@ fn choosing_a_listed_font_sets_it_on_the_selected_live_text() {
click(&mut app, &ctx, "Source Serif 4 Regular");
assert!(app.session.active().unwrap().doc == before);
}
/// Live text in Source Sans 3, selected, and a list of two fonts → the app and the text's id.
fn listed_with_live_text() -> (VectorcraftApp, u64) {
let mut app = app();
let font = |family: &str, style: &str| super::Found { family: family.into(), style: style.into(), matched: 1 };
app.ui.retype.searched = true;
app.ui.retype.fonts = vec![font("Source Sans 3", "Bold"), font("Source Serif 4", "Regular")];
let t = app.session.execute("text.create", &json!({"x": 10, "y": 300, "text": "live", "font": "Source Sans 3"})).unwrap()["id"].as_u64().unwrap();
select(&mut app, &[t]);
(app, t)
}
fn family_of(app: &VectorcraftApp, id: u64) -> String {
let NodeKind::Text(text) = &app.session.active().unwrap().doc.node(NodeId(id)).unwrap().kind else { panic!("text") };
text.first_style().font_family.clone()
}
fn undo_len(app: &VectorcraftApp) -> usize {
app.session.doc().unwrap().history.undo.len()
}
const SERIF: &str = "Source Serif 4 Regular";
const SANS: &str = "Source Sans 3 Bold";
#[test]
fn a_fonts_menu_selects_its_row_without_setting_the_font() {
use craft::ui::contract::Role;
let (app, t) = listed_with_live_text();
let mut panel = Panel::new(app, show);
let undo = undo_len(&panel.app());
panel.secondary_click(SERIF);
assert!(panel.menu_item_enabled("Apply Font"), "live text is selected");
assert_eq!(family_of(&panel.app(), t), "Source Sans 3", "the secondary click sets no font");
assert_eq!(undo_len(&panel.app()), undo);
panel.key(egui::Key::Escape, egui::Modifiers::NONE);
panel.frame();
assert!(!panel.shows_role("Apply Font", Role::MENU_ITEM));
assert!(panel.selected(SERIF), "the row the menu opened on is selected");
assert!(!panel.selected(SANS));
assert_eq!(family_of(&panel.app(), t), "Source Sans 3");
}
#[test]
fn apply_font_sets_the_rows_font_on_the_live_text_in_one_undo_step() {
let (app, t) = listed_with_live_text();
let mut panel = Panel::new(app, show);
let undo = undo_len(&panel.app());
// A menu opened on another row first, then closed: the menu acts on the row it opened on last.
panel.secondary_click(SANS);
panel.key(egui::Key::Escape, egui::Modifiers::NONE);
panel.secondary_click(SERIF);
panel.click_menu_item("Apply Font");
assert_eq!(family_of(&panel.app(), t), "Source Serif 4", "the font of the row the menu opened on");
assert_eq!(undo_len(&panel.app()), undo + 1);
}
#[test]
fn apply_font_is_off_without_live_text() {
let (mut app, t) = listed_with_live_text();
select(&mut app, &[]);
let mut panel = Panel::new(app, show);
panel.secondary_click(SERIF);
assert!(!panel.menu_item_enabled("Apply Font"));
assert!(panel.menu_item_enabled("Reset Retype Panel"), "the panel's own items stay on");
assert_eq!(family_of(&panel.app(), t), "Source Sans 3", "text that is not selected keeps its font");
}
#[test]
fn the_fonts_menu_sets_the_sample_size_and_resets_the_panel() {
use craft::behavior::Mixed;
use craft::ui::contract::Role;
let (app, _) = listed_with_live_text();
let mut panel = Panel::new(app, show);
let before = panel.app().ui.retype.size;
let (other, label) = if before == Size::Large { (Size::Small, "Small") } else { (Size::Large, "Large") };
panel.secondary_click(SERIF);
panel.click_role(label, Role::MENU_ITEM_CHECK_BOX);
assert_eq!(panel.app().ui.retype.size, other, "the size changed to the one chosen");
panel.secondary_click(SERIF);
assert_eq!(panel.toggled(label), Some(Mixed::Same(true)), "the size chosen is checked");
panel.click_menu_item("Reset Retype Panel");
assert!(!panel.app().ui.retype.searched, "the list is cleared");
assert_eq!(panel.app().ui.retype.size, other, "the size stays");
}
#[test]
fn keyboard_opens_the_fonts_menu_and_escape_returns_focus() {
use craft::ui::contract::Role;
let (app, t) = listed_with_live_text();
let mut panel = Panel::new(app, show);
panel.focus(SERIF);
panel.key(egui::Key::F10, egui::Modifiers::SHIFT);
panel.frame();
assert!(panel.menu_item_enabled("Apply Font"));
panel.key(egui::Key::Escape, egui::Modifiers::NONE);
panel.frame();
assert!(!panel.shows_role("Apply Font", Role::MENU_ITEM));
assert!(panel.focused(SERIF));
assert_eq!(family_of(&panel.app(), t), "Source Sans 3", "opening and closing the menu sets no font");
}
#[test]
fn the_fonts_menu_closes_when_the_list_or_the_document_changes() {
use craft::ui::contract::Role;
let (app, _) = listed_with_live_text();
let mut panel = Panel::new(app, show);
panel.secondary_click(SERIF);
assert!(panel.shows_role("Apply Font", Role::MENU_ITEM));
// Another search puts another font in the row's place.
panel.app().ui.retype.fonts.reverse();
panel.frame();
assert!(!panel.shows_role("Apply Font", Role::MENU_ITEM));
panel.secondary_click(SERIF);
assert!(panel.shows_role("Apply Font", Role::MENU_ITEM));
panel.app().run("file.new", json!({"width": 300, "height": 200})).unwrap();
panel.frame();
assert!(!panel.shows_role("Apply Font", Role::MENU_ITEM));
}
+21
View File
@@ -164,6 +164,27 @@ fn home_lists_recent_files_and_a_click_opens_one() {
assert!(!app.ui.status.is_empty(), "a file that can't be opened says so");
}
/// The Home screen heads its recent files "Recent Files", in the interface language where the catalog translates it.
#[test]
fn home_heads_the_recent_files_recent_files() {
use crate::i18n::LangExt as _;
let shown = |lang: &str| {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
app.session.prefs.interface_language = lang.into();
app.ui.recent_files = vec![std::env::temp_dir().join("vectorcraft-home-heading").join("Drawing.svg").to_string_lossy().into_owned()];
home_screen(app)
};
let home = shown("en");
assert!(home.shows("Recent Files"), "the recent files are headed Recent Files");
assert!(!home.shows("Recent"), "not Recent alone");
let home = shown("de");
let de = crate::i18n::Lang::from_code("de").expect("German is registered");
let german = crate::i18n::tr(de, "Recent Files");
// Without a German row for Recent Files, the framework's heading stays.
let heading = if german == "Recent Files" { crate::i18n::tr_id(de, "startScreen.recent", "Recent") } else { german };
assert!(home.shows(heading), "German shows {heading}");
}
/// The Home screen has a Learn section: every tutorial of the Learn panel under its skill. A
/// tutorial shows the Learn panel at its steps and no document is opened; the Quick skill guide
/// shows its list of skills.
@@ -510,6 +510,11 @@ impl Panel {
self.fixture.tree().focused_key() == self.look(name).node
}
/// Whether the row or item named `name` reports itself selected.
pub(crate) fn selected(&self, name: &str) -> bool {
self.fixture.tree().selected_of(self.look(name).node).unwrap_or(false)
}
/// Whether the zero-based control of `role` has focus, including rows with identical names.
pub(crate) fn focused_nth(&self, role: craft::ui::contract::Role, index: usize) -> bool {
self.fixture.tree().focused_key() == self.look_nth(role, index).node
+5 -2
View File
File diff suppressed because one or more lines are too long
+4 -3
View File
File diff suppressed because one or more lines are too long