Remove WindowBuilderExtIOS::with_root_view_class (#2459)

This commit is contained in:
Mads Marquart 2022-11-23 15:53:06 +01:00 committed by GitHub
parent 12df8b6c0c
commit 6d0cf6a275
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 51 deletions

View file

@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre
# Unreleased
- **Breaking:** Removed `WindowBuilderExtIOS::with_root_view_class`; instead, you should use `[[view layer] addSublayer: ...]` to add an instance of the desired layer class (e.g. `CAEAGLLayer` or `CAMetalLayer`). See `vulkano-win` or `wgpu` for examples of this.
- On MacOS and Windows, add `Window::set_content_protected`.
- On MacOS, add `EventLoopBuilderExtMacOS::with_activate_ignoring_other_apps`.
- On Windows, fix icons specified on `WindowBuilder` not taking effect for windows created after the first one.

View file

@ -151,7 +151,6 @@ If your PR makes notable changes to Winit's features, please update this section
* Home indicator visibility
* Status bar visibility
* Deferrring system gestures
* Support for custom `UIView` derived class
* Getting the device idiom
* Getting the preferred video mode

View file

@ -139,13 +139,6 @@ impl WindowExtIOS for Window {
/// Additional methods on [`WindowBuilder`] that are specific to iOS.
pub trait WindowBuilderExtIOS {
/// Sets the root view class used by the [`Window`], otherwise a barebones [`UIView`] is provided.
///
/// An instance of the class will be initialized by calling [`-[UIView initWithFrame:]`](https://developer.apple.com/documentation/uikit/uiview/1622488-initwithframe?language=objc).
///
/// [`UIView`]: https://developer.apple.com/documentation/uikit/uiview?language=objc
fn with_root_view_class(self, root_view_class: *const c_void) -> WindowBuilder;
/// Sets the [`contentScaleFactor`] of the underlying [`UIWindow`] to `scale_factor`.
///
/// The default value is device dependent, and it's recommended GLES or Metal applications set
@ -195,12 +188,6 @@ pub trait WindowBuilderExtIOS {
}
impl WindowBuilderExtIOS for WindowBuilder {
#[inline]
fn with_root_view_class(mut self, root_view_class: *const c_void) -> WindowBuilder {
self.platform_specific.root_view_class = unsafe { &*(root_view_class as *const _) };
self
}
#[inline]
fn with_scale_factor(mut self, scale_factor: f64) -> WindowBuilder {
self.platform_specific.scale_factor = Some(scale_factor);

View file

@ -1,5 +1,3 @@
use std::collections::HashMap;
use objc2::declare::ClassBuilder;
use objc2::foundation::NSObject;
use objc2::runtime::{Bool, Class, Object, Sel};
@ -23,21 +21,9 @@ use crate::{
};
// requires main thread
unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {
static mut CLASSES: Option<HashMap<*const Class, &'static Class>> = None;
static mut ID: usize = 0;
if CLASSES.is_none() {
CLASSES = Some(HashMap::default());
}
let classes = CLASSES.as_mut().unwrap();
classes.entry(root_view_class).or_insert_with(move || {
let uiview_class = class!(UIView);
let is_uiview: bool = msg_send![root_view_class, isSubclassOfClass: uiview_class];
assert!(is_uiview, "`root_view_class` must inherit from `UIView`");
unsafe fn get_view_class() -> &'static Class {
static mut CLASS: Option<&'static Class> = None;
if CLASS.is_none() {
extern "C" fn draw_rect(object: &Object, _: Sel, rect: CGRect) {
unsafe {
let window: id = msg_send![object, window];
@ -223,9 +209,8 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {
}
}
let mut decl = ClassBuilder::new(&format!("WinitUIView{}", ID), root_view_class)
let mut decl = ClassBuilder::new("WinitUIView", class!(UIView))
.expect("Failed to declare class `WinitUIView`");
ID += 1;
decl.add_method(sel!(drawRect:), draw_rect as extern "C" fn(_, _, _));
decl.add_method(sel!(layoutSubviews), layout_subviews as extern "C" fn(_, _));
decl.add_method(
@ -250,8 +235,9 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {
handle_touches as extern "C" fn(_, _, _, _),
);
decl.register()
})
CLASS = Some(decl.register());
}
CLASS.unwrap()
}
declare_class!(
@ -382,7 +368,7 @@ pub(crate) unsafe fn create_view(
platform_attributes: &PlatformSpecificWindowBuilderAttributes,
frame: CGRect,
) -> id {
let class = get_view_class(platform_attributes.root_view_class);
let class = get_view_class();
let view: id = msg_send![class, alloc];
assert!(!view.is_null(), "Failed to create `UIView` instance");

View file

@ -688,25 +688,11 @@ impl From<id> for WindowId {
}
}
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct PlatformSpecificWindowBuilderAttributes {
pub root_view_class: &'static Class,
pub scale_factor: Option<f64>,
pub valid_orientations: ValidOrientations,
pub prefers_home_indicator_hidden: bool,
pub prefers_status_bar_hidden: bool,
pub preferred_screen_edges_deferring_system_gestures: ScreenEdge,
}
impl Default for PlatformSpecificWindowBuilderAttributes {
fn default() -> PlatformSpecificWindowBuilderAttributes {
PlatformSpecificWindowBuilderAttributes {
root_view_class: class!(UIView),
scale_factor: None,
valid_orientations: Default::default(),
prefers_home_indicator_hidden: false,
prefers_status_bar_hidden: false,
preferred_screen_edges_deferring_system_gestures: Default::default(),
}
}
}