Look like production: filled push buttons, inline number fields (#9213)

Push buttons and number fields look like production's VectorCraft, through craft-libs options set once at the app's root.

- Push buttons that ask for no look are filled tiles with no edge at rest (`PushButtonLook::Filled`); hover adds the control edge and pressing tints them, as production's were. The Contextual Task Bar's actions ask for the outline, as production drew them.
- Number fields show their value and unit as one run at the field's start, in the interface face ("720 pt", "0°", "100%"; `NumberLook::Inline`), with production's precision (whole percentages, lengths to a thousandth of a point).

Tests: five field tests read production's text again. Select All covers "37 pt", Copy copies "37 pt", and Opacity reads "60%", "50%" and "100%", which is what production's own tests asserted. The port had moved them to its centred look ("37", "60 %").

Checks: `vectorcraft-ui-egui` lib tests 3775 passed, 0 failed (the last two test fixes were re-run in their modules). Clippy (`vectorcraft-ui-egui`, `vectorcraft`, all targets, `-D warnings`) and `cargo fmt --check` are clean.
This commit is contained in:
BFlat
2026-11-24 14:56:39 +07:00
committed by GitHub
parent c9b32651dc
commit 951aa208ae
4 changed files with 20 additions and 16 deletions
+7 -2
View File
@@ -3,6 +3,7 @@ use craft::host::{AppInfo, Host, Wake};
use craft::platform::clipboard::{Clipboard, ClipboardProbe, EventClipboard};
use craft::platform::clock::monotonic_ms;
use craft::theme::variant::Tone;
use craft::ui::buttons::PushButtonLook;
use craft::ui::contract::Bind;
use craft::ui::runtime::env::{RootEnv, Scale, ScrubDrags, WindowKey};
use craft::ui::runtime::frame::{FrameInput, FrameOutput};
@@ -10,7 +11,7 @@ use craft::ui::runtime::toast::{self, Toast};
use craft::ui::runtime::windows::WindowHost;
use craft::ui::shell::embed::CloseDecision;
use craft::ui::shell::{AppShell, CanvasPanel, Slot};
use craft::ui::text::NumberPrecision;
use craft::ui::text::{NumberLook, NumberPrecision};
use vectorcraft_engine::cmd::clipboard::PASTE_ORDER;
use vectorcraft_engine::cmd::toast::Level;
@@ -663,8 +664,12 @@ pub(crate) fn root_env(prefs: &vectorcraft_engine::Prefs, native_ppp: f32) -> Ro
root.sizes = theme::app_sizes();
root.values.set(view::zoom_scheme(prefs, native_ppp));
root.values.set(if prefs.scrub_numeric_fields { ScrubDrags::LabelOnly } else { ScrubDrags::Off });
// Percentages read whole (60 %), lengths to a thousandth of a point (357.114 pt), as production showed them.
// Number fields as production drew them: the value and its unit one run at the start ("720 pt"), percentages
// whole and lengths to a thousandth of a point (357.114 pt).
root.values.set(NumberPrecision::Measured);
root.values.set(NumberLook::Inline);
// Push buttons that ask for no look are filled tiles with no edge at rest, as production's were.
root.values.set(PushButtonLook::Filled);
// A bare Tab on the canvas, or with nothing focused, toggles the panels (`window.dock`) instead of moving focus.
root.tab_toggles_chrome = true;
// Escape in a text field gives up its focus, reverting any typing, so the next keys are the window's.
+2 -2
View File
@@ -1,7 +1,7 @@
use craft::behavior::CanvasView;
use craft::behavior::{IconId, Mixed};
use craft::color_ui::ui::PaintChip;
use craft::theme::Srgba;
use craft::theme::{Srgba, Variant};
use craft::ui::buttons::{Button, IconButton};
use craft::ui::canvas::CanvasSpace;
use craft::ui::canvas_controls::TaskBar;
@@ -469,7 +469,7 @@ pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpac
run = Some(("tool.setOption", json!({"tool": "smooth", "values": {"fidelity": x}})));
}
}
} else if Button::new(*label).icon(IconSpec::svg(IconId::new(icon))).show(ui).clicked() {
} else if Button::new(*label).variant(Variant::SECONDARY).icon(IconSpec::svg(IconId::new(icon))).show(ui).clicked() {
run = Some((*cmd, params.clone()));
}
}
+3 -3
View File
@@ -449,7 +449,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)));
@@ -533,11 +533,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 %"), "a percent field reads its number and its unit");
assert_eq!(panel.value("Opacity").as_deref(), Some("100%"), "a percent field reads its number and its unit");
assert!(panel.shows("No Selection") && !panel.enabled("Opacity"));
}
+8 -9
View File
@@ -145,16 +145,15 @@ fn click(at: Pos2, pressed: bool) -> Event {
fn cmd_a_in_a_panel_field_selects_its_text_and_leaves_the_art() {
let mut a = App::new();
assert_eq!(a.selected(), 1);
// The W field shows its number, with its unit painted after it.
let (id, rect) = a.field("37");
let (id, rect) = a.field("37 pt");
a.frame(vec![Event::PointerMoved(rect.center()), click(rect.center(), true)]);
a.frame(vec![click(rect.center(), false)]);
a.frame(vec![]);
assert!(a.has_keyboard(id), "the W field has the keyboard");
let all = Some((0, "37".chars().count()));
let all = Some((0, "37 pt".chars().count()));
// The window's Cmd+A (Windows, Linux, the web, macOS without the system menu).
a.frame(vec![press(Key::End, Modifiers::NONE)]);
assert_eq!(a.field_selection(id), Some((2, 2)), "End collapses the selection");
assert_eq!(a.field_selection(id), Some((5, 5)), "End collapses the selection");
a.frame(vec![press(Key::A, Modifiers::COMMAND)]);
assert_eq!(a.field_selection(id), all, "Cmd+A selects the field's text");
assert_eq!(a.selected(), 1, "and not the art");
@@ -168,7 +167,7 @@ fn cmd_a_in_a_panel_field_selects_its_text_and_leaves_the_art() {
let out = a.menu("edit.copy");
// A fired command reaches the field in the next pass.
let after = a.frame(vec![]);
assert_eq!([copied(&out), copied(&after)].concat(), ["37"]);
assert_eq!([copied(&out), copied(&after)].concat(), ["37 pt"]);
assert!(a.app.session.clipboard.is_empty(), "no art copied");
assert!(a.has_keyboard(id), "the field keeps the keyboard");
}
@@ -276,7 +275,7 @@ fn the_clipboard_keys_in_a_focused_field_edit_its_text() {
for _ in 0..3 {
a.frame(vec![]);
}
for text in ["37", "FFFFFF"] {
for text in ["37 pt", "FFFFFF"] {
let (id, rect) = a.field(text);
a.frame(vec![Event::PointerMoved(rect.center()), click(rect.center(), true)]);
a.frame(vec![click(rect.center(), false)]);
@@ -519,7 +518,7 @@ fn the_in_window_edit_menu_acts_on_the_field_it_was_opened_from() {
// Text on the system clipboard.
super::sysclip::copy_elsewhere(&board, vec![(vectorcraft_engine::cmd::clipboard::TEXT, b"42 pt".to_vec())]);
a.paste = Some("42 pt".into());
let (id, rect) = a.field("37");
let (id, rect) = a.field("37 pt");
a.frame(vec![Event::PointerMoved(rect.center()), click(rect.center(), true)]);
a.frame(vec![click(rect.center(), false)]);
let out = a.frame(vec![press(Key::End, Modifiers::NONE)]);
@@ -531,13 +530,13 @@ fn the_in_window_edit_menu_acts_on_the_field_it_was_opened_from() {
};
menu(&mut a, select, "All");
assert!(a.has_keyboard(id), "the field has the keyboard back");
assert_eq!(a.field_selection(id), Some((0, 2)), "Select All selected the field's text");
assert_eq!(a.field_selection(id), Some((0, 5)), "Select All selected the field's text");
assert_eq!(a.selected(), 1, "not the art");
a.frame(vec![press(Key::End, Modifiers::NONE)]);
a.frame(vec![press(Key::A, Modifiers::COMMAND)]);
a.frame(vec![]);
let out = menu(&mut a, edit, "Copy");
assert_eq!(copied(&out), ["37"], "Copy copied the field's text");
assert_eq!(copied(&out), ["37 pt"], "Copy copied the field's text");
assert!(a.app.session.clipboard.is_empty(), "no art copied");
// Art on the app's clipboard (Paste is enabled): the field still takes the text.
a.app.run("edit.copy", json!({})).unwrap();