mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 15:21:17 -05:00
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
This commit is contained in:
@@ -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(())
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<egui::Rangef> {
|
||||
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:?}"))
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user