Name the recolor wheel as production did, list open dialogs in ui.inspect, and answer place picks once they open

- Recolor Artwork's wheel is "Color wheel" or "Segmented color wheel" again; ui.dialog.set takes the
  Edit tab's fields that start unset (sliderMode, display, wheelTool, wheelAxes).
- ui.inspect lists the window's open dialogs under dialogs, as the framework's automation asks.
- Tests: wheel markers are named by lowercase hex as the framework names them, a channel's rail is its
  Slider (the number field shares the name), the dock is read under its saved name, and Place answers
  the file pick after it opens.
This commit is contained in:
bflatastic
2026-11-22 21:06:04 +07:00
parent 82759d66fe
commit f1f5eee697
7 changed files with 24 additions and 10 deletions
+2
View File
@@ -155,6 +155,8 @@ pub fn inspect(app: &VectorcraftApp, ctx: &egui::Context) -> Value {
"tool": app.session.tool_id(),
"toolOptions": app.session.tool_options(),
"ui": ui,
// The window's open dialogs, the top one last, with their fields.
"dialogs": app.dialogs().map_or_else(|| json!([]), |dialogs| dialogs.with(|host| craft::automation::dialogs::inspect(host))),
// Not saved with the UI state, so not in `ui`: 0 normal … 3 Presentation Mode.
"screenMode": app.ui.screen_mode,
// The Contextual Task Bar: pinned (not saved either); `ui.locate` finds where it shows.
+4 -1
View File
@@ -201,6 +201,9 @@ const COMPS: &str = "__comps";
/// The `__` controls `ui.dialog.set` can set: the selected rows, Randomize's seed and the New Color Group menu's
/// request.
const SETTABLE: [&str; 3] = ["__sel", "__seed", SAVE_GROUP];
/// The fields `ui.dialog.set` can set while they are unset: Preview, the Color Groups buttons, the Edit tab's slider
/// mode, display, wheel tool and wheel axes.
const UNSET_FIELDS: [&str; 6] = ["preview", GROUP_ACTION, "sliderMode", "display", WHEEL_TOOL, WHEEL_AXES];
/// The columns of the Assign tab's rows: the current colors, the arrow that excludes the row, the
/// new color and its hex.
@@ -1763,7 +1766,7 @@ impl RecolorDialog {
let known = if field.starts_with("__") {
SETTABLE.contains(&field)
} else {
self.fields.fields.contains_key(field) || field == "preview" || field == GROUP_ACTION
self.fields.fields.contains_key(field) || UNSET_FIELDS.contains(&field)
};
if !known {
return Err(FieldRefusal::Unknown.message(field));
@@ -98,8 +98,8 @@ pub(super) fn show(ui: &mut Ui, d: &mut Fields, feed: &Feed, rows: &mut Vec<Valu
let colors: Vec<Srgba> = active.iter().map(|&i| srgba(&rows.get(i).and_then(to_color).unwrap_or_default())).collect();
let at = |row: Option<usize>| row.and_then(|r| active.iter().position(|&i| i == r));
let look = if segmented { DiscLook::Segmented } else { DiscLook::Smooth };
let words = Env::of(ui).words::<HarmonyWords>();
let out = HarmonyWheel::new(words.harmony.clone(), &colors).selected_marker(at(sel)).base(at(base)).look(look).radius(axes).show(ui);
let name = if segmented { tl!("Segmented color wheel") } else { tl!("Color wheel") };
let out = HarmonyWheel::new(name, &colors).selected_marker(at(sel)).base(at(base)).look(look).radius(axes).show(ui);
// A right-click on the disc: a marker's menu, or Add New Color at the point, tied to the spoke it is on.
if let Some(hit) = out.context {
let row = |k: Option<usize>| k.and_then(|k| active.get(k)).copied();
@@ -7,6 +7,7 @@ use std::rc::Rc;
use craft::behavior::PartRef;
use craft::ui::dialog::{DialogHost, DialogId, HeldOk, dialog_id};
use craft::ui::runtime::access::Role;
use craft::ui::testing::{Fixture, Room, Target};
use egui::{Event, Modifiers, PointerButton, Pos2, Rect, Vec2};
use serde_json::{Value, json};
@@ -138,6 +139,12 @@ impl Recolor {
self.fixture.by_label(label)
}
/// The slider named `label`: a channel's rail, not the number field that shares its name.
pub(crate) fn slider(&self, label: &str) -> Option<Target> {
let tree = self.fixture.tree();
self.fixture.by_role(Role::SLIDER).into_iter().find(|t| tree.name_of(t.node) == Some(label))
}
/// The control named `label`; a trial without it fails.
fn target(&self, label: &str) -> Target {
self.by_label(label).unwrap_or_else(|| panic!("no control named {label:?}"))
+1 -1
View File
@@ -1262,7 +1262,7 @@ fn hide_panel(app: &mut VectorcraftApp, panel: String) {
/// The closed panels of a `ui.inspect` result's UI state, in order.
fn hidden_panels(ui: &Value) -> Vec<String> {
let hidden = ui["dock_workspace"]["hidden"].as_array().map(Vec::as_slice).unwrap_or_default();
let hidden = ui["dock"]["hidden"].as_array().map(Vec::as_slice).unwrap_or_default();
hidden.iter().filter_map(|entry| entry[0].as_str().map(str::to_owned)).collect()
}
+4 -2
View File
@@ -70,8 +70,9 @@ fn app() -> VectorcraftApp {
/// File → Place… with `paths` chosen in the file picker.
fn place_picked_all(app: &mut VectorcraftApp, ctx: &egui::Context, paths: &[&str]) {
scripted(app).answer(paths);
let picker = scripted(app);
app.run("file.place", json!({})).unwrap();
picker.answer(paths);
poll(app, ctx);
}
@@ -598,9 +599,10 @@ fn the_control_bars_file_name_relinks_the_image() {
}
let dir = Folder::new("ui-place-relink");
let other = dir.file("blue.png", &png(60, 30, 72.0));
scripted(&mut app).answer(&[&other]);
let picker = scripted(&mut app);
let p = item(&mut app, &ctx, "Replace…");
click_control(&mut app, &ctx, p);
picker.answer(&[&other]);
poll(&mut app, &ctx);
let image = selected_image(&app);
let NodeKind::Image(im) = &image.kind else { panic!("an image") };
+4 -4
View File
@@ -14,7 +14,7 @@ use crate::dialogs::recolor::fixture::Recolor;
use crate::{VectorcraftApp, dialogs};
// PLAN: assumed control names: the wheel's accessible name is "Color wheel" / "Segmented color wheel", its markers are
// named by their `#RRGGBB` hex, menu items carry no leading padding, and the Assign row's hex field is "Color N".
// named by their `#rrggbb` hex, menu items carry no leading padding, and the Assign row's hex field is "Color N".
fn app() -> VectorcraftApp {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
@@ -117,7 +117,7 @@ fn has(r: &Recolor, label: &str) -> bool {
/// Clicks the channel rail named `name` at `at` (0 to 1) of its width.
fn rail(r: &mut Recolor, name: &str, at: f32) {
let rail = rect(r, name);
let rail = r.slider(name).unwrap_or_else(|| panic!("no slider named {name}")).rect;
click(r, pos2(rail.left() + at * rail.width(), rail.center().y));
}
@@ -133,11 +133,11 @@ fn wheel_at(r: &Recolor, hue: f32, s: f32) -> Pos2 {
polar(c, hue, radius * s)
}
/// The marker's name: the hex of the colour `to`.
/// The marker's name: the lowercase hex of the colour `to`, as the wheel names it.
fn hex_of(to: &Value) -> String {
let [r, g, b] = vectorcraft_engine::cmd::color_value(to).unwrap().to_rgb();
let byte = |v: f32| (v * 255.0).round() as u8;
format!("#{:02X}{:02X}{:02X}", byte(r), byte(g), byte(b))
format!("#{:02x}{:02x}{:02x}", byte(r), byte(g), byte(b))
}
/// Where the wheel draws row `i`'s marker.