mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-11 22:22:25 +00:00
Step a blank Stroke Weight in points in every unit, and fix its arrow-key test (#5349)
This commit is contained in:
@@ -245,15 +245,17 @@ fn a_spinner_step_from_a_weight_shown_as_a_preset_moves_past_it() {
|
||||
}
|
||||
|
||||
/// With objects of different weights selected the Weight field is blank, and its spinner steps
|
||||
/// from 0.25 pt as Illustrator does: up gives 0.5 pt and down gives 0 pt, for all of them.
|
||||
/// from 0.25 pt (#5349): up gives 0.5 pt and down gives 0 pt, for all of them, whatever the
|
||||
/// Units > Stroke.
|
||||
#[test]
|
||||
fn the_spinner_of_a_blank_weight_steps_from_a_quarter_point() {
|
||||
use super::tests_appearance::frame_raw;
|
||||
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
for (up, after) in [(true, 0.5), (false, 0.0)] {
|
||||
for (unit, up, after) in [("points", true, 0.5), ("points", false, 0.0), ("millimeters", true, 0.5), ("millimeters", false, 0.0)] {
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let mut app = app_with_rect();
|
||||
app.session.prefs.units_stroke = unit.into();
|
||||
let a = app.session.active().unwrap().selection.objects[0];
|
||||
let b = run(&mut app, "shape.rectangle", json!({"x": 120, "y": 10, "width": 50, "height": 50}))["id"].as_u64().unwrap();
|
||||
run(&mut app, "stroke.set", json!({"ids": [b], "weight": 3}));
|
||||
@@ -268,7 +270,7 @@ fn the_spinner_of_a_blank_weight_steps_from_a_quarter_point() {
|
||||
}
|
||||
for id in [a.0, b] {
|
||||
run(&mut app, "select.set", json!({ "ids": [id] }));
|
||||
assert_eq!(app.session.shown_stroke().unwrap().width, after, "object {id}, up: {up}");
|
||||
assert_eq!(app.session.shown_stroke().unwrap().width, after, "object {id}, up: {up}, {unit}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,9 +278,11 @@ fn the_spinner_of_a_blank_weight_steps_from_a_quarter_point() {
|
||||
/// ↑/↓ in the focused blank Weight field step from 0.25 pt too, for every selected object.
|
||||
#[test]
|
||||
fn the_arrow_keys_in_a_blank_weight_step_from_a_quarter_point() {
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
for (key, after) in [(egui::Key::ArrowUp, 0.5), (egui::Key::ArrowDown, 0.0)] {
|
||||
// A new context each time: the field keeps its text in the context, and the 0.5 pt left by ArrowUp
|
||||
// would make the blank field of the next run start from 0.5 pt.
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let mut app = app_with_rect();
|
||||
let a = app.session.active().unwrap().selection.objects[0];
|
||||
let b = run(&mut app, "shape.rectangle", json!({"x": 120, "y": 10, "width": 50, "height": 50}))["id"].as_u64().unwrap();
|
||||
|
||||
@@ -644,9 +644,11 @@ pub fn spin_field_stops_named(
|
||||
) -> Option<f64> {
|
||||
let label = take_previous_label(ui);
|
||||
let blank_from = BLANK_WEIGHT_STEPS_FROM;
|
||||
// A blank field steps in points from `blank_from`, whatever the unit's preset ladder (#5349).
|
||||
let stops = if value.is_none() { &BLANK_WEIGHT_STOPS[..] } else { presets };
|
||||
let fmt = |v: f64| unit.format(v);
|
||||
spin_generic(ui, label, value, Some(blank_from), None, None, None, width, step, min, presets, presets, &fmt, &mut |ui, fw, label| {
|
||||
unit_field_from(ui, id, label, name, value, unit, fw, false, min..=f64::INFINITY, presets, false, Some(blank_from), "")
|
||||
spin_generic(ui, label, value, Some(blank_from), None, None, None, width, step, min, presets, stops, &fmt, &mut |ui, fw, label| {
|
||||
unit_field_from(ui, id, label, name, value, unit, fw, false, min..=f64::INFINITY, stops, false, Some(blank_from), "")
|
||||
})
|
||||
.and_then(SpinPick::value)
|
||||
}
|
||||
@@ -655,6 +657,10 @@ pub fn spin_field_stops_named(
|
||||
/// 0.5 pt and down to 0 pt. This is the behaviour #5349 asks for.
|
||||
const BLANK_WEIGHT_STEPS_FROM: f64 = 0.25;
|
||||
|
||||
/// The stops a blank Stroke Weight steps through, in points, so that up gives 0.5 pt in every
|
||||
/// Units > Stroke, not the first preset of the unit's own ladder above 0.25 pt.
|
||||
const BLANK_WEIGHT_STOPS: [f64; 2] = [BLANK_WEIGHT_STEPS_FROM, 0.5];
|
||||
|
||||
/// A distance field with spinner arrows kept within `bounds` (points), as the Drop Shadow and
|
||||
/// Outer Glow dialogs show their offsets and blur: the spinner steps one `unit` at a time
|
||||
/// (Shift ×10, Ctrl/Cmd ÷10), and it, ↑/↓, the wheel, a scrub and a typed value stop at both
|
||||
|
||||
Reference in New Issue
Block a user