mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 22:08:42 +00:00
Name panel controls and read their values as the framework reports them
Field labels drop the colon the form draws (Angle, Line Length, Corner, Pivot, guide X and Y), each corner's Corner select gets its own name, the Transform panel's own commands get their titles, the Appearance row swatches are named for their row and Blend's Direction label describes its button. Tests use the framework's names (X position, Width, Top left, Visibility, Format), read length and percent fields as the number they report, panel-menu checks from the panels' menu states, swatch values as #rrggbb, and frame effect dialogs in the app's own window.
This commit is contained in:
@@ -120,7 +120,7 @@ pub(crate) fn corner_entries() -> Vec<Entry<CornerKind>> {
|
||||
pub(crate) fn corner_radius_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) {
|
||||
let single = app.session.prefs.single_corner_radius;
|
||||
let mut toggled = None;
|
||||
Field::new(tl!("Corner Radius:")).show(ui, |ui, _| {
|
||||
Field::new(tl!("Corner Radius")).show(ui, |ui, _| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
if single {
|
||||
corner_radius_field(app, ui, n);
|
||||
@@ -145,7 +145,7 @@ fn corner_kind_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) {
|
||||
let Some(lc) = LiveCorners::of(n) else { return };
|
||||
let entries = corner_entries();
|
||||
let current = lc.style(&lc.all()).1;
|
||||
let picked = Field::new(tl!("Corner:")).show(ui, |ui, _| corner_select(ui, tl!("Corner:"), current, &entries)).inner.flatten();
|
||||
let picked = Field::new(tl!("Corner")).show(ui, |ui, _| corner_select(ui, tl!("Corner"), current, &entries)).inner.flatten();
|
||||
if let Some(kind) = picked {
|
||||
set_rectangle_kinds(app, kind, None);
|
||||
}
|
||||
@@ -188,9 +188,15 @@ fn set_rectangle_corners(app: &mut VectorcraftApp, mut p: Value, corner: Option<
|
||||
}
|
||||
}
|
||||
|
||||
/// The corners of a live rectangle in the order their fields show, with their labels.
|
||||
fn rectangle_corners() -> [(usize, &'static str); 4] {
|
||||
[(0, tl!("Top Left:")), (1, tl!("Top Right:")), (2, tl!("Bottom Right:")), (3, tl!("Bottom Left:"))]
|
||||
/// The corners of a live rectangle in the order their fields show, with their labels (which name their radius
|
||||
/// fields) and the names of their Corner selects.
|
||||
fn rectangle_corners() -> [(usize, &'static str, &'static str); 4] {
|
||||
[
|
||||
(0, tl!("Top Left"), tl!("Top Left Corner")),
|
||||
(1, tl!("Top Right"), tl!("Top Right Corner")),
|
||||
(2, tl!("Bottom Right"), tl!("Bottom Right Corner")),
|
||||
(3, tl!("Bottom Left"), tl!("Bottom Left Corner")),
|
||||
]
|
||||
}
|
||||
|
||||
/// The columns of [`corner_fields`]: each corner's labelled radius field, then its Corner select.
|
||||
@@ -207,11 +213,11 @@ fn corner_fields(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) {
|
||||
let mut radii = Vec::new();
|
||||
let mut kinds = Vec::new();
|
||||
let _ = Grid::new(&CORNER_COLUMNS).show(ui, |ui, _| {
|
||||
for (k, label) in rectangle_corners() {
|
||||
for (k, label, corner) in rectangle_corners() {
|
||||
Field::new(label).show(ui, |ui, _| {
|
||||
radii.push((k, NumberField::length(label, Bind::given(Some(lc.radius(k))), lengths).show(ui).edit));
|
||||
});
|
||||
if let Some(kind) = corner_select(ui, label, Some(lc.kind(k)), &entries) {
|
||||
if let Some(kind) = corner_select(ui, corner, Some(lc.kind(k)), &entries) {
|
||||
kinds.push((k, kind));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -833,7 +833,7 @@ fn item_row<'r>(cx: &'r RowCx<'_>, key: RowKey, i: usize) -> ListRow<'r> {
|
||||
}
|
||||
let painted = if new_art { Painted::NewArt { fill } } else { Painted::Item(i) };
|
||||
let pass = cx.pass;
|
||||
row.trailing_field(paint_swatch(it.paint()), move |out: SwatchOutput| {
|
||||
row.trailing_field(paint_swatch(it.is_fill(), it.paint()), move |out: SwatchOutput| {
|
||||
let mut pass = pass.borrow_mut();
|
||||
if let Some(activation) = out.activation {
|
||||
pass.acts.push(Act::Swatch(key, painted, activation.mods.shift));
|
||||
@@ -842,8 +842,9 @@ fn item_row<'r>(cx: &'r RowCx<'_>, key: RowKey, i: usize) -> ListRow<'r> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The well of a fill/stroke row: `paint` as its face, its colour (a solid paint's) as its value.
|
||||
fn paint_swatch(paint: &Paint) -> Swatch {
|
||||
/// The well of a fill (`fill`) or stroke row, named for it: `paint` as its face, its colour (a solid paint's) as its
|
||||
/// value.
|
||||
fn paint_swatch(fill: bool, paint: &Paint) -> Swatch {
|
||||
let color = paint.color().map_or(Srgba::BLACK, |c| {
|
||||
let [r, g, b] = c.to_rgb();
|
||||
Srgba::rgb(r, g, b)
|
||||
@@ -851,7 +852,8 @@ fn paint_swatch(paint: &Paint) -> Swatch {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
serde_json::to_string(paint).unwrap_or_default().hash(&mut hasher);
|
||||
let shown = paint.clone();
|
||||
Swatch::new(tl!("Color"), color)
|
||||
let row = if fill { tl!("Fill") } else { tl!("Stroke") };
|
||||
Swatch::new(crate::i18n::fmt(tl!("{row} swatch"), &[("row", row)]), color)
|
||||
.face(FacePaint::new(hasher.finish(), move |painter, rect| paint_preview::paint_rect(painter, rect, &shown)))
|
||||
.tooltip(tl!("Click to choose a swatch, Shift-click to mix a colour"))
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use std::ops::RangeInclusive;
|
||||
use craft::behavior::IconId;
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::choice::Segmented;
|
||||
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, clicked};
|
||||
use craft::ui::contract::{Bind, Entry, FieldLabelRole, Props as _, Show as _, ShowContainer as _, SideLabel, clicked};
|
||||
use craft::ui::display::Divider;
|
||||
use craft::ui::form::{Field, FieldGroup};
|
||||
use craft::ui::form::{SliderField, SliderFieldLayout};
|
||||
@@ -193,7 +193,10 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
create_spine(app, ui);
|
||||
Divider::horizontal().show(ui);
|
||||
FieldGroup::new(tl!("Blend Options")).enabled(blend || selection_len(app) >= 2).show(ui, |ui, _| settings(app, ui));
|
||||
Field::new(tl!("Direction:")).show(ui, |ui, _| action(app, ui, tl!("Reverse Front to Back"), "object.blend.reverseFrontToBack"));
|
||||
// The button keeps its own name: the label says what it changes.
|
||||
Field::new(tl!("Direction:"))
|
||||
.side(SideLabel::new().role(FieldLabelRole::Describes))
|
||||
.show(ui, |ui, _| action(app, ui, tl!("Reverse Front to Back"), "object.blend.reverseFrontToBack"));
|
||||
Divider::horizontal().show(ui);
|
||||
actions(app, ui, &[(tl!("Reverse Spine"), "object.blend.reverseSpine"), (tl!("Replace Spine"), "object.blend.replaceSpine")]);
|
||||
Divider::horizontal().show(ui);
|
||||
|
||||
@@ -53,7 +53,7 @@ pub(super) fn image_section(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
/// one), view, a button to reveal the tracing controls, Expand and Release.
|
||||
pub(super) fn trace_section(app: &mut VectorcraftApp, ui: &mut Ui, preset: &str, view: vectorcraft_doc::TraceView) {
|
||||
Section::fixed(tl!("Image Trace")).show(ui, |ui, _| {
|
||||
Field::new(tl!("Preset:")).show(ui, |ui, _| crate::panels::image_trace::preset_dropdown(app, ui, preset));
|
||||
Field::new(tl!("Preset")).show(ui, |ui, _| crate::panels::image_trace::preset_dropdown(app, ui, preset));
|
||||
crate::panels::image_trace::view_row(app, ui, view);
|
||||
crate::panels::image_trace::split_row(app, ui);
|
||||
if Button::new(tl!("Image Trace")).sizing(Sizing::FillWidth).show(ui).clicked() {
|
||||
@@ -119,7 +119,7 @@ pub(super) fn objects_on_path_section(app: &mut VectorcraftApp, ui: &mut Ui, oop
|
||||
}
|
||||
};
|
||||
Section::fixed(tl!("Objects on Path Options")).show(ui, |ui, _| {
|
||||
Field::new(tl!("Pivot:")).show(ui, |ui, _| {
|
||||
Field::new(tl!("Pivot")).show(ui, |ui, _| {
|
||||
// Mixed while the groups' pivots differ: no square is chosen.
|
||||
let shown = oop.pivot.map_or(Mixed::Mixed, |p| Mixed::Same(Anchor9::ALL.get(usize::from(p)).copied()));
|
||||
let out = ReferencePoint::new(tl!("Pivot"), Bind::given(shown)).look(ReferencePointLook::Squares).show(ui);
|
||||
@@ -129,7 +129,7 @@ pub(super) fn objects_on_path_section(app: &mut VectorcraftApp, ui: &mut Ui, oop
|
||||
set(app, json!({ "pivot": i }));
|
||||
}
|
||||
});
|
||||
Field::new(tl!("Rotate:")).show(ui, |ui, _| {
|
||||
Field::new(tl!("Rotate")).show(ui, |ui, _| {
|
||||
let presets: Vec<Entry<NumberPick>> =
|
||||
transform::ANGLE_PRESETS.iter().map(|v| Entry::new(NumberPick::Number(*v), format!("{v}°"))).collect();
|
||||
let out = NumberField::new(tl!("Rotate"), Bind::given(oop.rotate))
|
||||
|
||||
@@ -144,7 +144,7 @@ fn artboard_coordinate_fields_move_art_in_properties_and_transform() {
|
||||
app.select_tool("artboard");
|
||||
app.session.set_tool_option("moveArt", &json!(move_art));
|
||||
let mut panel = Panel::new(app, draw);
|
||||
panel.click("X");
|
||||
panel.click("X position");
|
||||
panel.key(Key::ArrowUp, Modifiers::NONE);
|
||||
let app = panel.app();
|
||||
let d = &app.session.doc().unwrap().doc;
|
||||
@@ -186,7 +186,7 @@ fn artboard_width_resizes_every_selected_artboard_in_properties_and_transform()
|
||||
let mut panel = Panel::new(two_selected_artboards(), draw);
|
||||
let before = boards(&panel.app());
|
||||
let undo = undo_depth(&panel.app());
|
||||
panel.type_into("W", "250");
|
||||
panel.type_into("Width", "250");
|
||||
let mut want = before.clone();
|
||||
for (i, shift) in [(0, 25.0), (2, -25.0)] {
|
||||
want[i].2 = 250.0;
|
||||
@@ -1184,7 +1184,7 @@ fn selected_guides_show_their_position_in_a_transform_section() {
|
||||
panel.app().run("select.set", json!({"ids": [id]})).unwrap();
|
||||
panel.app().run("guide.select", json!({"indexes": [v], "toggle": true})).unwrap();
|
||||
panel.frame();
|
||||
assert!(!panel.shows("Guides") && panel.shows("W"));
|
||||
assert!(!panel.shows("Guides") && panel.shows("Width"));
|
||||
}
|
||||
|
||||
/// Two 20 pt squares attached to a horizontal line in an Objects on Path group (`rotate` degrees),
|
||||
@@ -1250,7 +1250,7 @@ fn objects_on_path_options_set_pivot_and_rotate_in_one_undo_step() {
|
||||
let group = objects_on_path(&mut app, 150.0, 0.0);
|
||||
let mut panel = Panel::new(app, objects_on_path_options);
|
||||
let depth = undo_depth(&panel.app());
|
||||
panel.click("Top Left");
|
||||
panel.click("Top left");
|
||||
assert_eq!(pivot_rotate(&panel.app(), &group), (0, 0.0), "Pivot: top left");
|
||||
assert_eq!(undo_depth(&panel.app()), depth + 1, "one undo step");
|
||||
panel.type_into("Rotate", "30");
|
||||
|
||||
@@ -97,11 +97,11 @@ pub(super) fn corner_rows(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
// The corners differ in kind: no entry is the value.
|
||||
let kind = panels::corner_style(app, &n).1.map_or(Mixed::Mixed, Mixed::Same);
|
||||
let entries = panels::corner_entries();
|
||||
let picked = Field::new(tl!("Corner:")).show(ui, |ui, _| Select::new(tl!("Corner"), Bind::given(kind), &entries).show(ui).value().copied()).inner;
|
||||
let picked = Field::new(tl!("Corner")).show(ui, |ui, _| Select::new(tl!("Corner"), Bind::given(kind), &entries).show(ui).value().copied()).inner;
|
||||
if let Some(Some(kind)) = picked {
|
||||
app.run("object.setLiveShape", json!({"kind": kind})).ok();
|
||||
}
|
||||
Field::new(tl!("Corner Radius:")).show(ui, |ui, _| panels::corner_radius_field(app, ui, &n));
|
||||
Field::new(tl!("Corner Radius")).show(ui, |ui, _| panels::corner_radius_field(app, ui, &n));
|
||||
}
|
||||
|
||||
/// Ruler guides selected on their own: a Transform section with the X of the vertical ones and
|
||||
|
||||
@@ -541,7 +541,8 @@ mod tests {
|
||||
let mut panel = Panel::new(app, scrolled);
|
||||
panel.room(egui::vec2(300.0, 120.0));
|
||||
panel.frame();
|
||||
assert!(!panel.in_view(BPC), "the section starts below the view");
|
||||
// The section draws lazily: below the view it is not drawn at all.
|
||||
assert!(!panel.shows(BPC) || !panel.in_view(BPC), "the section starts below the view");
|
||||
panel.app().run(id, json!({})).unwrap();
|
||||
panel.frame();
|
||||
assert!(!panel.app().ui.color_settings_scroll, "{id}: the pass that read the request spent it");
|
||||
|
||||
@@ -69,9 +69,14 @@ pub(super) fn text_rect(texts: &[(String, egui::Rect)], s: &str) -> egui::Rect {
|
||||
texts.iter().find(|(t, _)| t == s).unwrap_or_else(|| panic!("`{s}` not drawn: {texts:?}")).1
|
||||
}
|
||||
|
||||
/// One whole app frame, so the dialog host and the effect dialogs' pump run as in production.
|
||||
/// One whole app frame in the app's window, so the dialog host and the effect dialogs' pump run as in production.
|
||||
pub(super) fn app_frame(app: &mut VectorcraftApp) {
|
||||
key_frame(app, &crate::testing::ui_context(), vec![]);
|
||||
key_frame(app, &window(app), vec![]);
|
||||
}
|
||||
|
||||
/// The app's window context, or a new window for an app without one: every frame of a window draws in its context.
|
||||
fn window(app: &VectorcraftApp) -> egui::Context {
|
||||
app.ui_ctx.clone().unwrap_or_else(crate::testing::ui_context)
|
||||
}
|
||||
|
||||
/// The id of the open effect dialog.
|
||||
@@ -152,7 +157,7 @@ fn shows(panel: &mut Panel, name: &str) -> bool {
|
||||
/// The Cmd+/ or Cmd+Alt+/ key pressed through the whole app frame.
|
||||
fn press_slash(app: &mut VectorcraftApp, modifiers: egui::Modifiers) {
|
||||
let ev = egui::Event::Key { key: egui::Key::Slash, physical_key: None, pressed: true, repeat: false, modifiers };
|
||||
key_frame(app, &crate::testing::ui_context(), vec![ev]);
|
||||
key_frame(app, &window(app), vec![ev]);
|
||||
}
|
||||
|
||||
/// The name of the colour chip of the "Fill:" or "Stroke:" row.
|
||||
@@ -166,7 +171,7 @@ fn stroke_panel_shows_the_active_rows_weight() {
|
||||
let mut app = app_with_rect();
|
||||
run(&mut app, "appearance.addStroke", json!({})); // [Fill, Stroke 1 pt, Stroke 1 pt]
|
||||
run(&mut app, "stroke.set", json!({"item": 1, "weight": 6}));
|
||||
let six = Unit::Points.format(6.0);
|
||||
let six = Unit::Points.number(6.0);
|
||||
let mut panel = Panel::new(app, stroke::show);
|
||||
// PLAN: assumed the weight field's accessible name
|
||||
let weight = |panel: &mut Panel| {
|
||||
@@ -1061,9 +1066,10 @@ fn panels_show_the_selected_object_after_an_edit_and_after_undo() {
|
||||
assert!(!shown.contains(not), "{name} no longer shows {not}: {shown}");
|
||||
}
|
||||
};
|
||||
edit_shows("transparency.set", json!({"opacity": 60}), "60%", "35%");
|
||||
edit_shows("transparency.set", json!({"opacity": 35}), "35%", "60%");
|
||||
edit_shows("edit.undo", json!({}), "60%", "35%");
|
||||
// A percent field's value is its number, with the % painted after it; the Appearance row reads "Opacity: 60%".
|
||||
edit_shows("transparency.set", json!({"opacity": 60}), "60", "35");
|
||||
edit_shows("transparency.set", json!({"opacity": 35}), "35", "60");
|
||||
edit_shows("edit.undo", json!({}), "60", "35");
|
||||
}
|
||||
|
||||
/// Right-clicking a stroke row, on its label, picks it and opens its menu: Duplicate, Delete and Hide Stroke.
|
||||
|
||||
@@ -72,7 +72,9 @@ fn saved_preset(p: &Panel, name: &str) -> Value {
|
||||
fn check(p: &Panel, id: &str, params: Value) -> Option<bool> {
|
||||
let mut states = CommandStates::new();
|
||||
menu_states(&p.app(), &mut states);
|
||||
states.get(&CommandRef::with_params(id, params)).and_then(|s| s.is_checked())
|
||||
// States match their rows by id and params, and a row without params holds `Null`, not `{}`.
|
||||
let command = if params == json!({}) { CommandRef::new(id) } else { CommandRef::with_params(id, params) };
|
||||
states.get(&command).and_then(|s| s.is_checked())
|
||||
}
|
||||
|
||||
/// Whether the panel menu lists the row `id` with `params`.
|
||||
@@ -133,9 +135,9 @@ fn finish_pick(p: &Panel) {
|
||||
crate::tests::picks::poll(&mut p.app(), &ctx);
|
||||
}
|
||||
|
||||
/// Picks `to` in the format select showing `from` (PLAN: assumed the select is named by its shown value).
|
||||
fn pick_format(p: &mut Panel, from: &str, to: &str) {
|
||||
p.click(from);
|
||||
/// Picks `to` in the format select named `select` (the first row's "Format", or "3D Format:").
|
||||
fn pick_format(p: &mut Panel, select: &str, to: &str) {
|
||||
p.click(select);
|
||||
p.click(to);
|
||||
}
|
||||
|
||||
@@ -560,7 +562,7 @@ fn tiff_dropdown_exports_only_the_selected_asset_and_shares_settings() {
|
||||
)
|
||||
.unwrap();
|
||||
let mut p = panel(app);
|
||||
pick_format(&mut p, "PNG", "TIFF");
|
||||
pick_format(&mut p, "Format", "TIFF");
|
||||
let saved = settings(&p);
|
||||
assert_eq!(saved["formats"], json!([{"format": "tiff", "scale": "2x", "suffix": "@2x"}]));
|
||||
p.click("Badge");
|
||||
@@ -637,7 +639,7 @@ fn tiff_cmyk_defaults_match_screens_and_preserve_explicit_rgb() {
|
||||
app.run("assets.settings.set", json!({"settings": {"tiff": {"colorModel": "rgb"}}})).unwrap();
|
||||
}
|
||||
let mut p = panel(app);
|
||||
pick_format(&mut p, "PNG", "TIFF");
|
||||
pick_format(&mut p, "Format", "TIFF");
|
||||
if !rgb_override {
|
||||
assert!(p.app().session.active().unwrap().doc.export_settings.get("settings").and_then(|s| s.get("tiff")).is_none());
|
||||
}
|
||||
@@ -679,7 +681,7 @@ fn tiff_panel_preserves_shared_antialias_and_explicit_overrides() {
|
||||
}
|
||||
app.run("assets.settings.set", json!({"formats": [row], "antiAlias": "none", "settings": shared_settings})).unwrap();
|
||||
let mut p = panel(app);
|
||||
pick_format(&mut p, "PNG", "TIFF");
|
||||
pick_format(&mut p, "Format", "TIFF");
|
||||
p.click("Export");
|
||||
{
|
||||
let log = log.borrow();
|
||||
@@ -766,7 +768,7 @@ fn a_3d_asset_takes_its_format_from_the_row_and_exports_as_a_mesh() {
|
||||
let list = assets(&mut p.app());
|
||||
assert_eq!((list[1]["name"].clone(), list[1]["format3D"].clone()), (json!("Box"), json!("usda")));
|
||||
assert!(p.shows("3D Format:"));
|
||||
pick_format(&mut p, "USDA", "OBJ");
|
||||
pick_format(&mut p, "3D Format:", "OBJ");
|
||||
assert_eq!(assets(&mut p.app())[1]["format3D"], "obj");
|
||||
// The menu left the new 3D asset selected: Export writes its OBJ and MTL alone, as one zip.
|
||||
p.click("Export 1 Selected");
|
||||
|
||||
@@ -10,9 +10,9 @@ use super::color_wheel::{bytes, vision_colors};
|
||||
use super::tests_color_wheel::Panel;
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
/// `#rrggbb` of display sRGB `rgb`, as the chips show it.
|
||||
/// `#rrggbb` of display sRGB `rgb`, as the chips report it.
|
||||
fn hex(rgb: [f32; 3]) -> String {
|
||||
super::color_wheel::hex(bytes(rgb))
|
||||
format!("#{}", super::color_wheel::hex(bytes(rgb)).to_lowercase())
|
||||
}
|
||||
|
||||
const NAMES: [&str; 4] = ["Protanopia", "Deuteranopia", "Tritanopia", "Achromatopsia"];
|
||||
@@ -52,11 +52,11 @@ fn the_chips_show_the_proof_setup_simulations_of_the_fill() {
|
||||
fn the_achromatopsia_chip_is_the_gray_of_the_colors_lightness() {
|
||||
let cms = cms::active();
|
||||
let [p, d, t, a] = vision_colors(&cms, &Color::rgb(1.0, 0.0, 0.0));
|
||||
assert_eq!(hex(a), "828282");
|
||||
assert_eq!(hex(a), "#828282");
|
||||
assert_ne!(hex(p), hex(d));
|
||||
assert_ne!(hex(t), hex(a));
|
||||
let panel = Panel::new(app(json!("#ff0000")));
|
||||
assert_eq!(panel.value("Achromatopsia").as_deref(), Some("828282"));
|
||||
assert_eq!(panel.value("Achromatopsia").as_deref(), Some("#828282"));
|
||||
}
|
||||
|
||||
/// A gray fill is the same gray in all four simulations.
|
||||
@@ -70,14 +70,14 @@ fn a_gray_fill_is_the_same_gray_in_every_chip() {
|
||||
}
|
||||
}
|
||||
|
||||
/// With a None fill the cells carry only their names, with no value.
|
||||
/// With a None fill the cells carry only their names, with no color: a swatch reports a clear one.
|
||||
#[test]
|
||||
fn with_a_none_fill_the_chips_have_no_color() {
|
||||
let mut a = app(json!("#ff0000"));
|
||||
a.run("paint.setFill", json!({"none": true})).unwrap();
|
||||
let p = Panel::new(a);
|
||||
for name in NAMES {
|
||||
assert_eq!(p.value(name), None, "{name} has no value");
|
||||
assert_eq!(p.value(name).as_deref(), Some("#00000000"), "{name} has no color");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,15 @@ fn side_mm() -> String {
|
||||
Unit::Millimeters.format(100.0)
|
||||
}
|
||||
|
||||
/// Whether a length field's `value` reads `pt` points in `unit`, to the decimals it shows: a length field's value is
|
||||
/// its number, with the unit painted after it.
|
||||
pub(crate) fn reads(value: Option<String>, unit: Unit, pt: f64) -> bool {
|
||||
value.is_some_and(|v| {
|
||||
let decimals = v.split_once('.').map_or(0, |(_, d)| d.len());
|
||||
v.parse::<f64>().is_ok_and(|shown| (shown - unit.from_pt(pt)).abs() <= 0.5 * 10f64.powi(-(decimals as i32)) + 1e-9)
|
||||
})
|
||||
}
|
||||
|
||||
fn general_mm(app: &mut VectorcraftApp) {
|
||||
app.run("prefs.set", json!({"key": "unitsGeneral", "value": "Millimeters"})).unwrap();
|
||||
}
|
||||
@@ -70,20 +79,19 @@ fn general_mm(app: &mut VectorcraftApp) {
|
||||
#[test]
|
||||
fn panels_show_millimetres_after_the_preference_changes() {
|
||||
let mut p = Panel::new(app_with_rect(), transform::show);
|
||||
assert_eq!(side_mm(), "35.2778 mm");
|
||||
assert_eq!(p.value("Width"), Some(Unit::Points.format(100.0)), "points first");
|
||||
assert!(reads(p.value("Width"), Unit::Points, 100.0), "points first: {:?}", p.value("Width"));
|
||||
general_mm(&mut p.app());
|
||||
// The next frame: no restart, nothing cached.
|
||||
p.frame();
|
||||
assert_eq!(p.value("Width"), Some(side_mm()), "Transform panel");
|
||||
assert!(reads(p.value("Width"), Unit::Millimeters, 100.0), "Transform panel: {:?}", p.value("Width"));
|
||||
let mut app = app_with_rect();
|
||||
general_mm(&mut app);
|
||||
let mut b = Panel::new(app, bar);
|
||||
assert_eq!(b.value("Width"), Some(side_mm()), "Control bar");
|
||||
assert!(reads(b.value("Width"), Unit::Millimeters, 100.0), "Control bar: {:?}", b.value("Width"));
|
||||
// Document Setup back to points: everything follows the document.
|
||||
run(&mut b.app(), "document.setUnits", json!({"units": "Points"}));
|
||||
b.frame();
|
||||
assert_eq!(b.value("Width"), Some(Unit::Points.format(100.0)));
|
||||
assert!(reads(b.value("Width"), Unit::Points, 100.0), "{:?}", b.value("Width"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -116,11 +124,11 @@ fn type_sizes_follow_units_type() {
|
||||
general_mm(&mut app);
|
||||
let mut p = Panel::new(app, character::show);
|
||||
assert_eq!(character::type_unit(&p.app()), character::doc_unit(Unit::Points), "General leaves type alone");
|
||||
assert_eq!(p.value("Font Size"), Some(Unit::Points.format(24.0)));
|
||||
assert!(reads(p.value("Font size"), Unit::Points, 24.0), "{:?}", p.value("Font size"));
|
||||
p.app().run("prefs.set", json!({"key": "unitsType", "value": "inches"})).unwrap();
|
||||
p.frame();
|
||||
assert_eq!(character::type_unit(&p.app()), character::doc_unit(Unit::Inches));
|
||||
assert_eq!(p.value("Font Size"), Some(Unit::Inches.format(24.0)));
|
||||
assert!(reads(p.value("Font size"), Unit::Inches, 24.0), "{:?}", p.value("Font size"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -131,11 +139,11 @@ fn the_preferences_dialog_shows_the_documents_units() {
|
||||
assert_eq!(crate::prefs_dialog::fields(&app).unwrap()["unitsGeneral"], json!("millimeters"));
|
||||
let inc = app.session.prefs.keyboard_increment;
|
||||
let mut p = Panel::new(app, |app, ui| crate::prefs_dialog::show(app, ui));
|
||||
assert_eq!(p.value("Keyboard Increment"), Some(Unit::Millimeters.format(inc)), "Keyboard Increment in mm");
|
||||
assert!(reads(p.value("Keyboard Increment"), Unit::Millimeters, inc), "Keyboard Increment in mm: {:?}", p.value("Keyboard Increment"));
|
||||
// Choosing another General unit in the dialog shows at once, and OK applies it.
|
||||
crate::prefs_dialog::set_field(&mut p.app(), "unitsGeneral", json!("inches")).unwrap();
|
||||
p.frame();
|
||||
assert_eq!(p.value("Keyboard Increment"), Some(Unit::Inches.format(inc)));
|
||||
assert!(reads(p.value("Keyboard Increment"), Unit::Inches, inc), "{:?}", p.value("Keyboard Increment"));
|
||||
crate::prefs_dialog::confirm(&mut p.app()).unwrap();
|
||||
let app = p.app();
|
||||
assert_eq!(app.session.active().unwrap().doc.units, Unit::Inches);
|
||||
|
||||
@@ -500,7 +500,7 @@ pub(crate) fn selected_guides(app: &VectorcraftApp) -> Option<(Option<f64>, Opti
|
||||
pub(crate) fn guide_fields(app: &mut VectorcraftApp, ui: &mut Ui, (x, y): (Option<f64>, Option<f64>)) {
|
||||
let lengths = general_lengths(app);
|
||||
let origin = app.ruler_origin();
|
||||
for (label, pos, zero, by, vertical) in [("X:", x, origin.x, "dx", true), ("Y:", y, origin.y, "dy", false)] {
|
||||
for (label, pos, zero, by, vertical) in [("X", x, origin.x, "dx", true), ("Y", y, origin.y, "dy", false)] {
|
||||
let edit = Field::new(tl!(label))
|
||||
.enabled(pos.is_some())
|
||||
.show(ui, |ui, _| NumberField::length(tl!(label), Bind::given(pos.map(|p| p - zero)), lengths).show(ui).edit)
|
||||
@@ -693,18 +693,21 @@ pub(crate) fn menu_states(app: &VectorcraftApp, states: &mut CommandStates) {
|
||||
let mut set = |id: &str, state: CommandState| states.set(CommandRef::new(id), state);
|
||||
let title = if part_hidden(app, HIDE_OPTIONS_KEY) { tl!("Show Options") } else { tl!("Hide Options") };
|
||||
set(HIDE_OPTIONS, CommandState::new().title(title));
|
||||
set(SHOW_ON_SHAPE_CREATION, CommandState::new().checked(prefs.show_on_shape_creation));
|
||||
set(FLIP_HORIZONTAL, CommandState::new().enabled(has));
|
||||
set(FLIP_VERTICAL, CommandState::new().enabled(has));
|
||||
set(SCALE_STROKES, CommandState::new().checked(prefs.scale_strokes));
|
||||
set(TYPE_GLYPH_BOUNDS, CommandState::new().checked(prefs.type_glyph_bounds));
|
||||
set(SHOW_ON_SHAPE_CREATION, CommandState::new().title(tl!("Show on Shape Creation")).checked(prefs.show_on_shape_creation));
|
||||
set(FLIP_HORIZONTAL, CommandState::new().title(tl!("Flip Horizontal")).enabled(has));
|
||||
set(FLIP_VERTICAL, CommandState::new().title(tl!("Flip Vertical")).enabled(has));
|
||||
set(SCALE_STROKES, CommandState::new().title(tl!("Scale Strokes & Effects")).checked(prefs.scale_strokes));
|
||||
set(TYPE_GLYPH_BOUNDS, CommandState::new().title(tl!("Measure Type by Glyph Bounds")).checked(prefs.type_glyph_bounds));
|
||||
let align_new = app.session.active().map(|st| st.doc.setup.align_new_objects_to_pixel_grid);
|
||||
set(ALIGN_NEW_OBJECTS, CommandState::new().enabled(align_new.is_some()).checked(align_new == Some(true)));
|
||||
set(
|
||||
ALIGN_NEW_OBJECTS,
|
||||
CommandState::new().title(tl!("Align New Objects to Pixel Grid")).enabled(align_new.is_some()).checked(align_new == Some(true)),
|
||||
);
|
||||
let current = pattern_mode(app);
|
||||
for (value, id) in PATTERN_MODES {
|
||||
set(id, CommandState::new().checked(value == current));
|
||||
for ((value, id), title) in PATTERN_MODES.into_iter().zip([tl!("Transform Object Only"), tl!("Transform Pattern Only"), tl!("Transform Both")]) {
|
||||
set(id, CommandState::new().title(title).checked(value == current));
|
||||
}
|
||||
set(REGISTRATION_POINT, CommandState::new().checked(prefs.use_registration_point_for_symbol));
|
||||
set(REGISTRATION_POINT, CommandState::new().title(tl!("Use Registration Point for Symbol")).checked(prefs.use_registration_point_for_symbol));
|
||||
}
|
||||
|
||||
/// Runs the panel menu row `id`; `None` for an id that is not one of its rows. An error is also shown in the status bar.
|
||||
|
||||
@@ -94,7 +94,7 @@ fn number_row(app: &mut VectorcraftApp, ui: &mut Ui, label: &'static str, value:
|
||||
/// them about its own center.
|
||||
fn angle_row(app: &mut VectorcraftApp, ui: &mut Ui, live: &LiveShape, key: &'static str) {
|
||||
let angle = shared_shape_angle(app, live);
|
||||
number_row(app, ui, tl!("Angle:"), angle, Quantity::Degrees, |a| json!({ key: a }));
|
||||
number_row(app, ui, tl!("Angle"), angle, Quantity::Degrees, |a| json!({ key: a }));
|
||||
}
|
||||
|
||||
/// The angle ([`LiveShape::shape_angle`]) every selected live shape of `live`'s kind shares, `None` when they
|
||||
@@ -145,8 +145,8 @@ fn line_rows(app: &mut VectorcraftApp, ui: &mut Ui, live: &LiveShape) -> bool {
|
||||
return false;
|
||||
}
|
||||
under_heading(ui, Some(tl!("Line Properties:")), |ui| {
|
||||
number_row(app, ui, tl!("Line Length:"), live.line_length(), Quantity::Length, |l| json!({ "lineLength": l }));
|
||||
number_row(app, ui, tl!("Line Angle:"), Some(live.line_angle().unwrap_or(0.0)), Quantity::Degrees, |a| json!({ "lineAngle": a }));
|
||||
number_row(app, ui, tl!("Line Length"), live.line_length(), Quantity::Length, |l| json!({ "lineLength": l }));
|
||||
number_row(app, ui, tl!("Line Angle"), Some(live.line_angle().unwrap_or(0.0)), Quantity::Degrees, |a| json!({ "lineAngle": a }));
|
||||
});
|
||||
true
|
||||
}
|
||||
@@ -156,7 +156,7 @@ fn line_rows(app: &mut VectorcraftApp, ui: &mut Ui, live: &LiveShape) -> bool {
|
||||
/// link on, a typed angle moves the other one by as much, so each selected ellipse keeps its span.
|
||||
fn pie_rows(app: &mut VectorcraftApp, ui: &mut Ui, pie: (f64, f64)) {
|
||||
let constrain = app.ui.constrain_pie_angle;
|
||||
for (label, key, v) in [(tl!("Pie Start Angle:"), "pieStart", pie.0), (tl!("Pie End Angle:"), "pieEnd", pie.1)] {
|
||||
for (label, key, v) in [(tl!("Pie Start Angle"), "pieStart", pie.0), (tl!("Pie End Angle"), "pieEnd", pie.1)] {
|
||||
number_row(
|
||||
app,
|
||||
ui,
|
||||
@@ -178,12 +178,12 @@ fn polygon_rows(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node, live: &LiveShap
|
||||
let LiveShape::Polygon { sides, .. } = live else { return };
|
||||
let radius = live.polygon_radius();
|
||||
let side = radius.map(|r| 2.0 * r * (std::f64::consts::PI / f64::from((*sides).max(3))).sin());
|
||||
number_row(app, ui, tl!("Sides:"), Some(f64::from(*sides)), Quantity::Sides, |s| json!({ "sides": s as u64 }));
|
||||
number_row(app, ui, tl!("Sides"), Some(f64::from(*sides)), Quantity::Sides, |s| json!({ "sides": s as u64 }));
|
||||
angle_row(app, ui, live, "polygonAngle");
|
||||
corner_kind_row(app, ui, corner_style(app, n).1);
|
||||
Field::new(tl!("Corner Radius:")).show(ui, |ui, _| corner_radius_field(app, ui, n));
|
||||
number_row(app, ui, tl!("Radius:"), radius, Quantity::Length, |r| json!({ "polygonRadius": r }));
|
||||
number_row(app, ui, tl!("Side Length:"), side, Quantity::Length, |l| json!({ "sideLength": l }));
|
||||
Field::new(tl!("Corner Radius")).show(ui, |ui, _| corner_radius_field(app, ui, n));
|
||||
number_row(app, ui, tl!("Radius"), radius, Quantity::Length, |r| json!({ "polygonRadius": r }));
|
||||
number_row(app, ui, tl!("Side Length"), side, Quantity::Length, |l| json!({ "sideLength": l }));
|
||||
if Button::new(tl!("Make Sides Equal")).enabled(!live.polygon_sides_equal()).show(ui).clicked() {
|
||||
set_live_shape(app, json!({"makeSidesEqual": true}));
|
||||
}
|
||||
@@ -193,8 +193,8 @@ fn polygon_rows(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node, live: &LiveShap
|
||||
fn corner_kind_row(app: &mut VectorcraftApp, ui: &mut Ui, kind: Option<CornerKind>) {
|
||||
let entries = corner_entries();
|
||||
let mut edit = None;
|
||||
Field::new(tl!("Corner:")).show(ui, |ui, _| {
|
||||
edit = Some(Select::new(tl!("Corner:"), Bind::given(kind.map_or(Mixed::Mixed, Mixed::Same)), &entries).show(ui));
|
||||
Field::new(tl!("Corner")).show(ui, |ui, _| {
|
||||
edit = Some(Select::new(tl!("Corner"), Bind::given(kind.map_or(Mixed::Mixed, Mixed::Same)), &entries).show(ui));
|
||||
});
|
||||
if let Some(edit) = edit {
|
||||
apply_edits(app, &edit, EditPath::Scope, |app, k, _| set_live_shape(app, json!({ "kind": k })));
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use serde_json::Value;
|
||||
use vectorcraft_doc::Unit;
|
||||
|
||||
use super::*;
|
||||
@@ -14,8 +13,9 @@ fn bar(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
object_bar_fields(app, ui);
|
||||
}
|
||||
|
||||
/// A length in points as a length field reads it: its number, with the unit painted after it.
|
||||
fn pt(v: f64) -> String {
|
||||
Unit::Points.format(v)
|
||||
Unit::Points.number(v)
|
||||
}
|
||||
|
||||
/// A shown angle, in degrees.
|
||||
@@ -23,8 +23,21 @@ fn degrees(p: &Panel, name: &str) -> Option<f64> {
|
||||
p.value(name)?.trim_end_matches('°').parse().ok()
|
||||
}
|
||||
|
||||
/// The state of panel-menu row `id`, as the panel menus' states give it.
|
||||
fn row_state(app: &VectorcraftApp, id: &str) -> Option<CommandState> {
|
||||
let mut states = CommandStates::new();
|
||||
crate::panels::panel_menu_states(app, &mut states);
|
||||
states.get(&CommandRef::new(id)).cloned()
|
||||
}
|
||||
|
||||
/// The check of panel-menu row `id`.
|
||||
fn checked(app: &VectorcraftApp, id: &str) -> Option<bool> {
|
||||
crate::menus::checked(app, id, &Value::Null)
|
||||
row_state(app, id)?.is_checked()
|
||||
}
|
||||
|
||||
/// Whether panel-menu row `id` is on.
|
||||
fn enabled(app: &VectorcraftApp, id: &str) -> bool {
|
||||
row_state(app, id).is_some_and(|s| s.is_enabled())
|
||||
}
|
||||
|
||||
fn blank(v: Option<String>) -> bool {
|
||||
@@ -328,7 +341,7 @@ fn the_artboard_tool_shows_the_active_artboard() {
|
||||
p.frame();
|
||||
// Centre reference point: X 150, Y 100, W 300, H 200; no rotate/shear for artboards.
|
||||
let r = p.app().session.active().unwrap().doc.artboards[0].rect;
|
||||
assert_eq!((p.value("X"), p.value("Y")), (Some(pt(r.center().x)), Some(pt(r.center().y))));
|
||||
assert_eq!((p.value("X position"), p.value("Y position")), (Some(pt(r.center().x)), Some(pt(r.center().y))));
|
||||
assert_eq!((p.value("Width"), p.value("Height")), (Some(pt(r.width())), Some(pt(r.height()))));
|
||||
assert!(!p.shows("Rotate"));
|
||||
}
|
||||
@@ -363,11 +376,11 @@ fn an_anchor_selection_shows_and_moves_its_own_box() {
|
||||
let square = json!({"anchors": [{"x": 20, "y": 30}, {"x": 120, "y": 30}, {"x": 120, "y": 130}, {"x": 20, "y": 130}], "closed": true});
|
||||
let id = app.run("path.create", square).unwrap()["id"].as_u64().unwrap();
|
||||
let mut p = panel(app);
|
||||
assert_eq!((p.value("X"), p.value("Width")), (Some(pt(70.0)), Some(pt(100.0))), "the whole path");
|
||||
assert_eq!((p.value("X position"), p.value("Width")), (Some(pt(70.0)), Some(pt(100.0))), "the whole path");
|
||||
p.app().run("select.anchors", json!({"id": id, "anchors": [[0, 1]]})).unwrap();
|
||||
p.frame();
|
||||
assert_eq!((p.value("X"), p.value("Y"), p.value("Width")), (Some(pt(120.0)), Some(pt(30.0)), Some(pt(0.0))));
|
||||
p.type_into("X", "150");
|
||||
assert_eq!((p.value("X position"), p.value("Y position"), p.value("Width")), (Some(pt(120.0)), Some(pt(30.0)), Some(pt(0.0))));
|
||||
p.type_into("X position", "150");
|
||||
let n = first_selected(&p.app()).unwrap();
|
||||
let Some(path) = n.path_data() else { panic!("a path") };
|
||||
let xs: Vec<f64> = path.subpaths[0].anchors.iter().map(|a| a.p.x).collect();
|
||||
@@ -433,7 +446,7 @@ fn the_menu_chooses_whether_the_object_its_pattern_or_both_transform() {
|
||||
assert_eq!(checked_modes(&app), [item], "{case}");
|
||||
// The centre reference point: X 150 becomes 170.
|
||||
let mut p = Panel::new(app, draw);
|
||||
p.type_into("X", "170");
|
||||
p.type_into("X position", "170");
|
||||
let mut guard = p.app();
|
||||
let app = &mut *guard;
|
||||
let x0 = app.selection_box().unwrap().rect.x0;
|
||||
@@ -484,19 +497,19 @@ fn use_registration_point_for_symbol_measures_an_instance_from_its_registration_
|
||||
let id = app.run("symbol.new", json!({"name": "Corner", "registration": 0})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
let mut p = Panel::new(app, draw);
|
||||
assert_eq!((p.value("X"), p.value("Y")), (Some(pt(140.0)), Some(pt(70.0))), "the centre");
|
||||
assert_eq!((p.value("X position"), p.value("Y position")), (Some(pt(140.0)), Some(pt(70.0))), "the centre");
|
||||
assert_ne!(checked(&p.app(), "ui.transform.registrationPoint"), Some(true));
|
||||
p.app().run("ui.transform.registrationPoint", json!({})).unwrap();
|
||||
assert!(p.app().session.prefs.use_registration_point_for_symbol);
|
||||
assert_eq!(checked(&p.app(), "ui.transform.registrationPoint"), Some(true));
|
||||
p.frame();
|
||||
assert_eq!((p.value("X"), p.value("Y")), (Some(pt(100.0)), Some(pt(50.0))), "the top-left");
|
||||
p.type_into("X", "30");
|
||||
assert_eq!((p.value("X position"), p.value("Y position")), (Some(pt(100.0)), Some(pt(50.0))), "the top-left");
|
||||
p.type_into("X position", "30");
|
||||
assert_eq!(p.app().selection_box().unwrap().rect, Rect::new(30.0, 50.0, 110.0, 90.0));
|
||||
// Any other selection: the reference point.
|
||||
p.app().run("shape.rectangle", json!({"x": 200, "y": 200, "width": 20, "height": 20})).unwrap();
|
||||
p.frame();
|
||||
assert_eq!(p.value("X"), Some(pt(210.0)), "the centre");
|
||||
assert_eq!(p.value("X position"), Some(pt(210.0)), "the centre");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,9 +534,9 @@ fn the_control_bar_fields_use_the_shared_reference_point() {
|
||||
app.ui.transform_panel.reference_point = refi;
|
||||
let mut p = Panel::new(app, bar);
|
||||
let before = revision(&p);
|
||||
assert_eq!((p.value("X"), p.value("Y")), (Some(pt(x)), Some(pt(y))), "reference {refi}");
|
||||
assert_eq!((p.value("X position"), p.value("Y position")), (Some(pt(x)), Some(pt(y))), "reference {refi}");
|
||||
assert_eq!(revision(&p), before, "reference {refi}: choosing the point leaves the art");
|
||||
p.type_into("X", new_x);
|
||||
p.type_into("X position", new_x);
|
||||
assert_eq!(p.app().selection_box().unwrap().rect, moved, "reference {refi}: X");
|
||||
assert_eq!(revision(&p), before + 1, "reference {refi}: one undo step");
|
||||
p.type_into("Width", "200");
|
||||
@@ -565,9 +578,9 @@ fn use_registration_point_for_symbol_follows_a_transformed_instance() {
|
||||
app.run("prefs.set", json!({"key": "useRegistrationPointForSymbol", "value": true})).unwrap();
|
||||
let q = registration(&app, id);
|
||||
let mut p = panel(app);
|
||||
assert_eq!((p.value("X"), p.value("Y")), (Some(pt(q.x)), Some(pt(q.y))), "{case}: X/Y at {q:?}");
|
||||
assert_eq!((p.value("X position"), p.value("Y position")), (Some(pt(q.x)), Some(pt(q.y))), "{case}: X/Y at {q:?}");
|
||||
// A new X moves the registration point there.
|
||||
p.type_into("X", &format!("{}", q.x - 40.0));
|
||||
p.type_into("X position", &format!("{}", q.x - 40.0));
|
||||
let q = vectorcraft_geom::Point::new(q.x - 40.0, q.y);
|
||||
assert!(near(registration(&p.app(), id), q), "{case}: moved to {q:?}, now {:?}", registration(&p.app(), id));
|
||||
// The rotation field turns it about the registration point.
|
||||
@@ -823,13 +836,13 @@ fn align_to_pixel_grid_state_is_measured_once_per_revision() {
|
||||
fn align_new_objects_menu_item_toggles_the_active_document() {
|
||||
const ID: &str = "ui.transform.alignNewObjects";
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
assert!(!crate::menus::enabled(&app, ID), "no document");
|
||||
assert!(!enabled(&app, ID), "no document");
|
||||
// The command refuses with no document; the refusal is what is checked next.
|
||||
let _ = app.run(ID, json!({}));
|
||||
assert!(app.session.active().is_none());
|
||||
app.run("file.new", json!({"width": 300, "height": 300})).unwrap();
|
||||
app.run("file.new", json!({"preset": "Web 1920×1080"})).unwrap();
|
||||
assert!(crate::menus::enabled(&app, ID));
|
||||
assert!(enabled(&app, ID));
|
||||
let on = |app: &VectorcraftApp, i: usize| app.session.documents()[i].doc.setup.align_new_objects_to_pixel_grid;
|
||||
assert_eq!((on(&app, 0), on(&app, 1)), (false, true));
|
||||
assert_eq!(checked(&app, ID), Some(true), "the Web document");
|
||||
|
||||
@@ -445,7 +445,7 @@ mod tests {
|
||||
run_cmd(&mut app, "transparency.makeOpacityMask", json!({}));
|
||||
run_cmd(&mut app, "shape.ellipse", json!({"x": 0, "y": 0, "width": 30, "height": 30}));
|
||||
let mut panel = Panel::new(app, show);
|
||||
assert_eq!(panel.value("Opacity").as_deref(), Some("60%"), "the masked object's opacity, not the mask art's");
|
||||
assert_eq!(panel.value("Opacity").as_deref(), Some("60"), "the masked object's opacity, not the mask art's");
|
||||
assert!(panel.shows("Release"));
|
||||
let (info, n) = state(&mut panel.app());
|
||||
assert_eq!((info.ids, n.as_ref().map(|n| n.id.0)), (vec![vectorcraft_doc::NodeId(a)], Some(a)));
|
||||
@@ -529,11 +529,11 @@ mod tests {
|
||||
assert!(blank(panel.value("Opacity")) && blank(panel.value("Blend Mode")));
|
||||
run_cmd(&mut panel.app(), "select.set", json!({"ids": [a]}));
|
||||
panel.frame();
|
||||
assert_eq!((panel.value("Opacity").as_deref(), panel.value("Blend Mode").as_deref()), (Some("50%"), Some("Screen")));
|
||||
assert_eq!((panel.value("Opacity").as_deref(), panel.value("Blend Mode").as_deref()), (Some("50"), Some("Screen")));
|
||||
// Nothing selected: the defaults for new art, disabled.
|
||||
run_cmd(&mut panel.app(), "select.none", json!({}));
|
||||
panel.frame();
|
||||
assert_eq!(panel.value("Opacity").as_deref(), Some("100%"));
|
||||
assert_eq!(panel.value("Opacity").as_deref(), Some("100"), "a percent field reads its number");
|
||||
assert!(panel.shows("No Selection") && !panel.enabled("Opacity"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user