From c55e0240d7d6e09d39a3a5ffcfb7a5cd8b865cf1 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 15 Nov 2026 15:40:48 +0000 Subject: [PATCH] ui-contract: testing::windows::set_os sets the shell's OS and egui's in one call --- crates/ui-contract/src/runtime/egui/fixture.rs | 9 --------- crates/ui-contract/src/runtime/windows/shell.rs | 7 ++++++- crates/ui-contract/src/testing/fixture.rs | 1 - crates/ui-contract/src/testing/windows.rs | 6 ++++++ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/ui-contract/src/runtime/egui/fixture.rs b/crates/ui-contract/src/runtime/egui/fixture.rs index d5f6309b7..4ee422628 100644 --- a/crates/ui-contract/src/runtime/egui/fixture.rs +++ b/crates/ui-contract/src/runtime/egui/fixture.rs @@ -576,15 +576,6 @@ pub(crate) fn access_set_value(target: egui::Id, value: f64) -> Event { }) } -/// Tells the context which operating system it runs on. -pub(crate) fn set_os(ctx: &Context, os: craft_host::target::Os) { - ctx.set_os(match os { - craft_host::target::Os::Mac => egui::os::OperatingSystem::Mac, - craft_host::target::Os::Windows => egui::os::OperatingSystem::Windows, - _ => egui::os::OperatingSystem::Nix, - }); -} - /// An IME preedit event of `text` with no cursor range. pub fn ime_preedit(text: &str) -> Event { Event::Ime(egui::ImeEvent::Preedit { text: text.into(), active_range_chars: None }) diff --git a/crates/ui-contract/src/runtime/windows/shell.rs b/crates/ui-contract/src/runtime/windows/shell.rs index a56ee033f..014869182 100644 --- a/crates/ui-contract/src/runtime/windows/shell.rs +++ b/crates/ui-contract/src/runtime/windows/shell.rs @@ -28,9 +28,14 @@ pub fn os_of(ctx: &Context) -> Os { } /// Makes the shell run on `os`, as a test of the OS matrix does: the capabilities and the menu placement of a -/// native build follow it. egui's own OS is the caller's to set. +/// native build follow it, and so does egui's own OS (its text editing keys). #[cfg(feature = "testing")] pub(crate) fn set_os(ctx: &Context, os: Os) { + ctx.set_os(match os { + Os::Mac => egui::os::OperatingSystem::Mac, + Os::Windows => egui::os::OperatingSystem::Windows, + _ => egui::os::OperatingSystem::Nix, + }); shared(ctx, |shared| { let root_chrome = shared.root_frame.as_ref().map(chrome_of); let shell = shared.shell.get_or_insert_with(ShellInfo::default); diff --git a/crates/ui-contract/src/testing/fixture.rs b/crates/ui-contract/src/testing/fixture.rs index 7f755293f..4ec8d39cb 100644 --- a/crates/ui-contract/src/testing/fixture.rs +++ b/crates/ui-contract/src/testing/fixture.rs @@ -304,7 +304,6 @@ impl Fixture { /// text editing. pub fn os(&mut self, os: Os) -> &mut Self { crate::runtime::windows::set_os(&self.frames.ctx, os); - fixture::set_os(&self.frames.ctx, os); self } diff --git a/crates/ui-contract/src/testing/windows.rs b/crates/ui-contract/src/testing/windows.rs index 13febed19..e1208f53b 100644 --- a/crates/ui-contract/src/testing/windows.rs +++ b/crates/ui-contract/src/testing/windows.rs @@ -13,6 +13,12 @@ pub fn install_spec() -> InstallSpec { InstallSpec::new(ShellInfo::default(), Arc::new(NoWindows)) } +/// Makes the shell of `ctx` run on `os`, for a test of the OS matrix: the key table, the chords shown, the chrome, +/// the capabilities of a native build and egui's own OS all follow it. +pub fn set_os(ctx: &egui::Context, os: craft_host::target::Os) { + crate::runtime::windows::set_os(ctx, os); +} + /// The window actions the platform applies out of reach of egui's commands (`SetOpacity`) since the last call. pub fn applied_actions(ctx: &egui::Context) -> Vec<(egui::ViewportId, crate::runtime::windows::WindowAction)> { crate::runtime::windows::take_sent(ctx)