@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,168 @@
|
|
|
1
|
+
//! Assistive-technology semantics derived from runtime state: radio options,
|
|
2
|
+
//! editable text (grapheme characters, selection, edit actions) and scrolling.
|
|
3
|
+
use mun_runtime::accessibility::AccessibilityAction as A;
|
|
4
|
+
use mun_runtime::ir::AccessibilityRole;
|
|
5
|
+
use mun_runtime::text_edit::{Composition, TextEdit};
|
|
6
|
+
use mun_runtime::{AccessibilityNode, InputEvent, Runtime};
|
|
7
|
+
|
|
8
|
+
const PROGRAM: &str = r##"{"version":1,"sourceLanguage":"mun","entry":"A11y","states":[
|
|
9
|
+
{"name":"choice","initial":"work"},{"name":"flag","initial":false},{"name":"name","initial":"한é👍🏽 ok"}],
|
|
10
|
+
"root":{"kind":"window","id":"window","title":"A11y","child":{"kind":"column","id":"stack","children":[
|
|
11
|
+
{"kind":"textField","id":"field","state":"name","placeholder":"Name","layout":{"width":{"kind":"literal","value":260},"height":{"kind":"literal","value":40}}},
|
|
12
|
+
{"kind":"radioGroup","id":"choices","state":"choice","options":[
|
|
13
|
+
{"label":"Work","value":"work"},{"label":"Personal","value":"personal"},{"label":"Off","value":"none","disabled":true}]},
|
|
14
|
+
{"kind":"scroll","id":"scroll","axis":"vertical","layout":{"height":{"kind":"literal","value":100}},"children":[
|
|
15
|
+
{"kind":"column","id":"content","children":[
|
|
16
|
+
{"kind":"text","id":"top","value":{"kind":"literal","value":"Top"},"layout":{"height":{"kind":"literal","value":300}}},
|
|
17
|
+
{"kind":"action","id":"deep","label":"Deep","action":{"kind":"toggle-state","state":"flag"}}]}]}]}}}"##;
|
|
18
|
+
|
|
19
|
+
fn runtime() -> Runtime {
|
|
20
|
+
Runtime::from_json(PROGRAM).unwrap()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fn node(runtime: &Runtime, id: &str) -> AccessibilityNode {
|
|
24
|
+
let tree = runtime.build_accessibility_tree(400.0, 400.0).unwrap();
|
|
25
|
+
tree.node(id).cloned().unwrap_or_else(|| panic!("{id}"))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#[test]
|
|
29
|
+
fn radio_options_are_checkable_children_that_select_through_the_group() {
|
|
30
|
+
let mut r = runtime();
|
|
31
|
+
let group = node(&r, "choices");
|
|
32
|
+
assert_eq!(
|
|
33
|
+
group.children,
|
|
34
|
+
["choices:option:0", "choices:option:1", "choices:option:2"]
|
|
35
|
+
);
|
|
36
|
+
let work = node(&r, "choices:option:0");
|
|
37
|
+
assert_eq!(work.role, AccessibilityRole::RadioButton);
|
|
38
|
+
assert_eq!(
|
|
39
|
+
(work.label.as_deref(), work.checked),
|
|
40
|
+
(Some("Work"), Some(true))
|
|
41
|
+
);
|
|
42
|
+
let off = node(&r, "choices:option:2");
|
|
43
|
+
assert!(!off.enabled && off.action_id.is_none());
|
|
44
|
+
|
|
45
|
+
let outcome = r.handle_accessibility_action("choices:option:1", A::Activate);
|
|
46
|
+
assert!(outcome.activated);
|
|
47
|
+
assert_eq!(r.state_value("choice").unwrap(), "personal");
|
|
48
|
+
assert_eq!(node(&r, "choices:option:1").checked, Some(true));
|
|
49
|
+
assert_eq!(node(&r, "choices:option:0").checked, Some(false));
|
|
50
|
+
assert_eq!(
|
|
51
|
+
r.focused_action(),
|
|
52
|
+
Some("choices"),
|
|
53
|
+
"focus lands on the group"
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
assert!(
|
|
57
|
+
!r.handle_accessibility_action("choices:option:2", A::Activate)
|
|
58
|
+
.activated
|
|
59
|
+
);
|
|
60
|
+
assert_eq!(r.state_value("choice").unwrap(), "personal");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#[test]
|
|
64
|
+
fn text_field_exposes_grapheme_characters_and_selection_and_edits_through_the_editor() {
|
|
65
|
+
let mut r = runtime();
|
|
66
|
+
let text = node(&r, "field").text.unwrap();
|
|
67
|
+
// 한 | e+combining acute | thumbs-up+skin tone | space | o | k
|
|
68
|
+
assert_eq!(text.character_lengths, [3, 3, 8, 1, 1, 1]);
|
|
69
|
+
assert_eq!(text.word_starts.first(), Some(&0));
|
|
70
|
+
assert!(
|
|
71
|
+
text.character_positions
|
|
72
|
+
.windows(2)
|
|
73
|
+
.all(|pair| pair[0] <= pair[1])
|
|
74
|
+
);
|
|
75
|
+
assert!(
|
|
76
|
+
text.selection.is_none(),
|
|
77
|
+
"selection exists only while focused"
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Select "e\u{301}👍🏽" (graphemes 1..3) and replace it with Korean text.
|
|
81
|
+
assert!(
|
|
82
|
+
r.handle_accessibility_action(
|
|
83
|
+
"field",
|
|
84
|
+
A::SetTextSelection {
|
|
85
|
+
anchor: 1,
|
|
86
|
+
focus: 3
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
.handled
|
|
90
|
+
);
|
|
91
|
+
assert_eq!(r.focused_action(), Some("field"));
|
|
92
|
+
assert_eq!(node(&r, "field").text.unwrap().selection, Some((1, 3)));
|
|
93
|
+
r.handle_accessibility_action("field", A::ReplaceSelectedText("국어".into()));
|
|
94
|
+
assert_eq!(r.state_value("name").unwrap(), "한국어 ok");
|
|
95
|
+
assert_eq!(node(&r, "field").text.unwrap().selection, Some((3, 3)));
|
|
96
|
+
|
|
97
|
+
r.handle_accessibility_action("field", A::SetValue("line\nbreak".into()));
|
|
98
|
+
assert_eq!(
|
|
99
|
+
r.state_value("name").unwrap(),
|
|
100
|
+
"line break",
|
|
101
|
+
"single-line sanitized"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
#[test]
|
|
106
|
+
fn assistive_selection_commits_an_active_composition_first() {
|
|
107
|
+
let mut r = runtime();
|
|
108
|
+
assert!(r.focus_action("field"));
|
|
109
|
+
r.handle_input(
|
|
110
|
+
InputEvent::TextEdit(TextEdit::End { select: false }),
|
|
111
|
+
400.0,
|
|
112
|
+
400.0,
|
|
113
|
+
)
|
|
114
|
+
.unwrap();
|
|
115
|
+
r.handle_input(
|
|
116
|
+
InputEvent::TextEdit(TextEdit::CompositionUpdate(Composition {
|
|
117
|
+
text: "가".into(),
|
|
118
|
+
selection: None,
|
|
119
|
+
})),
|
|
120
|
+
400.0,
|
|
121
|
+
400.0,
|
|
122
|
+
)
|
|
123
|
+
.unwrap();
|
|
124
|
+
assert_eq!(
|
|
125
|
+
node(&r, "field").value.as_deref(),
|
|
126
|
+
Some("한e\u{301}👍🏽 ok가"),
|
|
127
|
+
"the in-progress composition is part of the value"
|
|
128
|
+
);
|
|
129
|
+
r.handle_accessibility_action(
|
|
130
|
+
"field",
|
|
131
|
+
A::SetTextSelection {
|
|
132
|
+
anchor: 0,
|
|
133
|
+
focus: 0,
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
assert_eq!(r.state_value("name").unwrap(), "한e\u{301}👍🏽 ok가");
|
|
137
|
+
assert!(r.focused_text_editor().unwrap().composition().is_none());
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#[test]
|
|
141
|
+
fn scroll_views_expose_offsets_and_accept_paging_and_reveal() {
|
|
142
|
+
let mut r = runtime();
|
|
143
|
+
let scroll = node(&r, "scroll").scroll.expect("overflowing scroll view");
|
|
144
|
+
assert_eq!((scroll.offset, scroll.horizontal), (0.0, false));
|
|
145
|
+
assert!(scroll.max > 200.0);
|
|
146
|
+
assert!(node(&r, "content").scroll.is_none());
|
|
147
|
+
|
|
148
|
+
assert!(
|
|
149
|
+
r.handle_accessibility_action("scroll", A::ScrollByPages(1.0))
|
|
150
|
+
.handled
|
|
151
|
+
);
|
|
152
|
+
let paged = node(&r, "scroll").scroll.unwrap().offset;
|
|
153
|
+
assert!(paged > 0.0);
|
|
154
|
+
r.handle_accessibility_action("scroll", A::SetScrollOffset(0.0));
|
|
155
|
+
assert_eq!(node(&r, "scroll").scroll.unwrap().offset, 0.0);
|
|
156
|
+
|
|
157
|
+
assert!(
|
|
158
|
+
r.handle_accessibility_action("deep", A::ScrollIntoView)
|
|
159
|
+
.handled
|
|
160
|
+
);
|
|
161
|
+
let deep = node(&r, "deep");
|
|
162
|
+
let viewport = node(&r, "scroll").bounds;
|
|
163
|
+
assert!(
|
|
164
|
+
deep.bounds.height > 0.0
|
|
165
|
+
&& deep.bounds.y + deep.bounds.height <= viewport.y + viewport.height + 0.5
|
|
166
|
+
);
|
|
167
|
+
assert_eq!(r.focused_action(), None, "reveal does not move focus");
|
|
168
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
use std::{env, fs};
|
|
2
|
+
|
|
3
|
+
use mun_runtime::{Runtime, SEMANTIC_UI_IR_VERSION};
|
|
4
|
+
use serde_json::Value;
|
|
5
|
+
|
|
6
|
+
#[test]
|
|
7
|
+
#[ignore = "run through scripts/test-native-contract.sh after compiling canonical .mun source"]
|
|
8
|
+
fn compiler_output_deserializes_into_native_runtime() {
|
|
9
|
+
let path = env::var("MUN_COMPILER_CONTRACT_IR")
|
|
10
|
+
.expect("MUN_COMPILER_CONTRACT_IR must point at compiler-produced Semantic UI IR");
|
|
11
|
+
let source = fs::read_to_string(&path)
|
|
12
|
+
.unwrap_or_else(|error| panic!("read compiler-produced Semantic UI IR at {path}: {error}"));
|
|
13
|
+
|
|
14
|
+
let value: Value =
|
|
15
|
+
serde_json::from_str(&source).expect("compiler-produced Semantic UI IR must be valid JSON");
|
|
16
|
+
assert_eq!(
|
|
17
|
+
value.get("version").and_then(Value::as_u64),
|
|
18
|
+
Some(u64::from(SEMANTIC_UI_IR_VERSION)),
|
|
19
|
+
"TypeScript compiler and Rust runtime must agree on the Semantic UI IR version",
|
|
20
|
+
);
|
|
21
|
+
assert_eq!(
|
|
22
|
+
value.get("sourceLanguage").and_then(Value::as_str),
|
|
23
|
+
Some("mun"),
|
|
24
|
+
"native runtime contract only accepts canonical Mün semantic programs here",
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
Runtime::from_json(&source)
|
|
28
|
+
.expect("compiler-produced Semantic UI IR must deserialize into the native runtime");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// Compiler-produced keyed rows (NativeProductionSmoke `TaskRow`) keep per-key
|
|
32
|
+
/// View state through insertion, reordering and removal of neighbors.
|
|
33
|
+
#[test]
|
|
34
|
+
#[ignore = "run through scripts/verify-native-contracts.mjs with compiled NativeProductionSmoke"]
|
|
35
|
+
fn compiled_keyed_rows_keep_state_by_key() {
|
|
36
|
+
use mun_runtime::InputEvent;
|
|
37
|
+
use mun_runtime::text_edit::TextEdit;
|
|
38
|
+
let path = env::var("MUN_KEYED_CONTRACT_IR").expect("MUN_KEYED_CONTRACT_IR");
|
|
39
|
+
let mut runtime = Runtime::from_json(&fs::read_to_string(path).unwrap()).unwrap();
|
|
40
|
+
let (width, height) = (640.0, 900.0);
|
|
41
|
+
let nodes = |runtime: &Runtime| {
|
|
42
|
+
runtime
|
|
43
|
+
.build_accessibility_tree(width, height)
|
|
44
|
+
.unwrap()
|
|
45
|
+
.nodes
|
|
46
|
+
};
|
|
47
|
+
let find = |runtime: &Runtime, key: &str, label: &str| {
|
|
48
|
+
nodes(runtime)
|
|
49
|
+
.into_iter()
|
|
50
|
+
.find(|node| {
|
|
51
|
+
node.id.ends_with(&format!("[s:{key}]")) && node.label.as_deref() == Some(label)
|
|
52
|
+
})
|
|
53
|
+
.unwrap_or_else(|| panic!("row {key} control {label}"))
|
|
54
|
+
.id
|
|
55
|
+
};
|
|
56
|
+
let note_of = |runtime: &Runtime, key: &str| {
|
|
57
|
+
nodes(runtime)
|
|
58
|
+
.into_iter()
|
|
59
|
+
.find(|node| {
|
|
60
|
+
node.id.ends_with(&format!("[s:{key}]"))
|
|
61
|
+
&& node.label.as_deref() == Some("Note for this row")
|
|
62
|
+
})
|
|
63
|
+
.and_then(|node| node.value)
|
|
64
|
+
};
|
|
65
|
+
let order = |runtime: &Runtime| -> Vec<String> {
|
|
66
|
+
nodes(runtime)
|
|
67
|
+
.into_iter()
|
|
68
|
+
.filter(|node| node.label.as_deref() == Some("Remove"))
|
|
69
|
+
.map(|node| {
|
|
70
|
+
node.id
|
|
71
|
+
.rsplit("[s:")
|
|
72
|
+
.next()
|
|
73
|
+
.unwrap()
|
|
74
|
+
.trim_end_matches(']')
|
|
75
|
+
.to_owned()
|
|
76
|
+
})
|
|
77
|
+
.collect()
|
|
78
|
+
};
|
|
79
|
+
assert_eq!(order(&runtime), ["draft", "review", "ship"]);
|
|
80
|
+
for key in ["draft", "ship"] {
|
|
81
|
+
assert!(runtime.focus_action(&find(&runtime, key, "Note for this row")));
|
|
82
|
+
runtime
|
|
83
|
+
.handle_input(
|
|
84
|
+
InputEvent::TextEdit(TextEdit::Insert(format!("{key} 메모"))),
|
|
85
|
+
width,
|
|
86
|
+
height,
|
|
87
|
+
)
|
|
88
|
+
.unwrap();
|
|
89
|
+
}
|
|
90
|
+
runtime.activate_action(&find(&runtime, "ship", "Done"));
|
|
91
|
+
let add = nodes(&runtime)
|
|
92
|
+
.into_iter()
|
|
93
|
+
.find(|node| node.label.as_deref() == Some("Add task"))
|
|
94
|
+
.unwrap()
|
|
95
|
+
.id;
|
|
96
|
+
runtime.activate_action(&add);
|
|
97
|
+
runtime.activate_action(&find(&runtime, "ship", "Up"));
|
|
98
|
+
runtime.activate_action(&find(&runtime, "draft", "Remove"));
|
|
99
|
+
assert_eq!(order(&runtime), ["task1", "ship", "review"]);
|
|
100
|
+
assert_eq!(note_of(&runtime, "ship").as_deref(), Some("ship 메모"));
|
|
101
|
+
assert_eq!(note_of(&runtime, "task1").as_deref(), Some(""));
|
|
102
|
+
assert_eq!(note_of(&runtime, "review").as_deref(), Some(""));
|
|
103
|
+
let done_marks: Vec<_> = nodes(&runtime)
|
|
104
|
+
.into_iter()
|
|
105
|
+
.filter(|node| node.label.as_deref() == Some("✓"))
|
|
106
|
+
.map(|node| node.id)
|
|
107
|
+
.collect();
|
|
108
|
+
assert_eq!(done_marks.len(), 1);
|
|
109
|
+
assert!(done_marks[0].ends_with("[s:ship]"), "{done_marks:?}");
|
|
110
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//! `.frame(minWidth:maxWidth:minHeight:maxHeight:)`: flexible views take what
|
|
2
|
+
//! their parent offers (grow on its main axis, stretch across it), clamped to
|
|
3
|
+
//! their bounds; containers holding a flexible child become flexible.
|
|
4
|
+
use mun_runtime::Runtime;
|
|
5
|
+
use serde_json::json;
|
|
6
|
+
|
|
7
|
+
fn rect(r: &Runtime, id: &str, w: f32, h: f32) -> mun_runtime::AccessibilityBounds {
|
|
8
|
+
r.build_accessibility_tree(w, h)
|
|
9
|
+
.unwrap()
|
|
10
|
+
.node(id)
|
|
11
|
+
.unwrap()
|
|
12
|
+
.bounds
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#[test]
|
|
16
|
+
fn flexible_frames_follow_the_window_within_their_bounds() {
|
|
17
|
+
let lit = |v: f32| json!({"kind": "literal", "value": v});
|
|
18
|
+
let program = json!({
|
|
19
|
+
"version": 1, "sourceLanguage": "mun", "entry": "Flex", "states": [{"name": "s", "initial": ""}],
|
|
20
|
+
"root": {"kind": "window", "id": "w", "title": "Flex", "child": {
|
|
21
|
+
"kind": "column", "id": "col", "layout": {"alignment": "leading"}, "children": [
|
|
22
|
+
{"kind": "row", "id": "row", "children": [
|
|
23
|
+
{"kind": "textField", "id": "field", "state": "s",
|
|
24
|
+
"layout": {"height": lit(30.0), "minWidth": 100, "maxWidth": "infinity"}},
|
|
25
|
+
{"kind": "action", "id": "fixed", "label": "Go", "action": {"kind": "toggle-state", "state": "s"},
|
|
26
|
+
"layout": {"width": lit(50.0), "height": lit(30.0)}}
|
|
27
|
+
]},
|
|
28
|
+
{"kind": "panel", "id": "capped", "layout": {"maxWidth": 300, "maxHeight": "infinity", "minHeight": 20}},
|
|
29
|
+
{"kind": "text", "id": "label", "value": {"kind": "literal", "value": "hug"}}
|
|
30
|
+
]
|
|
31
|
+
}}
|
|
32
|
+
});
|
|
33
|
+
let r = Runtime::from_json(&program.to_string()).unwrap();
|
|
34
|
+
for (w, h) in [(400.0, 300.0), (800.0, 600.0)] {
|
|
35
|
+
// The row became flexible through its field: it spans the window and the
|
|
36
|
+
// field takes everything the fixed button leaves.
|
|
37
|
+
assert_eq!(rect(&r, "row", w, h).width, w);
|
|
38
|
+
assert_eq!(rect(&r, "field", w, h).width, w - 50.0);
|
|
39
|
+
// Stretches across the column up to its max; grows down the column.
|
|
40
|
+
assert_eq!(rect(&r, "capped", w, h).width, 300.0_f32.min(w));
|
|
41
|
+
assert!(rect(&r, "capped", w, h).height > h * 0.5);
|
|
42
|
+
// Non-flexible content keeps its intrinsic size.
|
|
43
|
+
assert_eq!(rect(&r, "label", w, h).width, 240.0);
|
|
44
|
+
}
|
|
45
|
+
// Below minWidth the field keeps its minimum.
|
|
46
|
+
assert_eq!(rect(&r, "field", 120.0, 300.0).width, 100.0);
|
|
47
|
+
}
|