1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Form design documents (step 8.1, item H28; ADR-1).
//!
//! Forms are DataCraft design objects — they live in the sidecar, not in
//! the Jet/ACE file (ARCHITECTURE §7 ADR-1). Controls arrive with step
//! 8.2's control kinds; the skeleton carries name, snap grid and the
//! control list.
use serde::{Deserialize, Serialize};
use crate::canvas::Rect;
/// One control kind (the Access toolbox palette).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", content = "value", rename_all = "snake_case")]
pub enum ControlKind {
/// Static text.
Label {
/// The displayed text.
text: String,
},
/// Single-line edit bound to a source field (read-only until bound
/// field edits land — step 11.10, BACKLOG H40).
TextBox {
/// Bound source field, if any.
bound_field: Option<String>,
},
/// Checkbox bound to a boolean source field.
CheckBox {
/// Bound source field, if any.
bound_field: Option<String>,
},
/// Drop-down bound to a source field.
ComboBox {
/// Bound source field, if any.
bound_field: Option<String>,
},
/// Command button.
Button {
/// Button caption.
caption: String,
},
/// Embedded subform.
SubForm {
/// The embedded form's name.
form: String,
},
}
/// Canvas size in points.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct CanvasSize {
/// Canvas width.
pub width: f32,
/// Canvas height.
pub height: f32,
}
impl Default for CanvasSize {
fn default() -> Self {
Self {
width: 640.0,
height: 400.0,
}
}
}
/// One placed control.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ControlDef {
/// Control name (unique within its form, case-insensitive).
pub name: String,
/// Kind-specific payload.
pub kind: ControlKind,
/// Canvas placement (snapped).
pub rect: Rect,
}
/// Design document of one form.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FormDef {
/// Form name (unique in its database, case-insensitive).
pub name: String,
/// Source table for bound controls (empty until assigned; whitelisted
/// by `Command::SetFormSource`).
#[serde(default)]
pub source: String,
/// Snap grid in points (Access-like default: 8).
pub grid: f32,
/// Canvas size (default 640 x 400).
#[serde(default)]
pub size: CanvasSize,
/// Controls in tab order (paint order: back to front).
pub controls: Vec<ControlDef>,
}
impl FormDef {
/// Creates an empty form with the default snap grid.
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
source: String::new(),
grid: 8.0,
size: CanvasSize::default(),
controls: Vec::new(),
}
}
}