mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
UI: dialog option rows stand beside or under their choice
- Transform effect: the Scale, Move and Rotate rows span the dialog instead of sitting behind a "Transform" label, and Reflect X, Reflect Y and Random show their names (the boxes were unlabeled). - Transform Each: the reference point picker shows its name. - Zig Zag, Roughen and Tweak: Relative and Absolute stand on one line, and so do Smooth and Corner. - Corners: Relative and Absolute stand on one line. - Drop Shadow: the color well stands under Color and the Darkness field under Darkness. - Print: the Range field stands under the Range choice instead of after Ignore Artboards. Each uses the form's own radio layouts (options_in_row, under_option) and plain check box rows. Tests in tests/dialog_layout.rs check where the dialogs paint these rows.
This commit is contained in:
1 parent
b24f5af47c
commit
84eef86c0a
6 files changed
+169
-11
No files matched your search
@@ -87,8 +87,11 @@ fn dialog<'a>(relative: bool, lengths: LengthUnits) -> ParamDialog<'a> {
|
||||
Param::number("radius", tl!("Radius:"), 0.0, 1.0, 3).length(lengths).bounds(Some(0.0), None)
|
||||
};
|
||||
let radii = vec![("relative".to_owned(), tl!("Relative").into()), ("absolute".to_owned(), tl!("Absolute").into())];
|
||||
let params =
|
||||
vec![Param::new("kind", tl!("Corner:"), ParamKind::radio(kinds, None)), Param::new("radii", "", ParamKind::radio(radii, None)), radius];
|
||||
let params = vec![
|
||||
Param::new("kind", tl!("Corner:"), ParamKind::radio(kinds, None)),
|
||||
Param::new("radii", "", ParamKind::radio(radii, None)).options_in_row(),
|
||||
radius,
|
||||
];
|
||||
ParamDialog::new(KIND, tl!("Corners"), params)
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ fn sized_row(key: &str, label: Label, default: f64, relative: bool, lengths: Len
|
||||
/// the flag's JSON values, which `form::json_of` writes back as a bool.
|
||||
pub(super) fn relative_radio(label: impl Into<Label>, default: bool) -> Param {
|
||||
let options = vec![("true".to_owned(), lbl!("Relative")), ("false".to_owned(), lbl!("Absolute"))];
|
||||
Param::new("relative", label, ParamKind::radio(options, Some(default.to_string())))
|
||||
Param::new("relative", label, ParamKind::radio(options, Some(default.to_string()))).options_in_row()
|
||||
}
|
||||
|
||||
/// Whether the pair's rows are shares of the object's size.
|
||||
@@ -71,14 +71,16 @@ pub(super) fn transform(cx: &EffectCx, _fields: &DialogFields) -> Vec<Param> {
|
||||
let lengths = cx.lengths;
|
||||
vec![
|
||||
Param::custom("transform", lbl!("Transform"), move |ui, fields, _| transform_each::rows(ui, fields, lengths, ScaleLink::None))
|
||||
.companions(["scaleH", "scaleV", "moveH", "moveV", "rotate"]),
|
||||
.companions(["scaleH", "scaleV", "moveH", "moveV", "rotate"])
|
||||
.full_width(),
|
||||
Param::section(lbl!("Options")),
|
||||
Param::new("objects", lbl!("Transform Objects"), ParamKind::bool(true)),
|
||||
Param::new("patterns", lbl!("Transform Patterns"), ParamKind::bool(false)),
|
||||
Param::new("strokes", lbl!("Scale Strokes & Effects"), ParamKind::bool(false)),
|
||||
Param::new("copies", lbl!("Copies:"), ParamKind::int(Some(0), Some(1000), 0)),
|
||||
Param::custom("__reflect", lbl!("Reflect"), |ui, fields, _| transform_each::reflect_checks(ui, fields))
|
||||
.companions(["reflectX", "reflectY", "random"]),
|
||||
Param::new("reflectX", lbl!("Reflect X"), ParamKind::bool(false)),
|
||||
Param::new("reflectY", lbl!("Reflect Y"), ParamKind::bool(false)),
|
||||
Param::new("random", lbl!("Random"), ParamKind::bool(false)),
|
||||
Param::custom("__reference", lbl!("Reference Point"), |ui, fields, _| transform_each::reference_point(ui, fields)).companions(["reference"]),
|
||||
]
|
||||
}
|
||||
@@ -102,7 +104,8 @@ pub(super) fn distort(cx: &EffectCx, fields: &DialogFields) -> Vec<Param> {
|
||||
"points",
|
||||
Label::from(crate::i18n::tr_ctx(crate::i18n::current(), "effect", "Points").to_string()),
|
||||
ParamKind::radio(points, None),
|
||||
),
|
||||
)
|
||||
.options_in_row(),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -185,12 +188,13 @@ pub(super) fn drop_shadow(cx: &EffectCx, fields: &DialogFields) -> Vec<Param> {
|
||||
.map(|p| if matches!(p.key.as_str(), "opacity" | "x" | "y" | "blur") { p.step_arrows(StepArrows::Leading) } else { p });
|
||||
rows.chain([
|
||||
Param::new("shade", Label::Empty, ParamKind::radio(shades, None)),
|
||||
Param::new("color", lbl!("Color"), ParamKind::color(None)).enabled_when("shade", "color"),
|
||||
Param::new("color", lbl!("Color"), ParamKind::color(None)).enabled_when("shade", "color").under_option("color"),
|
||||
Param::number("darkness", lbl!("Darkness"), 100.0, 1.0, 0)
|
||||
.bounds(Some(0.0), Some(100.0))
|
||||
.unit(UnitKind::Percent)
|
||||
.step_arrows(StepArrows::Leading)
|
||||
.enabled_when("shade", "darkness"),
|
||||
.enabled_when("shade", "darkness")
|
||||
.under_option("darkness"),
|
||||
])
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -706,7 +706,10 @@ fn sections(lists: &Lists) -> Vec<PrintSection> {
|
||||
flag("collate", tl!("Collate")).enabled_when_in("copies", counts),
|
||||
flag("reverse", tl!("Reverse Order")),
|
||||
Param::new("artboards", tl!("Artboards"), ParamKind::radio(artboards, None)),
|
||||
Param::new("range", tl!("Range:"), ParamKind::text("")).hint("1-3, 5").enabled_when("artboards", PrintArtboards::Range.id()),
|
||||
Param::new("range", tl!("Range:"), ParamKind::text(""))
|
||||
.hint("1-3, 5")
|
||||
.enabled_when("artboards", PrintArtboards::Range.id())
|
||||
.under_option(PrintArtboards::Range.id()),
|
||||
flag("skipBlank", tl!("Skip Blank Artboards")).enabled_when_in("artboards", [PrintArtboards::All.id(), PrintArtboards::Range.id()]),
|
||||
Param::section(tl!("Media")),
|
||||
pick::<Media>("media", tl!("Size:")),
|
||||
|
||||
@@ -445,6 +445,15 @@ pub(crate) fn reference_point(ui: &mut Ui, fields: &mut DialogFields) -> Respons
|
||||
shown.response
|
||||
}
|
||||
|
||||
/// The reference point picker with its name beside it, for a full-width row that draws no label of its own.
|
||||
fn labelled_reference_point(ui: &mut Ui, fields: &mut DialogFields) -> Response {
|
||||
let shown = Row::new().show(ui, |ui, _| {
|
||||
reference_point(ui, fields);
|
||||
Text::new(tl!("Reference Point")).show(ui);
|
||||
});
|
||||
shown.output
|
||||
}
|
||||
|
||||
/// The dialog's rows: Scale, Move and Rotate in one row, then the options.
|
||||
fn dialog_params(lengths: LengthUnits) -> Vec<Param> {
|
||||
vec![
|
||||
@@ -464,7 +473,7 @@ fn dialog_params(lengths: LengthUnits) -> Vec<Param> {
|
||||
Ok(())
|
||||
})
|
||||
.full_width(),
|
||||
Param::custom("reference", tl!("Reference Point"), |ui, f, _| reference_point(ui, f))
|
||||
Param::custom("reference", tl!("Reference Point"), |ui, f, _| labelled_reference_point(ui, f))
|
||||
.on_set(|f, key, value| {
|
||||
let at = value.as_i64().filter(|at| (0..=8).contains(at)).ok_or_else(|| FieldRefusal::Rejects(&value).message(key))?;
|
||||
f.set(key, at);
|
||||
|
||||
@@ -5,6 +5,7 @@ pub(super) mod background;
|
||||
mod clipboard;
|
||||
mod contextmenu;
|
||||
mod cut;
|
||||
mod dialog_layout;
|
||||
mod distortkeys;
|
||||
mod document_drag;
|
||||
mod drag_commands;
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
//! Where the parameter dialogs draw their rows: option rows stand beside or under the choice they belong to, and
|
||||
//! every check box and picker shows its name.
|
||||
|
||||
use egui::{Pos2, Rect};
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_engine::Session;
|
||||
|
||||
use crate::VectorcraftApp;
|
||||
|
||||
type Window = egui_kittest::Harness<'static, VectorcraftApp>;
|
||||
|
||||
/// A document with one selected rectangle, in a window that runs whole app frames.
|
||||
fn window() -> Window {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 120, "height": 90})).unwrap();
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
let mut fonts = false;
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 900.0)).build_ui_state(
|
||||
move |ui, app: &mut VectorcraftApp| {
|
||||
if !std::mem::replace(&mut fonts, true) {
|
||||
crate::testing::install(ui.ctx());
|
||||
return;
|
||||
}
|
||||
app.tick(ui.ctx());
|
||||
app.ui(ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
let root = h.input_mut().viewports.entry(egui::ViewportId::ROOT).or_default();
|
||||
root.inner_rect = Some(Rect::from_min_size(Pos2::ZERO, egui::vec2(1200.0, 900.0)));
|
||||
root.focused = Some(true);
|
||||
for _ in 0..2 {
|
||||
step(&mut h);
|
||||
}
|
||||
h
|
||||
}
|
||||
|
||||
/// One frame as the hosts run the window's; the commands it fired run as the next frame begins.
|
||||
fn step(h: &mut Window) {
|
||||
let ctx = h.ctx.clone();
|
||||
let app = h.state_mut();
|
||||
app.adopt_context(&ctx);
|
||||
craft::ui::shell::embed::before_input(&ctx, |out| app.frame_input(out));
|
||||
h.step();
|
||||
crate::testing::run_fired(h.state_mut(), &ctx);
|
||||
}
|
||||
|
||||
/// The texts the window paints with `command` run, each with where it was drawn, a field label's colon left off.
|
||||
fn texts(command: &str, params: Value) -> Vec<(String, Rect)> {
|
||||
fn collect(s: &egui::Shape, out: &mut Vec<(String, Rect)>) {
|
||||
match s {
|
||||
egui::Shape::Text(t) => out.push((t.galley.text().trim().trim_end_matches(':').to_owned(), t.visual_bounding_rect())),
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| collect(s, out)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut h = window();
|
||||
crate::menus::invoke(h.state_mut(), command, params);
|
||||
for _ in 0..6 {
|
||||
step(&mut h);
|
||||
}
|
||||
let mut out = vec![];
|
||||
h.output().shapes.iter().for_each(|c| collect(&c.shape, &mut out));
|
||||
out
|
||||
}
|
||||
|
||||
/// Where each painted `label` was drawn, top to bottom.
|
||||
fn all(texts: &[(String, Rect)], label: &str) -> Vec<Rect> {
|
||||
let mut found: Vec<Rect> = texts.iter().filter(|(t, _)| t == label).map(|(_, r)| *r).collect();
|
||||
found.sort_by(|a, b| a.top().total_cmp(&b.top()));
|
||||
found
|
||||
}
|
||||
|
||||
/// The one painted `label`.
|
||||
fn one(texts: &[(String, Rect)], label: &str) -> Rect {
|
||||
let found = all(texts, label);
|
||||
assert_eq!(found.len(), 1, "`{label}` drawn {} times in {:?}", found.len(), texts.iter().map(|t| &t.0).collect::<Vec<_>>());
|
||||
found[0]
|
||||
}
|
||||
|
||||
/// `b` stands on `a`'s line, to its right.
|
||||
fn beside(a: Rect, b: Rect) -> bool {
|
||||
(a.center().y - b.center().y).abs() < a.height() / 2.0 && b.left() > a.right()
|
||||
}
|
||||
|
||||
/// The Transform effect names its Reflect X, Reflect Y and Random check boxes.
|
||||
#[test]
|
||||
fn the_transform_effect_names_its_reflect_options() {
|
||||
let shown = texts("effect.dialog", json!({"effect": "distort.transform"}));
|
||||
for label in ["Reflect X", "Reflect Y", "Random"] {
|
||||
one(&shown, label);
|
||||
}
|
||||
}
|
||||
|
||||
/// Transform Each names its reference point picker.
|
||||
#[test]
|
||||
fn transform_each_names_its_reference_point() {
|
||||
let shown = texts("object.transformEach", json!({}));
|
||||
one(&shown, "Reference Point");
|
||||
}
|
||||
|
||||
/// Roughen's Relative and Absolute stand on one line, and so do Smooth and Corner.
|
||||
#[test]
|
||||
fn roughen_puts_each_choice_on_one_line() {
|
||||
let shown = texts("effect.dialog", json!({"effect": "distort.roughen"}));
|
||||
assert!(beside(one(&shown, "Relative"), one(&shown, "Absolute")), "Relative, then Absolute on its line");
|
||||
// The Properties panel also shows a Corner row; the dialog's Corner is the one on Smooth's line.
|
||||
let smooth = one(&shown, "Smooth");
|
||||
assert!(all(&shown, "Corner").into_iter().any(|corner| beside(smooth, corner)), "Smooth, then Corner on its line");
|
||||
}
|
||||
|
||||
/// The Corners dialog's Relative and Absolute stand on one line.
|
||||
#[test]
|
||||
fn corners_puts_relative_and_absolute_on_one_line() {
|
||||
let shown = texts("ui.corners", json!({}));
|
||||
assert!(beside(one(&shown, "Relative"), one(&shown, "Absolute")), "Relative, then Absolute on its line");
|
||||
}
|
||||
|
||||
/// Drop Shadow's color row stands under the Color choice, before Darkness, and the Darkness row under Darkness.
|
||||
#[test]
|
||||
fn drop_shadow_rows_stand_under_their_choice() {
|
||||
let shown = texts("effect.dialog", json!({"effect": "stylize.dropShadow"}));
|
||||
let mut order: Vec<(f32, &str)> = ["Color", "Darkness"].iter().flat_map(|l| all(&shown, l).into_iter().map(move |r| (r.top(), *l))).collect();
|
||||
order.sort_by(|a, b| a.0.total_cmp(&b.0));
|
||||
let labels: Vec<&str> = order.iter().map(|(_, l)| *l).collect();
|
||||
assert_eq!(labels, ["Color", "Color", "Darkness", "Darkness"], "each choice, then its row");
|
||||
}
|
||||
|
||||
/// Print's Range field stands under the Range choice, before Ignore Artboards.
|
||||
#[test]
|
||||
fn print_range_stands_under_its_choice() {
|
||||
let shown = texts("file.print", json!({}));
|
||||
let ignore = one(&shown, "Ignore Artboards (all the art as one page)");
|
||||
let ranges = all(&shown, "Range");
|
||||
assert_eq!(ranges.len(), 2, "the choice and the field");
|
||||
assert!(ranges.iter().all(|r| r.bottom() <= ignore.top()), "the Range field before Ignore Artboards");
|
||||
}
|
||||
Reference in new issue
Block a user