mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-02 10:38:15 -06:00
Format: the Font dialog gives an unknown preset or system name as the color it draws
A preset or system color name kept from an opened file that the color parser does not know is given to the dialog as its drawn RGB (black for a preset, the stored last color for a system color), so OK no longer rejects the color when another field changes.
This commit is contained in:
@@ -422,6 +422,24 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn font_dialog_ok_accepts_preset_and_system_names_it_does_not_know() {
|
||||
use deckcraft_color::Rgba;
|
||||
let last = Rgba::rgb(0x12, 0x34, 0x56);
|
||||
let preset = ColorRef { base: ColorBase::Preset { name: "notAColor".into() }, mods: vec![] }.with(ColorTransform::LumMod(50_000));
|
||||
let system = ColorRef { base: ColorBase::System { name: "notAColor".into(), last }, mods: vec![] };
|
||||
for (color, drawn) in [(preset, ColorRef::rgb(Rgba::BLACK).with(ColorTransform::LumMod(50_000))), (system, ColorRef::rgb(last))] {
|
||||
let mut s = shape();
|
||||
let fill = Fill::Solid { color };
|
||||
format_run(&mut s, &|r| r.fill = Some(fill.clone())).unwrap();
|
||||
s.ui_requests.clear();
|
||||
s.execute("format.fontDialog", &json!({})).unwrap();
|
||||
let Some(UiRequest::Dialog { params, .. }) = s.ui_requests.last().cloned() else { panic!("dialog request") };
|
||||
s.execute("format.fontDialog", &json!({"color": params["color"], "size": 20.0})).unwrap();
|
||||
assert_eq!(props(&s).fill, Some(Fill::Solid { color: drawn }), "{}", params["color"]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn font_dialog_color_mods_round_trip_and_unknown_ops_are_errors() {
|
||||
let two = ColorRef { base: ColorBase::Preset { name: "red".into() }, mods: vec![] }
|
||||
|
||||
@@ -396,7 +396,14 @@ fn color_command_value(c: &deckcraft_model::ColorRef) -> Value {
|
||||
}
|
||||
// `#RRGGBB`, or `#RRGGBBAA` for a color that is not opaque.
|
||||
let hex = |c: &deckcraft_color::Rgba| if c.a == 255 { format!("#{}", c.hex()) } else { format!("#{}{:02X}", c.hex(), c.a) };
|
||||
match &c.base {
|
||||
// A preset or system name that `color_value` does not know (kept from an opened file) is given as
|
||||
// the color it is drawn with, so OK does not reject it.
|
||||
let base = match &c.base {
|
||||
ColorBase::Preset { name } if !deckcraft_color::is_preset_name(name) => ColorBase::Rgb { rgb: deckcraft_color::Rgba::BLACK },
|
||||
ColorBase::System { name, last } if !deckcraft_color::is_system_name(name) => ColorBase::Rgb { rgb: *last },
|
||||
b => b.clone(),
|
||||
};
|
||||
match &base {
|
||||
ColorBase::Rgb { rgb } if o.is_empty() => json!(hex(rgb)),
|
||||
ColorBase::Rgb { rgb } => {
|
||||
o.insert("rgb".into(), json!(hex(rgb)));
|
||||
|
||||
Reference in New Issue
Block a user