Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion winit/examples/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,9 @@ struct WindowState {
rotated: f32,
/// The amount of pan of the window.
panned: PhysicalPosition<f32>,
/// The size passed to the last surface resize, used for drawing.
#[cfg(not(android_platform))]
surface_size: PhysicalSize<u32>,

#[cfg(macos_platform)]
option_as_alt: OptionAsAlt,
Expand All @@ -669,6 +672,8 @@ impl WindowState {

let size = window.surface_size();
let mut state = Self {
#[cfg(not(android_platform))]
surface_size: PhysicalSize::default(),
#[cfg(macos_platform)]
option_as_alt: window.option_as_alt(),
custom_idx: app.custom_cursors.as_ref().map(Vec::len).unwrap_or(1) - 1,
Expand Down Expand Up @@ -861,6 +866,7 @@ impl WindowState {
_ => return,
};
self.surface.resize(width, height).expect("failed to resize inner buffer");
self.surface_size = size;
}
self.window.request_redraw();
}
Expand Down Expand Up @@ -961,7 +967,9 @@ impl WindowState {
let mut buffer = self.surface.buffer_mut()?;

// Draw a different color inside the safe area
let surface_size = self.window.surface_size();
// Use the stored surface_size that matches the buffer dimensions from the last resize(),
// rather than self.window.surface_size() which may already reflect a newer pending size.
let surface_size = self.surface_size;
let insets = self.window.safe_area();
for y in 0..surface_size.height {
for x in 0..surface_size.width {
Expand Down