mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-24 10:09:01 -06:00
Merge PR #2626
This commit is contained in:
@@ -340,7 +340,7 @@ fn import_into_album(app: &mut LightcraftApp, p: &Value, r: Result<Value, String
|
|||||||
pub fn parse_rgb(v: &Value) -> Option<[u8; 3]> {
|
pub fn parse_rgb(v: &Value) -> Option<[u8; 3]> {
|
||||||
if let Some(s) = v.as_str() {
|
if let Some(s) = v.as_str() {
|
||||||
let h = s.strip_prefix('#').unwrap_or(s);
|
let h = s.strip_prefix('#').unwrap_or(s);
|
||||||
if h.len() != 6 {
|
if h.len() != 6 || !h.bytes().all(|b| b.is_ascii_hexdigit()) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let c = |i: usize| u8::from_str_radix(h.get(i..i + 2)?, 16).ok();
|
let c = |i: usize| u8::from_str_radix(h.get(i..i + 2)?, 16).ok();
|
||||||
|
|||||||
@@ -295,6 +295,21 @@ fn radial_body_drag_keeps_resize_and_rotation_handles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mask_overlay_color_refuses_anything_but_six_hex_digits() {
|
||||||
|
let mut h = detail("panel.masking");
|
||||||
|
exec(&mut h, "view.maskOverlayColor", json!({"color": "#2870f0"}));
|
||||||
|
for bad in ["#+f+f+f", "+12345", "#-0-0-0", "##ffffff"] {
|
||||||
|
let r = h.request("engine.execute", json!({"command": "view.maskOverlayColor", "params": {"color": bad}}), T);
|
||||||
|
assert_eq!(r["ok"], false, "{bad:?} is not a colour: {r}");
|
||||||
|
assert_eq!(h.app.ui.mask_overlay_color, [0x28, 0x70, 0xf0], "{bad:?} leaves the overlay colour alone");
|
||||||
|
}
|
||||||
|
exec(&mut h, "view.maskOverlayColor", json!({"color": "e63228"}));
|
||||||
|
assert_eq!(h.app.ui.mask_overlay_color, [0xe6, 0x32, 0x28]);
|
||||||
|
exec(&mut h, "view.maskOverlayColor", json!({"color": [10, 20, 30]}));
|
||||||
|
assert_eq!(h.app.ui.mask_overlay_color, [10, 20, 30]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mask_overlay_keys_and_pins() {
|
fn mask_overlay_keys_and_pins() {
|
||||||
use lightcraft_pipeline::{MaskView, Overlay};
|
use lightcraft_pipeline::{MaskView, Overlay};
|
||||||
|
|||||||
Reference in New Issue
Block a user