Save for Web: Lock, Transparent and Web Shift are off for a selected color the table no longer shows

The three buttons act on the last color clicked (__color). After a change of reduction or color count, or through ui.dialog.set, that color can be one the table no longer shows, and a click added it to locked, transparent or webShift. The buttons are now enabled only when the table shows that color, the same check Delete Color uses.
This commit is contained in:
dotCooCoo
2026-11-17 19:13:47 -08:00
parent fc5460d18e
commit d1e9fc67db
3 changed files with 34 additions and 4 deletions
+6 -3
View File
@@ -1177,10 +1177,15 @@ fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Re
d.fields.insert("__editStart".into(), json!(start));
}
let shifted = |c: &str| table.shifted.keys().any(|k| k.eq_ignore_ascii_case(c));
// The colors the table shows, by source: Lock, Transparent, Web Shift and Delete Color act only
// on these.
let palette: Vec<String> =
shot.colors.iter().filter(|c| !c.transparent).map(|c| hex(c.source)).chain(shot.mapped.iter().map(|c| hex(*c))).collect();
let shown = palette.iter().any(|p| p.eq_ignore_ascii_case(&selected));
ui.add_space(4.0);
let on = |list: &[String]| list.iter().any(|h| h.eq_ignore_ascii_case(&selected));
ui.horizontal(|ui| {
ui.add_enabled_ui(!selected.is_empty(), |ui| {
ui.add_enabled_ui(shown, |ui| {
for (list, on_label, off_label) in [
("transparent", tl!("Restore"), tl!("Transparent")),
("webShift", tl!("Unshift"), tl!("Web Shift")),
@@ -1207,8 +1212,6 @@ fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Re
});
// Delete Color (the button and the table's menu) and Restore Generated Table. Delete Color
// takes only selected colors the table shows (`palette`, by source).
let palette: Vec<String> =
shot.colors.iter().filter(|c| !c.transparent).map(|c| hex(c.source)).chain(shot.mapped.iter().map(|c| hex(*c))).collect();
let deletable = !selected_in(d, &palette).is_empty();
let (mut delete, mut restore, mut unshift_all) = (false, false, false);
ui.horizontal(|ui| {
@@ -928,6 +928,32 @@ fn dialog_set_edit_color_opens_the_color_picker() {
assert_eq!((kind(&app), shifted), (Some(save_for_web::KIND), Some(json!({"#0000ff": "#00ff00"}))));
}
/// Lock, Transparent and Web Shift are off while the selected color (`__color`) is one the table
/// no longer shows, so a click adds it to no list; with a color the table shows, Lock locks it.
#[test]
fn table_buttons_skip_a_selected_color_the_table_does_not_show() {
let dir = vectorcraft_testkit::temp_dir("sfw-stale-anchor");
let (mut app, _) = app(&dir, false);
app.run("shape.rectangle", json!({"x": 40, "y": 0, "width": 20, "height": 40})).unwrap();
app.run("paint.setFill", json!({"color": "#0000ff"})).unwrap();
app.run("file.saveForWeb", json!({})).unwrap();
for (k, v) in [("format", json!("gif")), ("antiAlias", json!("none")), ("dither", json!("none"))] {
set(&mut app, k, v);
}
let table = |app: &VectorcraftApp| app.ui.dialog.as_ref().and_then(|d| d.fields.get("colorTable").cloned()).unwrap_or_default();
let has = |app: &VectorcraftApp, list: &str, c: &str| table(app)[list].as_array().is_some_and(|l| l.iter().any(|v| v == c));
set(&mut app, "__color", json!("#abcdef"));
for label in ["Lock", "Transparent", "Web Shift"] {
click_text(&mut app, label);
}
for list in ["locked", "transparent", "webShift"] {
assert!(!has(&app, list, "#abcdef"), "{list}: {}", table(&app));
}
set(&mut app, "__color", json!("#0000ff"));
click_text(&mut app, "Lock");
assert!(has(&app, "locked", "#0000ff"), "{}", table(&app));
}
/// Click the dialog's text `label` with the pointer (frames a quarter second apart).
fn click_text(app: &mut VectorcraftApp, label: &str) {
let ctx = egui::Context::default();
+2 -1
View File
@@ -9050,7 +9050,8 @@ the dialog a click selects one color, Shift-click selects the colors between it
Ctrl-click (Command-click on macOS) adds or removes one (`__colors` holds the selection, `__color` the last one
clicked). The trash button and Delete Color in the table's menu delete the selected colors the table shows in one edit,
and are off when it shows none of them (a selected color can leave the table when the reduction or the color count
changes). Restore Generated
changes). The Lock, Transparent and Web Shift buttons act on the last color clicked, and are off when the table no longer
shows it. Restore Generated
Table in that menu clears `deleted` and `customPalette`, and the table reads Custom while either is set. Choosing
another reduction in the dialog also clears them.