mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Fix view frame in portrait when starting iOS app in landscape (#1703)
Co-authored-by: Francesca Lovebloom <francesca@brainiumstudios.com>
This commit is contained in:
parent
71e3d25422
commit
c9558c5f0e
|
@ -32,6 +32,7 @@
|
||||||
- On macOS, updated core-* dependencies and cocoa.
|
- On macOS, updated core-* dependencies and cocoa.
|
||||||
- Bump `parking_lot` to 0.11
|
- Bump `parking_lot` to 0.11
|
||||||
- On Android, bump `ndk`, `ndk-sys` and `ndk-glue` to 0.2. Checkout the new ndk-glue main proc attribute.
|
- On Android, bump `ndk`, `ndk-sys` and `ndk-glue` to 0.2. Checkout the new ndk-glue main proc attribute.
|
||||||
|
- On iOS, fixed starting the app in landscape where the view still had portrait dimensions.
|
||||||
- Deprecate the stdweb backend, to be removed in a future release
|
- Deprecate the stdweb backend, to be removed in a future release
|
||||||
- **Breaking:** Prefixed virtual key codes `Add`, `Multiply`, `Divide`, `Decimal`, and `Subtract` with `Numpad`.
|
- **Breaking:** Prefixed virtual key codes `Add`, `Multiply`, `Divide`, `Decimal`, and `Subtract` with `Numpad`.
|
||||||
- Added `Asterisk` and `Plus` virtual key codes.
|
- Added `Asterisk` and `Plus` virtual key codes.
|
||||||
|
|
|
@ -29,14 +29,14 @@ pub struct NSOperatingSystemVersion {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct CGPoint {
|
pub struct CGPoint {
|
||||||
pub x: CGFloat,
|
pub x: CGFloat,
|
||||||
pub y: CGFloat,
|
pub y: CGFloat,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct CGSize {
|
pub struct CGSize {
|
||||||
pub width: CGFloat,
|
pub width: CGFloat,
|
||||||
pub height: CGFloat,
|
pub height: CGFloat,
|
||||||
|
@ -52,7 +52,7 @@ impl CGSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct CGRect {
|
pub struct CGRect {
|
||||||
pub origin: CGPoint,
|
pub origin: CGPoint,
|
||||||
pub size: CGSize,
|
pub size: CGSize,
|
||||||
|
|
|
@ -123,17 +123,26 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {
|
||||||
|
|
||||||
let window: id = msg_send![object, window];
|
let window: id = msg_send![object, window];
|
||||||
assert!(!window.is_null());
|
assert!(!window.is_null());
|
||||||
let bounds: CGRect = msg_send![window, bounds];
|
let window_bounds: CGRect = msg_send![window, bounds];
|
||||||
let screen: id = msg_send![window, screen];
|
let screen: id = msg_send![window, screen];
|
||||||
let screen_space: id = msg_send![screen, coordinateSpace];
|
let screen_space: id = msg_send![screen, coordinateSpace];
|
||||||
let screen_frame: CGRect =
|
let screen_frame: CGRect =
|
||||||
msg_send![object, convertRect:bounds toCoordinateSpace:screen_space];
|
msg_send![object, convertRect:window_bounds toCoordinateSpace:screen_space];
|
||||||
let scale_factor: CGFloat = msg_send![screen, scale];
|
let scale_factor: CGFloat = msg_send![screen, scale];
|
||||||
let size = crate::dpi::LogicalSize {
|
let size = crate::dpi::LogicalSize {
|
||||||
width: screen_frame.size.width as f64,
|
width: screen_frame.size.width as f64,
|
||||||
height: screen_frame.size.height as f64,
|
height: screen_frame.size.height as f64,
|
||||||
}
|
}
|
||||||
.to_physical(scale_factor.into());
|
.to_physical(scale_factor.into());
|
||||||
|
|
||||||
|
// If the app is started in landscape, the view frame and window bounds can be mismatched.
|
||||||
|
// The view frame will be in portrait and the window bounds in landscape. So apply the
|
||||||
|
// window bounds to the view frame to make it consistent.
|
||||||
|
let view_frame: CGRect = msg_send![object, frame];
|
||||||
|
if view_frame != window_bounds {
|
||||||
|
let () = msg_send![object, setFrame: window_bounds];
|
||||||
|
}
|
||||||
|
|
||||||
app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
|
app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
|
||||||
window_id: RootWindowId(window.into()),
|
window_id: RootWindowId(window.into()),
|
||||||
event: WindowEvent::Resized(size),
|
event: WindowEvent::Resized(size),
|
||||||
|
|
Loading…
Reference in a new issue