Skip to main content

flowsurface_data/
layout.rs

1pub use dashboard::Dashboard;
2pub use pane::Pane;
3use serde::{Deserialize, Serialize};
4
5pub mod dashboard;
6pub mod pane;
7pub mod presets;
8
9pub const MAX_NAME_LENGTH: usize = 20;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Layout {
13    pub name: String,
14    pub dashboard: Dashboard,
15}
16
17impl Default for Layout {
18    fn default() -> Self {
19        Self {
20            name: "Default".to_string(),
21            dashboard: Dashboard::default(),
22        }
23    }
24}
25
26#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
27pub struct Window<T = f32> {
28    pub width: T,
29    pub height: T,
30    pub pos_x: T,
31    pub pos_y: T,
32}
33
34impl<T: Copy> Window<T> {
35    pub fn size(&self) -> iced_core::Size<T> {
36        iced_core::Size {
37            width: self.width,
38            height: self.height,
39        }
40    }
41
42    pub fn position(&self) -> iced_core::Point<T> {
43        iced_core::Point {
44            x: self.pos_x,
45            y: self.pos_y,
46        }
47    }
48}
49
50impl Default for Window<f32> {
51    fn default() -> Self {
52        Self {
53            width: 1024.0,
54            height: 768.0,
55            pos_x: 0.0,
56            pos_y: 0.0,
57        }
58    }
59}
60
61pub type WindowSpec = Window<f32>;
62
63impl From<(&iced_core::Point, &iced_core::Size)> for WindowSpec {
64    fn from((point, size): (&iced_core::Point, &iced_core::Size)) -> Self {
65        Self {
66            width: size.width,
67            height: size.height,
68            pos_x: point.x,
69            pos_y: point.y,
70        }
71    }
72}