From ae00dd0e5053bbc97f9d998cb80ae178d43336a6 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 21 Nov 2026 23:44:27 +0700 Subject: [PATCH] plugins-w8: net change of 2 commits - plugins-w8: written from its sheet - plugins-w8: repair 1 --- crates/ui-egui/src/addons/pen.rs | 43 +++--- crates/ui-egui/src/addons/pen/tests.rs | 57 -------- crates/ui-egui/src/addons/units.rs | 143 +++++++++++-------- crates/ui-egui/src/addons/units/tests.rs | 173 ++++------------------- 4 files changed, 127 insertions(+), 289 deletions(-) delete mode 100644 crates/ui-egui/src/addons/pen/tests.rs diff --git a/crates/ui-egui/src/addons/pen.rs b/crates/ui-egui/src/addons/pen.rs index 9e1a2e3d3c..88661b1fbc 100644 --- a/crates/ui-egui/src/addons/pen.rs +++ b/crates/ui-egui/src/addons/pen.rs @@ -3,6 +3,12 @@ //! a straight or a curved segment, and the point and path edits it shares with the tool. Everything //! acts through `addon.pen.*` and the `addon.pathtools.*` anchor edits. +use craft::behavior::IconId; +use craft_ui::buttons::Button; +use craft_ui::choice::Segmented; +use craft_ui::contract::{Bind, Entry, Show as _, ShowContainer as _}; +use craft_ui::display::{Shade, Text}; +use craft_ui::sections::Section; use egui::Ui; use serde_json::{Value, json}; use vectorcraft_tools::addons::smart_pen; @@ -10,7 +16,6 @@ use vectorcraft_tools::addons::smart_pen; use crate::VectorcraftApp; use crate::menus::Item; use crate::panels::empty_state; -use crate::widgets::{self, dim_label}; /// The Smart Pen panel's id (`window.panel {panel: "smartPen"}`). pub const ID: &str = "smartPen"; @@ -41,35 +46,27 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { return; }; let selected = !st.selection.is_empty(); - let curved = app.session.tool_options_of(smart_pen::ID)["next"] == json!("curved"); + let shown = app.session.tool_options_of(smart_pen::ID)["next"] == json!("curved"); + let mut curved = shown; let mut action: Option<(&str, Value)> = None; - // The label above its buttons, so a long translation stays within the dock's width. - widgets::subheader(ui, tl!("Next Segment")); - ui.horizontal(|ui| { - for (icon, tip, on) in [("dc-line", tl!("Straight"), false), ("spline", tl!("Curved"), true)] { - if widgets::icon_button(ui, icon, tip, curved == on, 24.0).clicked() { - action = Some(("addon.pen.nextSegment", json!({ "curved": on }))); - } - } + let segments = [Entry::new(false, tl!("Straight")).icon(IconId::new("dc-line")), Entry::new(true, tl!("Curved")).icon(IconId::new("spline"))]; + Section::fixed(tl!("Next Segment")).show(ui, |ui, _| { + Segmented::new(tl!("Next Segment"), Bind::bound(&mut curved), &segments).show(ui); }); - widgets::divider(ui); - if !selected { - dim_label(ui, tl!("Direct-select anchor points to edit them.")); + if curved != shown { + action = Some(("addon.pen.nextSegment", json!({ "curved": curved }))); } - let width = ui.available_width(); - ui.add_enabled_ui(selected, |ui| { - for (label, id, p) in edits() { - if widgets::flat_button(ui, label, width).clicked() { - action = Some((id, p)); - } + if !selected { + Text::new(tl!("Direct-select anchor points to edit them.")).shade(Shade::Muted).show(ui); + } + for (label, id, p) in edits() { + if Button::new(label).enabled(selected).show(ui).clicks > 0 { + action = Some((id, p)); } - }); + } if let Some((id, p)) = action && let Err(e) = app.run(id, p) { app.status(e); } } - -#[cfg(test)] -mod tests; diff --git a/crates/ui-egui/src/addons/pen/tests.rs b/crates/ui-egui/src/addons/pen/tests.rs deleted file mode 100644 index db0983b79f..0000000000 --- a/crates/ui-egui/src/addons/pen/tests.rs +++ /dev/null @@ -1,57 +0,0 @@ -use serde_json::json; -use vectorcraft_engine::Session; - -use super::{ID, show}; -use crate::tests_labels::painted_text; -use crate::{VectorcraftApp, menus}; - -fn app() -> VectorcraftApp { - let mut app = VectorcraftApp::new(Session::new(), Default::default()); - app.run("file.new", json!({"width": 300, "height": 300})).unwrap(); - app -} - -#[test] -fn the_plugins_submenu_selects_the_tool_and_opens_the_panel() { - let mut app = app(); - let entries = menus::menu_entries(&app); - let under = |label: &str| entries.iter().find(|e| e.path == ["Object", "Plug-ins", "Smart Pen"] && e.label == label); - let tool = under("Smart Pen Tool").expect("listed"); - assert_eq!((tool.command.as_deref(), &tool.params), (Some("tool.select"), &json!({ "tool": "smartPen" }))); - menus::invoke(&mut app, "tool.select", tool.params.clone()); - assert_eq!(app.session.tool_id(), "smartPen"); - let panel = under("Smart Pen Panel").expect("listed"); - assert!(!crate::panel_docking::showing(&app.ui, ID)); - menus::invoke(&mut app, "window.panel", panel.params.clone()); - assert!(crate::panel_docking::showing(&app.ui, ID), "the panel opens"); - // The other add-ons' submenus are still there, and the tool has no shortcut. - assert!(entries.iter().any(|e| e.path == ["Object", "Plug-ins", "Path Precision Tools"])); - assert!(vectorcraft_tools::tool_info("smartPen").is_some_and(|t| t.shortcut.is_none())); -} - -#[test] -fn the_panel_sets_the_next_segment_and_its_buttons_edit() { - let mut app = app(); - let text = painted_text(&mut app, show); - for label in [ - "Next Segment", - "Direct-select anchor points to edit them.", - "Remove Points, Keep Shape", - "Make Smooth", - "Make Corner", - "Retract Handles", - "Close or Join", - ] { - assert!(text.contains(label), "{label}: {text}"); - } - assert_eq!(app.session.tool_options_of("smartPen")["next"], json!("straight")); - app.run("addon.pen.nextSegment", json!({"curved": true})).unwrap(); - assert_eq!(app.session.tool_options_of("smartPen")["next"], json!("curved")); - // Close or Join closes an open path selected whole, as one undo step. - let r = app.run("path.create", json!({"anchors": [{"x": 10, "y": 10}, {"x": 110, "y": 10}, {"x": 110, "y": 110}], "closed": false})).unwrap(); - let id = vectorcraft_doc::NodeId(r["id"].as_u64().unwrap()); - let steps = app.session.doc().unwrap().history.undo.len(); - app.run("addon.pen.closeJoin", json!({})).unwrap(); - assert!(app.session.doc().unwrap().doc.node(id).unwrap().path_data().unwrap().subpaths[0].closed); - assert_eq!(app.session.doc().unwrap().history.undo.len(), steps + 1); -} diff --git a/crates/ui-egui/src/addons/units.rs b/crates/ui-egui/src/addons/units.rs index 8822b70167..9ba36c0829 100644 --- a/crates/ui-egui/src/addons/units.rs +++ b/crates/ui-egui/src/addons/units.rs @@ -1,7 +1,7 @@ //! Unit Converter in the interface: its submenu (Object › Plug-ins › Unit Converter), which opens //! the panel, and the panel. The panel shows one length in every unit of //! [`Unit::EAST_ASIAN`], one number field each. A value typed in any field (units and arithmetic, -//! as every number field reads them) updates the others as it is typed; text that does not read +//! as every number field reads them) updates the others; a length too large to show in every unit //! leaves them as they were. From Selection reads the selection's width and height //! (`addon.units.selectionSize`), and Width or Height picks which of the two the fields show; the //! size read is dropped when the document, its selection or the bounds measure changes. Apply gives the selection that @@ -10,28 +10,30 @@ //! Only or Both), as one undo step. Each field's copy button puts its value on the clipboard, with //! its unit when Copy with Units is on. +use craft::behavior::{IconId, NavShape}; +use craft_ui::buttons::{Button, IconButton}; +use craft_ui::choice::{Checkbox, Radio, RadioGroup}; +use craft_ui::contract::{Bind, Show as _, ShowContainer as _}; +use craft_ui::form::Field; +use craft_ui::layout_components::Row; +use craft_ui::runtime::env::{LengthUnits, UnitKind}; +use craft_ui::sections::Section; +use craft_ui::text::NumberField; use egui::Ui; use serde_json::json; use vectorcraft_doc::{Unit, finite_in_every_unit}; use crate::VectorcraftApp; +use crate::canvas::rulers::unit_kind; use crate::menus::Item; +use crate::panels::empty_state; use crate::panels::transform; -use crate::panels::{pstate, set_pstate}; -use crate::widgets; /// The panel's id (`window.panel {panel: "unitConverter"}`). pub const ID: &str = "unitConverter"; /// The command that measures the selection. pub const SELECTION_SIZE: &str = "addon.units.selectionSize"; -/// Where the panel keeps its length and choices (panel state). -const STATE: &str = "unit-converter"; -/// A row (label, field, copy button and two gaps) is 214 pt wide, inside the 240 pt body of the -/// default 260 pt floating panel with room for its scroll bar. -const LABEL_W: f32 = 90.0; -const FIELD_W: f32 = 90.0; - /// Object › Plug-ins › Unit Converter. pub fn menu() -> Vec { vec![Item::Cmd("Unit Converter Panel", "window.panel", json!({ "panel": ID }))] @@ -89,6 +91,18 @@ impl Converter { } } + /// The value a field now holds: a changed length that shows in every unit replaces the + /// length; one too large for some unit (near the largest number, in Q and Ha) leaves the + /// other fields as they were. + pub fn typed(&mut self, value: Option) { + if let Some(pt) = value + && Some(pt) != self.points + && finite_in_every_unit(pt) + { + self.set(pt); + } + } + /// Drop the size From Selection read when the active document is no longer the one it was /// read from or is measured another way (`now`: its uid and revision, which a change to the /// selection also moves, and the bounds measure). The length the fields show stays. @@ -129,70 +143,75 @@ pub(crate) fn from_selection(app: &mut VectorcraftApp, st: &mut Converter) -> Re /// Registration Point for Symbol on), with the other side following under Constrain Width and /// Height Proportions, and with the panel menu's Transform Object Only, Pattern Only or Both. /// Without a length it does nothing. -pub(crate) fn apply(app: &mut VectorcraftApp, ui: &Ui, st: &Converter) -> Result<(), String> { +pub(crate) fn apply(app: &mut VectorcraftApp, st: &Converter) -> Result<(), String> { let Some(pt) = st.points else { return Ok(()) }; - let reference = app.selection_box().map_or_else(|| transform::reference_index(ui), |b| transform::panel_reference(app, ui, &b).index); - let params = json!({ st.side.key(): pt, "reference": reference, "proportional": transform::proportional(app, ui) }); + let reference = app.selection_box().map_or_else(|| app.ui.transform_panel.reference_point, |b| transform::panel_reference(app, &b).index); + let params = json!({ st.side.key(): pt, "reference": reference, "proportional": app.session.prefs.constrain_proportions }); let params = transform::with_pattern_switches(app, params); app.run("object.setBounds", params)?; Ok(()) } pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { - let mut st: Converter = pstate(ui.ctx(), STATE); - st.follow(document_now(app)); - // A number typed without a unit is in its row's unit, so 2 in the Picas row is 2 picas, also - // with Preferences › Units › Numbers Without Units Are Points on; other panels' fields keep it. - let bare_points = widgets::typed_unit(ui.ctx(), Unit::Picas) == Unit::Points; - widgets::set_bare_numbers_are_points(ui.ctx(), false); + if app.session.active().is_none() { + empty_state(ui, "ruler", tl!("No document"), tl!("Open a document to convert lengths.")); + return; + } + let selected = app.session.active().is_some_and(|d| !d.selection.is_empty()); + let mut conv = std::mem::take(&mut app.addon_panels.units); + conv.follow(document_now(app)); + + let mut typed = conv.points; + let mut copy = None; for unit in Unit::EAST_ASIAN { - widgets::label_row(ui, unit.label(), LABEL_W, |ui| { - // A length too large to show in one of the units (near the largest number, in Q and - // Ha) leaves the others as they were, as text that does not read does. - if let Some(pt) = widgets::num_field_live(ui, ("unit-converter", unit.key()), st.points, unit, FIELD_W) - && finite_in_every_unit(pt) - { - st.set(pt); - } - // The button's name and tip carry the row's unit ("Copy Millimeters"). - let tip = format!("{} {}", tl!("Copy"), tl!(unit.label())); - let copy = widgets::icon_button_enabled(ui, "copy", &tip, false, st.points.is_some(), 22.0); - if copy.clicked() - && let Some(text) = st.copied(unit) - { - ui.ctx().copy_text(text); + let lengths = LengthUnits::new(UnitKind::Points, unit_kind(unit), 72.0); + Row::new().show(ui, |ui, _| { + Field::new(tl!(unit.label())).show(ui, |ui, _| { + NumberField::length(tl!(unit.label()), Bind::bound(&mut typed), lengths).show(ui); + }); + // The button's name carries the row's unit ("Copy Millimeters"). + let name = format!("{} {}", tl!("Copy"), tl!(unit.label())); + if IconButton::new(IconId::new("copy")).label(name).enabled(conv.points.is_some()).show(ui).clicks > 0 { + copy = conv.copied(unit); } }); } - widgets::set_bare_numbers_are_points(ui.ctx(), bare_points); - if widgets::check(ui, "Copy with Units", st.with_units, true) { - st.with_units = !st.with_units; + conv.typed(typed); + + Checkbox::new(Bind::bound(&mut conv.with_units)).label(tl!("Copy with Units")).show(ui); + + let mut side = conv.side; + let (mut read, mut set) = (false, false); + Section::fixed(tl!("Selection")).show(ui, |ui, _| { + RadioGroup::new(tl!("Side"), Bind::bound(&mut side)).nav(NavShape::Spatial).show(ui, |ui, _| { + Radio::new(Side::Width).label(tl!("Width")).show(ui); + Radio::new(Side::Height).label(tl!("Height")).show(ui); + }); + Row::new().show(ui, |ui, _| { + read = Button::new(tl!("From Selection")).enabled(selected).show(ui).clicks > 0; + set = Button::new(tl!("Apply")).enabled(selected && conv.points.is_some()).show(ui).clicks > 0; + }); + }); + if side != conv.side { + conv.pick(side); + } + + let mut failure = None; + if let Some(text) = copy + && let Err(e) = app.clipboard.write_text(&text) + { + failure = Some(e.to_string()); + } + if read && let Err(e) = from_selection(app, &mut conv) { + failure = Some(e); + } + if set && let Err(e) = apply(app, &conv) { + failure = Some(e); + } + app.addon_panels.units = conv; + if let Some(e) = failure { + app.status(e); } - ui.add_space(6.0); - widgets::subheader(ui, tl!("Selection")); - let selected = app.session.active().is_some_and(|d| !d.selection.is_empty()); - ui.horizontal(|ui| { - for (side, label) in [(Side::Width, "Width"), (Side::Height, "Height")] { - if widgets::radio(ui, label, st.side == side, true) { - st.pick(side); - } - } - }); - ui.horizontal(|ui| { - let read = ui.add_enabled_ui(selected, |ui| widgets::flat_button(ui, tl!("From Selection"), 110.0)).inner; - if read.clicked() - && let Err(e) = from_selection(app, &mut st) - { - app.status(e); - } - let set = ui.add_enabled_ui(selected && st.points.is_some(), |ui| widgets::flat_button(ui, tl!("Apply"), 70.0)).inner; - if set.clicked() - && let Err(e) = apply(app, ui, &st) - { - app.status(e); - } - }); - set_pstate(ui.ctx(), STATE, st); } #[cfg(test)] diff --git a/crates/ui-egui/src/addons/units/tests.rs b/crates/ui-egui/src/addons/units/tests.rs index 3959157032..280b40dcd0 100644 --- a/crates/ui-egui/src/addons/units/tests.rs +++ b/crates/ui-egui/src/addons/units/tests.rs @@ -1,17 +1,13 @@ -//! Unit Converter's submenu and panel: one field per unit, typing in one updates the others and -//! text that does not read leaves them alone, From Selection reads the selection's size, Apply -//! sets the side picked as one undo step and adds none when nothing changes, and Copy writes the -//! value with or without its unit. +//! Unit Converter's state and commands: a typed length that shows in every unit replaces the +//! length, From Selection reads the selection's size, Apply sets the side picked as one undo step +//! and adds none when nothing changes, and Copy writes the value with or without its unit. -use egui::{Event, Key, Modifiers, Pos2, Rect, vec2}; use serde_json::json; use vectorcraft_doc::Unit; use vectorcraft_engine::Session; -use super::{Converter, ID, STATE, Side, apply, document_now, from_selection, show}; -use crate::panels::{pstate, set_pstate}; -use crate::tests_labels::{painted_text, shapes_text}; -use crate::{VectorcraftApp, menus}; +use super::{Converter, Side, apply, document_now, from_selection}; +use crate::VectorcraftApp; /// An app with a selected 72 × 36 pt rectangle. fn app() -> VectorcraftApp { @@ -35,97 +31,17 @@ fn size(app: &mut VectorcraftApp) -> (f64, f64) { (r["width"]["points"].as_f64().unwrap(), r["height"]["points"].as_f64().unwrap()) } +/// A readable length replaces the length; one too large for some unit (Q and Ha) leaves it. #[test] -fn the_submenu_opens_the_panel() { - let mut app = app(); - let entries = menus::menu_entries(&app); - let item = entries.iter().find(|e| e.path == ["Object", "Plug-ins", "Unit Converter"] && e.label == "Unit Converter Panel").expect("listed"); - menus::invoke(&mut app, "window.panel", item.params.clone()); - assert!(crate::panel_docking::showing(&app.ui, ID), "the panel opens"); -} - -#[test] -fn the_panel_has_a_field_for_every_unit_and_its_buttons() { - let mut app = app(); - let text = painted_text(&mut app, |app, ui| { - set_pstate(ui.ctx(), STATE, Converter { points: Some(720.0 / 25.4), ..Converter::default() }); - show(app, ui); - }); - for u in Unit::EAST_ASIAN { - assert!(text.lines().any(|l| l == u.label()), "{} in {text}", u.label()); - } - for s in ["10 mm", "1 cm", "0.3937 in", "28.346 pt", "40 Q", "40 H"] { - assert!(text.lines().any(|l| l == s), "{s} in {text}"); - } - for s in ["Copy with Units", "Selection", "Width", "Height", "From Selection", "Apply"] { - assert!(text.lines().any(|l| l == s), "{s} in {text}"); - } -} - -#[test] -fn typing_in_a_field_updates_the_others_and_text_that_does_not_read_leaves_them() { - let mut app = app(); - let ctx = egui::Context::default(); - crate::theme::install_fonts(&ctx); - let mut time = 0.0; - let mut frame = |app: &mut VectorcraftApp, events: Vec| { - time += 0.05; - let screen_rect = Some(Rect::from_min_size(Pos2::ZERO, vec2(400.0, 800.0))); - let mut out = ctx.run_ui(egui::RawInput { events, time: Some(time), screen_rect, focused: true, ..Default::default() }, |ui| show(app, ui)); - out.textures_delta.clear(); - (pstate::(&ctx, STATE), shapes_text(&out)) - }; - let tab = Event::Key { key: Key::Tab, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }; - frame(&mut app, vec![]); - frame(&mut app, vec![]); - // Tab reaches the first field, Points, which selects its text so typing replaces it. - frame(&mut app, vec![tab]); - frame(&mut app, vec![]); - let (st, _) = frame(&mut app, vec![Event::Text("1in/2".into())]); - assert!(st.points.is_some_and(|pt| near(pt, 36.0)), "{st:?}"); - let (st, text) = frame(&mut app, vec![]); - assert!(near(st.points.unwrap(), 36.0)); - for s in ["0.5 in", "3 p", "12.7 mm", "1.27 cm"] { - assert!(text.lines().any(|l| l == s), "{s} in {text}"); - } - // Text that does not read keeps the length the other fields show. - let (st, text) = frame(&mut app, vec![Event::Text("x".into())]); - assert!(near(st.points.unwrap(), 36.0), "{st:?}"); - assert!(text.lines().any(|l| l == "12.7 mm"), "{text}"); - // So does a length too large to show in Q and Ha. - let select_all = Event::Key { key: Key::A, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::COMMAND }; - frame(&mut app, vec![select_all]); - // 1.7e308 pt: finite in points. - let (st, _) = frame(&mut app, vec![Event::Text(format!("17{}", "0".repeat(307)))]); - assert!(near(st.points.unwrap(), 36.0), "{st:?}"); -} - -#[test] -fn a_number_typed_without_a_unit_in_the_picas_row_is_in_picas() { - let mut app = app(); - let ctx = egui::Context::default(); - crate::theme::install_fonts(&ctx); - // Numbers Without Units Are Points is on (its default), and stays on for other fields. - crate::widgets::set_bare_numbers_are_points(&ctx, true); - let mut time = 0.0; - let mut frame = |app: &mut VectorcraftApp, events: Vec| { - time += 0.05; - let screen_rect = Some(Rect::from_min_size(Pos2::ZERO, vec2(400.0, 800.0))); - let mut out = ctx.run_ui(egui::RawInput { events, time: Some(time), screen_rect, focused: true, ..Default::default() }, |ui| show(app, ui)); - out.textures_delta.clear(); - pstate::(&ctx, STATE) - }; - let tab = Event::Key { key: Key::Tab, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }; - frame(&mut app, vec![]); - frame(&mut app, vec![]); - // Tab reaches the Points field, then the Picas field (the copy buttons are off with no length). - for _ in 0..2 { - frame(&mut app, vec![tab.clone()]); - frame(&mut app, vec![]); - } - let st = frame(&mut app, vec![Event::Text("2".into())]); - assert!(st.points.is_some_and(|pt| near(pt, 24.0)), "{st:?}"); - assert_eq!(crate::widgets::typed_unit(&ctx, Unit::Picas), Unit::Points, "other fields still read points"); +fn a_typed_length_that_shows_in_every_unit_replaces_the_length() { + let mut st = Converter::default(); + st.typed(Some(36.0)); + assert_eq!(st.points, Some(36.0)); + // 1.7e308 pt is finite in points but not in Q and Ha. + st.typed(Some(1.7e308)); + assert_eq!(st.points, Some(36.0), "too large to show in every unit"); + st.typed(None); + assert_eq!(st.points, Some(36.0), "a cleared field leaves the length"); } #[test] @@ -159,18 +75,15 @@ fn copy_writes_the_value_with_or_without_its_unit() { assert_eq!(Converter::default().copied(Unit::Points), None, "nothing to copy before a length"); } -/// Apply `st` in a frame whose shared reference point (the Transform panel's) is `reference`. +/// Apply `st` with the Transform panel's shared reference point at `reference`. fn apply_at(app: &mut VectorcraftApp, st: &Converter, reference: usize) { try_apply_at(app, st, reference).unwrap(); } /// [`apply_at`], with its result. fn try_apply_at(app: &mut VectorcraftApp, st: &Converter, reference: usize) -> Result<(), String> { - let ctx = egui::Context::default(); - ctx.data_mut(|d| d.insert_temp(egui::Id::unique("refpt"), reference)); - let mut result = Ok(()); - ctx.run_ui(Default::default(), |ui| result = apply(app, ui, st)).textures_delta.clear(); - result + app.ui.transform_panel.reference_point = reference; + apply(app, st) } /// The selection's bounding box. @@ -250,20 +163,18 @@ fn apply_keeps_a_symbol_instances_registration_point() { #[test] fn a_size_read_from_another_selection_is_dropped() { let mut app = app(); - let ctx = egui::Context::default(); - crate::theme::install_fonts(&ctx); - let frame = |app: &mut VectorcraftApp| { - ctx.run_ui(Default::default(), |ui| show(app, ui)).textures_delta.clear(); - pstate::(&ctx, STATE) - }; let mut st = Converter::default(); from_selection(&mut app, &mut st).unwrap(); - set_pstate(&ctx, STATE, st); - // Drawing the panel again with nothing changed keeps it. - assert_eq!(frame(&mut app).size, Some((72.0, 36.0))); + app.addon_panels.units = st; + // Nothing changed: the size stays. + let now = document_now(&app); + app.addon_panels.units.follow(now); + assert_eq!(app.addon_panels.units.size, Some((72.0, 36.0))); // Another object selected. app.run("shape.rectangle", json!({"x": 200, "y": 100, "width": 20, "height": 50})).unwrap(); - let mut st = frame(&mut app); + let now = document_now(&app); + app.addon_panels.units.follow(now); + let mut st = app.addon_panels.units.clone(); assert_eq!((st.size, st.points), (None, Some(72.0)), "{st:?}"); st.pick(Side::Height); assert_eq!(st.points, Some(72.0), "not the first object's height"); @@ -287,38 +198,6 @@ fn a_size_read_from_another_selection_is_dropped() { assert_eq!(st.size, None); } -/// Each row's copy button reads as copying that row's unit, so a screen reader tells the twelve -/// apart, and the fields are named by their rows. -#[test] -fn each_copy_button_and_field_is_named_with_its_unit() { - let mut app = app(); - let ctx = egui::Context::default(); - ctx.enable_accesskit(); - crate::theme::install_fonts(&ctx); - set_pstate(&ctx, STATE, Converter { points: Some(72.0), ..Converter::default() }); - ctx.run_ui(Default::default(), |ui| show(&mut app, ui)).textures_delta.clear(); - let mut out = ctx.run_ui(Default::default(), |ui| show(&mut app, ui)); - out.textures_delta.clear(); - let nodes = &out.platform_output.accesskit_update.as_ref().expect("an accessibility tree").nodes; - // A label node carries its text as its value. - let label_of = |id: egui::accesskit::NodeId| nodes.iter().find(|(n, _)| *n == id).and_then(|(_, n)| n.label().or(n.value())).map(str::to_string); - let buttons: Vec = - nodes.iter().filter(|(_, n)| n.role() == egui::accesskit::Role::Button).filter_map(|(_, n)| n.label().map(str::to_string)).collect(); - for u in Unit::EAST_ASIAN { - let name = format!("Copy {}", u.label()); - assert_eq!(buttons.iter().filter(|b| **b == name).count(), 1, "{name} in {buttons:?}"); - // The row fits the 240 pt body of the default 260 pt floating panel, with 10 pt left for - // its scroll bar. - let button = nodes.iter().find(|(_, n)| n.label() == Some(name.as_str())).and_then(|(_, n)| n.bounds()).unwrap(); - assert!(button.x1 <= 230.0, "{name} ends at {}", button.x1); - // The field of the row is labeled by the row's label. - let field = nodes - .iter() - .find(|(_, n)| n.role() != egui::accesskit::Role::Button && n.labelled_by().iter().any(|l| label_of(*l).as_deref() == Some(u.label()))); - assert!(field.is_some(), "a field labeled {}", u.label()); - } -} - #[test] fn from_selection_with_nothing_selected_reports_it_and_keeps_the_length() { let mut app = app();