logisheets_controller/controller/
display.rs1use crate::CellInfo;
2
3use super::style::Style;
4use logisheets_base::{BlockId, SheetId};
5use serde::Serialize;
6
7#[derive(Debug, Clone)]
8#[cfg_attr(
9 feature = "gents",
10 gents_derives::gents_header(file_name = "display_response.ts")
11)]
12pub struct DisplayResponse {
13 pub incremental: bool,
14 pub patches: Vec<DisplayPatch>,
15}
16
17#[derive(Debug, Clone)]
18#[cfg_attr(
19 feature = "gents",
20 gents_derives::gents_header(file_name = "cell_position.ts")
21)]
22pub struct CellPosition {
23 pub x: f64,
24 pub y: f64,
25}
26
27#[derive(Debug, Clone)]
28#[cfg_attr(
29 feature = "gents",
30 gents_derives::gents_header(file_name = "display_window.ts")
31)]
32pub struct DisplayWindow {
33 pub cells: Vec<CellInfo>,
34 pub rows: Vec<RowInfo>,
35 pub cols: Vec<ColInfo>,
36 pub comments: Vec<Comment>,
37 pub merge_cells: Vec<MergeCell>,
38 pub blocks: Vec<BlockInfo>,
39}
40
41#[derive(Debug, Clone)]
42#[cfg_attr(
43 feature = "gents",
44 gents_derives::gents_header(file_name = "display_window_with_start_point.ts")
45)]
46pub struct DisplayWindowWithStartPoint {
47 pub window: DisplayWindow,
48 pub start_x: f64,
49 pub start_y: f64,
50}
51
52#[derive(Debug, Clone)]
53#[cfg_attr(
54 feature = "gents",
55 gents_derives::gents_header(file_name = "display_patch.ts")
56)]
57pub enum DisplayPatch {
58 Values(SheetValues),
59 Styles(SheetStyles),
60 RowInfo(SheetRowInfo),
61 ColInfo(SheetColInfo),
62 MergeCells(SheetMergeCells),
63 Comments(SheetComments),
64 Blocks(SheetBlocks),
65 SheetNames(SheetNames),
66}
67
68#[derive(Debug, Clone)]
69#[cfg_attr(
70 feature = "gents",
71 gents_derives::gents_header(file_name = "sheet_names.ts")
72)]
73pub struct SheetNames {
74 pub names: Vec<String>,
75}
76
77#[cfg_attr(
78 feature = "gents",
79 gents_derives::gents_header(file_name = "sheet_info.ts")
80)]
81#[derive(Debug, Clone)]
82pub struct SheetInfo {
83 pub name: String,
84 pub id: SheetId,
85 pub hidden: bool,
86 pub tab_color: String,
87}
88
89#[derive(Debug, Clone)]
90#[cfg_attr(
91 feature = "gents",
92 gents_derives::gents_header(file_name = "sheet_blocks.ts")
93)]
94pub struct SheetBlocks {
95 pub sheet_idx: usize,
96 pub blocks: Vec<BlockInfo>,
97}
98
99#[derive(Debug, Clone)]
100#[cfg_attr(
101 feature = "gents",
102 gents_derives::gents_header(file_name = "block_info.ts")
103)]
104pub struct BlockInfo {
105 pub block_id: BlockId,
106 pub row_start: usize,
107 pub row_cnt: usize,
108 pub col_start: usize,
109 pub col_cnt: usize,
110}
111
112#[derive(Debug, Clone, Serialize)]
113#[cfg_attr(feature = "gents", derive(gents_derives::TS))]
114#[cfg_attr(
115 feature = "gents",
116 ts(file_name = "display_sheet_request.ts", rename_all = "camelCase")
117)]
118#[serde(rename_all = "camelCase")]
119pub struct DisplaySheetRequest {
120 pub sheet_idx: usize,
121 pub version: u32,
122}
123
124#[derive(Debug, Clone, Serialize)]
125#[cfg_attr(feature = "gents", derive(gents_derives::TS))]
126#[cfg_attr(
127 feature = "gents",
128 ts(file_name = "display_window_request.ts", rename_all = "camelCase")
129)]
130#[serde(rename_all = "camelCase")]
131pub struct DisplayWindowRequest {
132 pub sheet_idx: usize,
133 pub height: f64,
134 pub width: f64,
135 pub start_x: f64,
136 pub start_y: f64,
137}
138
139#[derive(Debug, Clone)]
140#[cfg_attr(
141 feature = "gents",
142 gents_derives::gents_header(file_name = "sheet_merge_cells.ts")
143)]
144pub struct SheetMergeCells {
145 pub sheet_idx: usize,
146 pub merge_cells: Vec<MergeCell>,
147}
148
149#[derive(Debug, Clone)]
150#[cfg_attr(
151 feature = "gents",
152 gents_derives::gents_header(file_name = "sheet_comments.ts")
153)]
154pub struct SheetComments {
155 pub sheet_idx: usize,
156 pub comments: Vec<Comment>,
157}
158
159#[derive(Debug, Clone)]
160#[cfg_attr(
161 feature = "gents",
162 gents_derives::gents_header(file_name = "merge_cell.ts")
163)]
164pub struct MergeCell {
165 pub row_start: usize,
166 pub col_start: usize,
167 pub row_end: usize,
168 pub col_end: usize,
169}
170
171#[derive(Debug, Clone)]
172#[cfg_attr(
173 feature = "gents",
174 gents_derives::gents_header(file_name = "comment.ts")
175)]
176pub struct Comment {
177 pub row: usize,
178 pub col: usize,
179 pub author: String,
180 pub content: String,
181}
182
183#[derive(Debug, Clone)]
184#[cfg_attr(
185 feature = "gents",
186 gents_derives::gents_header(file_name = "sheet_row_info.ts")
187)]
188pub struct SheetRowInfo {
189 pub sheet_idx: usize,
190 pub info: Vec<RowInfo>,
191 pub default_height: f64,
192}
193
194#[derive(Debug, Clone)]
195#[cfg_attr(
196 feature = "gents",
197 gents_derives::gents_header(file_name = "row_info.ts")
198)]
199pub struct RowInfo {
200 pub idx: usize,
201 pub height: f64,
202 pub hidden: bool,
203}
204
205impl RowInfo {
206 pub fn default(idx: usize) -> RowInfo {
207 Self {
208 idx,
209 height: get_default_row_height(),
210 hidden: false,
211 }
212 }
213}
214
215#[derive(Debug, Clone)]
216#[cfg_attr(
217 feature = "gents",
218 gents_derives::gents_header(file_name = "sheet_col_info.ts")
219)]
220pub struct SheetColInfo {
221 pub sheet_idx: usize,
222 pub info: Vec<ColInfo>,
223 pub default_width: f64,
224}
225
226#[derive(Debug, Clone)]
227#[cfg_attr(
228 feature = "gents",
229 gents_derives::gents_header(file_name = "col_info.ts")
230)]
231pub struct ColInfo {
232 pub idx: usize,
233 pub width: f64,
234 pub hidden: bool,
235}
236
237impl ColInfo {
238 pub fn default(idx: usize) -> Self {
239 Self {
240 idx,
241 width: get_default_col_width(),
242 hidden: false,
243 }
244 }
245}
246
247pub fn get_default_row_height() -> f64 {
248 15.
249}
250
251pub fn get_default_col_width() -> f64 {
252 8.43
253}
254
255#[derive(Debug, Clone, Default)]
256#[cfg_attr(feature = "gents", gents_derives::gents_header(file_name = "value.ts"))]
257pub enum Value {
258 Str(String),
259 Bool(bool),
260 Number(f64),
261 Error(String),
262 #[default]
263 Empty,
264}
265
266#[derive(Debug, Clone)]
267#[cfg_attr(
268 feature = "gents",
269 gents_derives::gents_header(file_name = "cell_formula_value.ts")
270)]
271pub struct CellFormulaValue {
272 pub row: usize,
273 pub col: usize,
274 pub formula: String,
275 pub value: Value,
276}
277
278#[derive(Debug, Clone)]
279#[cfg_attr(
280 feature = "gents",
281 gents_derives::gents_header(file_name = "sheet_values.ts")
282)]
283pub struct SheetValues {
284 pub sheet_idx: usize,
285 pub values: Vec<CellFormulaValue>,
286}
287
288#[derive(Debug, Clone)]
289#[cfg_attr(
290 feature = "gents",
291 gents_derives::gents_header(file_name = "cell_style.ts")
292)]
293pub struct CellStyle {
294 pub row: usize,
295 pub col: usize,
296 pub style: Style,
297}
298
299#[derive(Debug, Clone)]
300#[cfg_attr(
301 feature = "gents",
302 gents_derives::gents_header(file_name = "sheet_styles.ts")
303)]
304pub struct SheetStyles {
305 pub sheet_idx: usize,
306 pub styles: Vec<CellStyle>,
307}