From 48272d3932ae354fb4df4ad4e4c8e6d76f64123e Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 23 Oct 2026 16:42:36 +0000 Subject: [PATCH] docking: the host stand-in needs no expect, and the label count drops with New Window --- crates/ui/src/docking/native_tests.rs | 1 + crates/ui/src/docking/testing.rs | 13 +++++++++---- crates/ui/src/docking/trial_tests.rs | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/ui/src/docking/native_tests.rs b/crates/ui/src/docking/native_tests.rs index 380aadb1..ae7dc857 100644 --- a/crates/ui/src/docking/native_tests.rs +++ b/crates/ui/src/docking/native_tests.rs @@ -58,6 +58,7 @@ fn driver(layout: Layout) -> DockDriver { DockDriver::new(layout, Content::default()).with_style(|s| s.command_press_floats = true).with_native_host(ORIGIN) } +#[allow(clippy::expect_used)] fn window(d: &DockDriver, panel: u32) -> &Floating { d.layout.floating.iter().find(|w| w.contains(&panel)).expect("floating") } diff --git a/crates/ui/src/docking/testing.rs b/crates/ui/src/docking/testing.rs index 4876b624..f0444f49 100644 --- a/crates/ui/src/docking/testing.rs +++ b/crates/ui/src/docking/testing.rs @@ -46,9 +46,11 @@ pub struct DockDriver { pub float_bounds: Option, /// Passed to [`DockArea::monitors`]. pub monitors: Vec, - /// The stand-in for OS windows, from [`Self::with_native_host`]. + /// The stand-in for OS windows, in use after [`Self::with_native_host`]. #[cfg(feature = "native-windows")] - pub host: Option>>, + host: Option>>, + #[cfg(feature = "native-windows")] + no_host: std::cell::RefCell, style: Option, shapes: Vec, time: f64, @@ -74,6 +76,8 @@ impl> Do monitors: Vec::new(), #[cfg(feature = "native-windows")] host: None, + #[cfg(feature = "native-windows")] + no_host: std::cell::RefCell::new(NativeHost::new(Pos2::ZERO)), style: None, shapes: Vec::new(), time: 0.0, @@ -158,10 +162,11 @@ impl> Do self } - /// The stand-in for OS windows. Panics without [`Self::with_native_host`]. + /// The stand-in for OS windows: without [`Self::with_native_host`], one with no windows + /// that nothing uses. #[cfg(feature = "native-windows")] pub fn host(&self) -> std::cell::RefMut<'_, NativeHost> { - self.host.as_ref().expect("with_native_host").borrow_mut() + self.host.as_deref().unwrap_or(&self.no_host).borrow_mut() } /// The viewport of the floating window with this [`super::Floating::id`]. diff --git a/crates/ui/src/docking/trial_tests.rs b/crates/ui/src/docking/trial_tests.rs index d16cf98d..a8fe97da 100644 --- a/crates/ui/src/docking/trial_tests.rs +++ b/crates/ui/src/docking/trial_tests.rs @@ -195,7 +195,7 @@ fn localized_covers_every_label_and_contains_takes_a_borrowed_panel() { }); full.textures_delta.clear(); let values: Vec<&str> = debug.split("_label: \"").skip(1).filter_map(|rest| rest.split('"').next()).collect(); - assert_eq!(values.len(), 25, "{debug}"); + assert_eq!(values.len(), 24, "{debug}"); assert!(values.iter().all(|v| v.starts_with("dock.")), "a label without a key: {values:?}"); let unique: std::collections::HashSet<_> = values.iter().collect(); assert_eq!(unique.len(), values.len());