Drop Shadow: show opacity as a bounded percentage

This commit is contained in:
yoriswind committed 2026-12-03 11:39:42 -08:00
1 parent 64a7515fea
commit 37ebdf589d
2 files changed
+42 -4

No files matched your search

+36
View File
@@ -707,6 +707,42 @@ mod tests {
app.session.doc().unwrap().history.undo.len()
}
#[test]
fn drop_shadow_opacity_is_a_bounded_percentage() {
use crate::dialogs::tests::{frame, settle};
let mut app = app();
let node = rect(&mut app, 10);
app.run("select.all", json!({})).unwrap();
app.run("effect.dialog", json!({"effect": DROP_SHADOW})).unwrap();
settle(&mut app);
let output = frame(&mut app, vec![]);
let update = output.platform_output.accesskit_update.unwrap();
let (_, opacity) = update
.nodes
.iter()
.find(|(_, node)| node.label().is_some_and(|label| label.starts_with("Opacity")) && node.numeric_value() == Some(75.0))
.expect("the opacity number field");
assert!(opacity.value().is_some_and(|value| value.ends_with('%')));
assert_eq!((opacity.min_numeric_value(), opacity.max_numeric_value()), (Some(0.0), Some(100.0)));
let (ctx, dialog) = (app.ui_ctx.clone().unwrap(), id(&app));
let original_offsets = (number(&mut app, "x"), number(&mut app, "blur"));
for (bound, outside) in [(0.0, -5.0), (100.0, 125.0)] {
set(&mut app, "opacity", json!(bound));
let result = app.dialogs().unwrap().with(|h| h.set_json_field(&ctx, dialog, "opacity", json!(outside)));
assert!(result.is_err(), "out-of-range opacity {outside}");
assert_eq!(number(&mut app, "opacity"), Some(bound));
}
set(&mut app, "opacity", json!(40.5));
ok(&mut app);
let stored = params(&app, node);
assert_eq!(stored["opacity"].as_f64(), Some(40.5));
assert_eq!((stored["x"].as_f64(), stored["blur"].as_f64()), original_offsets);
app.run("effect.dialog", json!({"effect": DROP_SHADOW, "index": 0})).unwrap();
assert_eq!(number(&mut app, "opacity"), Some(40.5));
}
#[test]
fn halftone_dialog_normalizes_stored_style_case() {
let mut app = app();
+6 -4
View File
@@ -185,10 +185,12 @@ pub(super) fn scribble(cx: &EffectCx, fields: &DialogFields) -> Vec<Param> {
/// Drop Shadow: the generic rows with step arrows, then the Color/Darkness choice and its two fields.
pub(super) fn drop_shadow(cx: &EffectCx, fields: &DialogFields) -> Vec<Param> {
let shades = SHADES.iter().map(|(label, value)| ((*value).to_owned(), data_label(label))).collect();
let rows = generic(cx, fields)
.into_iter()
.filter(|p| !matches!(p.key.as_str(), "shade" | "color" | "darkness"))
.map(|p| if matches!(p.key.as_str(), "opacity" | "x" | "y" | "blur") { p.step_arrows(StepArrows::Leading) } else { p });
let rows = generic(cx, fields).into_iter().filter_map(|p| match p.key.as_str() {
"shade" | "color" | "darkness" => None,
"opacity" => Some(p.bounds(Some(0.0), Some(100.0)).unit(UnitKind::Percent).step_arrows(StepArrows::Leading)),
"x" | "y" | "blur" => Some(p.step_arrows(StepArrows::Leading)),
_ => Some(p),
});
rows.chain([
Param::new("shade", Label::Empty, ParamKind::radio(shades, None)),
Param::new("color", lbl!("Color"), ParamKind::color(None)).enabled_when("shade", "color").under_option("color"),