@mun-ui/ui 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +114 -2
- package/bin/compile.mjs +38 -0
- package/bin/desktop.mjs +143 -0
- package/bin/dev-protocol.mjs +94 -0
- package/bin/formatter.mjs +109 -0
- package/bin/hot-reload.mjs +38 -0
- package/bin/mun.mjs +538 -0
- package/bin/native.mjs +133 -0
- package/bin/pnpm-workspace.mjs +58 -0
- package/bin/program-patch.mjs +104 -0
- package/bin/project.mjs +322 -0
- package/bin/watch.mjs +316 -0
- package/bin/workflow.mjs +261 -0
- package/dist/astro.d.ts +3 -0
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +3 -0
- package/dist/astro.js.map +1 -0
- package/dist/closures.d.ts +2 -0
- package/dist/closures.d.ts.map +1 -0
- package/dist/closures.js +2 -0
- package/dist/closures.js.map +1 -0
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +2 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +3 -0
- package/dist/core.js.map +1 -0
- package/dist/experimental.d.ts +2 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +2 -0
- package/dist/experimental.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +2 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +2 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +2 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +2 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/legacy.d.ts +3 -0
- package/dist/legacy.d.ts.map +1 -0
- package/dist/legacy.js +3 -0
- package/dist/legacy.js.map +1 -0
- package/dist/mun.d.ts +5 -0
- package/dist/mun.d.ts.map +1 -0
- package/dist/mun.js +4 -0
- package/dist/mun.js.map +1 -0
- package/dist/progressive-blur/index.d.ts +8 -0
- package/dist/progressive-blur/index.d.ts.map +1 -0
- package/dist/progressive-blur/index.js +8 -0
- package/dist/progressive-blur/index.js.map +1 -0
- package/dist/progressive-blur/plan.d.ts +3 -0
- package/dist/progressive-blur/plan.d.ts.map +1 -0
- package/dist/progressive-blur/plan.js +3 -0
- package/dist/progressive-blur/plan.js.map +1 -0
- package/dist/react-types.d.ts +2 -0
- package/dist/react-types.d.ts.map +1 -0
- package/dist/react-types.js +2 -0
- package/dist/react-types.js.map +1 -0
- package/dist/rendering-quality.d.ts +4 -0
- package/dist/rendering-quality.d.ts.map +1 -0
- package/dist/rendering-quality.js +4 -0
- package/dist/rendering-quality.js.map +1 -0
- package/dist/state.d.ts +2 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +2 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +2 -0
- package/dist/vite.js.map +1 -0
- package/editors/install.mjs +102 -0
- package/editors/lsp/mun-lsp.mjs +123 -0
- package/editors/lsp/service.mjs +306 -0
- package/editors/lsp/source.mjs +58 -0
- package/editors/vscode/client.mjs +40 -0
- package/editors/vscode/dev-client.mjs +83 -0
- package/editors/vscode/discovery.mjs +46 -0
- package/editors/vscode/export.mjs +42 -0
- package/editors/vscode/extension.cjs +226 -0
- package/editors/vscode/language-configuration.json +15 -0
- package/editors/vscode/package.json +119 -0
- package/editors/vscode/protocol.mjs +29 -0
- package/editors/vscode/syntaxes/mun.tmLanguage.json +130 -0
- package/native/Cargo.lock +3581 -0
- package/native/Cargo.toml +21 -0
- package/native/README.md +21 -0
- package/native/mun-native/Cargo.toml +23 -0
- package/native/mun-native/src/accessibility.rs +738 -0
- package/native/mun-native/src/dev.rs +604 -0
- package/native/mun-native/src/host_services.rs +202 -0
- package/native/mun-native/src/lib.rs +2843 -0
- package/native/mun-native/src/main.rs +204 -0
- package/native/mun-native/src/offscreen.rs +393 -0
- package/native/mun-native/src/rect.wgsl +63 -0
- package/native/mun-native/src/text.rs +401 -0
- package/native/mun-native/tests/offscreen_rendering.rs +161 -0
- package/native/mun-native/tests/stress.rs +408 -0
- package/native/mun-native/tests/window_lifecycle.rs +183 -0
- package/native/mun-runtime/Cargo.toml +13 -0
- package/native/mun-runtime/src/accessibility.rs +193 -0
- package/native/mun-runtime/src/collection.rs +1090 -0
- package/native/mun-runtime/src/gesture.rs +1070 -0
- package/native/mun-runtime/src/input.rs +325 -0
- package/native/mun-runtime/src/ir.rs +852 -0
- package/native/mun-runtime/src/kinetics.rs +500 -0
- package/native/mun-runtime/src/layout.rs +258 -0
- package/native/mun-runtime/src/layout_cache.rs +209 -0
- package/native/mun-runtime/src/lib.rs +52 -0
- package/native/mun-runtime/src/motion.rs +1162 -0
- package/native/mun-runtime/src/retained.rs +574 -0
- package/native/mun-runtime/src/runtime.rs +7449 -0
- package/native/mun-runtime/src/scene.rs +567 -0
- package/native/mun-runtime/src/scroll.rs +521 -0
- package/native/mun-runtime/src/scroll_view.rs +220 -0
- package/native/mun-runtime/src/text_edit.rs +670 -0
- package/native/mun-runtime/src/timeline.rs +1534 -0
- package/native/mun-runtime/src/validate.rs +677 -0
- package/native/mun-runtime/tests/accessibility_semantics.rs +168 -0
- package/native/mun-runtime/tests/compiler_contract.rs +110 -0
- package/native/mun-runtime/tests/flexible_frames.rs +47 -0
- package/native/mun-runtime/tests/host_services.rs +107 -0
- package/native/mun-runtime/tests/hot_update.rs +367 -0
- package/native/mun-runtime/tests/incremental_runtime.rs +323 -0
- package/native/mun-runtime/tests/ir_validation.rs +167 -0
- package/native/mun-runtime/tests/keyed_collections.rs +251 -0
- package/native/mun-runtime/tests/minimum_window_size.rs +80 -0
- package/native/mun-runtime/tests/native_controls_style.rs +491 -0
- package/native/mun-runtime/tests/native_demo.rs +285 -0
- package/native/mun-runtime/tests/native_layout_style.rs +175 -0
- package/native/mun-runtime/tests/native_settings_pane.rs +152 -0
- package/native/mun-runtime/tests/priority_proposals.rs +69 -0
- package/native/mun-runtime/tests/scroll_view.rs +403 -0
- package/native/mun-runtime/tests/text_editing.rs +491 -0
- package/native/mun-runtime/tests/text_proposals.rs +42 -0
- package/native/mun-runtime/tests/typography.rs +63 -0
- package/package.json +213 -3
- package/schemas/README.md +19 -0
- package/schemas/semantic-ui-ir-v1.schema.json +2061 -0
- package/templates/desktop/gitignore +5 -0
- package/templates/desktop/package.json +10 -0
- package/templates/desktop/src-tauri/Cargo.toml +14 -0
- package/templates/desktop/src-tauri/build.rs +1 -0
- package/templates/desktop/src-tauri/capabilities/main.json +12 -0
- package/templates/desktop/src-tauri/icons/icon.icns +0 -0
- package/templates/desktop/src-tauri/icons/icon.ico +0 -0
- package/templates/desktop/src-tauri/icons/icon.png +0 -0
- package/templates/desktop/src-tauri/src/main.rs +2 -0
- package/templates/desktop/src-tauri/tauri.conf.json +42 -0
- package/templates/desktop/vite.config.ts +10 -0
- package/templates/native/App.mun +15 -0
- package/templates/native/gitignore +3 -0
- package/templates/native/mun.toml +8 -0
- package/templates/project/gitignore +5 -0
- package/templates/project/index.html +13 -0
- package/templates/project/package.json +24 -0
- package/templates/project/src/App.mun +13 -0
- package/templates/project/src/index.css +30 -0
- package/templates/project/src/main.ts +5 -0
- package/templates/project/tsconfig.json +20 -0
- package/templates/project/vite.config.ts +6 -0
- package/templates/vite/src/App.css +134 -0
- package/templates/vite/src/App.tsx +91 -0
- package/templates/vite/src/index.css +23 -0
- package/templates/vite/vite.config.ts +10 -0
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
use std::{env, fs};
|
|
2
|
+
|
|
3
|
+
use mun_runtime::{
|
|
4
|
+
Runtime,
|
|
5
|
+
input::{
|
|
6
|
+
ButtonState, InputEvent, InputPoint, KeyState, LogicalKey, PhysicalKey, PointerButton,
|
|
7
|
+
PointerId,
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
use serde_json::Value;
|
|
11
|
+
|
|
12
|
+
const WIDTH: f32 = 640.0;
|
|
13
|
+
const HEIGHT: f32 = 480.0;
|
|
14
|
+
|
|
15
|
+
fn approx(actual: f32, expected: f32) {
|
|
16
|
+
assert!(
|
|
17
|
+
(actual - expected).abs() < 0.01,
|
|
18
|
+
"expected {expected}, got {actual}"
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fn color_approx(actual: [f32; 4], expected: [f32; 4]) {
|
|
23
|
+
for (actual, expected) in actual.into_iter().zip(expected) {
|
|
24
|
+
assert!(
|
|
25
|
+
(actual - expected).abs() < 0.001,
|
|
26
|
+
"expected color channel {expected}, got {actual}"
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fn state_name<'a>(program: &'a Value, suffix: &str) -> &'a str {
|
|
32
|
+
program["states"]
|
|
33
|
+
.as_array()
|
|
34
|
+
.expect("states")
|
|
35
|
+
.iter()
|
|
36
|
+
.find_map(|state| {
|
|
37
|
+
let name = state["name"].as_str()?;
|
|
38
|
+
name.ends_with(suffix).then_some(name)
|
|
39
|
+
})
|
|
40
|
+
.unwrap_or_else(|| panic!("state ending in {suffix}"))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
fn child(node: &Value, index: usize) -> &Value {
|
|
44
|
+
&node["children"][index]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// The View inside the compiler's modifier layers (frame/padding/background
|
|
48
|
+
/// wrappers carry a `~n` id suffix and exactly one child).
|
|
49
|
+
fn core(node: &Value) -> &Value {
|
|
50
|
+
let mut current = node;
|
|
51
|
+
while current["kind"] == "overlay"
|
|
52
|
+
&& current["id"].as_str().is_some_and(|id| id.contains('~'))
|
|
53
|
+
&& current["children"]
|
|
54
|
+
.as_array()
|
|
55
|
+
.is_some_and(|children| children.len() == 1)
|
|
56
|
+
{
|
|
57
|
+
current = ¤t["children"][0];
|
|
58
|
+
}
|
|
59
|
+
current
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fn id(node: &Value) -> &str {
|
|
63
|
+
node["id"].as_str().expect("node id")
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fn click(runtime: &mut Runtime, x: f32, y: f32) {
|
|
67
|
+
let pointer = PointerId::MOUSE;
|
|
68
|
+
runtime
|
|
69
|
+
.handle_input(
|
|
70
|
+
InputEvent::PointerMoved {
|
|
71
|
+
pointer,
|
|
72
|
+
position: InputPoint::new(x, y),
|
|
73
|
+
},
|
|
74
|
+
WIDTH,
|
|
75
|
+
HEIGHT,
|
|
76
|
+
)
|
|
77
|
+
.expect("pointer move");
|
|
78
|
+
runtime
|
|
79
|
+
.handle_input(
|
|
80
|
+
InputEvent::PointerButton {
|
|
81
|
+
pointer,
|
|
82
|
+
button: PointerButton::Primary,
|
|
83
|
+
state: ButtonState::Pressed,
|
|
84
|
+
},
|
|
85
|
+
WIDTH,
|
|
86
|
+
HEIGHT,
|
|
87
|
+
)
|
|
88
|
+
.expect("pointer press");
|
|
89
|
+
runtime
|
|
90
|
+
.handle_input(
|
|
91
|
+
InputEvent::PointerButton {
|
|
92
|
+
pointer,
|
|
93
|
+
button: PointerButton::Primary,
|
|
94
|
+
state: ButtonState::Released,
|
|
95
|
+
},
|
|
96
|
+
WIDTH,
|
|
97
|
+
HEIGHT,
|
|
98
|
+
)
|
|
99
|
+
.expect("pointer release");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
fn key(runtime: &mut Runtime, logical: LogicalKey, physical: PhysicalKey) {
|
|
103
|
+
runtime
|
|
104
|
+
.handle_input(
|
|
105
|
+
InputEvent::Key {
|
|
106
|
+
logical,
|
|
107
|
+
physical,
|
|
108
|
+
state: KeyState::Pressed,
|
|
109
|
+
repeat: false,
|
|
110
|
+
},
|
|
111
|
+
WIDTH,
|
|
112
|
+
HEIGHT,
|
|
113
|
+
)
|
|
114
|
+
.expect("key press");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#[test]
|
|
118
|
+
#[ignore = "run through scripts/test-native-controls.sh after compiling canonical .mun source"]
|
|
119
|
+
fn canonical_controls_mutate_state_relayout_and_render_styles() {
|
|
120
|
+
let path = env::var("MUN_NATIVE_CONTROLS_IR")
|
|
121
|
+
.expect("MUN_NATIVE_CONTROLS_IR must point at compiler-produced IR");
|
|
122
|
+
let source = fs::read_to_string(&path).expect("read compiler-produced UI IR");
|
|
123
|
+
let program: Value = serde_json::from_str(&source).expect("parse compiler-produced UI IR");
|
|
124
|
+
|
|
125
|
+
// `.frame(300, 360).padding(12).background(c).cornerRadius(20)` is a
|
|
126
|
+
// padding layer around a frame layer around the VStack.
|
|
127
|
+
let padded = &program["root"]["child"];
|
|
128
|
+
let framed = child(padded, 0);
|
|
129
|
+
let root = core(padded);
|
|
130
|
+
assert_eq!(root["kind"], "column");
|
|
131
|
+
let field_layer = child(root, 0);
|
|
132
|
+
let radio_layer = child(root, 1);
|
|
133
|
+
let button_layer = child(root, 2);
|
|
134
|
+
let conditional = child(root, 3);
|
|
135
|
+
let tail_layer = child(root, 4);
|
|
136
|
+
let text_field = core(field_layer);
|
|
137
|
+
let radio = core(radio_layer);
|
|
138
|
+
let button = core(button_layer);
|
|
139
|
+
let tail = core(tail_layer);
|
|
140
|
+
assert_eq!(text_field["kind"], "textField");
|
|
141
|
+
assert_eq!(radio["kind"], "radioGroup");
|
|
142
|
+
assert_eq!(button["kind"], "action");
|
|
143
|
+
assert_eq!(conditional["kind"], "conditional");
|
|
144
|
+
assert_eq!(tail["kind"], "text");
|
|
145
|
+
|
|
146
|
+
let padded_id = id(padded);
|
|
147
|
+
let framed_id = id(framed);
|
|
148
|
+
let text_field_id = id(text_field);
|
|
149
|
+
let field_layer_id = id(field_layer);
|
|
150
|
+
let radio_id = id(radio);
|
|
151
|
+
let radio_layer_id = id(radio_layer);
|
|
152
|
+
let button_id = id(button);
|
|
153
|
+
let button_layer_id = id(button_layer);
|
|
154
|
+
let tail_id = id(tail);
|
|
155
|
+
let tail_layer_id = id(tail_layer);
|
|
156
|
+
let strip = &conditional["then"][0];
|
|
157
|
+
assert_eq!(strip["kind"], "row");
|
|
158
|
+
let strip_id = id(strip);
|
|
159
|
+
let circle = child(strip, 0);
|
|
160
|
+
let capsule = child(strip, 1);
|
|
161
|
+
let circle_id = id(circle);
|
|
162
|
+
let capsule_id = id(capsule);
|
|
163
|
+
|
|
164
|
+
let name_state = state_name(&program, "/name");
|
|
165
|
+
let choice_state = state_name(&program, "/choice");
|
|
166
|
+
let expanded_state = state_name(&program, "/expanded");
|
|
167
|
+
|
|
168
|
+
let mut runtime = Runtime::from_json(&source).expect("load compiler-produced UI IR");
|
|
169
|
+
assert_eq!(
|
|
170
|
+
runtime.state_value(name_state),
|
|
171
|
+
Some(&Value::String("Ada".into()))
|
|
172
|
+
);
|
|
173
|
+
assert_eq!(
|
|
174
|
+
runtime.state_value(choice_state),
|
|
175
|
+
Some(&Value::String("b".into()))
|
|
176
|
+
);
|
|
177
|
+
assert_eq!(
|
|
178
|
+
runtime.state_value(expanded_state),
|
|
179
|
+
Some(&Value::Bool(false))
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
let initial_accessibility = runtime
|
|
183
|
+
.build_accessibility_tree(WIDTH, HEIGHT)
|
|
184
|
+
.expect("initial accessibility/layout");
|
|
185
|
+
let bounds = |id: &str| initial_accessibility.node(id).expect("node bounds").bounds;
|
|
186
|
+
let padded_bounds = bounds(padded_id);
|
|
187
|
+
let framed_bounds = bounds(framed_id);
|
|
188
|
+
let field_bounds = bounds(text_field_id);
|
|
189
|
+
let field_layer_bounds = bounds(field_layer_id);
|
|
190
|
+
let radio_bounds = bounds(radio_id);
|
|
191
|
+
let radio_layer_bounds = bounds(radio_layer_id);
|
|
192
|
+
let button_bounds = bounds(button_id);
|
|
193
|
+
let button_layer_bounds = bounds(button_layer_id);
|
|
194
|
+
let tail_before = bounds(tail_layer_id);
|
|
195
|
+
|
|
196
|
+
// The fixed-size root is centered in the window; the frame is padded by 12.
|
|
197
|
+
approx(padded_bounds.width, 324.0);
|
|
198
|
+
approx(padded_bounds.height, 384.0);
|
|
199
|
+
approx(padded_bounds.x, (WIDTH - 324.0) / 2.0);
|
|
200
|
+
approx(padded_bounds.y, (HEIGHT - 384.0) / 2.0);
|
|
201
|
+
approx(framed_bounds.width, 300.0);
|
|
202
|
+
approx(framed_bounds.height, 360.0);
|
|
203
|
+
approx(framed_bounds.x, padded_bounds.x + 12.0);
|
|
204
|
+
// A TextField is flexible in width, so `.frame(width: 220)` sizes it;
|
|
205
|
+
// `.padding(6)` then surrounds it.
|
|
206
|
+
approx(field_bounds.width, 220.0);
|
|
207
|
+
approx(field_layer_bounds.width, 232.0);
|
|
208
|
+
approx(field_bounds.x, field_layer_bounds.x + 6.0);
|
|
209
|
+
approx(field_bounds.y, field_layer_bounds.y + 6.0);
|
|
210
|
+
// The Picker keeps its size and is centered in its 220×90 frame.
|
|
211
|
+
let radio_frame = bounds(id(child(radio_layer, 0)));
|
|
212
|
+
approx(radio_frame.width, 220.0);
|
|
213
|
+
approx(radio_frame.height, 90.0);
|
|
214
|
+
approx(radio_layer_bounds.width, 232.0);
|
|
215
|
+
approx(
|
|
216
|
+
radio_bounds.x - radio_frame.x,
|
|
217
|
+
(220.0 - radio_bounds.width) / 2.0,
|
|
218
|
+
);
|
|
219
|
+
approx(
|
|
220
|
+
radio_bounds.y - radio_frame.y,
|
|
221
|
+
(90.0 - radio_bounds.height) / 2.0,
|
|
222
|
+
);
|
|
223
|
+
// The Button keeps its size; its padding layer surrounds it.
|
|
224
|
+
approx(button_layer_bounds.width, button_bounds.width + 12.0);
|
|
225
|
+
approx(button_layer_bounds.height, button_bounds.height + 12.0);
|
|
226
|
+
// VStack(spacing: 8) between the outermost layers.
|
|
227
|
+
approx(
|
|
228
|
+
radio_layer_bounds.y,
|
|
229
|
+
field_layer_bounds.y + field_layer_bounds.height + 8.0,
|
|
230
|
+
);
|
|
231
|
+
approx(
|
|
232
|
+
button_layer_bounds.y,
|
|
233
|
+
radio_layer_bounds.y + radio_layer_bounds.height + 8.0,
|
|
234
|
+
);
|
|
235
|
+
approx(
|
|
236
|
+
tail_before.y,
|
|
237
|
+
button_layer_bounds.y + button_layer_bounds.height + 8.0,
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
let initial_scene = runtime.build_scene(WIDTH, HEIGHT).expect("initial scene");
|
|
241
|
+
let rect_of = |id: &str| {
|
|
242
|
+
initial_scene
|
|
243
|
+
.rects
|
|
244
|
+
.iter()
|
|
245
|
+
.find(|rect| rect.id == id)
|
|
246
|
+
.unwrap_or_else(|| panic!("scene rect {id}"))
|
|
247
|
+
};
|
|
248
|
+
let root_rect = rect_of(padded_id);
|
|
249
|
+
color_approx(
|
|
250
|
+
root_rect.color.0,
|
|
251
|
+
[8.0 / 255.0, 9.0 / 255.0, 10.0 / 255.0, 1.0],
|
|
252
|
+
);
|
|
253
|
+
approx(root_rect.corner_radius, 20.0);
|
|
254
|
+
|
|
255
|
+
let field_background = rect_of(field_layer_id);
|
|
256
|
+
color_approx(
|
|
257
|
+
field_background.color.0,
|
|
258
|
+
[32.0 / 255.0, 32.0 / 255.0, 48.0 / 255.0, 1.0],
|
|
259
|
+
);
|
|
260
|
+
approx(field_background.corner_radius, 8.0);
|
|
261
|
+
let field_text = initial_scene
|
|
262
|
+
.texts
|
|
263
|
+
.iter()
|
|
264
|
+
.find(|text| text.id == format!("{text_field_id}:text"))
|
|
265
|
+
.expect("textfield text");
|
|
266
|
+
assert_eq!(field_text.text, "Ada");
|
|
267
|
+
color_approx(
|
|
268
|
+
field_text.color.0,
|
|
269
|
+
[240.0 / 255.0, 240.0 / 255.0, 255.0 / 255.0, 1.0],
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
let button_background = rect_of(button_layer_id);
|
|
273
|
+
approx(button_background.corner_radius, 14.0);
|
|
274
|
+
color_approx(button_background.color.0, [1.0, 0.0, 0.0, 1.0]);
|
|
275
|
+
let button_gradient = initial_scene
|
|
276
|
+
.gradient_for(button_layer_id)
|
|
277
|
+
.expect("button gradient");
|
|
278
|
+
color_approx(button_gradient.start.0, [1.0, 0.0, 0.0, 1.0]);
|
|
279
|
+
color_approx(button_gradient.end.0, [0.0, 0.0, 1.0, 1.0]);
|
|
280
|
+
assert_eq!(button_gradient.start_point, [0.0, 0.5]);
|
|
281
|
+
assert_eq!(button_gradient.end_point, [1.0, 0.5]);
|
|
282
|
+
let button_label = initial_scene
|
|
283
|
+
.texts
|
|
284
|
+
.iter()
|
|
285
|
+
.find(|text| text.id == format!("{button_id}:label"))
|
|
286
|
+
.expect("button label");
|
|
287
|
+
color_approx(button_label.color.0, [1.0, 1.0, 1.0, 1.0]);
|
|
288
|
+
|
|
289
|
+
let tail_text = initial_scene
|
|
290
|
+
.texts
|
|
291
|
+
.iter()
|
|
292
|
+
.find(|text| text.id == tail_id)
|
|
293
|
+
.expect("tail text");
|
|
294
|
+
assert_eq!(tail_text.text, "Ada");
|
|
295
|
+
color_approx(
|
|
296
|
+
tail_text.color.0,
|
|
297
|
+
[171.0 / 255.0, 205.0 / 255.0, 239.0 / 255.0, 1.0],
|
|
298
|
+
);
|
|
299
|
+
let tail_background = rect_of(tail_layer_id);
|
|
300
|
+
color_approx(
|
|
301
|
+
tail_background.color.0,
|
|
302
|
+
[17.0 / 255.0, 18.0 / 255.0, 19.0 / 255.0, 1.0],
|
|
303
|
+
);
|
|
304
|
+
approx(tail_background.corner_radius, 4.0);
|
|
305
|
+
|
|
306
|
+
assert!(initial_scene.rects.iter().all(|rect| rect.id != circle_id));
|
|
307
|
+
assert!(initial_scene.rects.iter().all(|rect| rect.id != capsule_id));
|
|
308
|
+
|
|
309
|
+
// Pointer focus + real text input mutates the bound @State and redraws text.
|
|
310
|
+
click(
|
|
311
|
+
&mut runtime,
|
|
312
|
+
field_bounds.x + field_bounds.width * 0.5,
|
|
313
|
+
field_bounds.y + field_bounds.height * 0.5,
|
|
314
|
+
);
|
|
315
|
+
assert_eq!(runtime.focused_action(), Some(text_field_id));
|
|
316
|
+
runtime
|
|
317
|
+
.handle_input(
|
|
318
|
+
InputEvent::TextInput {
|
|
319
|
+
text: " Lovelace".into(),
|
|
320
|
+
},
|
|
321
|
+
WIDTH,
|
|
322
|
+
HEIGHT,
|
|
323
|
+
)
|
|
324
|
+
.expect("text input");
|
|
325
|
+
assert_eq!(
|
|
326
|
+
runtime.state_value(name_state),
|
|
327
|
+
Some(&Value::String("Ada Lovelace".into()))
|
|
328
|
+
);
|
|
329
|
+
key(&mut runtime, LogicalKey::Backspace, PhysicalKey::Backspace);
|
|
330
|
+
assert_eq!(
|
|
331
|
+
runtime.state_value(name_state),
|
|
332
|
+
Some(&Value::String("Ada Lovelac".into()))
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
let edited_scene = runtime.build_scene(WIDTH, HEIGHT).expect("edited scene");
|
|
336
|
+
assert_eq!(
|
|
337
|
+
edited_scene
|
|
338
|
+
.texts
|
|
339
|
+
.iter()
|
|
340
|
+
.find(|text| text.id == format!("{text_field_id}:text"))
|
|
341
|
+
.expect("edited field text")
|
|
342
|
+
.text,
|
|
343
|
+
"Ada Lovelac"
|
|
344
|
+
);
|
|
345
|
+
assert_eq!(
|
|
346
|
+
edited_scene
|
|
347
|
+
.texts
|
|
348
|
+
.iter()
|
|
349
|
+
.find(|text| text.id == tail_id)
|
|
350
|
+
.expect("edited bound Text")
|
|
351
|
+
.text,
|
|
352
|
+
"Ada Lovelac"
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
// Radio selection is a real interactive state mutation. Disabled options have no hit target.
|
|
356
|
+
assert!(
|
|
357
|
+
edited_scene
|
|
358
|
+
.actions
|
|
359
|
+
.iter()
|
|
360
|
+
.all(|action| action.id != format!("{radio_id}:option:2"))
|
|
361
|
+
);
|
|
362
|
+
let alpha_hit = edited_scene
|
|
363
|
+
.actions
|
|
364
|
+
.iter()
|
|
365
|
+
.find(|action| action.id == format!("{radio_id}:option:0"))
|
|
366
|
+
.expect("alpha radio hit");
|
|
367
|
+
click(
|
|
368
|
+
&mut runtime,
|
|
369
|
+
alpha_hit.rect.x + 5.0,
|
|
370
|
+
alpha_hit.rect.y + alpha_hit.rect.height * 0.5,
|
|
371
|
+
);
|
|
372
|
+
assert_eq!(runtime.focused_action(), Some(radio_id));
|
|
373
|
+
assert_eq!(
|
|
374
|
+
runtime.state_value(choice_state),
|
|
375
|
+
Some(&Value::String("a".into()))
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
key(
|
|
379
|
+
&mut runtime,
|
|
380
|
+
LogicalKey::ArrowRight,
|
|
381
|
+
PhysicalKey::ArrowRight,
|
|
382
|
+
);
|
|
383
|
+
assert_eq!(
|
|
384
|
+
runtime.state_value(choice_state),
|
|
385
|
+
Some(&Value::String("b".into()))
|
|
386
|
+
);
|
|
387
|
+
key(
|
|
388
|
+
&mut runtime,
|
|
389
|
+
LogicalKey::ArrowRight,
|
|
390
|
+
PhysicalKey::ArrowRight,
|
|
391
|
+
);
|
|
392
|
+
assert_eq!(
|
|
393
|
+
runtime.state_value(choice_state),
|
|
394
|
+
Some(&Value::String("a".into())),
|
|
395
|
+
"disabled radio option must be skipped"
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
// Activating the styled Button inserts a composed View and forces live re-layout.
|
|
399
|
+
let before_expand = runtime
|
|
400
|
+
.build_accessibility_tree(WIDTH, HEIGHT)
|
|
401
|
+
.expect("layout before expand");
|
|
402
|
+
let tail_y_before_expand = before_expand.node(tail_layer_id).expect("tail").bounds.y;
|
|
403
|
+
let button_hit = runtime
|
|
404
|
+
.build_scene(WIDTH, HEIGHT)
|
|
405
|
+
.expect("scene before expand")
|
|
406
|
+
.actions
|
|
407
|
+
.into_iter()
|
|
408
|
+
.find(|action| action.id == button_id)
|
|
409
|
+
.expect("button hit");
|
|
410
|
+
click(
|
|
411
|
+
&mut runtime,
|
|
412
|
+
button_hit.rect.x + button_hit.rect.width * 0.5,
|
|
413
|
+
button_hit.rect.y + button_hit.rect.height * 0.5,
|
|
414
|
+
);
|
|
415
|
+
assert_eq!(
|
|
416
|
+
runtime.state_value(expanded_state),
|
|
417
|
+
Some(&Value::Bool(true))
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
let expanded_accessibility = runtime
|
|
421
|
+
.build_accessibility_tree(WIDTH, HEIGHT)
|
|
422
|
+
.expect("expanded layout");
|
|
423
|
+
let strip_bounds = expanded_accessibility
|
|
424
|
+
.node(strip_id)
|
|
425
|
+
.expect("shape strip")
|
|
426
|
+
.bounds;
|
|
427
|
+
let circle_bounds = expanded_accessibility
|
|
428
|
+
.node(circle_id)
|
|
429
|
+
.expect("circle bounds")
|
|
430
|
+
.bounds;
|
|
431
|
+
let capsule_bounds = expanded_accessibility
|
|
432
|
+
.node(capsule_id)
|
|
433
|
+
.expect("capsule bounds")
|
|
434
|
+
.bounds;
|
|
435
|
+
let tail_after = expanded_accessibility
|
|
436
|
+
.node(tail_layer_id)
|
|
437
|
+
.expect("tail after")
|
|
438
|
+
.bounds;
|
|
439
|
+
|
|
440
|
+
// The VStack is centered in its fixed frame, so inserting the strip (plus
|
|
441
|
+
// one 8pt spacing) moves the tail down by half of that height.
|
|
442
|
+
approx(
|
|
443
|
+
tail_after.y - tail_y_before_expand,
|
|
444
|
+
(strip_bounds.height + 8.0) / 2.0,
|
|
445
|
+
);
|
|
446
|
+
approx(circle_bounds.width, 30.0);
|
|
447
|
+
approx(circle_bounds.height, 30.0);
|
|
448
|
+
approx(capsule_bounds.width, 60.0);
|
|
449
|
+
approx(capsule_bounds.height, 20.0);
|
|
450
|
+
approx(
|
|
451
|
+
capsule_bounds.x - (circle_bounds.x + circle_bounds.width),
|
|
452
|
+
8.0,
|
|
453
|
+
);
|
|
454
|
+
approx(
|
|
455
|
+
circle_bounds.y + circle_bounds.height,
|
|
456
|
+
capsule_bounds.y + capsule_bounds.height,
|
|
457
|
+
);
|
|
458
|
+
approx(circle_bounds.x, strip_bounds.x + 4.0);
|
|
459
|
+
|
|
460
|
+
let expanded_scene = runtime.build_scene(WIDTH, HEIGHT).expect("expanded scene");
|
|
461
|
+
let strip_background = expanded_scene
|
|
462
|
+
.rects
|
|
463
|
+
.iter()
|
|
464
|
+
.find(|rect| rect.id == strip_id)
|
|
465
|
+
.expect("composed view modifier background");
|
|
466
|
+
color_approx(
|
|
467
|
+
strip_background.color.0,
|
|
468
|
+
[12.0 / 255.0, 13.0 / 255.0, 14.0 / 255.0, 1.0],
|
|
469
|
+
);
|
|
470
|
+
approx(strip_background.corner_radius, 6.0);
|
|
471
|
+
|
|
472
|
+
let circle_rect = expanded_scene
|
|
473
|
+
.rects
|
|
474
|
+
.iter()
|
|
475
|
+
.find(|rect| rect.id == circle_id)
|
|
476
|
+
.expect("circle rect");
|
|
477
|
+
color_approx(circle_rect.color.0, [0.0, 1.0, 0.0, 1.0]);
|
|
478
|
+
approx(circle_rect.corner_radius, 15.0);
|
|
479
|
+
|
|
480
|
+
let capsule_rect = expanded_scene
|
|
481
|
+
.rects
|
|
482
|
+
.iter()
|
|
483
|
+
.find(|rect| rect.id == capsule_id)
|
|
484
|
+
.expect("capsule rect");
|
|
485
|
+
approx(capsule_rect.corner_radius, 10.0);
|
|
486
|
+
let capsule_gradient = expanded_scene
|
|
487
|
+
.gradient_for(capsule_id)
|
|
488
|
+
.expect("capsule foreground gradient");
|
|
489
|
+
color_approx(capsule_gradient.start.0, [0.0, 1.0, 1.0, 1.0]);
|
|
490
|
+
color_approx(capsule_gradient.end.0, [1.0, 0.0, 1.0, 1.0]);
|
|
491
|
+
}
|