@mun-ui/ui 0.0.0-stage → 0.2.0
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 +104 -2
- package/bin/compile.mjs +38 -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 +521 -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/lib.rs +2676 -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 +310 -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 +1073 -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 +782 -0
- package/native/mun-runtime/src/kinetics.rs +500 -0
- package/native/mun-runtime/src/layout.rs +173 -0
- package/native/mun-runtime/src/layout_cache.rs +209 -0
- package/native/mun-runtime/src/lib.rs +49 -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 +7078 -0
- package/native/mun-runtime/src/scene.rs +530 -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/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/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/scroll_view.rs +403 -0
- package/native/mun-runtime/tests/text_editing.rs +491 -0
- package/package.json +210 -3
- package/schemas/README.md +19 -0
- package/schemas/semantic-ui-ir-v1.schema.json +1972 -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 +21 -0
- package/templates/project/src/App.mun +13 -0
- package/templates/project/src/index.css +21 -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,403 @@
|
|
|
1
|
+
use mun_runtime::{InputEvent, InputPoint, PointerId, Runtime, ScrollDelta, ScrollPhase};
|
|
2
|
+
use serde_json::{Value, json};
|
|
3
|
+
fn literal(value: impl Into<Value>) -> Value {
|
|
4
|
+
json!({"kind":"literal","value":value.into()})
|
|
5
|
+
}
|
|
6
|
+
fn action(id: &str) -> Value {
|
|
7
|
+
json!({"kind":"action","id":id,"label":id,"layout":{"width":literal(100),"height":literal(40)},"action":{"kind":"toggle-state","state":"flag"}})
|
|
8
|
+
}
|
|
9
|
+
fn scroll(id: &str, height: i32, children: Vec<Value>) -> Value {
|
|
10
|
+
json!({"kind":"scroll","id":id,"axis":"vertical","layout":{"width":literal(100),"height":literal(height)},"children":children})
|
|
11
|
+
}
|
|
12
|
+
/// Pins the content to the window's top-leading corner (SwiftUI centers a
|
|
13
|
+
/// fixed-size root), so the fixtures can use window coordinates directly.
|
|
14
|
+
fn top_leading(child: Value) -> Value {
|
|
15
|
+
json!({"kind":"overlay","id":"frame","alignment":"topLeading","layout":{"maxWidth":"infinity","maxHeight":"infinity"},"children":[child]})
|
|
16
|
+
}
|
|
17
|
+
fn runtime(child: Value) -> Runtime {
|
|
18
|
+
Runtime::from_json(&json!({"version":1,"sourceLanguage":"mun","entry":"Test","states":[{"name":"flag","initial":false}],"root":{"kind":"window","id":"window","title":"Test","child":top_leading(child)}}).to_string()).unwrap()
|
|
19
|
+
}
|
|
20
|
+
fn wheel(r: &mut Runtime, x: f32, y: f32, delta: f32) {
|
|
21
|
+
r.handle_input(
|
|
22
|
+
InputEvent::PointerMoved {
|
|
23
|
+
pointer: PointerId::MOUSE,
|
|
24
|
+
position: InputPoint::new(x, y),
|
|
25
|
+
},
|
|
26
|
+
300.0,
|
|
27
|
+
300.0,
|
|
28
|
+
)
|
|
29
|
+
.unwrap();
|
|
30
|
+
let outcome = r
|
|
31
|
+
.handle_input(
|
|
32
|
+
InputEvent::Scroll {
|
|
33
|
+
pointer: Some(PointerId::MOUSE),
|
|
34
|
+
delta: ScrollDelta::Pixels { x: 0.0, y: delta },
|
|
35
|
+
phase: ScrollPhase::Changed,
|
|
36
|
+
},
|
|
37
|
+
300.0,
|
|
38
|
+
300.0,
|
|
39
|
+
)
|
|
40
|
+
.unwrap();
|
|
41
|
+
assert!(outcome.needs_redraw);
|
|
42
|
+
}
|
|
43
|
+
#[test]
|
|
44
|
+
fn viewport_layout_extent_clipping_hit_test_and_accessibility_agree() {
|
|
45
|
+
let mut r = runtime(scroll(
|
|
46
|
+
"scroll",
|
|
47
|
+
60,
|
|
48
|
+
vec![action("a"), action("b"), action("c")],
|
|
49
|
+
));
|
|
50
|
+
let frame = r.build_frame(300.0, 300.0).unwrap();
|
|
51
|
+
assert_eq!(r.scroll_view("scroll").unwrap().extent[1], 120.0);
|
|
52
|
+
assert_eq!(frame.scene.action_at(20.0, 20.0), Some("a"));
|
|
53
|
+
assert_eq!(frame.scene.action_at(20.0, 70.0), None);
|
|
54
|
+
wheel(&mut r, 20.0, 20.0, -40.0);
|
|
55
|
+
let frame = r.build_frame(300.0, 300.0).unwrap();
|
|
56
|
+
assert_eq!(r.scroll_view("scroll").unwrap().offset[1], 40.0);
|
|
57
|
+
assert_eq!(frame.scene.action_at(20.0, 20.0), Some("b"));
|
|
58
|
+
assert_eq!(frame.accessibility.node("b").unwrap().bounds.y, 0.0);
|
|
59
|
+
assert_eq!(frame.accessibility.node("c").unwrap().bounds.height, 20.0);
|
|
60
|
+
assert_eq!(frame.scene.action_at(20.0, 70.0), None);
|
|
61
|
+
}
|
|
62
|
+
#[test]
|
|
63
|
+
fn nested_scroll_consumes_inner_then_routes_residual_to_outer() {
|
|
64
|
+
let mut r = runtime(scroll(
|
|
65
|
+
"outer",
|
|
66
|
+
60,
|
|
67
|
+
vec![
|
|
68
|
+
scroll("inner", 40, vec![action("a"), action("b"), action("c")]),
|
|
69
|
+
action("d"),
|
|
70
|
+
action("e"),
|
|
71
|
+
],
|
|
72
|
+
));
|
|
73
|
+
wheel(&mut r, 20.0, 20.0, -90.0);
|
|
74
|
+
assert_eq!(r.scroll_view("inner").unwrap().offset[1], 80.0);
|
|
75
|
+
assert_eq!(r.scroll_view("outer").unwrap().offset[1], 10.0);
|
|
76
|
+
let frame = r.build_frame(300.0, 300.0).unwrap();
|
|
77
|
+
assert_eq!(frame.scene.action_at(20.0, 20.0), Some("c"));
|
|
78
|
+
assert_eq!(frame.scene.action_at(20.0, 35.0), Some("d"));
|
|
79
|
+
}
|
|
80
|
+
#[test]
|
|
81
|
+
fn conditional_removal_clamps_extent_and_resize_preserves_valid_offset() {
|
|
82
|
+
let branch = json!({"kind":"conditional","id":"branch","condition":{"kind":"state","state":"flag"},"then":[action("extra")],"otherwise":[]});
|
|
83
|
+
let mut r = runtime(scroll("scroll", 60, vec![action("a"), action("b"), branch]));
|
|
84
|
+
r.activate_action("a");
|
|
85
|
+
wheel(&mut r, 20.0, 20.0, -60.0);
|
|
86
|
+
assert_eq!(r.scroll_view("scroll").unwrap().offset[1], 60.0);
|
|
87
|
+
r.activate_action("a");
|
|
88
|
+
r.build_frame(300.0, 200.0).unwrap();
|
|
89
|
+
assert_eq!(r.scroll_view("scroll").unwrap().offset[1], 20.0);
|
|
90
|
+
assert!(
|
|
91
|
+
r.build_accessibility_tree(300.0, 200.0)
|
|
92
|
+
.unwrap()
|
|
93
|
+
.node("extra")
|
|
94
|
+
.is_none()
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#[test]
|
|
99
|
+
fn keyboard_focus_reveals_offscreen_control_and_pointer_activates_scrolled_control() {
|
|
100
|
+
let mut r = runtime(scroll(
|
|
101
|
+
"scroll",
|
|
102
|
+
60,
|
|
103
|
+
vec![action("a"), action("b"), action("c")],
|
|
104
|
+
));
|
|
105
|
+
r.build_frame(300.0, 300.0).unwrap();
|
|
106
|
+
r.focus_next_action(false);
|
|
107
|
+
r.focus_next_action(false);
|
|
108
|
+
r.focus_next_action(false);
|
|
109
|
+
let frame = r.build_frame(300.0, 300.0).unwrap();
|
|
110
|
+
assert_eq!(r.scroll_view("scroll").unwrap().offset[1], 60.0);
|
|
111
|
+
assert_eq!(frame.accessibility.node("c").unwrap().bounds.height, 40.0);
|
|
112
|
+
assert_eq!(frame.scene.action_at(20.0, 30.0), Some("c"));
|
|
113
|
+
for event in [
|
|
114
|
+
InputEvent::PointerMoved {
|
|
115
|
+
pointer: PointerId::MOUSE,
|
|
116
|
+
position: InputPoint::new(20.0, 30.0),
|
|
117
|
+
},
|
|
118
|
+
InputEvent::PointerButton {
|
|
119
|
+
pointer: PointerId::MOUSE,
|
|
120
|
+
button: mun_runtime::PointerButton::Primary,
|
|
121
|
+
state: mun_runtime::ButtonState::Pressed,
|
|
122
|
+
},
|
|
123
|
+
InputEvent::PointerButton {
|
|
124
|
+
pointer: PointerId::MOUSE,
|
|
125
|
+
button: mun_runtime::PointerButton::Primary,
|
|
126
|
+
state: mun_runtime::ButtonState::Released,
|
|
127
|
+
},
|
|
128
|
+
] {
|
|
129
|
+
r.handle_input(event, 300.0, 300.0).unwrap();
|
|
130
|
+
}
|
|
131
|
+
assert_eq!(r.state_value("flag").unwrap(), true);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[test]
|
|
135
|
+
fn scroll_inside_stack_keeps_following_sibling_at_viewport_edge() {
|
|
136
|
+
let child = json!({"kind":"column","id":"stack","layout":{"maxWidth":"infinity"},"children":[scroll("scroll",60,vec![action("a"),action("b"),action("c")]),action("after")]});
|
|
137
|
+
let mut r = runtime(child);
|
|
138
|
+
// The flexible root column fills the 300pt window width and centers its 100pt children.
|
|
139
|
+
wheel(&mut r, 120.0, 20.0, -40.0);
|
|
140
|
+
let frame = r.build_frame(300.0, 300.0).unwrap();
|
|
141
|
+
assert_eq!(frame.accessibility.node("after").unwrap().bounds.x, 100.0);
|
|
142
|
+
assert_eq!(frame.accessibility.node("after").unwrap().bounds.y, 60.0);
|
|
143
|
+
assert_eq!(frame.scene.action_at(120.0, 75.0), Some("after"));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
#[test]
|
|
147
|
+
fn resize_viewport_clamps_offsets_and_removal_discards_scroll_scope() {
|
|
148
|
+
let mut view = scroll("scroll", 60, vec![action("a"), action("b"), action("c")]);
|
|
149
|
+
view["layout"]["height"] = json!({"kind":"conditional","condition":{"kind":"state","state":"flag"},"then":literal(100),"otherwise":literal(60)});
|
|
150
|
+
let mut r = runtime(view);
|
|
151
|
+
wheel(&mut r, 20.0, 20.0, -60.0);
|
|
152
|
+
r.activate_action("a");
|
|
153
|
+
r.build_frame(300.0, 300.0).unwrap();
|
|
154
|
+
assert_eq!(r.scroll_view("scroll").unwrap().bounds.height, 100.0);
|
|
155
|
+
assert_eq!(r.scroll_view("scroll").unwrap().offset[1], 20.0);
|
|
156
|
+
let branch = json!({"kind":"conditional","id":"branch","condition":{"kind":"state","state":"flag"},"then":[],"otherwise":[scroll("gone",60,vec![action("x"),action("y")])]});
|
|
157
|
+
let mut r = runtime(branch);
|
|
158
|
+
r.build_frame(300.0, 300.0).unwrap();
|
|
159
|
+
assert!(r.scroll_view("gone").is_some());
|
|
160
|
+
r.activate_action("x");
|
|
161
|
+
r.build_frame(300.0, 300.0).unwrap();
|
|
162
|
+
assert!(r.scroll_view("gone").is_none());
|
|
163
|
+
assert!(r.focus_next_action(false).is_none());
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
#[test]
|
|
167
|
+
fn horizontal_scroll_and_line_input_use_logical_coordinates() {
|
|
168
|
+
let mut view = scroll("scroll", 40, vec![action("a"), action("b"), action("c")]);
|
|
169
|
+
view["axis"] = json!("horizontal");
|
|
170
|
+
let mut r = runtime(view);
|
|
171
|
+
r.handle_input(
|
|
172
|
+
InputEvent::PointerMoved {
|
|
173
|
+
pointer: PointerId::MOUSE,
|
|
174
|
+
position: InputPoint::new(20.0, 20.0),
|
|
175
|
+
},
|
|
176
|
+
300.0,
|
|
177
|
+
300.0,
|
|
178
|
+
)
|
|
179
|
+
.unwrap();
|
|
180
|
+
r.handle_input(
|
|
181
|
+
InputEvent::Scroll {
|
|
182
|
+
pointer: Some(PointerId::MOUSE),
|
|
183
|
+
delta: ScrollDelta::Lines { x: -2.0, y: 0.0 },
|
|
184
|
+
phase: ScrollPhase::Changed,
|
|
185
|
+
},
|
|
186
|
+
300.0,
|
|
187
|
+
300.0,
|
|
188
|
+
)
|
|
189
|
+
.unwrap();
|
|
190
|
+
let frame = r.build_frame(300.0, 300.0).unwrap();
|
|
191
|
+
assert_eq!(r.scroll_view("scroll").unwrap().offset[0], 64.0);
|
|
192
|
+
assert_eq!(frame.scene.action_at(70.0, 20.0), Some("b"));
|
|
193
|
+
assert_eq!(frame.scene.action_at(110.0, 20.0), None);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
#[test]
|
|
197
|
+
fn duplicate_ids_inside_scroll_fail_before_layout() {
|
|
198
|
+
let program = json!({"version":1,"sourceLanguage":"mun","entry":"Test","states":[],"root":{"kind":"window","id":"window","title":"Test","child":top_leading(scroll("scroll",60,vec![action("same"),action("same")]))}});
|
|
199
|
+
assert!(
|
|
200
|
+
Runtime::from_json(&program.to_string())
|
|
201
|
+
.err()
|
|
202
|
+
.expect("duplicate rejected")
|
|
203
|
+
.to_string()
|
|
204
|
+
.contains("same")
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
fn press_key(r: &mut Runtime, logical: mun_runtime::LogicalKey) -> mun_runtime::InputOutcome {
|
|
209
|
+
r.handle_input(
|
|
210
|
+
InputEvent::Key {
|
|
211
|
+
logical,
|
|
212
|
+
physical: mun_runtime::PhysicalKey::Other,
|
|
213
|
+
state: mun_runtime::KeyState::Pressed,
|
|
214
|
+
repeat: false,
|
|
215
|
+
},
|
|
216
|
+
300.0,
|
|
217
|
+
300.0,
|
|
218
|
+
)
|
|
219
|
+
.unwrap()
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
fn offset(r: &Runtime, id: &str) -> f32 {
|
|
223
|
+
r.scroll_view(id).unwrap().offset[1]
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
fn pointer(r: &mut Runtime, event: InputEvent) {
|
|
227
|
+
r.handle_input(event, 300.0, 300.0).unwrap();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
fn primary(state: mun_runtime::ButtonState) -> InputEvent {
|
|
231
|
+
InputEvent::PointerButton {
|
|
232
|
+
pointer: PointerId::MOUSE,
|
|
233
|
+
button: mun_runtime::PointerButton::Primary,
|
|
234
|
+
state,
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
fn moved(x: f32, y: f32) -> InputEvent {
|
|
239
|
+
InputEvent::PointerMoved {
|
|
240
|
+
pointer: PointerId::MOUSE,
|
|
241
|
+
position: InputPoint::new(x, y),
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
fn tall(id: &str, count: usize) -> Value {
|
|
246
|
+
scroll(
|
|
247
|
+
id,
|
|
248
|
+
200,
|
|
249
|
+
(0..count)
|
|
250
|
+
.map(|index| action(&format!("{id}-{index}")))
|
|
251
|
+
.collect(),
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
#[test]
|
|
256
|
+
fn keyboard_scrolling_is_owned_by_the_focused_scroll_container() {
|
|
257
|
+
use mun_runtime::LogicalKey;
|
|
258
|
+
// 10 x 40pt actions in a 200pt viewport: max offset 200.
|
|
259
|
+
let mut r = runtime(tall("list", 10));
|
|
260
|
+
r.build_frame(300.0, 300.0).unwrap();
|
|
261
|
+
r.focus_action("list-0");
|
|
262
|
+
r.build_frame(300.0, 300.0).unwrap();
|
|
263
|
+
assert!(press_key(&mut r, LogicalKey::ArrowDown).needs_redraw);
|
|
264
|
+
assert_eq!(offset(&r, "list"), 40.0);
|
|
265
|
+
press_key(&mut r, LogicalKey::PageDown);
|
|
266
|
+
assert_eq!(
|
|
267
|
+
offset(&r, "list"),
|
|
268
|
+
200.0,
|
|
269
|
+
"page = viewport - one line, clamped"
|
|
270
|
+
);
|
|
271
|
+
press_key(&mut r, LogicalKey::Home);
|
|
272
|
+
assert_eq!(offset(&r, "list"), 0.0);
|
|
273
|
+
press_key(&mut r, LogicalKey::End);
|
|
274
|
+
assert_eq!(offset(&r, "list"), 200.0);
|
|
275
|
+
assert!(
|
|
276
|
+
!press_key(&mut r, LogicalKey::PageDown).handled,
|
|
277
|
+
"already at end"
|
|
278
|
+
);
|
|
279
|
+
// Scrolling never moves semantic focus.
|
|
280
|
+
assert_eq!(r.focused_action(), Some("list-0"));
|
|
281
|
+
press_key(&mut r, LogicalKey::PageUp);
|
|
282
|
+
assert_eq!(offset(&r, "list"), 40.0);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
#[test]
|
|
286
|
+
fn unfocused_keyboard_scrolling_targets_the_hovered_viewport() {
|
|
287
|
+
use mun_runtime::LogicalKey;
|
|
288
|
+
let mut r = runtime(tall("list", 10));
|
|
289
|
+
r.build_frame(300.0, 300.0).unwrap();
|
|
290
|
+
assert!(
|
|
291
|
+
!press_key(&mut r, LogicalKey::PageDown).handled,
|
|
292
|
+
"no focus, no hover"
|
|
293
|
+
);
|
|
294
|
+
pointer(&mut r, moved(20.0, 20.0));
|
|
295
|
+
press_key(&mut r, LogicalKey::PageDown);
|
|
296
|
+
assert_eq!(offset(&r, "list"), 160.0);
|
|
297
|
+
assert_eq!(r.focused_action(), None);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
#[test]
|
|
301
|
+
fn nested_keyboard_scroll_routes_to_ancestor_when_inner_is_exhausted() {
|
|
302
|
+
use mun_runtime::LogicalKey;
|
|
303
|
+
let outer = json!({"kind":"scroll","id":"outer","axis":"vertical","layout":{"width":literal(120),"height":literal(150)},"children":[
|
|
304
|
+
tall("inner", 6), action("after-0"), action("after-1"), action("after-2")
|
|
305
|
+
]});
|
|
306
|
+
let mut r = runtime(outer);
|
|
307
|
+
r.build_frame(300.0, 300.0).unwrap();
|
|
308
|
+
r.focus_action("inner-0");
|
|
309
|
+
r.build_frame(300.0, 300.0).unwrap();
|
|
310
|
+
press_key(&mut r, LogicalKey::End);
|
|
311
|
+
assert_eq!(offset(&r, "inner"), 40.0);
|
|
312
|
+
assert_eq!(offset(&r, "outer"), 0.0, "inner absorbed the movement");
|
|
313
|
+
press_key(&mut r, LogicalKey::ArrowDown);
|
|
314
|
+
assert_eq!(offset(&r, "outer"), 40.0, "residual routed to the ancestor");
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
#[test]
|
|
318
|
+
fn focus_reveal_through_nested_ancestors_is_minimal() {
|
|
319
|
+
let outer = json!({"kind":"scroll","id":"outer","axis":"vertical","layout":{"width":literal(120),"height":literal(150)},"children":[
|
|
320
|
+
action("before-0"), action("before-1"), tall("inner", 8)
|
|
321
|
+
]});
|
|
322
|
+
let mut r = runtime(outer);
|
|
323
|
+
r.build_frame(300.0, 300.0).unwrap();
|
|
324
|
+
// inner viewport occupies outer content 80..280; target inner-6 sits at
|
|
325
|
+
// inner content 240..280.
|
|
326
|
+
r.focus_action("inner-6");
|
|
327
|
+
let frame = r.build_frame(300.0, 300.0).unwrap();
|
|
328
|
+
assert_eq!(offset(&r, "inner"), 80.0, "inner scrolls just enough");
|
|
329
|
+
assert_eq!(offset(&r, "outer"), 130.0, "outer scrolls just enough");
|
|
330
|
+
let bounds = frame.accessibility.node("inner-6").unwrap().bounds;
|
|
331
|
+
assert_eq!(
|
|
332
|
+
bounds.y + bounds.height,
|
|
333
|
+
150.0,
|
|
334
|
+
"target touches the visible edge"
|
|
335
|
+
);
|
|
336
|
+
// Revealing an already visible control does not move anything.
|
|
337
|
+
r.focus_action("inner-5");
|
|
338
|
+
r.build_frame(300.0, 300.0).unwrap();
|
|
339
|
+
assert_eq!((offset(&r, "inner"), offset(&r, "outer")), (80.0, 130.0));
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
#[test]
|
|
343
|
+
fn scrollbar_presentation_drag_and_track_paging_are_semantic_scroll_operations() {
|
|
344
|
+
let mut r = runtime(
|
|
345
|
+
json!({"kind":"row","id":"stack","layout":{"alignment":"leading"},"children":[tall("list", 10), tall("short", 2)]}),
|
|
346
|
+
);
|
|
347
|
+
let scene = r.build_scene(300.0, 300.0).unwrap();
|
|
348
|
+
let thumb = scene
|
|
349
|
+
.rects
|
|
350
|
+
.iter()
|
|
351
|
+
.find(|item| item.id == "list:scrollbar-thumb")
|
|
352
|
+
.expect("overflowing viewport shows a thumb")
|
|
353
|
+
.rect;
|
|
354
|
+
assert!(
|
|
355
|
+
!scene
|
|
356
|
+
.rects
|
|
357
|
+
.iter()
|
|
358
|
+
.any(|item| item.id.starts_with("short:scrollbar")),
|
|
359
|
+
"content that fits has no scrollbar"
|
|
360
|
+
);
|
|
361
|
+
// Thumb ratio: 200/400 of a 196pt track.
|
|
362
|
+
assert!((thumb.height - 98.0).abs() < 0.01);
|
|
363
|
+
|
|
364
|
+
// Drag the thumb by half its travel -> half the offset range.
|
|
365
|
+
let (x, y) = (thumb.x + 3.0, thumb.y + 10.0);
|
|
366
|
+
pointer(&mut r, moved(x, y));
|
|
367
|
+
pointer(&mut r, primary(mun_runtime::ButtonState::Pressed));
|
|
368
|
+
assert_eq!(
|
|
369
|
+
r.focused_action(),
|
|
370
|
+
None,
|
|
371
|
+
"scrollbar presses never take focus"
|
|
372
|
+
);
|
|
373
|
+
pointer(&mut r, moved(x, y + 49.0));
|
|
374
|
+
assert!((offset(&r, "list") - 100.0).abs() < 0.01);
|
|
375
|
+
pointer(&mut r, primary(mun_runtime::ButtonState::Released));
|
|
376
|
+
assert_eq!(
|
|
377
|
+
r.state_value("flag").unwrap(),
|
|
378
|
+
false,
|
|
379
|
+
"no activation under the bar"
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
// Track press below the thumb pages forward.
|
|
383
|
+
let scene = r.build_scene(300.0, 300.0).unwrap();
|
|
384
|
+
let track = scene
|
|
385
|
+
.rects
|
|
386
|
+
.iter()
|
|
387
|
+
.find(|item| item.id == "list:scrollbar-track")
|
|
388
|
+
.unwrap()
|
|
389
|
+
.rect;
|
|
390
|
+
pointer(&mut r, moved(track.x + 3.0, track.y + track.height - 2.0));
|
|
391
|
+
pointer(&mut r, primary(mun_runtime::ButtonState::Pressed));
|
|
392
|
+
pointer(&mut r, primary(mun_runtime::ButtonState::Released));
|
|
393
|
+
assert_eq!(offset(&r, "list"), 200.0);
|
|
394
|
+
let thumb = r
|
|
395
|
+
.build_scene(300.0, 300.0)
|
|
396
|
+
.unwrap()
|
|
397
|
+
.rects
|
|
398
|
+
.into_iter()
|
|
399
|
+
.find(|item| item.id == "list:scrollbar-thumb")
|
|
400
|
+
.unwrap()
|
|
401
|
+
.rect;
|
|
402
|
+
assert!((thumb.y + thumb.height - (track.y + track.height)).abs() < 0.01);
|
|
403
|
+
}
|