@mun-ui/ui 0.2.0 → 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/README.md +11 -1
- package/bin/desktop.mjs +143 -0
- package/bin/mun.mjs +27 -10
- package/native/mun-native/src/host_services.rs +202 -0
- package/native/mun-native/src/lib.rs +209 -42
- package/native/mun-native/src/text.rs +107 -16
- package/native/mun-runtime/src/collection.rs +18 -1
- package/native/mun-runtime/src/ir.rs +71 -1
- package/native/mun-runtime/src/layout.rs +85 -0
- package/native/mun-runtime/src/layout_cache.rs +6 -6
- package/native/mun-runtime/src/lib.rs +7 -4
- package/native/mun-runtime/src/runtime.rs +388 -17
- package/native/mun-runtime/src/scene.rs +37 -0
- package/native/mun-runtime/tests/host_services.rs +107 -0
- package/native/mun-runtime/tests/minimum_window_size.rs +80 -0
- package/native/mun-runtime/tests/priority_proposals.rs +69 -0
- package/native/mun-runtime/tests/text_proposals.rs +42 -0
- package/native/mun-runtime/tests/typography.rs +63 -0
- package/package.json +19 -16
- package/schemas/semantic-ui-ir-v1.schema.json +89 -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/project/package.json +3 -0
- package/templates/project/src/index.css +9 -0
|
@@ -195,6 +195,54 @@ impl<'de> Deserialize<'de> for UiPaint {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Hash)]
|
|
199
|
+
#[serde(rename_all = "camelCase")]
|
|
200
|
+
pub enum UiFontDesign {
|
|
201
|
+
#[default]
|
|
202
|
+
Default,
|
|
203
|
+
Monospaced,
|
|
204
|
+
Rounded,
|
|
205
|
+
Serif,
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
|
|
209
|
+
#[serde(rename_all = "camelCase")]
|
|
210
|
+
pub enum UiTextAlignment {
|
|
211
|
+
Leading,
|
|
212
|
+
Center,
|
|
213
|
+
Trailing,
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/// Static typography of a Text: semantic/system font metrics plus wrapping
|
|
217
|
+
/// limits. Absent fields use the renderer's body defaults.
|
|
218
|
+
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq)]
|
|
219
|
+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
|
220
|
+
pub struct UiTypography {
|
|
221
|
+
#[serde(default)]
|
|
222
|
+
pub size: Option<f32>,
|
|
223
|
+
#[serde(default)]
|
|
224
|
+
pub weight: Option<u16>,
|
|
225
|
+
#[serde(default)]
|
|
226
|
+
pub italic: Option<bool>,
|
|
227
|
+
#[serde(default)]
|
|
228
|
+
pub design: Option<UiFontDesign>,
|
|
229
|
+
#[serde(default)]
|
|
230
|
+
pub line_limit: Option<u32>,
|
|
231
|
+
#[serde(default)]
|
|
232
|
+
pub alignment: Option<UiTextAlignment>,
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
impl UiTypography {
|
|
236
|
+
pub fn style(&self, default_size: f32) -> crate::layout::TextStyle {
|
|
237
|
+
crate::layout::TextStyle {
|
|
238
|
+
size: self.size.unwrap_or(default_size),
|
|
239
|
+
weight: self.weight.unwrap_or(400),
|
|
240
|
+
italic: self.italic.unwrap_or(false),
|
|
241
|
+
design: self.design.unwrap_or_default(),
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
198
246
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
|
|
199
247
|
#[serde(rename_all = "camelCase")]
|
|
200
248
|
pub enum UiShapeKind {
|
|
@@ -229,11 +277,17 @@ pub struct UiLayout {
|
|
|
229
277
|
#[serde(default)]
|
|
230
278
|
pub min_width: Option<f32>,
|
|
231
279
|
#[serde(default)]
|
|
280
|
+
pub ideal_width: Option<f32>,
|
|
281
|
+
#[serde(default)]
|
|
232
282
|
pub max_width: Option<UiFrameBound>,
|
|
233
283
|
#[serde(default)]
|
|
234
284
|
pub min_height: Option<f32>,
|
|
235
285
|
#[serde(default)]
|
|
286
|
+
pub ideal_height: Option<f32>,
|
|
287
|
+
#[serde(default)]
|
|
236
288
|
pub max_height: Option<UiFrameBound>,
|
|
289
|
+
#[serde(default)]
|
|
290
|
+
pub layout_priority: Option<f32>,
|
|
237
291
|
}
|
|
238
292
|
|
|
239
293
|
/// Uniform padding or per-edge insets (leading/trailing follow layout direction).
|
|
@@ -479,6 +533,19 @@ pub enum UiAction {
|
|
|
479
533
|
#[serde(default)]
|
|
480
534
|
transaction: Option<UiTransaction>,
|
|
481
535
|
},
|
|
536
|
+
/// Call an operating-system service exposed by the host (file system,
|
|
537
|
+
/// workspace). With `state`, the result value is stored into that state.
|
|
538
|
+
#[serde(rename = "host")]
|
|
539
|
+
Host {
|
|
540
|
+
service: String,
|
|
541
|
+
operation: String,
|
|
542
|
+
#[serde(default)]
|
|
543
|
+
arguments: Vec<UiExpression>,
|
|
544
|
+
#[serde(default)]
|
|
545
|
+
state: Option<String>,
|
|
546
|
+
#[serde(default)]
|
|
547
|
+
transaction: Option<UiTransaction>,
|
|
548
|
+
},
|
|
482
549
|
}
|
|
483
550
|
|
|
484
551
|
impl UiAction {
|
|
@@ -487,7 +554,8 @@ impl UiAction {
|
|
|
487
554
|
Self::ToggleState { transaction, .. }
|
|
488
555
|
| Self::SetState { transaction, .. }
|
|
489
556
|
| Self::Collection { transaction, .. }
|
|
490
|
-
| Self::Sequence { transaction, .. }
|
|
557
|
+
| Self::Sequence { transaction, .. }
|
|
558
|
+
| Self::Host { transaction, .. } => transaction.as_ref(),
|
|
491
559
|
}
|
|
492
560
|
}
|
|
493
561
|
}
|
|
@@ -586,6 +654,8 @@ pub enum UiNode {
|
|
|
586
654
|
#[serde(flatten)]
|
|
587
655
|
base: NodeBase,
|
|
588
656
|
value: UiExpression,
|
|
657
|
+
#[serde(default)]
|
|
658
|
+
font: Option<UiTypography>,
|
|
589
659
|
},
|
|
590
660
|
#[serde(rename = "panel")]
|
|
591
661
|
Panel {
|
|
@@ -16,6 +16,39 @@ impl IntrinsicSize {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/// Retained layout input for a leaf. Text keeps its content as well as its
|
|
20
|
+
/// unconstrained size, so the Taffy measurement callback can answer a width
|
|
21
|
+
/// proposal instead of reusing a fixed single-line measurement.
|
|
22
|
+
#[derive(Clone, Debug, PartialEq)]
|
|
23
|
+
pub(crate) enum LeafMeasure {
|
|
24
|
+
Intrinsic(IntrinsicSize),
|
|
25
|
+
Text {
|
|
26
|
+
content: String,
|
|
27
|
+
natural: IntrinsicSize,
|
|
28
|
+
style: TextStyle,
|
|
29
|
+
line_limit: Option<usize>,
|
|
30
|
+
},
|
|
31
|
+
/// A leaf in a flexible frame. Like a SwiftUI view with `maxWidth:
|
|
32
|
+
/// .infinity`, it takes the space it is offered, so on its flexible axes
|
|
33
|
+
/// (`[width, height]`) its intrinsic size is its ideal size only: under a
|
|
34
|
+
/// min-content proposal it reports 0 there and never holds a stack (or the
|
|
35
|
+
/// window) open. An authored `minWidth` / `minHeight` still applies.
|
|
36
|
+
Flexible {
|
|
37
|
+
measure: Box<LeafMeasure>,
|
|
38
|
+
axes: [bool; 2],
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
impl LeafMeasure {
|
|
43
|
+
pub(crate) fn is_text(&self) -> bool {
|
|
44
|
+
match self {
|
|
45
|
+
Self::Text { .. } => true,
|
|
46
|
+
Self::Intrinsic(_) => false,
|
|
47
|
+
Self::Flexible { measure, .. } => measure.is_text(),
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
19
52
|
/// Shaped geometry of one single-line text run, exposed by a text backend.
|
|
20
53
|
///
|
|
21
54
|
/// `carets` holds one `(scalar offset, x)` stop for every extended grapheme
|
|
@@ -70,8 +103,60 @@ impl TextLineLayout {
|
|
|
70
103
|
/// Measurements are intentionally unconstrained content sizes. Explicit Mün
|
|
71
104
|
/// width/height constraints and container alignment remain authoritative in
|
|
72
105
|
/// the Taffy adapter.
|
|
106
|
+
/// Font request for shaping one Text: renderer-neutral metrics only.
|
|
107
|
+
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
108
|
+
pub struct TextStyle {
|
|
109
|
+
pub size: f32,
|
|
110
|
+
/// CSS/OpenType weight 100..=900.
|
|
111
|
+
pub weight: u16,
|
|
112
|
+
pub italic: bool,
|
|
113
|
+
pub design: crate::ir::UiFontDesign,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
impl TextStyle {
|
|
117
|
+
pub const fn body(size: f32) -> Self {
|
|
118
|
+
Self {
|
|
119
|
+
size,
|
|
120
|
+
weight: 400,
|
|
121
|
+
italic: false,
|
|
122
|
+
design: crate::ir::UiFontDesign::Default,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
pub fn line_height(&self) -> f32 {
|
|
127
|
+
self.size * 1.25
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
73
131
|
pub trait IntrinsicMeasurer {
|
|
74
132
|
fn measure_text(&self, text: &str) -> IntrinsicSize;
|
|
133
|
+
|
|
134
|
+
/// Measure a styled Text at an optional width proposal and line limit.
|
|
135
|
+
/// The default scales the unstyled single-size model so headless tooling
|
|
136
|
+
/// keeps working; native renderers shape with the real font.
|
|
137
|
+
fn measure_styled_text(
|
|
138
|
+
&self,
|
|
139
|
+
text: &str,
|
|
140
|
+
style: TextStyle,
|
|
141
|
+
available_width: Option<f32>,
|
|
142
|
+
line_limit: Option<usize>,
|
|
143
|
+
) -> IntrinsicSize {
|
|
144
|
+
let base =
|
|
145
|
+
self.measure_text_for_width(text, available_width.map(|w| w * 24.0 / style.size));
|
|
146
|
+
let scale = style.size / 24.0;
|
|
147
|
+
let mut height = base.height * scale;
|
|
148
|
+
if let Some(limit) = line_limit {
|
|
149
|
+
height = height.min((limit.max(1) as f32 * style.line_height() + 2.0).ceil());
|
|
150
|
+
}
|
|
151
|
+
IntrinsicSize::new((base.width * scale).ceil(), height.ceil())
|
|
152
|
+
}
|
|
153
|
+
/// Return the text's proposed size when laid out at the available width.
|
|
154
|
+
/// `None` means an unspecified width (its ideal, unwrapped measurement).
|
|
155
|
+
/// Default measurers preserve existing single-line headless behavior.
|
|
156
|
+
fn measure_text_for_width(&self, text: &str, available_width: Option<f32>) -> IntrinsicSize {
|
|
157
|
+
let _ = available_width;
|
|
158
|
+
self.measure_text(text)
|
|
159
|
+
}
|
|
75
160
|
fn measure_action(&self, label: &str) -> IntrinsicSize;
|
|
76
161
|
fn measure_panel(&self) -> IntrinsicSize;
|
|
77
162
|
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
use rustc_hash::FxHashMap;
|
|
10
10
|
use taffy::{TaffyError, prelude::*};
|
|
11
11
|
|
|
12
|
-
use crate::layout::
|
|
12
|
+
use crate::layout::LeafMeasure;
|
|
13
13
|
|
|
14
|
-
pub(crate) type LayoutTree = TaffyTree<
|
|
14
|
+
pub(crate) type LayoutTree = TaffyTree<LeafMeasure>;
|
|
15
15
|
/// Semantic node id -> retained layout node. Keys are long node-id strings
|
|
16
16
|
/// hashed for every node every frame, so a fast non-DoS hasher is used.
|
|
17
17
|
pub(crate) type LayoutNodes = FxHashMap<String, NodeId>;
|
|
@@ -21,7 +21,7 @@ pub(crate) struct LayoutSpec<'a> {
|
|
|
21
21
|
pub id: &'a str,
|
|
22
22
|
pub style: Style,
|
|
23
23
|
/// Intrinsic size of a leaf; always `None` for a node with children.
|
|
24
|
-
pub context: Option<
|
|
24
|
+
pub context: Option<LeafMeasure>,
|
|
25
25
|
/// Indices into the frame's spec list.
|
|
26
26
|
pub children: Vec<usize>,
|
|
27
27
|
}
|
|
@@ -103,7 +103,7 @@ impl LayoutCache {
|
|
|
103
103
|
stats.restyled += 1;
|
|
104
104
|
}
|
|
105
105
|
if self.taffy.get_node_context(node) != spec.context.as_ref() {
|
|
106
|
-
self.taffy.set_node_context(node, spec.context)?;
|
|
106
|
+
self.taffy.set_node_context(node, spec.context.clone())?;
|
|
107
107
|
self.invalidate(node)?;
|
|
108
108
|
stats.remeasured += 1;
|
|
109
109
|
}
|
|
@@ -111,10 +111,10 @@ impl LayoutCache {
|
|
|
111
111
|
node
|
|
112
112
|
}
|
|
113
113
|
None => {
|
|
114
|
-
let node = match spec.context {
|
|
114
|
+
let node = match &spec.context {
|
|
115
115
|
Some(context) => self
|
|
116
116
|
.taffy
|
|
117
|
-
.new_leaf_with_context(spec.style.clone(), context)?,
|
|
117
|
+
.new_leaf_with_context(spec.style.clone(), context.clone())?,
|
|
118
118
|
None => self.taffy.new_leaf(spec.style.clone())?,
|
|
119
119
|
};
|
|
120
120
|
stats.created += 1;
|
|
@@ -33,16 +33,19 @@ pub use input::{
|
|
|
33
33
|
ButtonState, InputEvent, InputOutcome, InputPoint, KeyState, LogicalKey, Modifiers,
|
|
34
34
|
PhysicalKey, PointerButton, PointerId, ScrollDelta, ScrollPhase,
|
|
35
35
|
};
|
|
36
|
-
pub use layout::{
|
|
36
|
+
pub use layout::{
|
|
37
|
+
FallbackIntrinsicMeasurer, IntrinsicMeasurer, IntrinsicSize, TextLineLayout, TextStyle,
|
|
38
|
+
};
|
|
37
39
|
pub use retained::{
|
|
38
40
|
RetainedIdentityKey, RetainedNode, RetainedNodeKind, RetainedNumberKey, RetainedReconciliation,
|
|
39
41
|
RetainedTree, RetainedTreeError,
|
|
40
42
|
};
|
|
41
43
|
pub use runtime::{
|
|
42
|
-
HotUpdateReport, HotUpdateTimings, ImeRequest, PlatformConventions, Runtime,
|
|
43
|
-
RuntimeFrame, RuntimeLoadError, SEMANTIC_UI_IR_VERSION, StateMutation,
|
|
44
|
+
HostServices, HotUpdateReport, HotUpdateTimings, ImeRequest, PlatformConventions, Runtime,
|
|
45
|
+
RuntimeDiagnostic, RuntimeFrame, RuntimeLoadError, SEMANTIC_UI_IR_VERSION, StateMutation,
|
|
46
|
+
Transaction,
|
|
44
47
|
};
|
|
45
|
-
pub use scene::{Color, Rect, Scene};
|
|
48
|
+
pub use scene::{Color, Rect, Scene, SceneTextStyle};
|
|
46
49
|
pub use scroll::{
|
|
47
50
|
NestedScrollRouteResult, ScrollAxis, ScrollContainerState, ScrollMetrics, ScrollRange,
|
|
48
51
|
ScrollRouteResult, ScrollState, ScrollTracker, route_nested_content_delta,
|