|
|
@@ -12,24 +12,53 @@ pub struct GapConfig { |
| 12 |
12 |
pub outer_vertical: u32, |
| 13 |
13 |
} |
| 14 |
14 |
|
| 15 |
|
-pub const TILING: &str = "tiling"; |
| 16 |
|
-pub const NORMIE: &str = "normie"; |
| 17 |
|
-pub const FLOATING: &str = "floating"; |
|
15 |
+pub enum LayoutType { |
|
16 |
+ Tiling, |
|
17 |
+ Normie, |
|
18 |
+} |
| 18 |
19 |
|
| 19 |
|
-pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> { |
| 20 |
|
- match s.to_lowercase().as_str() { |
| 21 |
|
- TILING => Ok(Box::new(tiling::TilingLayout)), |
| 22 |
|
- NORMIE | FLOATING => Ok(Box::new(normie::NormieLayout)), |
| 23 |
|
- _ => Err(format!("Unknown layout: {}", s)), |
|
20 |
+impl LayoutType { |
|
21 |
+ pub fn new(&self) -> LayoutBox { |
|
22 |
+ match self { |
|
23 |
+ Self::Tiling => Box::new(tiling::TilingLayout), |
|
24 |
+ Self::Normie => Box::new(normie::NormieLayout), |
|
25 |
+ } |
|
26 |
+ } |
|
27 |
+ |
|
28 |
+ pub fn next(&self) -> Self { |
|
29 |
+ match self { |
|
30 |
+ Self::Tiling => Self::Normie, |
|
31 |
+ Self::Normie => Self::Tiling, |
|
32 |
+ } |
|
33 |
+ } |
|
34 |
+ |
|
35 |
+ pub fn as_str(&self) -> &'static str { |
|
36 |
+ match self { |
|
37 |
+ Self::Tiling => "tiling", |
|
38 |
+ Self::Normie => "normie", |
|
39 |
+ } |
| 24 |
40 |
} |
|
41 |
+ |
|
42 |
+ pub fn from_str(s: &str) -> Result<Self, String> { |
|
43 |
+ match s.to_lowercase().as_str() { |
|
44 |
+ "tiling" => Ok(Self::Tiling), |
|
45 |
+ "normie" | "floating" => Ok(Self::Normie), |
|
46 |
+ _ => Err(format!("Invalid Layout Type: {}", s)), |
|
47 |
+ } |
|
48 |
+ } |
|
49 |
+} |
|
50 |
+ |
|
51 |
+pub fn layout_from_str(s: &str) -> Result<LayoutBox, String> { |
|
52 |
+ let layout_type = LayoutType::from_str(s)?; |
|
53 |
+ Ok(layout_type.new()) |
| 25 |
54 |
} |
| 26 |
55 |
|
| 27 |
56 |
pub fn next_layout(current_name: &str) -> &'static str { |
| 28 |
|
- match current_name { |
| 29 |
|
- TILING => NORMIE, |
| 30 |
|
- NORMIE => TILING, |
| 31 |
|
- _ => TILING, |
| 32 |
|
- } |
|
57 |
+ LayoutType::from_str(current_name) |
|
58 |
+ .ok() |
|
59 |
+ .map(|layout_type| layout_type.next()) |
|
60 |
+ .unwrap_or(LayoutType::Tiling) |
|
61 |
+ .as_str() |
| 33 |
62 |
} |
| 34 |
63 |
|
| 35 |
64 |
pub trait Layout { |