mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 04:33:43 +00:00
Merge pull request #7899 from dotCooCoo/feat/recolor-edit-base-color-menus
Recolor Artwork: Edit tab right-click menus set the base color, pick a shade and add colors
This commit is contained in:
@@ -836,6 +836,21 @@ fn a_null_in_group_colors_removes_that_swatch_and_the_ones_after_it_keep_their_p
|
||||
assert_eq!(link(&s, green), ("#00ff00".into(), Some(names[2].clone())), "art linked to a swatch that stays keeps its link");
|
||||
}
|
||||
|
||||
/// "keep" in `groupColors` leaves the group's swatch at its place as it is, without Global Adjust,
|
||||
/// and past the group's swatches it adds none.
|
||||
#[test]
|
||||
fn keep_in_group_colors_leaves_that_swatch_as_it_is() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.newGroup", json!({"name": "Brand", "colors": ["#2878f0", "#ff0000"]}));
|
||||
let p = json!({"map": [], "group": "Brand", "groupColors": ["keep", "#00ff00", "keep"], "globalAdjust": {"brightness": -50}});
|
||||
run(&mut s, "recolor.apply", p);
|
||||
let g = &s.doc().unwrap().doc.swatch_groups.iter().find(|g| g.name == "Brand").unwrap().swatches;
|
||||
let g: Vec<String> = g.iter().map(|w| w.paint.color().unwrap().to_hex()).collect();
|
||||
assert_eq!(g.len(), 2, "{g:?}");
|
||||
assert_eq!(g[0], "#2878f0", "the kept swatch takes no Global Adjust");
|
||||
assert_ne!(g[1], "#00ff00", "the other new color takes it");
|
||||
}
|
||||
|
||||
/// A gradient or pattern swatch of the group keeps its place and its paint when `recolor.apply`
|
||||
/// rewrites the group: the group's colors, from the rows or from `groupColors`, go to its color
|
||||
/// swatches in order.
|
||||
|
||||
@@ -160,6 +160,37 @@ fn save_and_load_round_trip_keeps_cmyk_spot_and_groups() {
|
||||
assert!(s.execute("swatch.library.save", &json!({"user": true})).is_err(), "no user folder in a headless session");
|
||||
}
|
||||
|
||||
/// A library color group that holds a gradient comes into the document whole, the gradient at its
|
||||
/// place in the group, as a `.ai` library's pattern swatch comes in its color group.
|
||||
#[test]
|
||||
fn add_brings_a_library_color_group_holding_a_gradient_whole() {
|
||||
let mut s = session();
|
||||
run(&mut s, "swatch.newGroup", json!({"name": "Brand", "colors": ["#123456", "#abcdef"]}));
|
||||
let r = run(&mut s, "swatch.library.save", json!({"names": ["Brand", "Sunset"], "name": "Mixed"}));
|
||||
// Move the Sunset gradient into the library's Brand group, as a hand-edited file can.
|
||||
let mut lib: Value = serde_json::from_str(r["data"].as_str().unwrap()).unwrap();
|
||||
let swatches = lib["swatches"].as_array_mut().unwrap();
|
||||
let at = swatches.iter().position(|w| w["name"] == "Sunset").unwrap();
|
||||
let sunset = swatches.remove(at);
|
||||
lib["groups"][0]["swatches"].as_array_mut().unwrap().insert(1, sunset);
|
||||
let r = run(&mut s, "swatch.library.load", json!({"data": lib.to_string(), "name": "mixed.vcswatches"}));
|
||||
let id = r["library"].as_str().unwrap().to_string();
|
||||
let (_, loaded) = cmd::swatchlib::library(&s, &id).unwrap();
|
||||
assert!(matches!(loaded.groups[0].swatches[1].paint, Paint::Gradient(_)), "the reader keeps the gradient in the group");
|
||||
run(&mut s, "swatch.delete", json!({"names": ["Brand", "Sunset"]}));
|
||||
for p in [json!({"library": id}), json!({"library": id, "names": ["Brand"]})] {
|
||||
let undo = undo_len(&s);
|
||||
let r = run(&mut s, "swatch.library.add", p.clone());
|
||||
assert!(r["added"].as_array().unwrap().iter().any(|n| n == "Sunset"), "{p}: {r}");
|
||||
let brand = doc(&s).swatch_groups.iter().find(|g| g.name == "Brand").map(|g| g.swatches.clone()).unwrap_or_default();
|
||||
let kinds: Vec<(&str, bool)> = brand.iter().map(|w| (w.name.as_str(), matches!(w.paint, Paint::Gradient(_)))).collect();
|
||||
assert_eq!(kinds.len(), 3, "{p}: {kinds:?}");
|
||||
assert_eq!(kinds[1], ("Sunset", true), "{p}: the gradient keeps its place in the group");
|
||||
assert_eq!(undo_len(&s), undo + 1, "{p}: one undo step");
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
}
|
||||
}
|
||||
|
||||
/// The swatch library commands, and the graphic style library save and load that share their file
|
||||
/// handling, refuse a parameter of the wrong form, such as `user: "true"` or `names: "Grays"`, with
|
||||
/// an error that names it; the document keeps its swatches and no undo step is recorded. A null
|
||||
|
||||
@@ -31,10 +31,17 @@
|
||||
//! Color too. The base color can't be removed. A removed color's row goes, unless it has current
|
||||
//! colors and art or a group is open: it then keeps them, with no new color, so that art keeps its
|
||||
//! colors and the group's swatch at that place goes. Under the tools, a button switches both wheels
|
||||
//! to hue and brightness (black at the center, full brightness at the edge, at the base color's
|
||||
//! to hue and brightness (black at the center, full brightness at the edge, at the selected color's
|
||||
//! saturation; a marker drag sets hue and brightness, Add Color adds the hue and brightness clicked
|
||||
//! at the base color's saturation, and the slider under the wheel is a Saturation slider) and back;
|
||||
//! switching changes no color, and the dialog opens on hue and saturation. With art, the Prominent Colors bar under the wheel shows the new
|
||||
//! at the selected color's saturation, and the slider under the wheel is a Saturation slider) and
|
||||
//! back; switching changes no color, and the dialog opens on hue and saturation. The base color is the one the harmony rules
|
||||
//! build from, drawn with the larger marker; it stays the base when another color is selected for
|
||||
//! the sliders. A right-click on a marker or a color bar offers Set As Base Color, Select Shade (a
|
||||
//! grid of the color's hue at 7 saturations by 7 brightnesses; a click moves the marker there as a
|
||||
//! drag would), Color Picker and Remove Color; a right-click elsewhere on the wheel offers Add New
|
||||
//! Color, which adds the hue and saturation there as the Add Color tool does, and a color added on
|
||||
//! the line from the center to a marker moves with that marker when the colors are unlinked. Set
|
||||
//! Current Color As Base Color, before the color chips, makes the selected color the base. With art, the Prominent Colors bar under the wheel shows the new
|
||||
//! colors, each part as wide as its row's share of the art's uses, the largest first; dragging the
|
||||
//! edge between two parts moves width between them, and when the drag ends the rows' current
|
||||
//! colors move toward those widths (`recolor.weigh`), and the art previews them. The New Color
|
||||
@@ -78,7 +85,10 @@
|
||||
//!
|
||||
//! Fields (`ui.dialog.set`): `rows` ([{from: [keys], to: key, exclude?, tint?: percent of a spot
|
||||
//! color, added?}]; a row with no current colors, `from: []`, recolors no art, and with `added: true`
|
||||
//! (a color the Add Color tool added) adds its new color to the color group; `to: null`, no new color), `colors` (null: Auto, or a count), `method`, `preserveWhite`, `preserveBlack`,
|
||||
//! (a color the Add Color tool added) adds its new color to the color group; `to: null`, no new color;
|
||||
//! `base: true`, the base color, else the first color the Edit tab shows; `tie: n` on a marker and
|
||||
//! `follows: n` on a color added on its line, which moves with it; the dialog sends `recolor.apply`
|
||||
//! the rows without these three), `colors` (null: Auto, or a count), `method`, `preserveWhite`, `preserveBlack`,
|
||||
//! `preserveGrays`, `limitTo` (library id, "document" for the document's swatches, "" for none),
|
||||
//! `group`, `groupName`, `tab` (`assign` or `edit`), `rule` (harmony id), `linked`, `preview`,
|
||||
//! `sliderMode` (`hsb`, `rgb`, `cmyk`, `lab` or `tint`; unset: the row color's own model, HSB for
|
||||
@@ -213,7 +223,8 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
None => String::new(),
|
||||
};
|
||||
// Without art the rows are the group's colours, as they are.
|
||||
let start: Vec<Value> = if art { vec![] } else { assign.iter().map(|k| json!({"from": [k], "to": k})).collect() };
|
||||
let mut start: Vec<Value> = if art { vec![] } else { assign.iter().map(|k| json!({"from": [k], "to": k})).collect() };
|
||||
number_slots(&mut start);
|
||||
// The Preserve checkboxes as they were last confirmed (#2960).
|
||||
let kept = |k: &str, default: bool| app.ui.recolor_preserve.get(k).and_then(Value::as_bool).unwrap_or(default);
|
||||
let fields = json!({
|
||||
@@ -276,6 +287,7 @@ fn sync(app: &mut VectorcraftApp, d: &mut Dialog) {
|
||||
for (row, to) in rows.iter_mut().zip(assign) {
|
||||
row["to"] = to;
|
||||
}
|
||||
number_slots(&mut rows);
|
||||
snap(app, d, &mut rows);
|
||||
d.fields.insert("rows".into(), Value::Array(rows));
|
||||
// Find dims the preserved colors with the rows that aren't selected.
|
||||
@@ -335,7 +347,9 @@ fn sync_weights(app: &mut VectorcraftApp, d: &mut Dialog) {
|
||||
match app.session.execute("recolor.weigh", &json!({"map": rows(d), "weights": w})) {
|
||||
Ok(r) => {
|
||||
if let Some(m) = r["map"].as_array() {
|
||||
d.fields.insert("rows".into(), Value::Array(m.clone()));
|
||||
let mut m = m.clone();
|
||||
keep_marks(&rows(d), &mut m);
|
||||
d.fields.insert("rows".into(), Value::Array(m));
|
||||
}
|
||||
}
|
||||
Err(e) => app.status(e.to_string()),
|
||||
@@ -451,14 +465,14 @@ fn group_colors<'a>(app: &VectorcraftApp, d: &Dialog, rs: impl Iterator<Item = &
|
||||
}
|
||||
|
||||
/// The New Color Group menu's request: save the new colors of the rows that aren't excluded and
|
||||
/// hold current colors or were added on the Edit tab (Save All Colors, in row order; a row without one gives its first current
|
||||
/// color) or of the Prominent Colors bar (Save Prominent Colors, in its order) as a new color
|
||||
/// group, a step of its own (`swatch.newGroup`).
|
||||
/// hold current colors or were added on the Edit tab (Save All Colors, in row order) or of the
|
||||
/// Prominent Colors bar (Save Prominent Colors, in its order) as a new color group, a step of its
|
||||
/// own (`swatch.newGroup`). Either way a row whose new color was removed gives none.
|
||||
fn save_group(app: &mut VectorcraftApp, d: &mut Dialog, which: &str) -> Result<(), String> {
|
||||
let rs = rows(d);
|
||||
let order: Vec<usize> = match which {
|
||||
"prominent" => prominent_parts(d, &rs).into_iter().map(|p| p.0).collect(),
|
||||
_ => (0..rs.len()).filter(|&i| in_group(&rs[i])).collect(),
|
||||
"prominent" => prominent_parts(d, &rs).into_iter().map(|p| p.0).filter(|&i| to_color(&rs[i]).is_some()).collect(),
|
||||
_ => (0..rs.len()).filter(|&i| in_group(&rs[i]) && to_color(&rs[i]).is_some()).collect(),
|
||||
};
|
||||
let colors = group_colors(app, d, order.iter().filter_map(|&i| rs.get(i)));
|
||||
if colors.is_empty() {
|
||||
@@ -541,6 +555,7 @@ fn select_group(app: &mut VectorcraftApp, d: &mut Dialog) -> Result<(), String>
|
||||
d.fields.remove(REDUCED);
|
||||
} else {
|
||||
let mut rs: Vec<Value> = assign.iter().map(|k| json!({"from": [k], "to": k})).collect();
|
||||
number_slots(&mut rs);
|
||||
snap(app, d, &mut rs);
|
||||
d.fields.insert("rows".into(), Value::Array(rs));
|
||||
d.fields.insert("__sel".into(), json!([]));
|
||||
@@ -601,7 +616,7 @@ fn group_action(app: &mut VectorcraftApp, d: &mut Dialog, action: &Value) -> Res
|
||||
// An excluded row leaves its swatch the color it has now, as OK's `"keep"` does: with
|
||||
// art, the swatch's color in `__assign`; without art, the swatch's color in the group,
|
||||
// which an earlier Save Changes may have changed.
|
||||
let filled: Vec<&Value> = rs.iter().filter(|r| !no_current(r)).collect();
|
||||
let filled = by_place(&rs);
|
||||
let rest: Vec<Value> =
|
||||
p["groupColors"].as_array().map(|a| a.iter().skip(filled.len()).map(|k| json!({"from": [k], "to": k})).collect()).unwrap_or_default();
|
||||
let assign: Vec<Value> =
|
||||
@@ -1169,7 +1184,7 @@ fn apply_params(d: &Dialog) -> Value {
|
||||
.chain(added)
|
||||
.collect()
|
||||
} else {
|
||||
let filled: Vec<&Value> = rs.iter().filter(|r| !no_current(r)).collect();
|
||||
let filled = by_place(&rs);
|
||||
let rest = assign.get(filled.len()..).unwrap_or_default();
|
||||
let took = filled.iter().map(|r| if excluded(r) { &keep } else { &r["to"] });
|
||||
took.chain(rest).chain(added).collect()
|
||||
@@ -1177,8 +1192,10 @@ fn apply_params(d: &Dialog) -> Value {
|
||||
};
|
||||
Some(json!({"group": g, "groupColors": colors, "rename": rename}))
|
||||
});
|
||||
// A row edited with the sliders carries `model: "new"`: its art takes the mode they showed.
|
||||
let mut p = json!({"map": rs, "method": d.str("method"), "limitTo": d.str("limitTo")});
|
||||
// A row edited with the sliders carries `model: "new"`: its art takes the mode they showed. The
|
||||
// Edit tab's own marks (the base color, colors tied to a marker) stay in the dialog.
|
||||
let map: Vec<Value> = rs.iter().map(without_marks).collect();
|
||||
let mut p = json!({"map": map, "method": d.str("method"), "limitTo": d.str("limitTo")});
|
||||
// The Global Adjust amounts, kept while the sliders show another mode; at 0% they are left out.
|
||||
let values = adjust_values(d);
|
||||
if values.iter().any(|v| *v != 0.0) {
|
||||
@@ -1406,7 +1423,7 @@ fn main(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog) -> Option<(usize,
|
||||
}
|
||||
let mut rs = rows(d);
|
||||
let top = ui.cursor().top();
|
||||
let (changed, pick) = if d.str("tab") == "edit" { (edit_tab(app, ui, d, &mut rs), None) } else { assign_tab(app, ui, d, &mut rs) };
|
||||
let (changed, pick) = if d.str("tab") == "edit" { edit_tab(app, ui, d, &mut rs) } else { assign_tab(app, ui, d, &mut rs) };
|
||||
if d.str("tab") != "edit" {
|
||||
ui.add_space((TAB_H - (ui.cursor().top() - top)).max(0.0));
|
||||
}
|
||||
@@ -1663,7 +1680,7 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String> {
|
||||
r?;
|
||||
}
|
||||
if d.bool("__newGroup") {
|
||||
let colors = group_colors(app, &d, rows(&d).iter().filter(|r| in_group(r)));
|
||||
let colors = group_colors(app, &d, rows(&d).iter().filter(|r| in_group(r) && to_color(r).is_some()));
|
||||
let r = form::commit_preview(app, "swatch.newGroup", json!({"name": d.str("groupName"), "colors": colors, "keepModel": true}))?;
|
||||
app.ui.recolor_history = History::default();
|
||||
return Ok(r);
|
||||
@@ -1897,7 +1914,9 @@ fn assign_tab(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog, rows: &mut
|
||||
let p = json!({"map": rows, "order": !sb, "saturationBrightness": sb, "seed": seed});
|
||||
match app.session.execute("recolor.randomize", &p) {
|
||||
Ok(r) => {
|
||||
*rows = r["map"].as_array().cloned().unwrap_or_default();
|
||||
let mut shuffled = r["map"].as_array().cloned().unwrap_or_default();
|
||||
keep_marks(rows, &mut shuffled);
|
||||
*rows = shuffled;
|
||||
if !sb {
|
||||
d.fields.insert(SHUFFLED.into(), json!(true));
|
||||
}
|
||||
@@ -2264,6 +2283,21 @@ fn merge(rows: &mut Vec<Value>, sel: &[usize]) {
|
||||
for &i in rest.iter().rev() {
|
||||
let row = rows.remove(i);
|
||||
moved.splice(0..0, row["from"].as_array().cloned().unwrap_or_default());
|
||||
// The base color merged into another row makes that row the base, and the colors that
|
||||
// followed the merged row's marker follow that row's.
|
||||
if row[BASE] == json!(true) {
|
||||
rows[first][BASE] = json!(true);
|
||||
}
|
||||
if let Some(t) = row[TIE].as_u64() {
|
||||
match rows[first][TIE].as_u64() {
|
||||
Some(to) => {
|
||||
for r in rows.iter_mut().filter(|r| r[FOLLOWS].as_u64() == Some(t)) {
|
||||
r[FOLLOWS] = json!(to);
|
||||
}
|
||||
}
|
||||
None => rows[first][TIE] = json!(t),
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(dst) = rows[first]["from"].as_array_mut() {
|
||||
dst.extend(moved);
|
||||
@@ -2275,7 +2309,17 @@ fn separate(rows: &mut Vec<Value>, sel: &[usize]) {
|
||||
let mut out = vec![];
|
||||
for (i, row) in rows.drain(..).enumerate() {
|
||||
match row["from"].as_array() {
|
||||
Some(a) if sel.contains(&i) && a.len() > 1 => out.extend(a.iter().map(|k| json!({"from": [k], "to": k}))),
|
||||
Some(a) if sel.contains(&i) && a.len() > 1 => {
|
||||
let at = out.len();
|
||||
out.extend(a.iter().map(|k| json!({"from": [k], "to": k})));
|
||||
// A separated row's marks (the base color, a marker's tie, a color it follows, its place) go
|
||||
// to the row of its first color.
|
||||
for k in [BASE, TIE, FOLLOWS, SLOT] {
|
||||
if let Some(v) = row.get(k) {
|
||||
out[at][k] = v.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => out.push(row),
|
||||
}
|
||||
}
|
||||
@@ -2306,13 +2350,29 @@ fn edit_slider_row(d: &Dialog, rows: &[Value], active: &[usize], base: Option<us
|
||||
}
|
||||
|
||||
/// Set row `i`'s new colour to hue/saturation/brightness `hsb` ([`move_on_wheel`]: with `linked`
|
||||
/// the other rows keep their relation to it). Excluded rows stay.
|
||||
/// the other rows keep their relation to it; unlinked, the colors added on its marker's line, which
|
||||
/// follow its `tie`, and those that follow theirs, keep theirs). Excluded rows stay.
|
||||
fn move_color(rows: &mut [Value], i: usize, hsb: [f32; 3], linked: bool) {
|
||||
let active = active_rows(rows);
|
||||
let all = active_rows(rows);
|
||||
let active: Vec<usize> = if linked {
|
||||
all
|
||||
} else {
|
||||
// Row `i` and the rows that follow it, directly or through another follower.
|
||||
let mut moving = vec![i];
|
||||
let mut n = 0;
|
||||
while let Some(&j) = moving.get(n) {
|
||||
if let Some(t) = rows.get(j).and_then(|r| r[TIE].as_u64()) {
|
||||
let next: Vec<usize> = all.iter().copied().filter(|&k| rows[k][FOLLOWS].as_u64() == Some(t) && !moving.contains(&k)).collect();
|
||||
moving.extend(next);
|
||||
}
|
||||
n += 1;
|
||||
}
|
||||
all.into_iter().filter(|j| moving.contains(j)).collect()
|
||||
};
|
||||
let Some(k) = active.iter().position(|&j| j == i) else { return };
|
||||
let before: Vec<Color> = active.iter().filter_map(|&j| to_color(&rows[j])).collect();
|
||||
let mut colors = before.clone();
|
||||
move_on_wheel(&mut colors, k, hsb, linked);
|
||||
move_on_wheel(&mut colors, k, hsb, true);
|
||||
for ((&j, c), old) in active.iter().zip(&colors).zip(&before) {
|
||||
if key(c) != key(old) {
|
||||
set_to(&mut rows[j], c);
|
||||
@@ -2337,7 +2397,7 @@ fn wheel_axes(d: &Dialog) -> widgets::WheelAxes {
|
||||
|
||||
/// The new color the Add Color tool gives a click at hue `h` (degrees) and `t`, the saturation (or
|
||||
/// with [`widgets::WheelAxes::HueBrightness`] the brightness) clicked: with the other component of
|
||||
/// `base` (the base color, whose other component the wheel shows; full without one), the segmented
|
||||
/// `base` (the selected color, whose other component the wheel shows; full without one), the segmented
|
||||
/// wheel's patch color with `segmented`, in `base`'s model.
|
||||
fn added_color(base: Option<Color>, h: f32, t: f32, segmented: bool, axes: widgets::WheelAxes) -> Color {
|
||||
let o = base.map_or(1.0, |b| b.to_hsb()[axes.other()]);
|
||||
@@ -2391,16 +2451,244 @@ fn removed(d: &mut Dialog, base: usize) {
|
||||
d.fields.remove(COMPS);
|
||||
}
|
||||
|
||||
/// The Edit tab. Returns true when the rows changed.
|
||||
fn edit_tab(app: &VectorcraftApp, ui: &mut Ui, d: &mut Dialog, rows: &mut Vec<Value>) -> bool {
|
||||
/// A row's mark as the base color, the color the harmony rules build from (`true`).
|
||||
const BASE: &str = "base";
|
||||
/// A row's number on a marker that the colors added on its line follow.
|
||||
const TIE: &str = "tie";
|
||||
/// A row's mark as a color added on a marker's line: the marker's `tie`, which it moves with.
|
||||
const FOLLOWS: &str = "follows";
|
||||
/// A row's place when the rows were made (the group swatch it took), which it keeps when it moves.
|
||||
const SLOT: &str = "slot";
|
||||
|
||||
/// Give each row its place in `rows` as its [`SLOT`].
|
||||
fn number_slots(rows: &mut [Value]) {
|
||||
for (i, r) in rows.iter_mut().enumerate() {
|
||||
r[SLOT] = json!(i);
|
||||
}
|
||||
}
|
||||
|
||||
/// The rows with current colors in the order of their group swatches: each row takes the swatch at
|
||||
/// its [`SLOT`], so a row moved among the color bars keeps its swatch; rows that don't all carry a
|
||||
/// place go in row order.
|
||||
fn by_place(rs: &[Value]) -> Vec<&Value> {
|
||||
let mut filled: Vec<&Value> = rs.iter().filter(|r| !no_current(r)).collect();
|
||||
if filled.iter().all(|r| r[SLOT].is_u64()) {
|
||||
filled.sort_by_key(|r| r[SLOT].as_u64());
|
||||
}
|
||||
filled
|
||||
}
|
||||
|
||||
/// The target of the wheel's right-click menu: `{marker, line, hs}` (row indexes and the hue and
|
||||
/// saturation clicked).
|
||||
const MENU_AT: &str = "__wheelMenu";
|
||||
/// Select Shade's grid: saturations across, from 0% to 100%, and brightnesses down, from 100%.
|
||||
const SHADE_COLS: usize = 7;
|
||||
const SHADE_ROWS: usize = 7;
|
||||
const SHADE_CELL: f32 = 16.0;
|
||||
|
||||
/// The base color's row: the row of `active` (the rows the Edit tab shows) marked `base`, else
|
||||
/// the first of them.
|
||||
fn base_row(rows: &[Value], active: &[usize]) -> Option<usize> {
|
||||
active.iter().copied().find(|&i| rows[i][BASE] == json!(true)).or(active.first().copied())
|
||||
}
|
||||
|
||||
/// Whether Set As Base Color would change anything for row `i`: it is shown on the Edit tab, and it
|
||||
/// isn't the base already, or it is the base only because the marked row is hidden (excluded, or
|
||||
/// with no new color), whose mark would make it the base again once shown.
|
||||
fn can_set_base(rows: &[Value], i: usize) -> bool {
|
||||
let active = active_rows(rows);
|
||||
active.contains(&i) && (base_row(rows, &active) != Some(i) || rows.iter().enumerate().any(|(k, r)| k != i && r[BASE] == json!(true)))
|
||||
}
|
||||
|
||||
/// Make row `i` the base color (Set As Base Color). Returns false when that changes nothing
|
||||
/// ([`can_set_base`]).
|
||||
fn set_base(rows: &mut [Value], i: usize) -> bool {
|
||||
if !can_set_base(rows, i) {
|
||||
return false;
|
||||
}
|
||||
for r in rows.iter_mut() {
|
||||
if let Some(o) = r.as_object_mut() {
|
||||
o.remove(BASE);
|
||||
}
|
||||
}
|
||||
rows[i][BASE] = json!(true);
|
||||
true
|
||||
}
|
||||
|
||||
/// Make row `follower` move with the marker of row `leader`: the leader keeps its `tie` (a new
|
||||
/// number, past every `tie` and `follows`, when it has none, so that colors left from a removed
|
||||
/// marker follow no other) and the follower takes it as `follows`.
|
||||
fn tie_to(rows: &mut [Value], leader: usize, follower: usize) {
|
||||
if leader == follower || leader >= rows.len() || follower >= rows.len() {
|
||||
return;
|
||||
}
|
||||
let used = rows.iter().flat_map(|r| [r[TIE].as_u64(), r[FOLLOWS].as_u64()]).flatten().max();
|
||||
let t = rows[leader][TIE].as_u64().unwrap_or_else(|| used.map_or(1, |m| m.saturating_add(1)));
|
||||
rows[leader][TIE] = json!(t);
|
||||
rows[follower][FOLLOWS] = json!(t);
|
||||
}
|
||||
|
||||
/// Give each row of `after` the base, tie and follows marks of the row at its place in `before`,
|
||||
/// when the two have as many rows (the engine's `recolor.randomize` and `recolor.weigh` keep the
|
||||
/// rows in order and return them without the dialog's own marks).
|
||||
fn keep_marks(before: &[Value], after: &mut [Value]) {
|
||||
if before.len() != after.len() {
|
||||
return;
|
||||
}
|
||||
for (a, b) in after.iter_mut().zip(before) {
|
||||
for k in [BASE, TIE, FOLLOWS, SLOT] {
|
||||
if a.get(k).is_none()
|
||||
&& let Some(v) = b.get(k)
|
||||
{
|
||||
a[k] = v.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `row` without the dialog's base, tie, follows and place marks.
|
||||
fn without_marks(row: &Value) -> Value {
|
||||
let mut r = row.clone();
|
||||
if let Some(o) = r.as_object_mut() {
|
||||
for k in [BASE, TIE, FOLLOWS, SLOT] {
|
||||
o.remove(k);
|
||||
}
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
/// The saturation and brightness of Select Shade's cell in column `col` and row `row`.
|
||||
fn shade_at(col: usize, row: usize) -> [f32; 2] {
|
||||
[col as f32 / (SHADE_COLS - 1) as f32, 1.0 - row as f32 / SHADE_ROWS as f32]
|
||||
}
|
||||
|
||||
/// Select Shade's grid of `c`'s hue, the cell nearest `c` framed. Returns the saturation and
|
||||
/// brightness of the cell clicked.
|
||||
fn shade_grid(ui: &mut Ui, c: &Color) -> Option<[f32; 2]> {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let [h, s0, v0] = c.to_hsb();
|
||||
let near = ((s0 * (SHADE_COLS - 1) as f32).round() as usize, (((1.0 - v0) * SHADE_ROWS as f32).round() as usize).min(SHADE_ROWS - 1));
|
||||
let mut out = None;
|
||||
egui::Grid::new("recolor-shades").spacing([2.0, 2.0]).show(ui, |ui| {
|
||||
for row in 0..SHADE_ROWS {
|
||||
for col in 0..SHADE_COLS {
|
||||
let [s, v] = shade_at(col, row);
|
||||
let (r, resp) = ui.allocate_exact_size(vec2(SHADE_CELL, SHADE_CELL), Sense::click());
|
||||
ui.painter().rect_filled(r, 1.0, c32(&Color::from_hsb(h, s, v)));
|
||||
if (col, row) == near {
|
||||
ui.painter().rect_stroke(r, 1.0, egui::Stroke::new(1.5, t.accent), egui::StrokeKind::Outside);
|
||||
}
|
||||
let name = format!("{} {}%, {} {}%", tl!("Saturation"), (s * 100.0).round(), tl!("Brightness"), (v * 100.0).round());
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, &name));
|
||||
if resp.clicked() {
|
||||
out = Some([s, v]);
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
out
|
||||
}
|
||||
|
||||
/// What a marker's or a color bar's right-click menu, or the wheel's, chose.
|
||||
enum MenuChoice {
|
||||
/// Set As Base Color for the row.
|
||||
Base(usize),
|
||||
/// Select Shade: the row's color at this saturation and brightness.
|
||||
Shade(usize, [f32; 2]),
|
||||
/// Color Picker for the row.
|
||||
Picker(usize),
|
||||
/// Remove Color for the row.
|
||||
Remove(usize),
|
||||
/// Add New Color at this hue and saturation, moving with the marker of the row on whose line
|
||||
/// it is.
|
||||
Add([f32; 2], Option<usize>),
|
||||
}
|
||||
|
||||
/// A marker's or a color bar's right-click menu for row `i`: Set As Base Color and Remove Color
|
||||
/// (neither for the base color `base`), Select Shade and Color Picker.
|
||||
fn color_menu(ui: &mut Ui, rows: &[Value], i: usize, base: Option<usize>) -> Option<MenuChoice> {
|
||||
let mut choice = None;
|
||||
if widgets::menu_item_name(ui, tl!("Set As Base Color"), can_set_base(rows, i), false) {
|
||||
choice = Some(MenuChoice::Base(i));
|
||||
}
|
||||
if let Some(c) = rows.get(i).and_then(to_color) {
|
||||
// Indented like the items beside it (their check column).
|
||||
ui.menu_button(format!(" {}", tl!("Select Shade")), |ui| {
|
||||
if let Some(sv) = shade_grid(ui, &c) {
|
||||
choice = Some(MenuChoice::Shade(i, sv));
|
||||
}
|
||||
});
|
||||
}
|
||||
if widgets::menu_item_name(ui, tl!("Color Picker"), true, false) {
|
||||
choice = Some(MenuChoice::Picker(i));
|
||||
}
|
||||
if widgets::menu_item_name(ui, tl!("Remove Color"), Some(i) != base, false) {
|
||||
choice = Some(MenuChoice::Remove(i));
|
||||
}
|
||||
choice
|
||||
}
|
||||
|
||||
/// Carry out a right-click menu's `choice` on the rows (`base`: the base color's row; `shown`: the
|
||||
/// color whose brightness the wheel shows; `segmented`: the menu was on the segmented wheel).
|
||||
/// Returns whether the rows changed and the row whose new color the Color Picker is to edit.
|
||||
fn choose(
|
||||
d: &mut Dialog,
|
||||
rows: &mut Vec<Value>,
|
||||
choice: MenuChoice,
|
||||
base: Option<usize>,
|
||||
shown: Option<Color>,
|
||||
segmented: bool,
|
||||
axes: widgets::WheelAxes,
|
||||
) -> (bool, Option<usize>) {
|
||||
match choice {
|
||||
MenuChoice::Base(i) => (set_base(rows, i), None),
|
||||
MenuChoice::Shade(i, [s, v]) => {
|
||||
let Some(h) = rows.get(i).and_then(to_color).map(|c| c.to_hsb()[0]) else { return (false, None) };
|
||||
let before = rows.clone();
|
||||
move_color(rows, i, [h, s, v], d.bool("linked"));
|
||||
d.fields.insert("__sel".into(), json!([i]));
|
||||
d.fields.remove(COMPS);
|
||||
(*rows != before, None)
|
||||
}
|
||||
MenuChoice::Picker(i) => {
|
||||
d.fields.insert("__sel".into(), json!([i]));
|
||||
(false, Some(i))
|
||||
}
|
||||
MenuChoice::Remove(i) => match remove_color(rows, i, base, keeps_rows(d)) {
|
||||
Some(b) => {
|
||||
removed(d, b);
|
||||
(true, None)
|
||||
}
|
||||
None => (false, None),
|
||||
},
|
||||
MenuChoice::Add([h, s], line) => {
|
||||
let i = add_color(rows, &added_color(shown, h, s, segmented, axes));
|
||||
if let Some(l) = line {
|
||||
tie_to(rows, l, i);
|
||||
}
|
||||
d.fields.insert("__sel".into(), json!([i]));
|
||||
d.fields.remove(COMPS);
|
||||
(true, None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The Edit tab. Returns whether the rows changed and the row whose new color a right-click menu's
|
||||
/// Color Picker is to edit.
|
||||
fn edit_tab(app: &VectorcraftApp, ui: &mut Ui, d: &mut Dialog, rows: &mut Vec<Value>) -> (bool, Option<(usize, bool)>) {
|
||||
let top = ui.cursor().top();
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let mut changed = false;
|
||||
let mut pick = None;
|
||||
let linked = d.bool("linked");
|
||||
let active = active_rows(rows);
|
||||
let base = selection(d).into_iter().find(|i| active.contains(i)).or(active.first().copied());
|
||||
let slider_row = edit_slider_row(d, rows, &active, base);
|
||||
let target = SliderTarget::at(app, d, rows, slider_row);
|
||||
// The harmony rules build from the base color; the sliders and the Brightness slider edit the
|
||||
// selected color (the base color when the tab does not show the first selected row).
|
||||
let base = base_row(rows, &active);
|
||||
let sel = edit_slider_row(d, rows, &active, base);
|
||||
let target = SliderTarget::at(app, d, rows, sel);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(egui::RichText::new(tl!("Harmony Rules:")).color(t.text_dim));
|
||||
let rule = Harmony::parse(&d.str("rule")).unwrap_or(Harmony::Complementary);
|
||||
@@ -2421,9 +2709,9 @@ fn edit_tab(app: &VectorcraftApp, ui: &mut Ui, d: &mut Dialog, rows: &mut Vec<Va
|
||||
}
|
||||
// New Color Group: save the wheel's colors or the Prominent Colors as a color group.
|
||||
let button = widgets::icon_button(ui, "dc-folder", tl!("New Color Group"), false, 24.0);
|
||||
let prominent = d.bool("__art") && !prominent_parts(d, rows).is_empty();
|
||||
let prominent = d.bool("__art") && prominent_parts(d, rows).iter().any(|p| rows.get(p.0).and_then(to_color).is_some());
|
||||
let saved = egui::Popup::menu(&button).show(|ui| {
|
||||
if widgets::menu_item_name(ui, tl!("Save All Colors"), rows.iter().any(in_group), false) {
|
||||
if widgets::menu_item_name(ui, tl!("Save All Colors"), rows.iter().any(|r| in_group(r) && to_color(r).is_some()), false) {
|
||||
return Some("all");
|
||||
}
|
||||
widgets::menu_item_name(ui, tl!("Save Prominent Colors"), prominent, false).then_some("prominent")
|
||||
@@ -2445,6 +2733,9 @@ fn edit_tab(app: &VectorcraftApp, ui: &mut Ui, d: &mut Dialog, rows: &mut Vec<Va
|
||||
}
|
||||
let colors: Vec<Color> = active.iter().filter_map(|&i| to_color(&rows[i])).collect();
|
||||
let marked = base.and_then(|b| active.iter().position(|&i| i == b));
|
||||
let selected = sel.and_then(|s| active.iter().position(|&i| i == s));
|
||||
let shown = sel.and_then(|s| to_color(&rows[s]));
|
||||
let mut choice = None;
|
||||
let display = d.str("display");
|
||||
let tool = d.str(WHEEL_TOOL);
|
||||
let axes = wheel_axes(d);
|
||||
@@ -2482,15 +2773,56 @@ fn edit_tab(app: &VectorcraftApp, ui: &mut Ui, d: &mut Dialog, rows: &mut Vec<Va
|
||||
}
|
||||
});
|
||||
ui.vertical(|ui| match display.as_str() {
|
||||
"bars" => changed |= color_bars(ui, d, rows, &active, base),
|
||||
_ => w = widgets::wheel_of(ui, "recolor-wheel", WHEEL, &colors, marked, display == "segmented", axes),
|
||||
"bars" => {
|
||||
let (moved, chosen) = color_bars(ui, d, rows, &active, base);
|
||||
changed |= moved;
|
||||
choice = chosen;
|
||||
}
|
||||
_ => w = widgets::recolor_wheel(ui, "recolor-wheel", WHEEL, &colors, marked, selected, display == "segmented", axes),
|
||||
});
|
||||
});
|
||||
// A right-click on the wheel: a marker's menu, or Add New Color elsewhere. Its target is kept
|
||||
// while the menu stays open.
|
||||
if let Some((hit, line, hs)) = w.secondary {
|
||||
d.fields.insert(MENU_AT.into(), json!({"marker": hit.map(|k| active[k]), "line": line.map(|k| active[k]), "hs": hs}));
|
||||
} else if w.response.as_ref().is_some_and(egui::Response::secondary_clicked) {
|
||||
// A right-click off the wheel (in a corner of its square) targets nothing: its menu's Add
|
||||
// New Color is off, and no earlier marker is changed.
|
||||
d.fields.remove(MENU_AT);
|
||||
}
|
||||
if let Some(resp) = &w.response {
|
||||
let at = d.fields.get(MENU_AT).cloned().unwrap_or_default();
|
||||
let row = |k: &str| at[k].as_u64().map(|i| i as usize).filter(|i| active.contains(i));
|
||||
let hs = at["hs"].as_array().and_then(|a| Some([a.first()?.as_f64()? as f32, a.get(1)?.as_f64()? as f32]));
|
||||
resp.context_menu(|ui| match row("marker") {
|
||||
Some(i) => choice = color_menu(ui, rows, i, base),
|
||||
None => {
|
||||
if widgets::menu_item_name(ui, tl!("Add New Color"), hs.is_some(), false)
|
||||
&& let Some(hs) = hs
|
||||
{
|
||||
choice = Some(MenuChoice::Add(hs, row("line")));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// A menu's choice changes the rows the wheel's indexes were for, so the wheel's own clicks and
|
||||
// drags of this frame are left alone.
|
||||
let chosen = choice.is_some();
|
||||
if let Some(c) = choice {
|
||||
let (did, picked) = choose(d, rows, c, base, shown, display == "segmented", axes);
|
||||
changed |= did;
|
||||
pick = picked.map(|i| (i, false));
|
||||
}
|
||||
if chosen {
|
||||
w.pressed = None;
|
||||
w.moved = None;
|
||||
w.clicked = None;
|
||||
}
|
||||
// A click with a wheel tool adds a color there, or removes the color of the marker clicked.
|
||||
let clicked = w.clicked.filter(|_| on_wheel && matches!(tool.as_str(), "add" | "remove"));
|
||||
if let Some((hit, [h, out])) = clicked {
|
||||
if tool == "add" {
|
||||
let c = added_color(base.and_then(|b| to_color(&rows[b])), h, out, display == "segmented", axes);
|
||||
let c = added_color(shown, h, out, display == "segmented", axes);
|
||||
let i = add_color(rows, &c);
|
||||
d.fields.insert("__sel".into(), json!([i]));
|
||||
d.fields.remove(COMPS);
|
||||
@@ -2534,43 +2866,57 @@ fn edit_tab(app: &VectorcraftApp, ui: &mut Ui, d: &mut Dialog, rows: &mut Vec<Va
|
||||
}
|
||||
// A color added or removed above changed the rows, so the sliders and chips read them afresh.
|
||||
let active = active_rows(rows);
|
||||
let base = selection(d).into_iter().find(|i| active.contains(i)).or(active.first().copied());
|
||||
let base = base_row(rows, &active);
|
||||
let sel = edit_slider_row(d, rows, &active, base);
|
||||
if d.str("sliderMode") == GLOBAL {
|
||||
let sample = base.and_then(|b| to_color(&rows[b])).unwrap_or(Color::rgb(0.8, 0.45, 0.25));
|
||||
let sample = sel.and_then(|b| to_color(&rows[b])).unwrap_or(Color::rgb(0.8, 0.45, 0.25));
|
||||
global_sliders(ui, d, sample);
|
||||
} else {
|
||||
changed |= sliders(app, ui, d, rows, slider_row);
|
||||
changed |= sliders(app, ui, d, rows, sel);
|
||||
}
|
||||
// The new colours: click one to make it the base colour.
|
||||
// The new colours: click one to select it; Set Current Color As Base Color, before them, makes
|
||||
// the selected one the base color, which carries a double ring as its marker does.
|
||||
let min_height = (TAB_H - (ui.cursor().top() - top)).max(0.0);
|
||||
let mut make_base = None;
|
||||
super::modal::scrolled_rows(ui, "recolor-edit-colors", |ui| {
|
||||
// Keep the usual tab height when it fits; the empty space scrolls with the chips.
|
||||
ui.set_min_height(min_height);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
let can = sel.is_some_and(|s| can_set_base(rows, s));
|
||||
if widgets::icon_button_enabled(ui, "circle-dot", tl!("Set Current Color As Base Color"), false, can, 20.0).clicked() {
|
||||
make_base = sel;
|
||||
}
|
||||
for &i in &active {
|
||||
let (r, resp) = ui.allocate_exact_size(vec2(28.0, 20.0), Sense::click());
|
||||
chip(ui, r, to_color(&rows[i]).unwrap_or_default(), false);
|
||||
if Some(i) == base {
|
||||
if Some(i) == sel {
|
||||
ui.painter().rect_stroke(r.expand(1.5), 2.0, egui::Stroke::new(1.5, t.accent), egui::StrokeKind::Outside);
|
||||
}
|
||||
if Some(i) == base {
|
||||
ui.painter().circle_stroke(r.center(), 4.0, egui::Stroke::new(1.5, egui::Color32::WHITE));
|
||||
ui.painter().circle_stroke(r.center(), 5.5, egui::Stroke::new(1.0, egui::Color32::BLACK));
|
||||
}
|
||||
if resp.on_hover_text(rows[i]["to"].as_str().unwrap_or_default()).clicked() {
|
||||
d.fields.insert("__sel".into(), json!([i]));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
changed
|
||||
if let Some(i) = make_base {
|
||||
changed |= set_base(rows, i);
|
||||
}
|
||||
(changed, pick)
|
||||
}
|
||||
|
||||
/// The Edit tab's color bars: a solid bar per row of `active` with its new color, in row order, the
|
||||
/// base row's framed, scrolling past the wheel's height. A click on a bar selects its row (the
|
||||
/// sliders under it edit that row's new color); a drag moves the bar's row to where the line under
|
||||
/// the pointer shows, keeping every new color. A bar's right-click menu has Remove Color (not for the
|
||||
/// base row's). Returns true when the rows moved or a color was removed.
|
||||
fn color_bars(ui: &mut Ui, d: &mut Dialog, rows: &mut Vec<Value>, active: &[usize], base: Option<usize>) -> bool {
|
||||
/// the pointer shows, keeping every new color. A bar's right-click menu is a marker's
|
||||
/// ([`color_menu`]). Returns true when the rows moved, and the menu's choice.
|
||||
fn color_bars(ui: &mut Ui, d: &mut Dialog, rows: &mut [Value], active: &[usize], base: Option<usize>) -> (bool, Option<MenuChoice>) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let mut rects: Vec<Rect> = Vec::with_capacity(active.len());
|
||||
let (mut dragging, mut released, mut dropped, mut remove) = (None, None, None, None);
|
||||
let (mut dragging, mut released, mut dropped, mut choice) = (None, None, None, None);
|
||||
// The area is given its full height first: in the row beside the display buttons a scroll area
|
||||
// alone is only as tall as the room the row has.
|
||||
let area = vec2(ui.available_width(), BARS_H);
|
||||
@@ -2603,8 +2949,8 @@ fn color_bars(ui: &mut Ui, d: &mut Dialog, rows: &mut Vec<Value>, active: &[usiz
|
||||
rects.push(r);
|
||||
let resp = resp.on_hover_text(rows[i]["to"].as_str().unwrap_or_default());
|
||||
resp.context_menu(|ui| {
|
||||
if widgets::menu_item_name(ui, tl!("Remove Color"), Some(i) != base, false) {
|
||||
remove = Some(i);
|
||||
if let Some(c) = color_menu(ui, rows, i, base) {
|
||||
choice = Some(c);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -2621,15 +2967,14 @@ fn color_bars(ui: &mut Ui, d: &mut Dialog, rows: &mut Vec<Value>, active: &[usiz
|
||||
dropped = released.zip(at);
|
||||
});
|
||||
});
|
||||
if let Some(b) = remove.and_then(|i| remove_color(rows, i, base, keeps_rows(d))) {
|
||||
removed(d, b);
|
||||
return true;
|
||||
if choice.is_some() {
|
||||
return (false, choice);
|
||||
}
|
||||
let Some(moved) = dropped.and_then(|(n, to)| move_bar(rows, active, n, to)) else { return false };
|
||||
let Some(moved) = dropped.and_then(|(n, to)| move_bar(rows, active, n, to)) else { return (false, None) };
|
||||
d.fields.insert("__sel".into(), json!([moved]));
|
||||
// The slider values held are those of a row index that may now hold another row.
|
||||
d.fields.remove(COMPS);
|
||||
true
|
||||
(true, None)
|
||||
}
|
||||
|
||||
/// Move the row of the `from`th active row (of `active`, ascending row indexes) to before the
|
||||
@@ -2790,6 +3135,67 @@ mod tests {
|
||||
assert_eq!(apply_params(&d)["groupColors"], json!(["rgb 1 1 1", null, "rgb 3 3 3"]));
|
||||
}
|
||||
|
||||
/// An excluded row with current colors keeps the group's swatch at its place as it is, even
|
||||
/// after its new color was edited or removed, and with Global Adjust on.
|
||||
#[test]
|
||||
fn an_excluded_row_keeps_its_group_swatch() {
|
||||
let mut d = Dialog::new(KIND, json!({"group": "G", "groupName": "G", "__art": true, "__assign": ["rgb 1 1 1", "rgb 2 2 2", "rgb 3 3 3"]}));
|
||||
let rs = json!([
|
||||
{"from": ["rgb 255 0 0"], "to": "rgb 7 7 7", "exclude": true},
|
||||
{"from": ["rgb 0 0 255"], "to": null, "exclude": true},
|
||||
{"from": ["rgb 0 255 0"], "to": "rgb 8 8 8"},
|
||||
]);
|
||||
d.fields.insert("rows".into(), rs);
|
||||
assert_eq!(apply_params(&d)["groupColors"], json!(["keep", "keep", "rgb 8 8 8"]));
|
||||
// Without art the rows are the group's colors.
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
app.run("swatch.newGroup", json!({"name": "G", "colors": ["#2878f0", "#ff0000"]})).unwrap();
|
||||
app.run("ui.recolorDialog", json!({"group": "G"})).unwrap();
|
||||
let mut d = app.ui.dialog.clone().unwrap();
|
||||
let mut rs = super::rows(&d);
|
||||
rs[0]["to"] = json!("#00ff00");
|
||||
rs[0]["exclude"] = json!(true);
|
||||
rs[1]["to"] = json!("#0000ff");
|
||||
d.fields.insert("rows".into(), json!(rs));
|
||||
d.fields.insert("globalAdjust".into(), json!({"brightness": -50}));
|
||||
confirm(&mut app, &d).unwrap();
|
||||
let g = app.session.doc().unwrap().doc.swatch_groups.iter().find(|g| g.name == "G").unwrap();
|
||||
let hex: Vec<String> = g.swatches.iter().map(|w| w.paint.color().unwrap().to_hex()).collect();
|
||||
assert_eq!(hex[0], "#2878f0", "{hex:?}");
|
||||
assert_ne!(hex[1], "#ff0000", "{hex:?}");
|
||||
}
|
||||
|
||||
/// A row moved among the color bars keeps the group swatch it took when the rows were made, so
|
||||
/// an excluded row's swatch stays as it is and the other swatches keep their places.
|
||||
#[test]
|
||||
fn a_moved_row_keeps_its_group_swatch() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
app.run("swatch.newGroup", json!({"name": "G", "colors": ["#ff0000", "#0000ff", "#00ff00"]})).unwrap();
|
||||
app.run("ui.recolorDialog", json!({"group": "G"})).unwrap();
|
||||
let mut d = app.ui.dialog.clone().unwrap();
|
||||
let mut rs = super::rows(&d);
|
||||
rs[1]["exclude"] = json!(true);
|
||||
rs[2]["to"] = json!("#ffff00");
|
||||
let active = active_rows(&rs);
|
||||
assert_eq!(active, [0, 2]);
|
||||
// Drag the last bar (green, now yellow) above the first (red).
|
||||
assert_eq!(move_bar(&mut rs, &active, 1, 0), Some(0));
|
||||
d.fields.insert("rows".into(), json!(rs));
|
||||
let colors = &apply_params(&d)["groupColors"];
|
||||
assert_eq!(colors[1], json!("keep"), "{colors}");
|
||||
confirm(&mut app, &d).unwrap();
|
||||
let g = app.session.doc().unwrap().doc.swatch_groups.iter().find(|g| g.name == "G").unwrap();
|
||||
let hex: Vec<String> = g.swatches.iter().map(|w| w.paint.color().unwrap().to_hex()).collect();
|
||||
assert_eq!(hex, ["#ff0000", "#0000ff", "#ffff00"]);
|
||||
// Rows reduced from art carry their place too, and `recolor.apply` gets none.
|
||||
let mut rows = vec![json!({"from": ["rgb 255 0 0"], "to": "rgb 1 1 1"}), json!({"from": ["rgb 0 0 255"], "to": "rgb 2 2 2"})];
|
||||
number_slots(&mut rows);
|
||||
assert_eq!(rows.iter().map(|r| r[SLOT].clone()).collect::<Vec<_>>(), [json!(0), json!(1)]);
|
||||
assert!(without_marks(&rows[0]).get(SLOT).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_and_separate_rows() {
|
||||
let mut r = rows();
|
||||
@@ -2927,6 +3333,117 @@ mod tests {
|
||||
assert_eq!([&r[0]["to"], &r[1]["to"], &r[2]["to"]], ["rgb 255 0 0", "rgb 0 255 0", "rgb 0 0 255"]);
|
||||
}
|
||||
|
||||
/// The base color is the row marked `base`, else the first row shown; Set As Base Color moves the
|
||||
/// mark, and does nothing for the base row already or a row the Edit tab doesn't show.
|
||||
#[test]
|
||||
fn set_base_moves_the_base_mark() {
|
||||
let mut r = rows();
|
||||
assert_eq!(base_row(&r, &active_rows(&r)), Some(0));
|
||||
assert!(!set_base(&mut r, 0), "the first row is the base already");
|
||||
assert!(set_base(&mut r, 2));
|
||||
assert_eq!(base_row(&r, &active_rows(&r)), Some(2));
|
||||
assert!(set_base(&mut r, 1));
|
||||
assert_eq!(r.iter().filter(|x| x[BASE] == json!(true)).count(), 1, "one base mark: {r:?}");
|
||||
assert!(!set_base(&mut r, 1));
|
||||
r[2]["exclude"] = json!(true);
|
||||
assert!(!set_base(&mut r, 2), "an excluded row isn't shown");
|
||||
assert!(!set_base(&mut r, 9));
|
||||
// An excluded base row leaves the first row shown as the base.
|
||||
r[1]["exclude"] = json!(true);
|
||||
assert_eq!(base_row(&r, &active_rows(&r)), Some(0));
|
||||
// Setting that row as the base keeps it the base once the marked row is shown again.
|
||||
assert!(set_base(&mut r, 0), "the hidden row's mark moves to it");
|
||||
r[1]["exclude"] = json!(false);
|
||||
assert_eq!(base_row(&r, &active_rows(&r)), Some(0), "{r:?}");
|
||||
}
|
||||
|
||||
/// Merge and Separate keep the base mark on a row of the base color's colors; Randomize's rows
|
||||
/// (as the engine returns them) take the marks at their places again; `recolor.apply` gets no marks.
|
||||
#[test]
|
||||
fn the_base_mark_follows_merge_separate_and_randomize() {
|
||||
let mut r = rows();
|
||||
set_base(&mut r, 2);
|
||||
merge(&mut r, &[0, 2]);
|
||||
assert_eq!(r[0][BASE], json!(true), "merged into the first row: {r:?}");
|
||||
let mut r = rows();
|
||||
set_base(&mut r, 1);
|
||||
separate(&mut r, &[1]);
|
||||
assert_eq!(r.len(), 4);
|
||||
assert_eq!((r[1][BASE].clone(), r[2].get(BASE)), (json!(true), None), "{r:?}");
|
||||
// A marker's tie goes with it too.
|
||||
let mut t = rows();
|
||||
t[1][TIE] = json!(1);
|
||||
separate(&mut t, &[1]);
|
||||
assert_eq!((t[1][TIE].clone(), t[2].get(TIE)), (json!(1), None));
|
||||
let mut t = rows();
|
||||
t[0][TIE] = json!(1);
|
||||
t[2][TIE] = json!(3);
|
||||
t.push(json!({"from": [], "to": "rgb 1 2 3", "follows": 3}));
|
||||
merge(&mut t, &[0, 2]);
|
||||
assert_eq!((t[0][TIE].clone(), t[2][FOLLOWS].clone()), (json!(1), json!(1)), "its follower follows the row merged into: {t:?}");
|
||||
let before = r.clone();
|
||||
let mut shuffled: Vec<Value> = r.iter().map(without_marks).collect();
|
||||
assert!(shuffled.iter().all(|x| x.get(BASE).is_none()));
|
||||
keep_marks(&before, &mut shuffled);
|
||||
assert_eq!(shuffled, before);
|
||||
let mut fewer = vec![json!({"from": [], "to": "rgb 1 1 1"})];
|
||||
keep_marks(&before, &mut fewer);
|
||||
assert!(fewer[0].get(BASE).is_none(), "rows of another count take no marks");
|
||||
let mut d = Dialog::new(KIND, json!({}));
|
||||
d.fields.insert("rows".into(), json!(before));
|
||||
assert!(apply_params(&d)["map"].as_array().unwrap().iter().all(|x| x.get(BASE).is_none()));
|
||||
}
|
||||
|
||||
/// A color added on a marker's line moves with that marker when the colors are unlinked; it
|
||||
/// moves alone itself, and linked colors all move together as before.
|
||||
#[test]
|
||||
fn a_color_added_on_a_markers_line_moves_with_it() {
|
||||
let hue = |r: &[Value], i: usize| to_color(&r[i]).unwrap().to_hsb()[0];
|
||||
let mut r = rows();
|
||||
let added = add_color(&mut r, &Color::from_hsb(240.0, 0.5, 1.0));
|
||||
tie_to(&mut r, 1, added);
|
||||
assert_eq!((r[1][TIE].clone(), r[added][FOLLOWS].clone()), (json!(1), json!(1)));
|
||||
move_color(&mut r, 1, [270.0, 1.0, 1.0], false);
|
||||
assert!((hue(&r, added) - 270.0).abs() < 0.5, "the added color turns with its marker: {}", hue(&r, added));
|
||||
assert!((hue(&r, 0) - 0.0).abs() < 0.5 && (hue(&r, 2) - 120.0).abs() < 0.5, "the others stay");
|
||||
move_color(&mut r, added, [300.0, 0.5, 1.0], false);
|
||||
assert!((hue(&r, 1) - 270.0).abs() < 0.5, "its marker stays");
|
||||
// A second color tied to the same marker shares its number.
|
||||
let next = add_color(&mut r, &Color::from_hsb(270.0, 0.2, 1.0));
|
||||
tie_to(&mut r, 1, next);
|
||||
assert_eq!(r[next][FOLLOWS], json!(1));
|
||||
let other = add_color(&mut r, &Color::from_hsb(0.0, 0.2, 1.0));
|
||||
tie_to(&mut r, 0, other);
|
||||
assert_eq!(r[0][TIE], json!(2), "another marker takes a new number");
|
||||
tie_to(&mut r, 0, 0);
|
||||
assert!(r[0].get(FOLLOWS).is_none(), "a row isn't tied to itself");
|
||||
// Colors left from a removed marker follow no marker tied later.
|
||||
let mut r = rows();
|
||||
let added = add_color(&mut r, &Color::from_hsb(240.0, 0.5, 1.0));
|
||||
tie_to(&mut r, 1, added);
|
||||
r.remove(1);
|
||||
let next = add_color(&mut r, &Color::from_hsb(0.0, 0.5, 1.0));
|
||||
tie_to(&mut r, 0, next);
|
||||
assert_eq!(r[0][TIE], json!(2), "{r:?}");
|
||||
// A color added on an added color's line moves with the first marker too.
|
||||
let mut r = rows();
|
||||
let added = add_color(&mut r, &Color::from_hsb(240.0, 0.5, 1.0));
|
||||
tie_to(&mut r, 1, added);
|
||||
let chained = add_color(&mut r, &Color::from_hsb(240.0, 0.25, 1.0));
|
||||
tie_to(&mut r, added, chained);
|
||||
move_color(&mut r, 1, [250.0, 1.0, 1.0], false);
|
||||
assert!((hue(&r, chained) - 250.0).abs() < 0.5, "{r:?}");
|
||||
}
|
||||
|
||||
/// Select Shade's grid runs from 0% to 100% saturation across and from 100% brightness down.
|
||||
#[test]
|
||||
fn the_shade_grid_spans_saturation_and_brightness() {
|
||||
assert_eq!(shade_at(0, 0), [0.0, 1.0]);
|
||||
assert_eq!(shade_at(SHADE_COLS - 1, 0)[0], 1.0);
|
||||
let last = shade_at(0, SHADE_ROWS - 1)[1];
|
||||
assert!(last > 0.0 && last < 0.2, "{last}");
|
||||
}
|
||||
|
||||
/// A row made with New Row is not on the Edit tab while it is empty: a harmony rule gives it
|
||||
/// no color and a linked move leaves its new color as it is.
|
||||
#[test]
|
||||
@@ -3407,6 +3924,41 @@ mod tests {
|
||||
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo + 2, "a step for each group");
|
||||
}
|
||||
|
||||
/// A color removed on the Edit tab leaves its row with no new color, and neither Save All
|
||||
/// Colors, Save Prominent Colors nor OK on colors opened alone puts the row's current color in
|
||||
/// the new color group.
|
||||
#[test]
|
||||
fn a_removed_color_joins_no_saved_color_group() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
prominent_setup(&mut app, &ctx);
|
||||
let last = |app: &VectorcraftApp| -> Vec<String> {
|
||||
let doc = &app.session.doc().unwrap().doc;
|
||||
doc.swatch_groups.last().unwrap().swatches.iter().map(|w| w.paint.color().unwrap().to_hex()).collect()
|
||||
};
|
||||
let d = app.ui.dialog.as_mut().unwrap();
|
||||
d.fields.insert("rows".into(), json!([{"from": [BLUE], "to": null}, {"from": [RED, PURPLE], "to": "rgb 0 255 0"}]));
|
||||
d.fields.insert(SAVE_GROUP.into(), json!("all"));
|
||||
frame(&mut app, &ctx, 0.1, vec![], 0);
|
||||
frame(&mut app, &ctx, 0.11, vec![], 0);
|
||||
assert_eq!(last(&app), ["#00ff00"], "Save All Colors");
|
||||
let n = app.session.doc().unwrap().doc.swatch_groups.len();
|
||||
app.ui.dialog.as_mut().unwrap().fields.insert(SAVE_GROUP.into(), json!("prominent"));
|
||||
frame(&mut app, &ctx, 0.2, vec![], 0);
|
||||
frame(&mut app, &ctx, 0.21, vec![], 0);
|
||||
assert_eq!(app.session.doc().unwrap().doc.swatch_groups.len(), n + 1, "Save Prominent Colors makes a group");
|
||||
assert_eq!(last(&app), ["#00ff00"], "Save Prominent Colors");
|
||||
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
app.run("ui.recolorDialog", json!({"colors": ["#ff0000", "#0000ff"]})).unwrap();
|
||||
let d = app.ui.dialog.as_mut().unwrap();
|
||||
d.fields.insert("rows".into(), json!([{"from": ["rgb 255 0 0"], "to": "rgb 255 0 0"}, {"from": ["rgb 0 0 255"], "to": null}]));
|
||||
let d = d.clone();
|
||||
confirm(&mut app, &d).unwrap();
|
||||
assert_eq!(last(&app), ["#ff0000"], "OK on colors opened alone");
|
||||
}
|
||||
|
||||
/// Save All Colors leaves out a row made with New Row while it is empty; with only empty rows
|
||||
/// it saves no group and records no step.
|
||||
#[test]
|
||||
@@ -3794,6 +4346,31 @@ mod tests {
|
||||
assert_eq!(group_hex(&app, "A"), Some(vec!["#ff0000".into(), "#00ff00".into()]), "other groups are left as they are");
|
||||
}
|
||||
|
||||
/// Without art: rows of a group picked in the list keep their swatches when a color bar moves,
|
||||
/// at OK and at Save Changes, and an excluded row's swatch stays as it is.
|
||||
#[test]
|
||||
fn a_moved_row_of_a_listed_group_keeps_its_swatch_at_save_changes() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
app.run("swatch.newGroup", json!({"name": "A", "colors": ["#000000"], "keepModel": true})).unwrap();
|
||||
app.run("swatch.newGroup", json!({"name": "G", "colors": ["#ff0000", "#0000ff", "#00ff00"], "keepModel": true})).unwrap();
|
||||
app.run("ui.recolorDialog", json!({"group": "A"})).unwrap();
|
||||
set(&mut app, "group", json!("G")).unwrap();
|
||||
let d = app.ui.dialog.as_mut().unwrap();
|
||||
let mut rs = super::rows(d);
|
||||
rs[1]["exclude"] = json!(true);
|
||||
rs[2]["to"] = json!("#ffff00");
|
||||
let active = active_rows(&rs);
|
||||
// Drag the last bar (green, now yellow) above the first (red).
|
||||
assert_eq!(move_bar(&mut rs, &active, 1, 0), Some(0));
|
||||
d.fields.insert("rows".into(), Value::Array(rs));
|
||||
assert_eq!(apply_params(d)["groupColors"][1], json!("keep"));
|
||||
act(&mut app, &ctx, 0.1, "save").unwrap();
|
||||
assert_eq!(group_hex(&app, "G"), Some(vec!["#ff0000".into(), "#0000ff".into(), "#ffff00".into()]));
|
||||
}
|
||||
|
||||
/// Without art: selecting another color group in the list and Save Changes leave Undo Changes
|
||||
/// and Redo Changes no step to go to, so OK gives the selected group the rows read for it.
|
||||
#[test]
|
||||
|
||||
@@ -1630,6 +1630,10 @@ font-technology Variable Променливи
|
||||
Add Color Tool Инструмент „Добавяне на цвят“
|
||||
Remove Color Tool Инструмент „Премахване на цвят“
|
||||
Remove Color Премахване на цвят
|
||||
Set As Base Color Задаване като основен цвят
|
||||
Select Shade Избор на нюанс
|
||||
Add New Color Добавяне на нов цвят
|
||||
Set Current Color As Base Color Задаване на текущия цвят като основен
|
||||
Find the selected colors in the artwork Намиране на избраните цветове в илюстрацията
|
||||
Harmony Sets Набори от хармонии
|
||||
Height Височина
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3102,6 +3102,10 @@ digits Malayalam Malajalam
|
||||
Add Color Tool Alat za dodavanje boje
|
||||
Remove Color Tool Alat za uklanjanje boje
|
||||
Remove Color Ukloni boju
|
||||
Set As Base Color Postavi kao osnovnu boju
|
||||
Select Shade Odaberi nijansu
|
||||
Add New Color Dodaj novu boju
|
||||
Set Current Color As Base Color Postavi trenutnu boju kao osnovnu
|
||||
Find the selected colors in the artwork Pronađi odabrane boje u crtežu
|
||||
Harmony Rules Pravila harmonije
|
||||
Keep this row's colors (exclude) Zadrži boje ovog reda (isključi)
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -2197,6 +2197,10 @@ digits Malayalam Malaiàlam
|
||||
Add Color Tool Eina Afegeix color
|
||||
Remove Color Tool Eina Elimina color
|
||||
Remove Color Elimina el color
|
||||
Set As Base Color Defineix com a color base
|
||||
Select Shade Selecciona el to
|
||||
Add New Color Afegeix un color nou
|
||||
Set Current Color As Base Color Defineix el color actual com a color base
|
||||
Find the selected colors in the artwork Troba els colors seleccionats a l’obra
|
||||
Harmony Sets Conjunts d’harmonia
|
||||
HDTV 1080p HDTV 1080p
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3185,6 +3185,10 @@ digits Malayalam Malajálamské
|
||||
Add Color Tool Nástroj Přidat barvu
|
||||
Remove Color Tool Nástroj Odstranit barvu
|
||||
Remove Color Odstranit barvu
|
||||
Set As Base Color Nastavit jako základní barvu
|
||||
Select Shade Vybrat odstín
|
||||
Add New Color Přidat novou barvu
|
||||
Set Current Color As Base Color Nastavit aktuální barvu jako základní
|
||||
Find the selected colors in the artwork Najít vybrané barvy v kresbě
|
||||
Harmony Rules Pravidla harmonie
|
||||
Keep this row's colors (exclude) Ponechat barvy tohoto řádku (vyloučit)
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -5709,6 +5709,10 @@ digits Malayalam Malayalam
|
||||
Add Color Tool Værktøjet Tilføj farve
|
||||
Remove Color Tool Værktøjet Fjern farve
|
||||
Remove Color Fjern farve
|
||||
Set As Base Color Angiv som grundfarve
|
||||
Select Shade Vælg nuance
|
||||
Add New Color Tilføj ny farve
|
||||
Set Current Color As Base Color Angiv aktuel farve som grundfarve
|
||||
Find the selected colors in the artwork Find de valgte farver i grafikken
|
||||
Harmony Rules Harmoniregler
|
||||
Keep this row's colors (exclude) Behold farverne i denne række (ekskludér)
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1694,6 +1694,10 @@ file-filter Templates Vorlagen
|
||||
Add Color Tool Farbe-hinzufügen-Werkzeug
|
||||
Remove Color Tool Farbe-entfernen-Werkzeug
|
||||
Remove Color Farbe entfernen
|
||||
Set As Base Color Als Grundfarbe festlegen
|
||||
Select Shade Schattierung auswählen
|
||||
Add New Color Neue Farbe hinzufügen
|
||||
Set Current Color As Base Color Aktuelle Farbe als Grundfarbe festlegen
|
||||
Find the selected colors in the artwork Ausgewählte Farben in der Grafik finden
|
||||
Harmony Sets Harmoniesätze
|
||||
Height Höhe
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1617,6 +1617,10 @@ font-technology Variable Μεταβλητές
|
||||
Add Color Tool Εργαλείο προσθήκης χρώματος
|
||||
Remove Color Tool Εργαλείο αφαίρεσης χρώματος
|
||||
Remove Color Αφαίρεση χρώματος
|
||||
Set As Base Color Ορισμός ως βασικό χρώμα
|
||||
Select Shade Επιλογή απόχρωσης
|
||||
Add New Color Προσθήκη νέου χρώματος
|
||||
Set Current Color As Base Color Ορισμός τρέχοντος χρώματος ως βασικού
|
||||
Find the selected colors in the artwork Εύρεση των επιλεγμένων χρωμάτων στο σχέδιο
|
||||
Harmony Sets Σύνολα χρωματικής αρμονίας
|
||||
Height Ύψος
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1707,6 +1707,10 @@ font-technology Variable Variables
|
||||
Add Color Tool Herramienta Añadir color
|
||||
Remove Color Tool Herramienta Eliminar color
|
||||
Remove Color Eliminar color
|
||||
Set As Base Color Establecer como color base
|
||||
Select Shade Seleccionar matiz
|
||||
Add New Color Añadir nuevo color
|
||||
Set Current Color As Base Color Establecer el color actual como color base
|
||||
Find the selected colors in the artwork Buscar los colores seleccionados en la ilustración
|
||||
Harmony Sets Conjuntos de armonía
|
||||
Height Altura
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3127,6 +3127,10 @@ digits Malayalam Malajalam
|
||||
Add Color Tool Lisää väri -työkalu
|
||||
Remove Color Tool Poista väri -työkalu
|
||||
Remove Color Poista väri
|
||||
Set As Base Color Aseta perusväriksi
|
||||
Select Shade Valitse sävy
|
||||
Add New Color Lisää uusi väri
|
||||
Set Current Color As Base Color Aseta nykyinen väri perusväriksi
|
||||
Find the selected colors in the artwork Etsi valitut värit kuvituksesta
|
||||
Harmony Rules Harmoniasäännöt
|
||||
Keep this row's colors (exclude) Säilytä tämän rivin värit (jätä pois)
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1696,6 +1696,10 @@ font-technology Variable Variables
|
||||
Add Color Tool Outil Ajouter une couleur
|
||||
Remove Color Tool Outil Supprimer une couleur
|
||||
Remove Color Supprimer la couleur
|
||||
Set As Base Color Définir comme couleur de base
|
||||
Select Shade Sélectionner une nuance
|
||||
Add New Color Ajouter une nouvelle couleur
|
||||
Set Current Color As Base Color Définir la couleur actuelle comme couleur de base
|
||||
Find the selected colors in the artwork Rechercher les couleurs sélectionnées dans l’illustration
|
||||
Harmony Rules: Règles d’harmonie :
|
||||
Harmony Sets Ensembles d’harmonies
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3988,6 +3988,10 @@ arrowhead Feather પીંછું
|
||||
Add Color Tool રંગ ઉમેરો સાધન
|
||||
Remove Color Tool રંગ દૂર કરો સાધન
|
||||
Remove Color રંગ દૂર કરો
|
||||
Set As Base Color આધાર રંગ તરીકે સેટ કરો
|
||||
Select Shade છાયા પસંદ કરો
|
||||
Add New Color નવો રંગ ઉમેરો
|
||||
Set Current Color As Base Color વર્તમાન રંગને આધાર રંગ તરીકે સેટ કરો
|
||||
Find the selected colors in the artwork પસંદ કરેલા રંગો આર્ટવર્કમાં શોધો
|
||||
Show handles when multiple anchors are selected બહુવિધ એન્કર પસંદ હોય ત્યારે હૅન્ડલ બતાવો
|
||||
Show in Folder ફોલ્ડરમાં બતાવો
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 72 and column 5.
|
@@ -5336,6 +5336,10 @@ arrowhead Feather पंख
|
||||
Add Color Tool रंग जोड़ें टूल
|
||||
Remove Color Tool रंग हटाएँ टूल
|
||||
Remove Color रंग हटाएँ
|
||||
Set As Base Color आधार रंग के रूप में सेट करें
|
||||
Select Shade शेड चुनें
|
||||
Add New Color नया रंग जोड़ें
|
||||
Set Current Color As Base Color वर्तमान रंग को आधार रंग के रूप में सेट करें
|
||||
Find the selected colors in the artwork चयनित रंगों को आर्टवर्क में खोजें
|
||||
Show Color Groups रंग समूह दिखाएँ
|
||||
Show Color Swatches रंग स्वॉचेस दिखाएँ
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2120,6 +2120,10 @@ file-filter Templates Sablonok
|
||||
Add Color Tool Szín hozzáadása eszköz
|
||||
Remove Color Tool Szín eltávolítása eszköz
|
||||
Remove Color Szín eltávolítása
|
||||
Set As Base Color Beállítás alapszínként
|
||||
Select Shade Árnyalat kiválasztása
|
||||
Add New Color Új szín hozzáadása
|
||||
Set Current Color As Base Color Aktuális szín beállítása alapszínként
|
||||
Find the selected colors in the artwork A kijelölt színek keresése a grafikában
|
||||
Harmony Sets Harmóniakészletek
|
||||
HDTV 1080p HDTV 1080p
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3581,6 +3581,10 @@ digits Malayalam Malayalam
|
||||
Add Color Tool Alat Tambah Warna
|
||||
Remove Color Tool Alat Hapus Warna
|
||||
Remove Color Hapus Warna
|
||||
Set As Base Color Atur sebagai Warna Dasar
|
||||
Select Shade Pilih Corak
|
||||
Add New Color Tambah Warna Baru
|
||||
Set Current Color As Base Color Atur Warna Saat Ini sebagai Warna Dasar
|
||||
Find the selected colors in the artwork Temukan warna yang dipilih di karya seni
|
||||
Harmony Rules Aturan harmoni
|
||||
Keep this row's colors (exclude) Pertahankan warna baris ini (kecualikan)
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1731,6 +1731,10 @@ file-filter Templates Modelli
|
||||
Add Color Tool Strumento Aggiungi colore
|
||||
Remove Color Tool Strumento Rimuovi colore
|
||||
Remove Color Rimuovi colore
|
||||
Set As Base Color Imposta come colore base
|
||||
Select Shade Seleziona sfumatura
|
||||
Add New Color Aggiungi nuovo colore
|
||||
Set Current Color As Base Color Imposta il colore corrente come colore base
|
||||
Find the selected colors in the artwork Trova i colori selezionati nella grafica
|
||||
Harmony Sets Gruppi di armonia
|
||||
Height Altezza
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2115,6 +2115,10 @@ antiAlias Sharp シャープ
|
||||
Add Color Tool カラー追加ツール
|
||||
Remove Color Tool カラー削除ツール
|
||||
Remove Color カラーを削除
|
||||
Set As Base Color ベースカラーに設定
|
||||
Select Shade シェードを選択
|
||||
Add New Color 新規カラーを追加
|
||||
Set Current Color As Base Color 現在のカラーをベースカラーに設定
|
||||
Find the selected colors in the artwork 選択したカラーをアートワーク内で検索
|
||||
Height 高さ
|
||||
Height: 高さ:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -5067,6 +5067,10 @@ digits Malayalam მალაიალამური
|
||||
Add Color Tool ფერის დამატების ხელსაწყო
|
||||
Remove Color Tool ფერის წაშლის ხელსაწყო
|
||||
Remove Color ფერის წაშლა
|
||||
Set As Base Color საბაზო ფერად დაყენება
|
||||
Select Shade ელფერის არჩევა
|
||||
Add New Color ახალი ფერის დამატება
|
||||
Set Current Color As Base Color მიმდინარე ფერის საბაზო ფერად დაყენება
|
||||
Find the selected colors in the artwork მონიშნული ფერების ძებნა ნახატში
|
||||
Keep this row's colors (exclude) ამ სტრიქონის ფერების შენარჩუნება (გამორიცხვა)
|
||||
Limit to Library: ბიბლიოთეკით შეზღუდვა:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2105,6 +2105,10 @@ antiAlias Sharp 날카롭게
|
||||
Add Color Tool 색상 추가 도구
|
||||
Remove Color Tool 색상 제거 도구
|
||||
Remove Color 색상 제거
|
||||
Set As Base Color 기본 색상으로 설정
|
||||
Select Shade 음영 선택
|
||||
Add New Color 새 색상 추가
|
||||
Set Current Color As Base Color 현재 색상을 기본 색상으로 설정
|
||||
Find the selected colors in the artwork 선택한 색상을 아트웍에서 찾기
|
||||
Height 높이
|
||||
Height: 높이:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3580,6 +3580,10 @@ digits Malayalam Malayalam
|
||||
Add Color Tool Gereedschap Kleur toevoegen
|
||||
Remove Color Tool Gereedschap Kleur verwijderen
|
||||
Remove Color Kleur verwijderen
|
||||
Set As Base Color Instellen als basiskleur
|
||||
Select Shade Schakering selecteren
|
||||
Add New Color Nieuwe kleur toevoegen
|
||||
Set Current Color As Base Color Huidige kleur instellen als basiskleur
|
||||
Find the selected colors in the artwork De geselecteerde kleuren zoeken in de artwork
|
||||
Harmony Rules Harmonieregels
|
||||
Keep this row's colors (exclude) De kleuren van deze rij behouden (uitsluiten)
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3095,6 +3095,10 @@ digits Malayalam Malajalam
|
||||
Add Color Tool Narzędzie Dodaj kolor
|
||||
Remove Color Tool Narzędzie Usuń kolor
|
||||
Remove Color Usuń kolor
|
||||
Set As Base Color Ustaw jako kolor bazowy
|
||||
Select Shade Wybierz odcień
|
||||
Add New Color Dodaj nowy kolor
|
||||
Set Current Color As Base Color Ustaw bieżący kolor jako bazowy
|
||||
Find the selected colors in the artwork Znajdź zaznaczone kolory w kompozycji
|
||||
Keep this row's colors (exclude) Zachowaj kolory tego wiersza (wyklucz)
|
||||
Limit to Library: Ogranicz do biblioteki:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1481,6 +1481,10 @@ antiAlias Sharp Nítido
|
||||
Add Color Tool Ferramenta Adicionar cor
|
||||
Remove Color Tool Ferramenta Remover cor
|
||||
Remove Color Remover cor
|
||||
Set As Base Color Definir como cor base
|
||||
Select Shade Selecionar tonalidade
|
||||
Add New Color Adicionar nova cor
|
||||
Set Current Color As Base Color Definir cor atual como cor base
|
||||
Find the selected colors in the artwork Localizar as cores selecionadas na arte
|
||||
Harmony Sets Conjuntos de Harmonia
|
||||
Height Altura
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1717,6 +1717,10 @@ file-filter Templates Шаблоны
|
||||
Add Color Tool Инструмент «Добавить цвет»
|
||||
Remove Color Tool Инструмент «Удалить цвет»
|
||||
Remove Color Удалить цвет
|
||||
Set As Base Color Сделать базовым цветом
|
||||
Select Shade Выбрать оттенок
|
||||
Add New Color Добавить новый цвет
|
||||
Set Current Color As Base Color Сделать текущий цвет базовым
|
||||
Find the selected colors in the artwork Найти выбранные цвета в рисунке
|
||||
Harmony Sets Наборы гармонии
|
||||
Height Высота
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1654,6 +1654,10 @@ font-technology Variable Variabla
|
||||
Add Color Tool Verktyget Lägg till färg
|
||||
Remove Color Tool Verktyget Ta bort färg
|
||||
Remove Color Ta bort färg
|
||||
Set As Base Color Ange som grundfärg
|
||||
Select Shade Välj nyans
|
||||
Add New Color Lägg till ny färg
|
||||
Set Current Color As Base Color Ange aktuell färg som grundfärg
|
||||
Find the selected colors in the artwork Hitta de markerade färgerna i teckningen
|
||||
Harmony Sets Harmoniuppsättningar
|
||||
Height Höjd
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1617,6 +1617,10 @@ font-technology Variable Değişken
|
||||
Add Color Tool Renk Ekle aracı
|
||||
Remove Color Tool Renk Kaldır aracı
|
||||
Remove Color Rengi kaldır
|
||||
Set As Base Color Temel renk olarak ayarla
|
||||
Select Shade Ton seç
|
||||
Add New Color Yeni renk ekle
|
||||
Set Current Color As Base Color Geçerli rengi temel renk olarak ayarla
|
||||
Find the selected colors in the artwork Seçili renkleri resimde bul
|
||||
Harmony Sets Armoni Setleri
|
||||
Height Yükseklik
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1725,6 +1725,10 @@ file-filter Templates Шаблони
|
||||
Add Color Tool Інструмент «Додати колір»
|
||||
Remove Color Tool Інструмент «Вилучити колір»
|
||||
Remove Color Вилучити колір
|
||||
Set As Base Color Зробити базовим кольором
|
||||
Select Shade Вибрати відтінок
|
||||
Add New Color Додати новий колір
|
||||
Set Current Color As Base Color Зробити поточний колір базовим
|
||||
Find the selected colors in the artwork Знайти вибрані кольори в малюнку
|
||||
Harmony Sets Набори гармонії
|
||||
Height Висота
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1968,6 +1968,10 @@ file-filter Templates Mẫu
|
||||
Add Color Tool Công cụ Thêm màu
|
||||
Remove Color Tool Công cụ Xóa màu
|
||||
Remove Color Xóa màu
|
||||
Set As Base Color Đặt làm màu cơ sở
|
||||
Select Shade Chọn sắc độ
|
||||
Add New Color Thêm màu mới
|
||||
Set Current Color As Base Color Đặt màu hiện tại làm màu cơ sở
|
||||
Find the selected colors in the artwork Tìm các màu đã chọn trong tác phẩm
|
||||
Harmony Sets Bộ hài hòa màu
|
||||
Height Chiều cao
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1659,6 +1659,10 @@ file-filter Templates 模板
|
||||
Add Color Tool 添加颜色工具
|
||||
Remove Color Tool 删除颜色工具
|
||||
Remove Color 删除颜色
|
||||
Set As Base Color 设为基色
|
||||
Select Shade 选择色调
|
||||
Add New Color 添加新颜色
|
||||
Set Current Color As Base Color 将当前颜色设为基色
|
||||
Find the selected colors in the artwork 在图稿中查找所选颜色
|
||||
Harmony Sets 色彩调和组
|
||||
Height 高度
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1696,6 +1696,10 @@ file-filter Templates 範本
|
||||
Add Color Tool 新增顏色工具
|
||||
Remove Color Tool 移除顏色工具
|
||||
Remove Color 移除顏色
|
||||
Set As Base Color 設為基色
|
||||
Select Shade 選取色調
|
||||
Add New Color 新增顏色
|
||||
Set Current Color As Base Color 將目前顏色設為基色
|
||||
Find the selected colors in the artwork 在圖稿中尋找所選顏色
|
||||
Harmony Sets 色彩調和組
|
||||
Height 高度
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1496,6 +1496,169 @@ fn a_color_bars_menu_removes_its_color() {
|
||||
assert_eq!(field(h.state(), "__sel"), json!([0]));
|
||||
}
|
||||
|
||||
/// Right-clicks the point `at`.
|
||||
fn right_click_at(h: &mut egui_kittest::Harness<'_, VectorcraftApp>, at: Pos2) {
|
||||
h.event(Event::PointerMoved(at));
|
||||
h.event(Event::PointerButton { pos: at, button: PointerButton::Secondary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.event(Event::PointerButton { pos: at, button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
/// The smaller angle between hues `a` and `b`, in degrees.
|
||||
fn hue_gap(a: f32, b: f32) -> f32 {
|
||||
(a - b).rem_euclid(360.0).min((b - a).rem_euclid(360.0))
|
||||
}
|
||||
|
||||
/// A marker's right-click menu has Set As Base Color, Select Shade, Color Picker and Remove Color.
|
||||
/// Set As Base Color marks the row as the base, whose menu then has neither Set As Base Color nor
|
||||
/// Remove Color; with another color selected, a harmony rule builds from the base color, and OK
|
||||
/// recolors the art.
|
||||
#[test]
|
||||
fn a_markers_menu_sets_the_base_color_that_the_rules_build_from() {
|
||||
let mut h = edit_harness(&["#ff0000", "#0000ff", "#00ff00"]);
|
||||
let hsb = new_hsb(h.state());
|
||||
let at = wheel_at(&h, hsb[1][0], hsb[1][1]);
|
||||
right_click_at(&mut h, at);
|
||||
for item in [" Set As Base Color", " Select Shade", " Color Picker", " Remove Color"] {
|
||||
assert!(h.query_by_label(item).is_some(), "{item}");
|
||||
}
|
||||
h.get_by_label(" Set As Base Color").click();
|
||||
h.run_steps(3);
|
||||
let rows = field(h.state(), "rows");
|
||||
assert_eq!(rows[1]["base"], json!(true), "{rows}");
|
||||
assert!(rows[0].get("base").is_none() && rows[2].get("base").is_none());
|
||||
right_click_at(&mut h, at);
|
||||
assert!(h.get_by_label(" Set As Base Color").accesskit_node().is_disabled(), "it is the base already");
|
||||
assert!(h.get_by_label(" Remove Color").accesskit_node().is_disabled(), "the base color can't be removed");
|
||||
h.key_press(egui::Key::Escape);
|
||||
h.run_steps(2);
|
||||
// The selected color is another one; the rule still builds from the base.
|
||||
set(h.state_mut(), "__sel", json!([0]));
|
||||
h.run_steps(3);
|
||||
h.get_by_role_and_label(egui::accesskit::Role::ComboBox, "Harmony Rules:").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Triad").click();
|
||||
h.run_steps(3);
|
||||
let now = new_hsb(h.state());
|
||||
assert!(hue_gap(now[1][0], hsb[1][0]) < 1.0, "the base color keeps its hue: {hsb:?} -> {now:?}");
|
||||
assert!(hue_gap(now[0][0], now[1][0]) > 110.0 && hue_gap(now[2][0], now[1][0]) > 110.0, "the others are a triad from it: {now:?}");
|
||||
assert_eq!(field(h.state(), "rows")[1]["base"], json!(true), "the rule keeps the base mark");
|
||||
let before = fills(h.state());
|
||||
let app = h.state_mut();
|
||||
dialogs::confirm(app).unwrap();
|
||||
assert_eq!(fills(app), before, "OK keeps the previewed colors");
|
||||
}
|
||||
|
||||
/// Select Shade on a marker's menu shows a grid of the color's hue; a click on a cell gives the color
|
||||
/// that saturation and brightness, keeping its hue, and closes the menu. Unlinked, the other colors
|
||||
/// stay; linked, they move as a drag would move them.
|
||||
#[test]
|
||||
fn select_shade_gives_a_marker_the_shade_clicked() {
|
||||
for linked in [false, true] {
|
||||
let mut h = edit_harness(&["rgb 200 100 100", "rgb 100 200 200"]);
|
||||
set(h.state_mut(), "linked", json!(linked));
|
||||
h.run_steps(3);
|
||||
let hsb = new_hsb(h.state());
|
||||
let at = wheel_at(&h, hsb[0][0], hsb[0][1]);
|
||||
right_click_at(&mut h, at);
|
||||
h.get_by_label(" Select Shade").click();
|
||||
h.run_steps(2);
|
||||
let cell = "Saturation 50%, Brightness 57%";
|
||||
h.get_by_label(cell).click();
|
||||
h.run_steps(3);
|
||||
let now = new_hsb(h.state());
|
||||
assert!(hue_gap(now[0][0], hsb[0][0]) < 1.0 && (now[0][1] - 0.5).abs() < 0.01 && (now[0][2] - 4.0 / 7.0).abs() < 0.01, "{now:?}");
|
||||
let other_moved = (now[1][2] - hsb[1][2]).abs() > 0.01;
|
||||
assert_eq!(other_moved, linked, "linked {linked}: {hsb:?} -> {now:?}");
|
||||
assert!(h.query_by_label(cell).is_none(), "the menu closes");
|
||||
assert_eq!(field(h.state(), "__sel"), json!([0]));
|
||||
}
|
||||
}
|
||||
|
||||
/// Color Picker on a marker's menu opens the Color Picker for that color.
|
||||
#[test]
|
||||
fn a_markers_menu_opens_the_color_picker() {
|
||||
let mut h = edit_harness(&["rgb 200 100 100", "rgb 100 200 200"]);
|
||||
let hsb = new_hsb(h.state());
|
||||
let at = wheel_at(&h, hsb[1][0], hsb[1][1]);
|
||||
right_click_at(&mut h, at);
|
||||
h.get_by_label(" Color Picker").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().ui.dialog.as_ref().map(|d| d.kind.as_str()), Some("colorPicker"));
|
||||
}
|
||||
|
||||
/// A right-click on the wheel away from the markers offers Add New Color, which adds the hue and
|
||||
/// saturation there as a new color. A color added on the line from the center to a marker moves
|
||||
/// with that marker when the colors are unlinked, and the others stay.
|
||||
#[test]
|
||||
fn add_new_color_on_a_markers_line_moves_with_that_marker() {
|
||||
let mut h = edit_harness(&["rgb 200 100 100", "rgb 100 200 200"]);
|
||||
set(h.state_mut(), "linked", json!(false));
|
||||
set(h.state_mut(), "__sel", json!([0]));
|
||||
h.run_steps(4);
|
||||
let hsb = new_hsb(h.state());
|
||||
let at = wheel_at(&h, 90.0, 0.6);
|
||||
right_click_at(&mut h, at);
|
||||
assert!(h.query_by_label(" Set As Base Color").is_none(), "no marker there");
|
||||
h.get_by_label(" Add New Color").click();
|
||||
h.run_steps(3);
|
||||
let rows = field(h.state(), "rows");
|
||||
assert_eq!(rows.as_array().unwrap().len(), 3, "{rows}");
|
||||
assert_eq!((&rows[2]["from"], &rows[2]["added"]), (&json!([]), &json!(true)));
|
||||
assert!(rows[2].get("follows").is_none(), "off every marker's line");
|
||||
let [hue, s, v] = new_hsb(h.state())[2];
|
||||
assert!((hue - 90.0).abs() < 1.0 && (s - 0.6).abs() < 0.01 && (v - hsb[0][2]).abs() < 0.01, "{:?}", [hue, s, v]);
|
||||
assert_eq!(field(h.state(), "__sel"), json!([2]));
|
||||
// Halfway along the second color's line.
|
||||
let on_line = wheel_at(&h, hsb[1][0], hsb[1][1] / 2.0);
|
||||
right_click_at(&mut h, on_line);
|
||||
h.get_by_label(" Add New Color").click();
|
||||
h.run_steps(3);
|
||||
let rows = field(h.state(), "rows");
|
||||
assert_eq!(rows.as_array().unwrap().len(), 4);
|
||||
assert!(rows[1]["tie"].is_u64() && rows[3]["follows"] == rows[1]["tie"], "{rows}");
|
||||
// Drag the second color's marker a little way round: the color on its line turns with it.
|
||||
let before = new_hsb(h.state());
|
||||
let start = wheel_at(&h, before[1][0], before[1][1]);
|
||||
h.hover_at(start);
|
||||
h.run_steps(1);
|
||||
h.drag_at(start);
|
||||
h.run_steps(1);
|
||||
let mut p = start;
|
||||
for k in 1..=6 {
|
||||
p = wheel_at(&h, before[1][0] + 5.0 * k as f32, before[1][1]);
|
||||
h.hover_at(p);
|
||||
h.run_steps(1);
|
||||
}
|
||||
h.drop_at(p);
|
||||
h.run_steps(2);
|
||||
let after = new_hsb(h.state());
|
||||
let turned = hue_gap(after[1][0], before[1][0]);
|
||||
assert!(turned > 20.0, "the marker turned: {before:?} -> {after:?}");
|
||||
assert!((hue_gap(after[3][0], before[3][0]) - turned).abs() < 1.0, "the color on its line turned as far: {before:?} -> {after:?}");
|
||||
assert!(hue_gap(after[0][0], before[0][0]) < 0.5 && hue_gap(after[2][0], before[2][0]) < 0.5, "the others stay: {before:?} -> {after:?}");
|
||||
}
|
||||
|
||||
/// Set Current Color As Base Color makes the selected color the base; it is off while the selected
|
||||
/// color is the base. A color bar's menu has Set As Base Color too.
|
||||
#[test]
|
||||
fn set_current_color_as_base_color_marks_the_selected_color() {
|
||||
let mut h = edit_harness(&["#ff0000", "#0000ff", "#00ff00"]);
|
||||
let name = "Set Current Color As Base Color";
|
||||
assert!(h.get_by_role_and_label(egui::accesskit::Role::Button, name).accesskit_node().is_disabled(), "the base color is the selected one");
|
||||
set(h.state_mut(), "__sel", json!([2]));
|
||||
h.run_steps(3);
|
||||
click_button(&mut h, name);
|
||||
assert_eq!(field(h.state(), "rows")[2]["base"], json!(true));
|
||||
assert!(h.get_by_role_and_label(egui::accesskit::Role::Button, name).accesskit_node().is_disabled());
|
||||
show_display(&mut h, "Show color bars");
|
||||
right_click_bar(&mut h, "Color 1");
|
||||
h.get_by_label(" Set As Base Color").click();
|
||||
h.run_steps(3);
|
||||
let rows = field(h.state(), "rows");
|
||||
assert_eq!((&rows[0]["base"], rows[2].get("base")), (&json!(true), None), "{rows}");
|
||||
}
|
||||
|
||||
// Optional local visual QA; these captures are not committed assets.
|
||||
fn capture_recolor(h: &mut egui_kittest::Harness<'_, VectorcraftApp>, name: &str) {
|
||||
if let Some(dir) = std::env::var_os("VECTORCRAFT_RECOLOR_CAPTURE_DIR") {
|
||||
|
||||
@@ -39,8 +39,8 @@ pub use chips::{ProxyClicks, chip_button, chip_button_named, fill_stroke_proxy,
|
||||
pub use color::{
|
||||
FieldAxis, Live, MarkerResponse, RingResponse, SliderValue, WheelAxes, WheelResponse, channel_slider, channel_slider_named,
|
||||
channel_slider_stepped, channel_slider_valued, color_field, color_mesh, color_slider, color_slider_named, color_slider_stepped,
|
||||
color_slider_valued, harmony_wheel, hex_field, hex_field_named, hsb32, hue_ring, region_texture, ring_markers, ring_square, segment_color,
|
||||
segment_color_on, segmented_wheel, stepped_area, wheel_of,
|
||||
color_slider_valued, harmony_wheel, hex_field, hex_field_named, hsb32, hue_ring, recolor_wheel, region_texture, ring_markers, ring_square,
|
||||
segment_color, segment_color_on, segmented_wheel, stepped_area, wheel_of,
|
||||
};
|
||||
pub(crate) use color::{HEX_FIELD_CHARS, focus_by_pointer, hex_text, pointer_phase};
|
||||
pub use drag::{
|
||||
|
||||
@@ -1097,6 +1097,12 @@ pub struct WheelResponse {
|
||||
/// A click on the wheel: the color whose marker is within reach of it (if any), and the hue
|
||||
/// (degrees) and the saturation (or brightness) under the pointer (1 past the wheel's edge).
|
||||
pub clicked: Option<(Option<usize>, [f32; 2])>,
|
||||
/// A right-click on the wheel, or on a marker past its edge: the color whose marker is within
|
||||
/// reach of it (if any), the color on whose line from the center it is (when it is on no
|
||||
/// marker), and the hue (degrees) and saturation under the pointer.
|
||||
pub secondary: Option<(Option<usize>, Option<usize>, [f32; 2])>,
|
||||
/// The wheel's own response, for a right-click menu.
|
||||
pub response: Option<egui::Response>,
|
||||
}
|
||||
|
||||
/// The harmony wheel of Recolor Artwork's Edit tab and the Color Themes panel: a hue and saturation
|
||||
@@ -1104,25 +1110,60 @@ pub struct WheelResponse {
|
||||
/// marker per colour joined to the centre (the selected colour, `base`, larger) and a Brightness
|
||||
/// slider for the selected colour below it.
|
||||
pub fn harmony_wheel(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option<usize>) -> WheelResponse {
|
||||
wheel_of(ui, id, size, colors, base, false, WheelAxes::HueSaturation)
|
||||
wheel_of(ui, id, size, colors, base, base, false, WheelAxes::HueSaturation)
|
||||
}
|
||||
|
||||
/// [`harmony_wheel`] drawn as solid patches (24 hues by 5 saturations, each in its
|
||||
/// [`segment_color`]). The markers sit at their colors' own hue and
|
||||
/// Recolor Artwork's wheel: [`harmony_wheel`] with the base color's marker (`base`) larger and the
|
||||
/// selected color's (`selected`, when another) ringed, at the selected color's brightness, with the
|
||||
/// Brightness slider for it. With `segmented` it is drawn as solid patches (24 hues by 5
|
||||
/// saturations, each in its [`segment_color`]); the markers sit at their colors' own hue and
|
||||
/// saturation, and a drag moves them as freely as on the smooth wheel.
|
||||
pub fn segmented_wheel(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option<usize>) -> WheelResponse {
|
||||
wheel_of(ui, id, size, colors, base, true, WheelAxes::HueSaturation)
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn recolor_wheel(
|
||||
ui: &mut Ui,
|
||||
id: &str,
|
||||
size: f32,
|
||||
colors: &[Color],
|
||||
base: Option<usize>,
|
||||
selected: Option<usize>,
|
||||
segmented: bool,
|
||||
axes: WheelAxes,
|
||||
) -> WheelResponse {
|
||||
wheel_of(ui, id, size, colors, base, selected.or(base), segmented, axes)
|
||||
}
|
||||
|
||||
/// [`harmony_wheel`], or with `segmented` [`segmented_wheel`], showing `axes`. With
|
||||
/// The distance from `p` to the segment from `a` to `b`.
|
||||
fn segment_distance(p: egui::Pos2, a: egui::Pos2, b: egui::Pos2) -> f32 {
|
||||
let ab = b - a;
|
||||
let len2 = ab.length_sq();
|
||||
let t = if len2 > 0.0 { ((p - a).dot(ab) / len2).clamp(0.0, 1.0) } else { 0.0 };
|
||||
p.distance(a + ab * t)
|
||||
}
|
||||
|
||||
pub fn segmented_wheel(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option<usize>) -> WheelResponse {
|
||||
wheel_of(ui, id, size, colors, base, base, true, WheelAxes::HueSaturation)
|
||||
}
|
||||
|
||||
/// [`harmony_wheel`], [`recolor_wheel`], or with `segmented` [`segmented_wheel`], showing `axes`. The
|
||||
/// big marker is `base`'s, and the wheel's background and the slider under it are `selected`'s. With
|
||||
/// [`WheelAxes::HueBrightness`] the distance from the center is brightness (black at the center,
|
||||
/// full brightness at the edge, a ring of patches per 20% on the segmented wheel), the wheel is drawn
|
||||
/// at the selected colour's saturation (full without one), a marker drag sets hue and brightness,
|
||||
/// and the slider under the wheel is a Saturation slider.
|
||||
pub fn wheel_of(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option<usize>, segmented: bool, axes: WheelAxes) -> WheelResponse {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn wheel_of(
|
||||
ui: &mut Ui,
|
||||
id: &str,
|
||||
size: f32,
|
||||
colors: &[Color],
|
||||
base: Option<usize>,
|
||||
selected: Option<usize>,
|
||||
segmented: bool,
|
||||
axes: WheelAxes,
|
||||
) -> WheelResponse {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let mut out = WheelResponse::default();
|
||||
let base_hsb = base.and_then(|b| colors.get(b)).map(Color::to_hsb);
|
||||
let base_hsb = selected.and_then(|b| colors.get(b)).map(Color::to_hsb);
|
||||
let (radial, other) = (axes.radial(), axes.other());
|
||||
// The component the wheel does not show: the slider's value, and the wheel's background at it.
|
||||
let o = base_hsb.map_or(1.0, |c| c[other]);
|
||||
@@ -1144,6 +1185,24 @@ pub fn wheel_of(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option
|
||||
painter.line_segment([c, p], Stroke::new(1.0, Color32::from_white_alpha(160)));
|
||||
painter.circle(p, if big { 8.0 } else { 5.5 }, crate::panels::c32(col), Stroke::new(1.5, Color32::WHITE));
|
||||
painter.circle_stroke(p, if big { 9.0 } else { 6.5 }, Stroke::new(1.0, Color32::BLACK));
|
||||
if Some(i) == selected && selected != base {
|
||||
painter.circle_stroke(p, 8.5, Stroke::new(1.5, t.accent));
|
||||
}
|
||||
}
|
||||
// A right-click: the marker under it, or else the line from the center to a marker.
|
||||
if resp.secondary_clicked()
|
||||
&& let Some(p) = resp.interact_pointer_pos()
|
||||
{
|
||||
let near = colors.iter().map(at).enumerate().map(|(i, m)| (i, m.distance(p))).filter(|x| x.1 <= 14.0).min_by(|a, b| a.1.total_cmp(&b.1));
|
||||
let dv = p - c;
|
||||
if dv.length() <= r || near.is_some() {
|
||||
let line = near.is_none().then(|| {
|
||||
let on = colors.iter().map(at).enumerate().map(|(i, m)| (i, segment_distance(p, c, m))).filter(|x| x.1 <= 4.0);
|
||||
on.min_by(|a, b| a.1.total_cmp(&b.1)).map(|x| x.0)
|
||||
});
|
||||
let h = (-dv.y).atan2(dv.x).to_degrees().rem_euclid(360.0);
|
||||
out.secondary = Some((near.map(|x| x.0), line.flatten(), [h, (dv.length() / r).clamp(0.0, 1.0)]));
|
||||
}
|
||||
}
|
||||
// Drag a marker: the nearest one within reach of the press.
|
||||
let drag = ui.scope_id().with((id, "drag"));
|
||||
@@ -1173,6 +1232,7 @@ pub fn wheel_of(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option
|
||||
}
|
||||
let name = if segmented { tl!("Segmented color wheel") } else { tl!("Color wheel") };
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Slider, ui.is_enabled(), name));
|
||||
out.response = Some(resp);
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.horizontal(|ui| {
|
||||
@@ -1181,7 +1241,7 @@ pub fn wheel_of(ui: &mut Ui, id: &str, size: f32, colors: &[Color], base: Option
|
||||
ui.add_sized([70.0, 22.0], egui::Label::new(egui::RichText::new(name).color(t.text_dim)));
|
||||
// Screen readers get the value in percent, as the Color panel's HSB fields show it.
|
||||
let shown = SliderValue::field((f64::from(o) * 100.0).round(), 0.0..=100.0, "%", 0);
|
||||
if let (Some(b), Some(hsb)) = (base, base_hsb)
|
||||
if let (Some(b), Some(hsb)) = (selected, base_hsb)
|
||||
&& let (Some(nv), _) = color_slider_valued(ui, (id, key), name, Some(shown), o, size, &|x| {
|
||||
let [h, s, v] = axes.hsb(hsb[0], hsb[radial], x);
|
||||
crate::panels::c32(&Color::from_hsb(h, s, v))
|
||||
|
||||
@@ -300,18 +300,30 @@ luminosity}`, percent from -100 to 100, 0 by default). The dialog sends a non-ze
|
||||
colors; colors opened alone are saved as a group with the change. `display` sets how the Edit tab shows the new
|
||||
colors: `smooth` (the smooth wheel, also when unset; each opening starts there), `segmented` (a wheel of solid patches,
|
||||
24 hues by 5 saturations, whose markers move as freely) or `bars` (a solid bar per recolored color in row order; a click
|
||||
selects its row for the sliders and a drag moves the row without changing a color). `wheelTool` turns on a wheel tool
|
||||
on either wheel: `add` (the Add Color tool) adds a click as a new color, the hue and saturation clicked at the base
|
||||
color's brightness (the patch's color on the segmented wheel), in a new row with no current colors (`from: []`) and
|
||||
selects its row for the sliders and a drag moves the row without changing a color; the moved row keeps the color group
|
||||
swatch it took). `wheelTool` turns on a wheel tool
|
||||
on either wheel: `add` (the Add Color tool) adds a click as a new color, the hue and saturation clicked at the selected
|
||||
color's brightness (the base color's when none is selected; the patch's color on the segmented wheel), in a new row with no current colors (`from: []`) and
|
||||
`added: true` that becomes the selected row; `remove` (the Remove Color tool) removes the color of the marker clicked.
|
||||
`wheelAxes: "hueBrightness"` makes both wheels show hue and brightness: brightness runs from black at the center to
|
||||
full at the edge, the wheel is drawn at the base color's saturation, a marker drag sets hue and brightness, the slider
|
||||
under the wheel sets saturation, and Add Color adds the hue and brightness clicked at the base color's saturation.
|
||||
full at the edge, the wheel is drawn at the selected color's saturation (the base color's when none is selected), a marker drag sets hue and brightness, the slider
|
||||
under the wheel sets saturation, and Add Color adds the hue and brightness clicked at the selected color's saturation.
|
||||
`hueSaturation`, unset (each opening) or any other value shows hue and saturation; switching changes no color. A color bar's
|
||||
right-click menu has Remove Color too. The base color can't be removed. A removed color's row is dropped, unless it
|
||||
has current colors and art or a group is open: it then keeps them with `to: null`, that art keeps its colors, and the
|
||||
group's swatch at that place is removed. A row with no current colors recolors no art; with a group, the new color of
|
||||
group's swatch at that place is removed, unless the row is excluded: an excluded row with current colors leaves the group's swatch at its place as it is. A row with no current colors recolors no art; with a group, the new color of
|
||||
one with `added: true` that is not excluded is added to the group after the group's other colors, and a row made with New Row adds none.
|
||||
The base color is the row with `base: true`, or the first color the Edit tab shows when no row has it; the harmony rules
|
||||
build from it, and selecting another color for the sliders leaves it the base. A right-click on a wheel marker or a
|
||||
color bar opens a menu with Set As Base Color (moves `base: true` to that row), Select Shade (a grid of the color's hue
|
||||
at 7 saturations, 0% to 100%, by 7 brightnesses, 100% down to 14%; a click moves the color there as a drag of its
|
||||
marker would, so linked colors follow), Color Picker and Remove Color; the base color's menu has neither Set As Base
|
||||
Color nor Remove Color. A right-click elsewhere on either wheel offers Add New Color, which adds a color as the Add
|
||||
Color tool does. A color added on the line from the center to a marker moves with that marker while the colors are
|
||||
unlinked: the marker's row gets `tie: n` and the added row `follows: n`, and dragging the marker, or Select Shade on
|
||||
it, moves every row that follows its `tie` by the same change. Set Current Color As Base Color, before the color chips,
|
||||
makes the selected color the base. The rows keep these marks when Randomize (`recolor.randomize`) or Prominent Colors
|
||||
(`recolor.weigh`) changes them, and the rows the dialog sends `recolor.apply` leave `base`, `tie` and `follows` out.
|
||||
`groupStorage` shows the Color Groups list (true when the dialog opens); setting `group` to a color group's name makes
|
||||
it the group being edited, as opening on it does, and refuses a name no group has; `groupAction` (`save`, `new` or
|
||||
`delete`) runs the list's Save Changes, New Color Group or Delete button on the next frame, or first on confirm (see
|
||||
|
||||
+3
-3
@@ -5341,7 +5341,7 @@ without `groupColors`, its new color then joins `group` after the new colors of
|
||||
`recolor.randomize` and `recolor.weigh` keep such a row, and `recolor.randomize` keeps its `added`. A row without `from`, or with
|
||||
a current color that is not a color, is refused. With art selected, the Recolor Artwork dialog's New Row button (beside
|
||||
Merge) adds such a row above the first selected row, or at the top, with that row's new color, and selects it; Shift-click a row below it and Merge to move that row's colors into it (Merge keeps the topmost selected row's new color). An
|
||||
empty row does not count toward Colors. While it is empty, the dialog's Edit tab does not show it (its sliders edit
|
||||
empty row does not count toward Colors. While it is empty and not `added`, the dialog's Edit tab does not show it (its sliders edit
|
||||
the base color when the empty row is selected), the harmony rules,
|
||||
linked moves and the Color Theme Picker leave its new color as it is, and Save All Colors and a new color group saved
|
||||
from colors alone leave its new color out. With `limitTo`, a row's `tint` (a percentage, default 100) gives the art
|
||||
@@ -5392,7 +5392,7 @@ objects are read. As VectorCraft's own rule, each object read weighs the same, s
|
||||
among its pixels; the vector art a symbol instance places counts as one object, and each image it places counts on
|
||||
its own), and similar colors merge (k-means in Lab) into at most `colors` (1 to 64, default 5), each shown by its
|
||||
most used color in its own model. Picks that touch no art return no colors. In the Recolor Artwork dialog the picks are the `themePicks` field: the rows that aren't
|
||||
excluded and hold current colors take the palette as their new colors in row order, the colors repeating when the rows outnumber them.
|
||||
excluded and hold current colors or were added on the Edit tab take the palette as their new colors in row order, the colors repeating when the rows outnumber them.
|
||||
|
||||
```json
|
||||
{"name":"run_command","arguments":{"command":"recolor.pickTheme","params":{"picks":[{"at":[120,80]},{"rect":[200,40,320,140]}],"colors":4}}}
|
||||
@@ -5418,7 +5418,7 @@ bar sits under the Edit tab's wheel: each row with a share is a part as wide as
|
||||
the largest first. Dragging the edge between two parts moves width between them, and when the drag ends the widths
|
||||
become the `weights` field, which moves the rows' current colors and previews the result. The New Color Group menu
|
||||
beside the link button runs `swatch.newGroup` right away, as its own undo step: Save All Colors saves the new colors
|
||||
of the rows that are not excluded and hold current colors, in row order, and Save Prominent Colors saves the bar's colors in the bar's order.
|
||||
of the rows that are not excluded, hold current colors or were added on the Edit tab, and still have one, in row order, and Save Prominent Colors saves the bar's colors in the bar's order.
|
||||
|
||||
The Recolor Artwork dialog lists the document's color groups on its right, or under the tabs in a window too narrow
|
||||
for both ([Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html)).
|
||||
|
||||
@@ -1956,6 +1956,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Document Color Mode for effects and graphs:** File › Document Color Mode and `document.open {colorMode}` convert the colors of effects (Drop Shadow, Inner Glow, Outer Glow and the other effects with a color, on objects, their fills and strokes and in graphic styles) and the series paints and label styles that a graph keeps, so a graph drawn again from new data keeps the converted colors; File › Document Color Mode also converts the fill and stroke that new art takes. Undo restores the original new-art fill and stroke and Redo applies the conversion again.
|
||||
- **Recolor Artwork layout (#3416):** the Edit chip list uses the modal scroll helper and its actual remaining height; the tab's minimum-height space scrolls with the chips. `tests_recolor` covers 5/20/200/400 colors, window resizing, 100/125/150/200% UI scaling, scrolling to and editing the final chip, Preview, Cancel, Confirm and Undo, alongside the existing #1733 drag regressions. Scores and estimates unchanged.
|
||||
- **Recolor Artwork Edit displays:** buttons beside the Edit tab's wheel show the colors on a smooth color wheel, a segmented color wheel or as color bars ([Edit colors using Recolor Artwork](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/edit-colors-using-edit-colors-dialog.html)). The segmented wheel draws 24 hues by 5 saturations as solid patches, and its markers move freely as on the smooth wheel. The bars show one solid bar per recolored color in row order: a click selects a bar for the color sliders, and a drag moves its row without changing a color ([Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html)). The dialog opens on the smooth wheel; `display` (`smooth`, `segmented`, `bars`) is the dialog field. `tests_recolor` covers switching, the dialog height, segmented dragging and Brightness, and bar selection, editing, reordering, scrolling, Preview, Cancel and OK. Scores and estimates unchanged.
|
||||
- **Recolor Artwork base color and right-click menus:** a right-click on an Edit tab wheel marker or a color bar offers Set As Base Color, Select Shade, Color Picker and Remove Color, and a right-click elsewhere on the wheel offers Add New Color; a color added on a marker's line moves with that marker; Set Current Color As Base Color makes the selected color the base, and the harmony rules build from the base color whichever color is selected ([Edit swatch groups using the color wheel](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/edit-color-groups-using-the-color-wheel.html), [Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html), [archived user guide, pages 137 to 140](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf)). The base color is the row with `base: true`, or the first color shown; a color added on a marker's line follows the marker's `tie` with `follows`. VectorCraft's own rules: an added color takes the selected color's brightness, or its saturation on the brightness wheel (the base color's when none is selected), Select Shade's grid is 7 saturations by 7 brightnesses of the color's hue and moves the color as a drag of its marker would, and a tied color follows its marker only while the colors are unlinked (linked, every color moves). Tests: `a_markers_menu_sets_the_base_color_that_the_rules_build_from`, `select_shade_gives_a_marker_the_shade_clicked`, `a_markers_menu_opens_the_color_picker`, `add_new_color_on_a_markers_line_moves_with_that_marker` and `set_current_color_as_base_color_marks_the_selected_color` in `crates/ui-egui/src/tests/recolor.rs`, and `set_base_moves_the_base_mark`, `the_base_mark_follows_merge_separate_and_randomize`, `a_color_added_on_a_markers_line_moves_with_it` and `the_shade_grid_spans_saturation_and_brightness` in `crates/ui-egui/src/dialogs/recolor.rs`. Scores and estimates unchanged.
|
||||
- **Recolor Artwork Add Color and Remove Color tools:** under the display buttons beside the Edit tab's wheel, the Add Color tool adds the color clicked on either wheel to the color group, and the Remove Color tool removes the color whose marker is clicked; a color bar's right-click menu has Remove Color, and the base color can't be removed ([Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html), [Edit swatch groups using the color wheel](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/edit-color-groups-using-the-color-wheel.html)). An added color is a new row with no current colors and `added: true`; unlike a row made with New Row, it adds its new color to a rewritten color group, after the group's other colors. VectorCraft's own rules: an added color takes the base color's brightness, and with art or a group a removed color's row stays with its current colors and no new color, so that art keeps its colors and the group's swatch at that place is removed. `wheelTool` (`add`, `remove`) is the dialog field. Tests: `the_add_color_tool_adds_a_row_with_no_current_colors`, `an_added_color_joins_the_color_group`, `the_remove_color_tool_removes_a_marker_but_not_the_base_colors` and `a_color_bars_menu_removes_its_color` in `crates/ui-egui/src/tests/recolor.rs`, `apply_params_give_the_group_added_colors_and_keep_its_other_colors` in `crates/ui-egui/src/dialogs/recolor.rs`, and `an_added_empty_row_gives_the_group_its_color_after_the_others` in `crates/engine/src/tests/recolor.rs`. Scores and estimates unchanged.
|
||||
- **Recolor Artwork brightness and hue wheel:** a button under the Edit tab's wheel tools switches the wheel between hue with saturation and hue with brightness; a marker's angle sets its hue, and its distance from the center sets the component the wheel shows ([Recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/recolor-options-overview.html), [archived help, Edit colors](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=144)). VectorCraft's own rules: brightness runs from black at the center to full at the edge, the segmented wheel's five rings become brightness steps, the slider under the wheel edits the component the wheel leaves out (Saturation on the brightness wheel), Add Color takes the hue and brightness clicked at the base color's saturation, the choice holds for both wheels while the dialog is open and the button is off for the color bars, and each opening shows hue and saturation. `wheelAxes` (`hueSaturation`, `hueBrightness`) is the dialog field. Tests: `the_brightness_and_hue_wheel_swaps_the_wheel_axis_and_the_slider`, `a_marker_on_the_brightness_wheel_sets_hue_and_brightness`, `the_add_color_tool_on_the_brightness_wheel_adds_the_brightness_clicked` and `the_segmented_brightness_wheel_has_24_hues_by_5_brightnesses` in `crates/ui-egui/src/tests/recolor.rs`, and `an_added_color_on_the_brightness_wheel_takes_the_base_colors_saturation` in `crates/ui-egui/src/dialogs/recolor.rs`. Scores and estimates unchanged.
|
||||
- **Recolor Artwork Find:** the Assign tab's Find button finds the colors of the selected rows in the art ([Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html)): while it is on, their art shows as the preview shows it and the rest of the selected art shows dimmed, until a second click ([archived help, Recolor Artwork](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=149)). VectorCraft's own rules: a dimmed color is a 25% tint of its current color (or the nearest lighter tint when that one is a color a selected row lists), a color a selected row also lists is not dimmed, and Find records no undo step. `findColors` is the dialog field. Tests: `find_dims_the_colors_of_the_rows_not_selected` and `find_shows_the_selected_rows_art_and_dims_the_rest` in `crates/ui-egui/src/dialogs/recolor.rs`. Scores and estimates unchanged.
|
||||
|
||||
Reference in New Issue
Block a user