Unit Converter: a number typed in the Picas row is in picas

With Preferences > Units > Numbers Without Units Are Points on (the
default), 2 typed in the panel's Picas row read as 2 pt and showed 0.167 p.
Each row now reads a number without a unit in its own unit, so 2 in the
Picas row is 2 picas, as addon.units.convert reads it with unit picas.
Length fields in other panels still follow the preference.
This commit is contained in:
dotCooCoo
2026-11-14 20:33:57 -08:00
parent 71686757ec
commit 27fa52b97f
2 changed files with 33 additions and 0 deletions
+5
View File
@@ -141,6 +141,10 @@ pub(crate) fn apply(app: &mut VectorcraftApp, ui: &Ui, st: &Converter) -> Result
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);
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
@@ -160,6 +164,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
}
});
}
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;
}
+28
View File
@@ -100,6 +100,34 @@ fn typing_in_a_field_updates_the_others_and_text_that_does_not_read_leaves_them(
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<Event>| {
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::<Converter>(&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");
}
#[test]
fn picking_a_side_shows_that_side_of_the_size_read() {
let mut st = Converter { size: Some((72.0, 36.0)), ..Converter::default() };