theme: derive elevations from the platform's native shadows

This commit is contained in:
2026-11-01 09:54:35 +07:00
parent 5a32401e25
commit d107f35084
4 changed files with 127 additions and 37 deletions
+31 -2
View File
@@ -220,7 +220,7 @@ pub(crate) fn resolve(
},
colors,
radius,
elevations: Elevations::default(),
elevations: Elevations::for_platform(system.source, variant),
motion: Motion::default(),
scrollbar: Scrollbar::default(),
root_font_size,
@@ -361,13 +361,42 @@ mod tests {
);
// The popover shadow is softer and tighter than the dialog's.
assert!(resolved.elevations.popover.blur_radius < resolved.elevations.dialog.blur_radius);
assert!(
resolved.elevations.popover.layers[0].blur_radius
< resolved.elevations.dialog.layers[0].blur_radius
);
assert!(resolved.motion.overlay > std::time::Duration::ZERO);
let shadows = resolved.elevations.popover.shadows();
assert_eq!(shadows.len(), 1);
assert!(!shadows[0].inset);
}
#[test]
fn elevations_follow_the_platform_in_light_mode_and_share_one_dark_stack() {
let popover = |source| {
let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None);
stated.source = source;
resolve(&stated, None, None).elevations.popover
};
// macOS paints a soft layered stack; Linux keeps a compact single one.
assert_eq!(popover(SourceKind::Macos).shadows().len(), 2);
assert_eq!(popover(SourceKind::Gnome).shadows().len(), 1);
assert!(
popover(SourceKind::Macos).layers[0].color.a
< popover(SourceKind::Gnome).layers[0].color.a
);
// Dark mode is one shared stack, however the adapter detected.
let dark = |source| {
let mut stated = system(ThemeVariant::Dark, PartialPalette::default(), None);
stated.source = source;
resolve(&stated, None, None).elevations
};
assert_eq!(dark(SourceKind::Macos), dark(SourceKind::Windows));
assert_eq!(dark(SourceKind::Macos), dark(SourceKind::Fallback));
}
#[test]
fn system_colors_override_the_base_but_leave_the_rest_intact() {
let palette = PartialPalette {