From e7ffbbec55c60cd7fc7425704122740904f3844e Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 23 Nov 2026 11:45:35 +0700 Subject: [PATCH] Recolor Artwork: Undo Changes, Redo Changes and the Randomize buttons act on every click, a quick second one too, as production's did; the Edit tab's colour chips are named New Color N, apart from the bars and markers named Color N; Import PDF's path can be set as production's fields took it (OK checks the roots). Tests: a channel rail is clicked along its thumb's travel --- crates/ui-egui/src/dialogs/import_pdf.rs | 5 ++++- crates/ui-egui/src/dialogs/recolor.rs | 6 +++--- crates/ui-egui/src/dialogs/recolor/edit_tab.rs | 7 +++++-- crates/ui-egui/src/dialogs/recolor/fixture.rs | 8 ++++++++ crates/ui-egui/src/tests/recolor.rs | 7 ++++--- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/dialogs/import_pdf.rs b/crates/ui-egui/src/dialogs/import_pdf.rs index 295cf1d2a2..d29d9742c4 100644 --- a/crates/ui-egui/src/dialogs/import_pdf.rs +++ b/crates/ui-egui/src/dialogs/import_pdf.rs @@ -243,7 +243,8 @@ impl State { fields } - /// Sets the field as the user editing that control would; the `__` fields and the file's name are not editable. + /// Sets the field as the user editing that control would, or the file's path as automation does; the `__` fields + /// and the file's name are not editable. fn set_field(&mut self, field: &str, value: Value) -> Result<(), String> { let text = || value.as_str().ok_or_else(|| format!("{field} takes text")); match field { @@ -270,6 +271,8 @@ impl State { self.text_as = text_as_of(id); } "password" => self.password = text()?.to_string(), + // As production's fields took it; OK checks the file against the caller's roots. + "path" => self.path = Some(text()?.to_string()), _ => return Err(format!("no field {field}")), } Ok(()) diff --git a/crates/ui-egui/src/dialogs/recolor.rs b/crates/ui-egui/src/dialogs/recolor.rs index b4a02dcc87..4aabb40a01 100644 --- a/crates/ui-egui/src/dialogs/recolor.rs +++ b/crates/ui-egui/src/dialogs/recolor.rs @@ -1996,10 +1996,10 @@ fn toolbar(ui: &mut Ui, d: &mut Fields, feed: &Feed, filed: &mut Filed, (can_und } } toggle_field(ui, d, THEME_PICKER, tl!("Color Theme Picker"), "pipette", true); - if IconButton::new(IconId::new("undo-2")).label(tl!("Undo Changes")).enabled(can_undo).show(ui).clicks == 1 { + if IconButton::new(IconId::new("undo-2")).label(tl!("Undo Changes")).enabled(can_undo).show(ui).clicked() { filed.step = Some(true); } - if IconButton::new(IconId::new("redo-2")).label(tl!("Redo Changes")).enabled(can_redo).show(ui).clicks == 1 { + if IconButton::new(IconId::new("redo-2")).label(tl!("Redo Changes")).enabled(can_redo).show(ui).clicked() { filed.step = Some(false); } toggle_field(ui, d, GROUP_STORAGE, tl!("Show Color Groups"), "library", true); @@ -2246,7 +2246,7 @@ fn assign_tab( for (icon, label, sb) in [("arrow-left-right", tl!("Randomly change color order"), false), ("sparkles", tl!("Randomly change saturation and brightness"), true)] { - if IconButton::new(IconId::new(icon)).label(label).enabled(rows.len() > 1 || sb).show(ui).clicks == 1 { + if IconButton::new(IconId::new(icon)).label(label).enabled(rows.len() > 1 || sb).show(ui).clicked() { filed.randomize = Some(sb); } } diff --git a/crates/ui-egui/src/dialogs/recolor/edit_tab.rs b/crates/ui-egui/src/dialogs/recolor/edit_tab.rs index aed025e176..4221f84893 100644 --- a/crates/ui-egui/src/dialogs/recolor/edit_tab.rs +++ b/crates/ui-egui/src/dialogs/recolor/edit_tab.rs @@ -489,8 +489,11 @@ fn chips(ui: &mut Ui, d: &mut Fields, rows: &mut [Value], active: &[usize], base .show(ui) .clicked(); for (i, color, hex) in &shown { - let chip = - Swatch::new(color_name(*i), *color).selected(Some(*i) == sel).tooltip(hex.clone()).marks(CellMarks::default().edge(Some(*i) == base)); + // Named apart from the colour's bar and marker ("Color N"), which the menus and drags find by that name. + let chip = Swatch::new(format!("{} {}", tl!("New Color"), i + 1), *color) + .selected(Some(*i) == sel) + .tooltip(hex.clone()) + .marks(CellMarks::default().edge(Some(*i) == base)); if chip.show(ui).clicked { chosen = Some(*i); } diff --git a/crates/ui-egui/src/dialogs/recolor/fixture.rs b/crates/ui-egui/src/dialogs/recolor/fixture.rs index fb9513bd1d..f90f44f34e 100644 --- a/crates/ui-egui/src/dialogs/recolor/fixture.rs +++ b/crates/ui-egui/src/dialogs/recolor/fixture.rs @@ -8,6 +8,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::pointer::part_rect_of_node; use craft::ui::testing::{Fixture, Room, Target}; use egui::{Event, Modifiers, PointerButton, Pos2, Rect, Vec2}; use serde_json::{Value, json}; @@ -145,6 +146,13 @@ impl Recolor { self.fixture.by_role(Role::SLIDER).into_iter().find(|t| tree.name_of(t.node) == Some(label)) } + /// Where the thumb of the slider named `label` runs, left to right: its track inset by half the thumb. + pub(crate) fn slider_travel(&self, label: &str) -> Option { + let rail = self.slider(label)?; + let thumb = part_rect_of_node(self.fixture.ctx(), rail.node.into(), craft::behavior::PartKey::new("thumb"))?.width(); + Some(egui::Rangef::new(rail.rect.left() + thumb / 2.0, rail.rect.right() - thumb / 2.0)) + } + /// 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:?}")) diff --git a/crates/ui-egui/src/tests/recolor.rs b/crates/ui-egui/src/tests/recolor.rs index 3ff004aa0f..551d6da5dc 100644 --- a/crates/ui-egui/src/tests/recolor.rs +++ b/crates/ui-egui/src/tests/recolor.rs @@ -115,10 +115,11 @@ fn has(r: &Recolor, label: &str) -> bool { r.by_label(label).is_some() } -/// Clicks the channel rail named `name` at `at` (0 to 1) of its width. +/// Clicks the channel rail named `name` at `at` (0 to 1) of its thumb's travel. fn rail(r: &mut Recolor, name: &str, at: f32) { - 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)); + let y = r.slider(name).unwrap_or_else(|| panic!("no slider named {name}")).rect.center().y; + let travel = r.slider_travel(name).unwrap_or_else(|| panic!("{name}'s rail has no thumb")); + click(r, pos2(travel.min + at * travel.span(), y)); } /// The wheel's centre and radius. The disc sits inside its control's rect by the theme's padding, so the radius is