@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.
Files changed (33) hide show
  1. package/README.md +11 -1
  2. package/bin/desktop.mjs +143 -0
  3. package/bin/mun.mjs +27 -10
  4. package/native/mun-native/src/host_services.rs +202 -0
  5. package/native/mun-native/src/lib.rs +209 -42
  6. package/native/mun-native/src/text.rs +107 -16
  7. package/native/mun-runtime/src/collection.rs +18 -1
  8. package/native/mun-runtime/src/ir.rs +71 -1
  9. package/native/mun-runtime/src/layout.rs +85 -0
  10. package/native/mun-runtime/src/layout_cache.rs +6 -6
  11. package/native/mun-runtime/src/lib.rs +7 -4
  12. package/native/mun-runtime/src/runtime.rs +388 -17
  13. package/native/mun-runtime/src/scene.rs +37 -0
  14. package/native/mun-runtime/tests/host_services.rs +107 -0
  15. package/native/mun-runtime/tests/minimum_window_size.rs +80 -0
  16. package/native/mun-runtime/tests/priority_proposals.rs +69 -0
  17. package/native/mun-runtime/tests/text_proposals.rs +42 -0
  18. package/native/mun-runtime/tests/typography.rs +63 -0
  19. package/package.json +19 -16
  20. package/schemas/semantic-ui-ir-v1.schema.json +89 -0
  21. package/templates/desktop/gitignore +5 -0
  22. package/templates/desktop/package.json +10 -0
  23. package/templates/desktop/src-tauri/Cargo.toml +14 -0
  24. package/templates/desktop/src-tauri/build.rs +1 -0
  25. package/templates/desktop/src-tauri/capabilities/main.json +12 -0
  26. package/templates/desktop/src-tauri/icons/icon.icns +0 -0
  27. package/templates/desktop/src-tauri/icons/icon.ico +0 -0
  28. package/templates/desktop/src-tauri/icons/icon.png +0 -0
  29. package/templates/desktop/src-tauri/src/main.rs +2 -0
  30. package/templates/desktop/src-tauri/tauri.conf.json +42 -0
  31. package/templates/desktop/vite.config.ts +10 -0
  32. package/templates/project/package.json +3 -0
  33. package/templates/project/src/index.css +9 -0
@@ -19,7 +19,7 @@ use crate::{
19
19
  UiAction, UiAlignment, UiBinaryOperator, UiExpression, UiNode, UiOverlayAlignment, UiPaint,
20
20
  UiProgram, UiShapeKind, UiTransition,
21
21
  },
22
- layout::{FallbackIntrinsicMeasurer, IntrinsicMeasurer},
22
+ layout::{FallbackIntrinsicMeasurer, IntrinsicMeasurer, LeafMeasure},
23
23
  layout_cache::{LayoutCache, LayoutNodes, LayoutSpec, LayoutSyncStats, LayoutTree},
24
24
  motion::{MotionChannelKey, MotionScheduler},
25
25
  retained::{
@@ -35,6 +35,20 @@ use crate::{
35
35
  pub const SEMANTIC_UI_IR_VERSION: u32 = 1;
36
36
 
37
37
  const TEXT_FIELD_FONT_SIZE: f32 = 16.0;
38
+ /// Body size of ordinary Text without a `.font` modifier.
39
+ const TEXT_FONT_SIZE: f32 = 24.0;
40
+
41
+ fn text_style(font: Option<&crate::ir::UiTypography>) -> crate::layout::TextStyle {
42
+ font.map_or(crate::layout::TextStyle::body(TEXT_FONT_SIZE), |font| {
43
+ font.style(TEXT_FONT_SIZE)
44
+ })
45
+ }
46
+
47
+ fn text_line_limit(font: Option<&crate::ir::UiTypography>) -> Option<usize> {
48
+ font.and_then(|font| font.line_limit)
49
+ .filter(|limit| *limit > 0)
50
+ .map(|limit| limit as usize)
51
+ }
38
52
  const TEXT_FIELD_INSET_X: f32 = 12.0;
39
53
  const TEXT_FIELD_INSET_Y: f32 = 7.0;
40
54
  const TEXT_CARET_WIDTH: f32 = 1.5;
@@ -80,6 +94,26 @@ pub enum RuntimeDiagnostic {
80
94
  /// onAppear/onDisappear actions kept changing which Views are present;
81
95
  /// reconciliation stopped after a bounded number of passes.
82
96
  LifecycleLimit { passes: usize },
97
+ /// A host service call failed (missing file, denied access, no host);
98
+ /// the rest of the transaction still applied.
99
+ HostServiceFailed {
100
+ action: Option<String>,
101
+ service: String,
102
+ operation: String,
103
+ message: String,
104
+ },
105
+ }
106
+
107
+ /// Operating-system services the embedding host offers to Mün programs.
108
+ /// The runtime never touches the file system or shell itself; a host decides
109
+ /// which services exist. Without a host every call fails with a diagnostic.
110
+ pub trait HostServices {
111
+ fn call(
112
+ &mut self,
113
+ service: &str,
114
+ operation: &str,
115
+ arguments: &[Value],
116
+ ) -> Result<Value, String>;
83
117
  }
84
118
 
85
119
  /// Bounded lifecycle reconciliation: actions that toggle presence forever
@@ -98,6 +132,8 @@ struct FrameLayoutSpec<'a> {
98
132
  spec: LayoutSpec<'a>,
99
133
  /// Flexible-frame intent ([width, height]); applied by the parent.
100
134
  flexible: [bool; 2],
135
+ ideal: [Option<f32>; 2],
136
+ priority: f32,
101
137
  axis_leaf: Option<AxisLeaf>,
102
138
  }
103
139
 
@@ -465,6 +501,7 @@ pub struct Runtime {
465
501
  conventions: PlatformConventions,
466
502
  measurer: Rc<dyn IntrinsicMeasurer>,
467
503
  clipboard_requests: Vec<crate::input::ClipboardRequest>,
504
+ host: Option<Box<dyn HostServices>>,
468
505
  pending_cut: Option<(u64, String, crate::text_edit::TextEditor)>,
469
506
  pending_paste: Option<(u64, String)>,
470
507
  /// Active scrollbar thumb drag: pointer, scroll view id, grab offset.
@@ -563,6 +600,7 @@ impl Runtime {
563
600
  conventions: PlatformConventions::default(),
564
601
  measurer: Rc::new(FallbackIntrinsicMeasurer),
565
602
  clipboard_requests: Vec::new(),
603
+ host: None,
566
604
  pending_cut: None,
567
605
  pending_paste: None,
568
606
  scrollbar_drag: None,
@@ -678,6 +716,7 @@ impl Runtime {
678
716
  let started = std::time::Instant::now();
679
717
  next.measurer = self.measurer.clone();
680
718
  next.conventions = self.conventions;
719
+ next.host = self.host.take();
681
720
  next.revision = self.revision + 1;
682
721
  next.retained = std::mem::take(&mut self.retained);
683
722
  // Semantic ids are stable across compatible updates: unchanged nodes
@@ -899,6 +938,10 @@ impl Runtime {
899
938
  self.conventions = conventions;
900
939
  }
901
940
 
941
+ pub fn set_host_services(&mut self, host: Box<dyn HostServices>) {
942
+ self.host = Some(host);
943
+ }
944
+
902
945
  pub fn take_ime_requests(&mut self) -> Vec<ImeRequest> {
903
946
  std::mem::take(&mut self.ime_requests)
904
947
  }
@@ -944,6 +987,102 @@ impl Runtime {
944
987
  (width, height)
945
988
  }
946
989
 
990
+ /// Changes whenever a state transaction (and so, possibly, the layout)
991
+ /// was committed. Hosts key derived layout facts such as
992
+ /// [`Self::minimum_window_size`] on it instead of recomputing per frame.
993
+ pub fn revision(&self) -> u64 {
994
+ self.revision
995
+ }
996
+
997
+ /// The smallest logical window size the root view can be laid out in
998
+ /// without being clipped, measured with the runtime's own measurer.
999
+ pub fn minimum_window_size(&self) -> (f32, f32) {
1000
+ let measurer = self.measurer.clone();
1001
+ self.minimum_window_size_with_measurer(measurer.as_ref())
1002
+ }
1003
+
1004
+ /// Lays the frame's own layout input out under a min-content proposal, in
1005
+ /// a scratch tree (the retained [`LayoutCache`] is left untouched), with
1006
+ /// everything the window is allowed to compress taken out:
1007
+ ///
1008
+ /// - flexible frames stop filling, so they count only their authored
1009
+ /// `minWidth` / `minHeight` (a flexible leaf's intrinsic size is dropped
1010
+ /// on its flexible axes; a stack still counts its children);
1011
+ /// - a ScrollView counts its own frame and padding, never its content;
1012
+ /// - Text counts no width, because it wraps or truncates rather than
1013
+ /// holding the window open (and its content is often dynamic), and the
1014
+ /// height of its unwrapped lines.
1015
+ ///
1016
+ /// A fixed frame on the root view is therefore its minimum on that axis.
1017
+ /// The window node's own size is only the initial window size (the
1018
+ /// compiler always emits one), so it does not take part.
1019
+ pub fn minimum_window_size_with_measurer(
1020
+ &self,
1021
+ measurer: &dyn IntrinsicMeasurer,
1022
+ ) -> (f32, f32) {
1023
+ use taffy::style::Overflow;
1024
+ let mut specs = Vec::new();
1025
+ let roots = self.build_layout_nodes(&self.program.root.child, &mut specs, measurer);
1026
+ let specs = specs
1027
+ .into_iter()
1028
+ .map(|item| {
1029
+ let FrameLayoutSpec {
1030
+ mut spec, flexible, ..
1031
+ } = item;
1032
+ spec.style.flex_grow = 0.0;
1033
+ spec.style.flex_basis = Dimension::auto();
1034
+ if spec.style.overflow.x == Overflow::Scroll
1035
+ || spec.style.overflow.y == Overflow::Scroll
1036
+ {
1037
+ spec.children.clear();
1038
+ }
1039
+ spec.context = spec.context.map(|context| {
1040
+ let mut size = minimum_leaf_size(&context);
1041
+ if flexible[0] {
1042
+ size.width = 0.0;
1043
+ }
1044
+ if flexible[1] {
1045
+ size.height = 0.0;
1046
+ }
1047
+ LeafMeasure::Intrinsic(size)
1048
+ });
1049
+ spec
1050
+ })
1051
+ .collect::<Vec<_>>();
1052
+ let mut scratch = LayoutCache::default();
1053
+ let content = (|| {
1054
+ scratch.sync(&specs, &roots, Style::default())?;
1055
+ let wrapper = scratch.wrapper().expect("synced layout has a window node");
1056
+ scratch.taffy.compute_layout_with_measure(
1057
+ wrapper,
1058
+ Size::MIN_CONTENT,
1059
+ |inputs, _, context, style| {
1060
+ taffy::compute_leaf_layout(
1061
+ inputs,
1062
+ style,
1063
+ |_, _| 0.0,
1064
+ |known_dimensions, _| {
1065
+ let intrinsic = match context {
1066
+ Some(LeafMeasure::Intrinsic(size)) => *size,
1067
+ _ => Default::default(),
1068
+ };
1069
+ Size {
1070
+ width: known_dimensions.width.unwrap_or(intrinsic.width),
1071
+ height: known_dimensions.height.unwrap_or(intrinsic.height),
1072
+ }
1073
+ },
1074
+ )
1075
+ },
1076
+ )?;
1077
+ Ok::<_, taffy::TaffyError>(scratch.taffy.layout(wrapper)?.size)
1078
+ })()
1079
+ .unwrap_or(Size::ZERO);
1080
+ (
1081
+ content.width.max(0.0).ceil(),
1082
+ content.height.max(0.0).ceil(),
1083
+ )
1084
+ }
1085
+
947
1086
  pub fn step(&mut self, dt_seconds: f32) -> bool {
948
1087
  self.motion.step(dt_seconds);
949
1088
  self.entering
@@ -2126,6 +2265,9 @@ impl Runtime {
2126
2265
  UiAction::ToggleState { state, .. } | UiAction::SetState { state, .. } => {
2127
2266
  self.scope_model.structural_states.contains(state)
2128
2267
  }
2268
+ UiAction::Host { state, .. } => state
2269
+ .as_ref()
2270
+ .is_some_and(|state| self.scope_model.structural_states.contains(state)),
2129
2271
  UiAction::Sequence { actions, .. } => {
2130
2272
  actions.iter().any(|action| self.may_reject(action))
2131
2273
  }
@@ -2372,6 +2514,38 @@ impl Runtime {
2372
2514
  self.apply_action_mutations(action, mutations)?;
2373
2515
  }
2374
2516
  }
2517
+ UiAction::Host {
2518
+ service,
2519
+ operation,
2520
+ arguments,
2521
+ state,
2522
+ ..
2523
+ } => {
2524
+ let arguments: Vec<Value> = arguments.iter().map(|a| self.eval(a)).collect();
2525
+ let result = match self.host.as_mut() {
2526
+ Some(host) => host.call(service, operation, &arguments),
2527
+ None => Err("this host offers no operating-system services".to_string()),
2528
+ };
2529
+ match result {
2530
+ Ok(new) => {
2531
+ if let Some(state) = state {
2532
+ let old = self.state.get(state).cloned().unwrap_or(Value::Null);
2533
+ self.state.insert(state.clone(), new.clone());
2534
+ mutations.push(StateMutation {
2535
+ state: state.clone(),
2536
+ old,
2537
+ new,
2538
+ });
2539
+ }
2540
+ }
2541
+ Err(message) => self.diagnostics.push(RuntimeDiagnostic::HostServiceFailed {
2542
+ action: None,
2543
+ service: service.clone(),
2544
+ operation: operation.clone(),
2545
+ message,
2546
+ }),
2547
+ }
2548
+ }
2375
2549
  }
2376
2550
  Ok(())
2377
2551
  }
@@ -2675,14 +2849,25 @@ impl Runtime {
2675
2849
  height: AvailableSpace::Definite(height),
2676
2850
  },
2677
2851
  |inputs, _, context, style| {
2678
- let intrinsic = context.copied().unwrap_or_default();
2679
2852
  taffy::compute_leaf_layout(
2680
2853
  inputs,
2681
2854
  style,
2682
2855
  |_, _| 0.0,
2683
- |known_dimensions, _| Size {
2684
- width: known_dimensions.width.unwrap_or(intrinsic.width),
2685
- height: known_dimensions.height.unwrap_or(intrinsic.height),
2856
+ |known_dimensions, available_space| {
2857
+ let intrinsic = context
2858
+ .map(|context| {
2859
+ measure_leaf(
2860
+ context,
2861
+ known_dimensions,
2862
+ available_space,
2863
+ measurer,
2864
+ )
2865
+ })
2866
+ .unwrap_or_default();
2867
+ Size {
2868
+ width: known_dimensions.width.unwrap_or(intrinsic.width),
2869
+ height: known_dimensions.height.unwrap_or(intrinsic.height),
2870
+ }
2686
2871
  },
2687
2872
  )
2688
2873
  },
@@ -3293,6 +3478,18 @@ impl Runtime {
3293
3478
  .map(crate::ir::UiPadding::edges)
3294
3479
  .unwrap_or([0.0; 4]);
3295
3480
  let spacing = layout.and_then(|layout| layout.spacing).unwrap_or(0.0);
3481
+ let ideal = [
3482
+ layout
3483
+ .and_then(|layout| layout.ideal_width)
3484
+ .filter(|value| value.is_finite() && *value >= 0.0),
3485
+ layout
3486
+ .and_then(|layout| layout.ideal_height)
3487
+ .filter(|value| value.is_finite() && *value >= 0.0),
3488
+ ];
3489
+ let priority = layout
3490
+ .and_then(|layout| layout.layout_priority)
3491
+ .filter(|value| value.is_finite())
3492
+ .unwrap_or(0.0);
3296
3493
  // Flexible frames: a max bound on an axis without a fixed size makes the
3297
3494
  // view take what its parent offers on that axis (applied by the parent,
3298
3495
  // which knows its main axis), clamped to [min, max].
@@ -3412,8 +3609,15 @@ impl Runtime {
3412
3609
  style.align_items = Some(vertical);
3413
3610
  style.justify_items = Some(horizontal);
3414
3611
  }
3415
- UiNode::Text { .. }
3416
- | UiNode::Action { .. }
3612
+ UiNode::Text { .. } => {
3613
+ // Text accepts a bounded width proposal and reports the
3614
+ // corresponding wrapped height, instead of forcing a stack
3615
+ // to fit its unbounded single-line ideal width.
3616
+ if width.is_none() && layout.and_then(|layout| layout.max_width).is_none() {
3617
+ style.max_size.width = LengthPercentageAuto::percent(1.0);
3618
+ }
3619
+ }
3620
+ UiNode::Action { .. }
3417
3621
  | UiNode::Panel { .. }
3418
3622
  | UiNode::TextField { .. }
3419
3623
  | UiNode::RadioGroup { .. }
@@ -3439,24 +3643,49 @@ impl Runtime {
3439
3643
  }
3440
3644
 
3441
3645
  let intrinsic = match node {
3442
- UiNode::Text { value, .. } => Some(measurer.measure_text(&self.eval_text(value))),
3443
- UiNode::Action { label, .. } => Some(measurer.measure_action(label)),
3444
- UiNode::Panel { .. } => Some(measurer.measure_panel()),
3646
+ UiNode::Text { value, font, .. } => {
3647
+ let content = self.eval_text(value);
3648
+ let style = text_style(font.as_ref());
3649
+ let line_limit = text_line_limit(font.as_ref());
3650
+ let natural = if font.is_some() {
3651
+ measurer.measure_styled_text(&content, style, None, line_limit)
3652
+ } else {
3653
+ measurer.measure_text(&content)
3654
+ };
3655
+ Some(LeafMeasure::Text {
3656
+ natural,
3657
+ content,
3658
+ style,
3659
+ line_limit,
3660
+ })
3661
+ }
3662
+ UiNode::Action { label, .. } => {
3663
+ Some(LeafMeasure::Intrinsic(measurer.measure_action(label)))
3664
+ }
3665
+ UiNode::Panel { .. } => Some(LeafMeasure::Intrinsic(measurer.measure_panel())),
3445
3666
  UiNode::TextField {
3446
3667
  state, placeholder, ..
3447
3668
  } => {
3448
3669
  let value = self.state.get(state).and_then(Value::as_str).unwrap_or("");
3449
- Some(measurer.measure_text_field(value, placeholder.as_deref()))
3670
+ Some(LeafMeasure::Intrinsic(
3671
+ measurer.measure_text_field(value, placeholder.as_deref()),
3672
+ ))
3450
3673
  }
3451
3674
  UiNode::RadioGroup { options, .. } => {
3452
3675
  let labels = options
3453
3676
  .iter()
3454
3677
  .map(|option| option.label.clone())
3455
3678
  .collect::<Vec<_>>();
3456
- Some(measurer.measure_radio_group(&labels))
3679
+ Some(LeafMeasure::Intrinsic(
3680
+ measurer.measure_radio_group(&labels),
3681
+ ))
3457
3682
  }
3458
- UiNode::Toggle { label, .. } => Some(measurer.measure_toggle(label)),
3459
- UiNode::Progress { label, .. } => Some(measurer.measure_progress(label.as_deref())),
3683
+ UiNode::Toggle { label, .. } => {
3684
+ Some(LeafMeasure::Intrinsic(measurer.measure_toggle(label)))
3685
+ }
3686
+ UiNode::Progress { label, .. } => Some(LeafMeasure::Intrinsic(
3687
+ measurer.measure_progress(label.as_deref()),
3688
+ )),
3460
3689
  _ => None,
3461
3690
  };
3462
3691
 
@@ -3475,7 +3704,38 @@ impl Runtime {
3475
3704
  for &child_id in &child_nodes {
3476
3705
  let axis_leaf = specs[child_id].axis_leaf;
3477
3706
  let child_flex = specs[child_id].flexible;
3707
+ let child_ideal = specs[child_id].ideal;
3708
+ let is_text = specs[child_id]
3709
+ .spec
3710
+ .context
3711
+ .as_ref()
3712
+ .is_some_and(LeafMeasure::is_text);
3478
3713
  let child_style = &mut specs[child_id].spec.style;
3714
+ if is_text
3715
+ && main_axis_horizontal == Some(true)
3716
+ && child_style.min_size.width == LengthPercentageAuto::auto()
3717
+ {
3718
+ // CSS flexbox defaults to an automatic min-content width.
3719
+ // SwiftUI instead lets Text give up width and gain lines.
3720
+ child_style.min_size.width = LengthPercentageAuto::length(0.0);
3721
+ }
3722
+ // A ScrollView proposes nil on its scrolling axis; this is
3723
+ // precisely where SwiftUI's idealWidth / idealHeight matters.
3724
+ // A definite Stack/window proposal must not turn the ideal
3725
+ // size into an unconditional fixed size.
3726
+ if let UiNode::Scroll { axis, .. } = node {
3727
+ let horizontal = matches!(axis, crate::ir::UiScrollAxis::Horizontal);
3728
+ let (chosen, ideal) = if horizontal {
3729
+ (&mut child_style.size.width, child_ideal[0])
3730
+ } else {
3731
+ (&mut child_style.size.height, child_ideal[1])
3732
+ };
3733
+ if *chosen == Dimension::auto() {
3734
+ if let Some(ideal) = ideal {
3735
+ *chosen = Dimension::length(ideal);
3736
+ }
3737
+ }
3738
+ }
3479
3739
  if let (Some(leaf), Some(main)) = (axis_leaf, main_axis_horizontal) {
3480
3740
  let fixed = |dimension: Dimension| dimension != Dimension::auto();
3481
3741
  match leaf {
@@ -3572,6 +3832,28 @@ impl Runtime {
3572
3832
  }
3573
3833
  children.extend(child_nodes);
3574
3834
  }
3835
+ // Relative layoutPriority influences resistance to compression, not
3836
+ // intrinsic size. With equal priorities, preserve ordinary flex sizing.
3837
+ if matches!(node, UiNode::Row { .. } | UiNode::Column { .. }) && children.len() > 1 {
3838
+ let highest = children
3839
+ .iter()
3840
+ .map(|&id| specs[id].priority)
3841
+ .fold(f32::NEG_INFINITY, f32::max);
3842
+ let lowest = children
3843
+ .iter()
3844
+ .map(|&id| specs[id].priority)
3845
+ .fold(f32::INFINITY, f32::min);
3846
+ if highest > lowest {
3847
+ for &id in &children {
3848
+ let rank_below_highest = (highest - specs[id].priority).clamp(0.0, 10.0);
3849
+ specs[id].spec.style.flex_shrink = if rank_below_highest == 0.0 {
3850
+ 0.001
3851
+ } else {
3852
+ (rank_below_highest * 10.0).exp().min(1_000.0)
3853
+ };
3854
+ }
3855
+ }
3856
+ }
3575
3857
  let axis_leaf = match node {
3576
3858
  UiNode::Spacer { min_length, .. } => Some(AxisLeaf::Spacer {
3577
3859
  min_length: min_length.unwrap_or(DEFAULT_SPACER_LENGTH),
@@ -3583,10 +3865,25 @@ impl Runtime {
3583
3865
  spec: LayoutSpec {
3584
3866
  id: &base.id,
3585
3867
  style,
3586
- context: if children.is_empty() { intrinsic } else { None },
3868
+ context: if children.is_empty() {
3869
+ intrinsic.map(|measure| {
3870
+ if flexible == [false, false] {
3871
+ measure
3872
+ } else {
3873
+ LeafMeasure::Flexible {
3874
+ measure: Box::new(measure),
3875
+ axes: flexible,
3876
+ }
3877
+ }
3878
+ })
3879
+ } else {
3880
+ None
3881
+ },
3587
3882
  children,
3588
3883
  },
3589
3884
  flexible,
3885
+ ideal,
3886
+ priority,
3590
3887
  axis_leaf,
3591
3888
  });
3592
3889
  vec![specs.len() - 1]
@@ -3822,13 +4119,15 @@ impl Runtime {
3822
4119
  }
3823
4120
 
3824
4121
  match node {
3825
- UiNode::Text { base, value } => {
4122
+ UiNode::Text { base, value, font } => {
4123
+ let style = text_style(font.as_ref());
3826
4124
  scene.texts.push(SceneText {
3827
4125
  id: base.id.clone(),
3828
4126
  text: self.eval_text(value),
3829
4127
  x,
3830
4128
  y: y + 3.0,
3831
- font_size: 24.0,
4129
+ font_size: style.size,
4130
+ wrap_width: Some(rect.width.max(0.0)),
3832
4131
  color: base
3833
4132
  .visual
3834
4133
  .as_ref()
@@ -3836,6 +4135,16 @@ impl Runtime {
3836
4135
  .and_then(paint_start_color)
3837
4136
  .unwrap_or(Color::TEXT)
3838
4137
  .with_opacity(opacity),
4138
+ style: crate::scene::SceneTextStyle {
4139
+ weight: style.weight,
4140
+ italic: style.italic,
4141
+ design: style.design,
4142
+ line_limit: text_line_limit(font.as_ref()),
4143
+ alignment: font
4144
+ .as_ref()
4145
+ .and_then(|font| font.alignment)
4146
+ .unwrap_or(crate::ir::UiTextAlignment::Leading),
4147
+ },
3839
4148
  });
3840
4149
  }
3841
4150
  UiNode::Action { base, label, .. } => {
@@ -3868,6 +4177,7 @@ impl Runtime {
3868
4177
  x: x + 16.0,
3869
4178
  y: y + 8.0,
3870
4179
  font_size: 16.0,
4180
+ wrap_width: None,
3871
4181
  color: base
3872
4182
  .visual
3873
4183
  .as_ref()
@@ -3875,6 +4185,7 @@ impl Runtime {
3875
4185
  .and_then(paint_start_color)
3876
4186
  .unwrap_or(Color::TEXT)
3877
4187
  .with_opacity(opacity),
4188
+ style: crate::scene::SceneTextStyle::default(),
3878
4189
  });
3879
4190
  scene.actions.push(ActionHit {
3880
4191
  id: base.id.clone(),
@@ -4034,7 +4345,9 @@ impl Runtime {
4034
4345
  x: text_x,
4035
4346
  y: origin_y,
4036
4347
  font_size: TEXT_FIELD_FONT_SIZE,
4348
+ wrap_width: None,
4037
4349
  color: foreground.with_opacity(opacity * text_opacity),
4350
+ style: crate::scene::SceneTextStyle::default(),
4038
4351
  });
4039
4352
  scene.actions.push(ActionHit {
4040
4353
  id: base.id.clone(),
@@ -4101,11 +4414,13 @@ impl Runtime {
4101
4414
  x: x + 28.0,
4102
4415
  y: row_y + 5.0,
4103
4416
  font_size: 16.0,
4417
+ wrap_width: None,
4104
4418
  color: foreground.with_opacity(if option.disabled {
4105
4419
  opacity * 0.45
4106
4420
  } else {
4107
4421
  opacity
4108
4422
  }),
4423
+ style: crate::scene::SceneTextStyle::default(),
4109
4424
  });
4110
4425
  if !option.disabled {
4111
4426
  scene.actions.push(ActionHit {
@@ -4167,7 +4482,9 @@ impl Runtime {
4167
4482
  x: x + TOGGLE_BOX + 6.0,
4168
4483
  y: y + (rect.height - line.line_height) * 0.5,
4169
4484
  font_size: CONTROL_LABEL_FONT_SIZE,
4485
+ wrap_width: None,
4170
4486
  color: foreground.with_opacity(opacity),
4487
+ style: crate::scene::SceneTextStyle::default(),
4171
4488
  });
4172
4489
  scene.actions.push(ActionHit {
4173
4490
  id: base.id.clone(),
@@ -4187,6 +4504,7 @@ impl Runtime {
4187
4504
  x,
4188
4505
  y,
4189
4506
  font_size: CONTROL_LABEL_FONT_SIZE,
4507
+ wrap_width: None,
4190
4508
  color: base
4191
4509
  .visual
4192
4510
  .as_ref()
@@ -4194,6 +4512,7 @@ impl Runtime {
4194
4512
  .and_then(paint_start_color)
4195
4513
  .unwrap_or(Color::TEXT)
4196
4514
  .with_opacity(opacity),
4515
+ style: crate::scene::SceneTextStyle::default(),
4197
4516
  });
4198
4517
  track_y += line.line_height + 4.0;
4199
4518
  }
@@ -7076,3 +7395,55 @@ mod tests {
7076
7395
  );
7077
7396
  }
7078
7397
  }
7398
+
7399
+ /// Intrinsic size of a layout leaf for one Taffy measurement.
7400
+ fn measure_leaf(
7401
+ context: &LeafMeasure,
7402
+ known_dimensions: Size<Option<f32>>,
7403
+ available_space: Size<AvailableSpace>,
7404
+ measurer: &dyn IntrinsicMeasurer,
7405
+ ) -> crate::layout::IntrinsicSize {
7406
+ match context {
7407
+ LeafMeasure::Text {
7408
+ content,
7409
+ natural,
7410
+ style,
7411
+ line_limit,
7412
+ } => {
7413
+ let proposed_width = known_dimensions
7414
+ .width
7415
+ .or_else(|| match available_space.width {
7416
+ AvailableSpace::Definite(width) if width.is_finite() => Some(width.max(0.0)),
7417
+ _ => None,
7418
+ });
7419
+ // Keep unbounded proposals cheap; shaping a wrapped
7420
+ // run is only necessary if it might actually wrap.
7421
+ if proposed_width.is_some_and(|width| width < natural.width) {
7422
+ measurer.measure_styled_text(content, *style, proposed_width, *line_limit)
7423
+ } else {
7424
+ *natural
7425
+ }
7426
+ }
7427
+ LeafMeasure::Intrinsic(size) => *size,
7428
+ LeafMeasure::Flexible { measure, axes } => {
7429
+ let mut size = measure_leaf(measure, known_dimensions, available_space, measurer);
7430
+ if axes[0] && available_space.width == AvailableSpace::MinContent {
7431
+ size.width = 0.0;
7432
+ }
7433
+ if axes[1] && available_space.height == AvailableSpace::MinContent {
7434
+ size.height = 0.0;
7435
+ }
7436
+ size
7437
+ }
7438
+ }
7439
+ }
7440
+
7441
+ /// What a leaf contributes to [`Runtime::minimum_window_size`] before its
7442
+ /// flexible axes are dropped: Text keeps only the height of its unwrapped lines.
7443
+ fn minimum_leaf_size(context: &LeafMeasure) -> crate::layout::IntrinsicSize {
7444
+ match context {
7445
+ LeafMeasure::Text { natural, .. } => crate::layout::IntrinsicSize::new(0.0, natural.height),
7446
+ LeafMeasure::Intrinsic(size) => *size,
7447
+ LeafMeasure::Flexible { measure, .. } => minimum_leaf_size(measure),
7448
+ }
7449
+ }
@@ -362,7 +362,44 @@ pub struct SceneText {
362
362
  pub x: f32,
363
363
  pub y: f32,
364
364
  pub font_size: f32,
365
+ /// Width proposal for ordinary Text; control labels remain single-line.
366
+ pub wrap_width: Option<f32>,
365
367
  pub color: Color,
368
+ pub style: SceneTextStyle,
369
+ }
370
+
371
+ /// Typography beyond size: weight/slant/family, line limit and alignment
372
+ /// inside `wrap_width`. `Default` is the regular body style.
373
+ #[derive(Clone, Copy, Debug, PartialEq)]
374
+ pub struct SceneTextStyle {
375
+ pub weight: u16,
376
+ pub italic: bool,
377
+ pub design: crate::ir::UiFontDesign,
378
+ pub line_limit: Option<usize>,
379
+ pub alignment: crate::ir::UiTextAlignment,
380
+ }
381
+
382
+ impl Default for SceneTextStyle {
383
+ fn default() -> Self {
384
+ Self {
385
+ weight: 400,
386
+ italic: false,
387
+ design: crate::ir::UiFontDesign::Default,
388
+ line_limit: None,
389
+ alignment: crate::ir::UiTextAlignment::Leading,
390
+ }
391
+ }
392
+ }
393
+
394
+ impl SceneTextStyle {
395
+ pub fn text_style(&self, size: f32) -> crate::layout::TextStyle {
396
+ crate::layout::TextStyle {
397
+ size,
398
+ weight: self.weight,
399
+ italic: self.italic,
400
+ design: self.design,
401
+ }
402
+ }
366
403
  }
367
404
 
368
405
  #[derive(Clone, Debug)]