Skip to main content

webizen_studio/
canvas_model.rs

1//! Shared workspace **manifold** types (work surfaces).
2//!
3//! A manifold is a page of panes — not an HTML `<canvas>` and not a wgpu surface.
4//! Those drawing surfaces stay named canvas.
5
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9use crate::theme_engine::{ThemeBinding, ThemeDefinition};
10
11#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
12pub enum LayoutStrategy {
13    PointGrid {
14        width_points: u16,
15        height_points: u16,
16        snap_step: u16,
17        gutter: u16,
18    },
19    CssGrid {
20        cols: u8,
21        rows: u8,
22        gap: u8,
23    },
24    FlexBox,
25    Masonry,
26}
27
28impl Default for LayoutStrategy {
29    fn default() -> Self {
30        Self::PointGrid {
31            width_points: 96,
32            height_points: 64,
33            snap_step: 2,
34            gutter: 2,
35        }
36    }
37}
38
39#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
40pub enum PresentationMode {
41    GridBound,
42    NodeRelational,
43    Spatial,
44}
45
46impl Default for PresentationMode {
47    fn default() -> Self {
48        Self::GridBound
49    }
50}
51
52#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
53pub enum CoordinateSpace {
54    GlobalCartesian,
55    RelativeAnchored,
56}
57
58impl Default for CoordinateSpace {
59    fn default() -> Self {
60        Self::GlobalCartesian
61    }
62}
63
64#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
65pub enum UiMode {
66    NativeAether,
67    IFrameSandbox,
68}
69
70#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
71pub enum LayerBehavior {
72    Docked,
73    FloatingOverlay,
74    ModalOverlay,
75    #[serde(alias = "FullCanvas")]
76    FullManifold,
77}
78
79impl Default for LayerBehavior {
80    fn default() -> Self {
81        Self::Docked
82    }
83}
84
85#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
86pub struct PanePlacement {
87    pub component_id: String,
88    pub x: u16,
89    pub y: u16,
90    pub w: u16,
91    pub h: u16,
92    pub data_bindings: Vec<String>,
93    #[serde(default)]
94    pub binds_rpc: Option<String>,
95    #[serde(default)]
96    pub requires_capability: Vec<String>,
97    #[serde(default)]
98    pub ui_mode: Option<UiMode>,
99    #[serde(default)]
100    pub layer: LayerBehavior,
101    #[serde(default)]
102    pub anchor: Option<String>,
103    #[serde(default)]
104    pub min_w_points: u16,
105    #[serde(default)]
106    pub min_h_points: u16,
107    #[serde(default)]
108    pub supported_presentations: Vec<PresentationMode>,
109    #[serde(default)]
110    pub theme: ThemeBinding,
111}
112
113/// One work surface. Product name: manifold.
114#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
115pub struct Page {
116    pub url_path: String,
117    pub name: String,
118    #[serde(default)]
119    pub layout_strategy: LayoutStrategy,
120    pub panes: Vec<PanePlacement>,
121    #[serde(default)]
122    pub presentation_mode: PresentationMode,
123    #[serde(default)]
124    pub coordinate_space: CoordinateSpace,
125    #[serde(default)]
126    pub pan_and_zoom: bool,
127    #[serde(default)]
128    pub theme: ThemeBinding,
129}
130
131#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
132pub struct WebizenWorkspace {
133    pub pages: Vec<Page>,
134    #[serde(default)]
135    pub theme_tokens: HashMap<String, String>,
136    #[serde(default)]
137    pub themes: Vec<ThemeDefinition>,
138    #[serde(default)]
139    pub environment_theme: ThemeBinding,
140    #[serde(default)]
141    pub app_theme: ThemeBinding,
142}
143
144/// Product name for a work-surface page.
145pub type Manifold = Page;