Skip to main content

native_theme/model/
dialog_entrance_style.rs

1// Dialog entrance motion convention
2
3use serde::{Deserialize, Serialize};
4
5/// How a dialog moves onto the screen as it opens.
6///
7/// A **platform convention**, like
8/// [`DialogButtonOrder`](crate::model::DialogButtonOrder): WinUI's
9/// `ContentDialog`, libadwaita's floating `AdwDialog` and Material's dialog
10/// scale up while they fade in, KDE's `Kirigami.Dialog` fades in while it
11/// rises into place (`docs/platform-facts.md` ยง2.22, `entrance`). It names
12/// the motion only; its durations and curves are the toolkit's.
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
14pub enum DialogEntranceStyle {
15    /// Fades in while scaling up to its full size -- Windows, GNOME, Material.
16    #[serde(rename = "scale_fade")]
17    ScaleFade,
18    /// Fades in while rising into place from below -- KDE.
19    #[serde(rename = "fade_rise")]
20    FadeRise,
21}
22
23#[cfg(test)]
24#[allow(clippy::unwrap_used, clippy::expect_used)]
25mod tests {
26    use super::*;
27
28    // TOML cannot serialize a bare enum as a top-level value; use a wrapper struct.
29    #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
30    struct Wrapper {
31        entrance: DialogEntranceStyle,
32    }
33
34    #[test]
35    fn serde_round_trip_both_variants() {
36        for (variant, expected_str) in [
37            (DialogEntranceStyle::ScaleFade, "scale_fade"),
38            (DialogEntranceStyle::FadeRise, "fade_rise"),
39        ] {
40            let original = Wrapper { entrance: variant };
41            let serialized = toml::to_string(&original).unwrap();
42            assert!(serialized.contains(expected_str), "got: {serialized}");
43            let deserialized: Wrapper = toml::from_str(&serialized).unwrap();
44            assert_eq!(deserialized, original);
45        }
46    }
47
48    #[test]
49    fn an_unknown_entrance_is_rejected() {
50        assert!(toml::from_str::<Wrapper>(r#"entrance = "slide_down""#).is_err());
51    }
52}