dioxus_use_window/layouts/
mod.rs1use std::{
2 fmt::{Debug, Display, Formatter},
3 num::ParseIntError,
4 str::FromStr,
5};
6
7#[derive(Debug, Copy, Clone)]
22pub enum ResponsiveLayout {
23 Tiny,
28 Small,
32 Medium,
36 Large,
40 ExtraLarge,
44 UltraLarge,
48}
49
50impl Default for ResponsiveLayout {
51 fn default() -> Self {
52 Self::Large
53 }
54}
55
56impl Display for ResponsiveLayout {
57 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
58 match self {
59 Self::Tiny => f.write_str("xs"),
60 Self::Small => f.write_str("sm"),
61 Self::Medium => f.write_str("md"),
62 Self::Large => f.write_str("lg"),
63 Self::ExtraLarge => f.write_str("xl"),
64 Self::UltraLarge => f.write_str("ul"),
65 }
66 }
67}
68
69impl From<usize> for ResponsiveLayout {
70 fn from(n: usize) -> Self {
71 match n {
72 n if n <= 375 => Self::Tiny,
73 n if n <= 640 => Self::Small,
74 n if n <= 992 => Self::Medium,
75 n if n <= 1366 => Self::Large,
76 n if n <= 2048 => Self::ExtraLarge,
77 _ => Self::UltraLarge,
78 }
79 }
80}
81
82impl FromStr for ResponsiveLayout {
83 type Err = ParseIntError;
84
85 #[inline]
86 fn from_str(s: &str) -> Result<Self, Self::Err> {
87 let out = match s.to_ascii_lowercase().as_str() {
88 "t" | "xs" | "tiny" => Self::Tiny,
89 "s" | "sm" | "small" => Self::Small,
90 "m" | "md" | "medium" => Self::Medium,
91 "l" | "lg" | "large" => Self::Large,
92 "x" | "xl" | "extra" => Self::ExtraLarge,
93 "u" | "ul" | "xxl" | "2xl" | "ultra" => Self::UltraLarge,
94 s => Self::from(s.parse::<usize>()?),
95 };
96 Ok(out)
97 }
98}