@effindomv2/fui-rs 0.1.10 → 0.1.11

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/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "fui-rs"
3
- version = "0.1.10"
3
+ version = "0.1.11"
4
4
  edition = "2021"
5
5
  license = "AGPL-3.0-only OR LicenseRef-EffinDom-Commercial"
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effindomv2/fui-rs",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "private": false,
5
5
  "license": "AGPL-3.0-only OR LicenseRef-EffinDom-Commercial",
6
6
  "description": "EffinDom v2 Rust frontend framework SDK and host generators",
@@ -271,6 +271,19 @@ impl NavLink {
271
271
  self
272
272
  }
273
273
 
274
+ pub fn bind_theme(&self, handler: impl Fn(&NavLink, crate::theme::Theme) + 'static) -> &Self {
275
+ let target = self.event_target();
276
+ let guard = subscribe(move |theme| {
277
+ if let Some(link) = target.upgrade() {
278
+ handler(&link, theme);
279
+ }
280
+ });
281
+ self.root
282
+ .retained_node_ref()
283
+ .retain_attachment(Rc::new(guard));
284
+ self
285
+ }
286
+
274
287
  pub fn on_navigate(&self, handler: impl Fn(NavigateEventArgs) + 'static) -> &Self {
275
288
  *self.navigate.borrow_mut() = Some(Rc::new(handler));
276
289
  self
@@ -334,6 +347,24 @@ struct NavLinkEventTarget {
334
347
  }
335
348
 
336
349
  impl NavLinkEventTarget {
350
+ fn upgrade(&self) -> Option<NavLink> {
351
+ Some(NavLink {
352
+ root: self.weak_root.upgrade()?,
353
+ label: self.label.clone(),
354
+ href: self.href.clone(),
355
+ open_in_new_tab: self.open_in_new_tab.clone(),
356
+ navigate: self.navigate.clone(),
357
+ hovered: self.hovered.clone(),
358
+ focused: self.focused.clone(),
359
+ pointer_pressed: self.pointer_pressed.clone(),
360
+ pointer_pressed_open_in_new_tab: self.pointer_pressed_open_in_new_tab.clone(),
361
+ enter_pressed: self.enter_pressed.clone(),
362
+ enter_pressed_open_in_new_tab: self.enter_pressed_open_in_new_tab.clone(),
363
+ preview_pinned_for_context_menu: self.preview_pinned_for_context_menu.clone(),
364
+ text_color_override: self.text_color_override.clone(),
365
+ })
366
+ }
367
+
337
368
  fn is_enabled(&self) -> bool {
338
369
  self.weak_root
339
370
  .upgrade()
@@ -1151,6 +1151,40 @@ fn retained_button_and_nav_link_keep_theme_subscriptions_after_wrappers_drop() {
1151
1151
  use_system_theme();
1152
1152
  }
1153
1153
 
1154
+ #[test]
1155
+ fn nav_link_bind_theme_preserves_concrete_control_dx_and_retained_lifetime() {
1156
+ ffi::test::reset();
1157
+ let previous_theme = current_theme();
1158
+ let parent = column();
1159
+ let link = NavLink::with_label("/docs", "Docs");
1160
+ link.bind_theme(|link, theme| {
1161
+ link.bg_color(theme.colors.surface)
1162
+ .text_color(theme.colors.text_muted);
1163
+ });
1164
+ parent.child(&link);
1165
+ Application::mount(parent);
1166
+ let link_handle = link.handle().raw();
1167
+ let label_handle = link.label_node().handle().raw();
1168
+ drop(link);
1169
+ ffi::test::take_calls();
1170
+
1171
+ let changed = generate_theme(false, 0x2468ACFF);
1172
+ use_custom_theme(changed.clone());
1173
+ let calls = ffi::test::take_calls();
1174
+ assert!(calls.iter().any(|call| matches!(
1175
+ call,
1176
+ Call::SetBgColor { handle, color }
1177
+ if *handle == link_handle && *color == changed.colors.surface
1178
+ )));
1179
+ assert!(calls.iter().any(|call| matches!(
1180
+ call,
1181
+ Call::SetTextColor { handle, color }
1182
+ if *handle == label_handle && *color == changed.colors.text_muted
1183
+ )));
1184
+
1185
+ use_custom_theme(previous_theme);
1186
+ }
1187
+
1154
1188
  #[test]
1155
1189
  fn retained_pressable_and_slider_keep_theme_subscriptions_after_wrappers_drop() {
1156
1190
  ffi::test::reset();