diff --git a/crates/gpui/src/app/headless_app_context.rs b/crates/gpui/src/app/headless_app_context.rs index c7f7c913451..3eb2ebeef9c 100644 --- a/crates/gpui/src/app/headless_app_context.rs +++ b/crates/gpui/src/app/headless_app_context.rs @@ -13,7 +13,7 @@ use crate::{ Context, Entity, EntityId, ForegroundExecutor, Global, Pixels, PlatformHeadlessRenderer, PlatformTextSystem, Render, Reservation, Size, Task, TestDispatcher, TestPlatform, TextSystem, Window, WindowBounds, WindowHandle, WindowOptions, - app::{GpuiBorrow, GpuiMode}, + app::{GpuiBorrow, GpuiMode, test_context::test_window}, }; use anyhow::Result; use image::RgbaImage; @@ -130,6 +130,15 @@ impl HeadlessAppContext { self.dispatcher.run_until_parked(); } + /// Simulates the window moving to a display with a different scale factor. + pub fn simulate_window_scale_factor_change( + &mut self, + window: AnyWindowHandle, + scale_factor: f32, + ) { + test_window(&self.app, window).simulate_scale_factor_change(scale_factor); + } + /// Advances the simulated clock. pub fn advance_clock(&self, duration: Duration) { self.dispatcher.advance_clock(duration); diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rs index 4e6bf835798..df3cce6f760 100644 --- a/crates/gpui/src/app/test_context.rs +++ b/crates/gpui/src/app/test_context.rs @@ -16,6 +16,19 @@ use std::{ cell::RefCell, future::Future, ops::Deref, path::PathBuf, rc::Rc, sync::Arc, time::Duration, }; +pub(crate) fn test_window(app: &AppCell, window: AnyWindowHandle) -> TestWindow { + app.borrow_mut() + .windows + .get_mut(window.id) + .expect("window not found") + .as_deref_mut() + .expect("window is being updated") + .platform_window + .as_test() + .expect("window is not a TestWindow") + .clone() +} + /// A TestAppContext is provided to tests created with `#[gpui::test]`, it provides /// an implementation of `Context` with additional methods that are useful in tests. #[derive(Clone)] @@ -670,17 +683,7 @@ impl TestAppContext { /// Returns the `TestWindow` backing the given handle. pub(crate) fn test_window(&self, window: AnyWindowHandle) -> TestWindow { - self.app - .borrow_mut() - .windows - .get_mut(window.id) - .unwrap() - .as_deref_mut() - .unwrap() - .platform_window - .as_test() - .unwrap() - .clone() + test_window(&self.app, window) } /// Returns a stream of notifications whenever the Entity is updated.