mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
gpui: Add simulate_window_scale_factor_change to HeadlessAppContext (#67113)
## Summary I was writing a skill for agents to iterate on their GPUI UI changes by screenshotting frames in a headless app context, and I ran into this missing function, which meant all headless renders used the same scale factor. There are likely many other functions that could be useful if forwarded, but this is the first one I ran into. ## Testing Ran a heavier test locally, but not worth pushing here ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - N/A - [GPUI] Added `simulate_window_scale_factor_change` to `HeadlessAppContext`
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user