diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c73544e..0f15ae5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,9 @@ - On iOS, disable overscan compensation for external displays (removes black bars surrounding the image). - On Linux, the functions `is_wayland`, `is_x11`, `xlib_xconnection` and `wayland_display` have been moved to a new `EventLoopWindowTargetExtUnix` trait. - +- On iOS, add `set_prefers_status_bar_hidden` extension function instead of + hijacking `set_decorations` for this purpose. + # 0.20.0 Alpha 2 (2019-07-09) - On X11, non-resizable windows now have maximize explicitly disabled. diff --git a/FEATURES.md b/FEATURES.md index fd4c2bf9..134aef96 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -140,6 +140,7 @@ If your PR makes notable changes to Winit's features, please update this section * Setting the `UIView` hidpi factor * Valid orientations * Home indicator visibility +* Status bar visibility * Deferrring system gestures * Support for custom `UIView` derived class * Getting the device idiom @@ -164,8 +165,8 @@ Legend: |Window initialization |✔️ |✔️ |▢[#5] |✔️ |▢[#33]|▢[#33] |❓ | |Providing pointer to init OpenGL |✔️ |✔️ |✔️ |✔️ |✔️ |✔️ |❓ | |Providing pointer to init Vulkan |✔️ |✔️ |✔️ |✔️ |✔️ |❓ |**N/A** | -|Window decorations |✔️ |✔️ |✔️ |▢[#306] |**N/A**|✔️ |**N/A** | -|Window decorations toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |**N/A** | +|Window decorations |✔️ |✔️ |✔️ |▢[#306] |**N/A**|**N/A**|**N/A** | +|Window decorations toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A** | |Window resizing |✔️ |▢[#219]|✔️ |▢[#306] |**N/A**|**N/A**|❓ | |Window resize increments |❌ |❌ |❌ |❌ |❌ |❌ |❌ | |Window transparency |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A** | diff --git a/src/platform/ios.rs b/src/platform/ios.rs index a2a06a65..fd69489a 100644 --- a/src/platform/ios.rs +++ b/src/platform/ios.rs @@ -80,6 +80,16 @@ pub trait WindowExtIOS { /// and then calls /// [`-[UIViewController setNeedsUpdateOfScreenEdgesDeferringSystemGestures]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/2887507-setneedsupdateofscreenedgesdefer?language=objc). fn set_preferred_screen_edges_deferring_system_gestures(&self, edges: ScreenEdge); + + /// Sets whether the [`Window`] prefers the status bar hidden. + /// + /// The default is to prefer showing the status bar. + /// + /// This changes the value returned by + /// [`-[UIViewController prefersStatusBarHidden]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621440-prefersstatusbarhidden?language=objc), + /// and then calls + /// [`-[UIViewController setNeedsStatusBarAppearanceUpdate]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621354-setneedsstatusbarappearanceupdat?language=objc). + fn set_prefers_status_bar_hidden(&self, hidden: bool); } impl WindowExtIOS for Window { @@ -118,6 +128,11 @@ impl WindowExtIOS for Window { self.window .set_preferred_screen_edges_deferring_system_gestures(edges) } + + #[inline] + fn set_prefers_status_bar_hidden(&self, hidden: bool) { + self.window.set_prefers_status_bar_hidden(hidden) + } } /// Additional methods on [`WindowBuilder`] that are specific to iOS. @@ -163,6 +178,14 @@ pub trait WindowBuilderExtIOS { self, edges: ScreenEdge, ) -> WindowBuilder; + + /// Sets whether the [`Window`] prefers the status bar hidden. + /// + /// The default is to prefer showing the status bar. + /// + /// This sets the initial value returned by + /// [`-[UIViewController prefersStatusBarHidden]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621440-prefersstatusbarhidden?language=objc). + fn with_prefers_status_bar_hidden(self, hidden: bool) -> WindowBuilder; } impl WindowBuilderExtIOS for WindowBuilder { @@ -199,6 +222,12 @@ impl WindowBuilderExtIOS for WindowBuilder { .preferred_screen_edges_deferring_system_gestures = edges; self } + + #[inline] + fn with_prefers_status_bar_hidden(mut self, hidden: bool) -> WindowBuilder { + self.platform_specific.prefers_status_bar_hidden = hidden; + self + } } /// Additional methods on [`MonitorHandle`] that are specific to iOS. diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 4bc5096a..2e385c6f 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -331,7 +331,7 @@ pub unsafe fn create_view( // requires main thread pub unsafe fn create_view_controller( - window_attributes: &WindowAttributes, + _window_attributes: &WindowAttributes, platform_attributes: &PlatformSpecificWindowBuilderAttributes, view: id, ) -> id { @@ -347,10 +347,10 @@ pub unsafe fn create_view_controller( !view_controller.is_null(), "Failed to initialize `UIViewController` instance" ); - let status_bar_hidden = if window_attributes.decorations { - NO - } else { + let status_bar_hidden = if platform_attributes.prefers_status_bar_hidden { YES + } else { + NO }; let idiom = event_loop::get_idiom(); let supported_orientations = UIInterfaceOrientationMask::from_valid_orientations_idiom( diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 7c8b9501..4e2167fc 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -214,14 +214,8 @@ impl Inner { } } - pub fn set_decorations(&self, decorations: bool) { - unsafe { - let status_bar_hidden = if decorations { NO } else { YES }; - let () = msg_send![ - self.view_controller, - setPrefersStatusBarHidden: status_bar_hidden - ]; - } + pub fn set_decorations(&self, _decorations: bool) { + warn!("`Window::set_decorations` is ignored on iOS") } pub fn set_always_on_top(&self, _always_on_top: bool) { @@ -414,6 +408,16 @@ impl Inner { ]; } } + + pub fn set_prefers_status_bar_hidden(&self, hidden: bool) { + unsafe { + let status_bar_hidden = if hidden { YES } else { NO }; + let () = msg_send![ + self.view_controller, + setPrefersStatusBarHidden: status_bar_hidden + ]; + } + } } impl Inner { @@ -536,6 +540,7 @@ pub struct PlatformSpecificWindowBuilderAttributes { pub hidpi_factor: Option, pub valid_orientations: ValidOrientations, pub prefers_home_indicator_hidden: bool, + pub prefers_status_bar_hidden: bool, pub preferred_screen_edges_deferring_system_gestures: ScreenEdge, } @@ -546,6 +551,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes { hidpi_factor: None, valid_orientations: Default::default(), prefers_home_indicator_hidden: false, + prefers_status_bar_hidden: false, preferred_screen_edges_deferring_system_gestures: Default::default(), } } diff --git a/src/window.rs b/src/window.rs index f983d791..36079051 100644 --- a/src/window.rs +++ b/src/window.rs @@ -585,10 +585,7 @@ impl Window { /// /// ## Platform-specific /// - /// - **iOS:** Can only be called on the main thread. Controls whether the status bar is hidden - /// via [`setPrefersStatusBarHidden`]. - /// - /// [`setPrefersStatusBarHidden`]: https://developer.apple.com/documentation/uikit/uiviewcontroller/1621440-prefersstatusbarhidden?language=objc + /// - **iOS:** Has no effect. #[inline] pub fn set_decorations(&self, decorations: bool) { self.window.set_decorations(decorations)