mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-26 03:36:32 +11:00
Remove WindowBuilderExtIOS::with_root_view_class (#2459)
This commit is contained in:
parent
12df8b6c0c
commit
6d0cf6a275
5 changed files with 10 additions and 51 deletions
|
@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
||||||
|
|
||||||
# Unreleased
|
# 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 and Windows, add `Window::set_content_protected`.
|
||||||
- On MacOS, add `EventLoopBuilderExtMacOS::with_activate_ignoring_other_apps`.
|
- 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.
|
- On Windows, fix icons specified on `WindowBuilder` not taking effect for windows created after the first one.
|
||||||
|
|
|
@ -151,7 +151,6 @@ If your PR makes notable changes to Winit's features, please update this section
|
||||||
* Home indicator visibility
|
* Home indicator visibility
|
||||||
* Status bar visibility
|
* Status bar visibility
|
||||||
* Deferrring system gestures
|
* Deferrring system gestures
|
||||||
* Support for custom `UIView` derived class
|
|
||||||
* Getting the device idiom
|
* Getting the device idiom
|
||||||
* Getting the preferred video mode
|
* Getting the preferred video mode
|
||||||
|
|
||||||
|
|
|
@ -139,13 +139,6 @@ impl WindowExtIOS for Window {
|
||||||
|
|
||||||
/// Additional methods on [`WindowBuilder`] that are specific to iOS.
|
/// Additional methods on [`WindowBuilder`] that are specific to iOS.
|
||||||
pub trait WindowBuilderExtIOS {
|
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`.
|
/// 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
|
/// 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 {
|
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]
|
#[inline]
|
||||||
fn with_scale_factor(mut self, scale_factor: f64) -> WindowBuilder {
|
fn with_scale_factor(mut self, scale_factor: f64) -> WindowBuilder {
|
||||||
self.platform_specific.scale_factor = Some(scale_factor);
|
self.platform_specific.scale_factor = Some(scale_factor);
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use objc2::declare::ClassBuilder;
|
use objc2::declare::ClassBuilder;
|
||||||
use objc2::foundation::NSObject;
|
use objc2::foundation::NSObject;
|
||||||
use objc2::runtime::{Bool, Class, Object, Sel};
|
use objc2::runtime::{Bool, Class, Object, Sel};
|
||||||
|
@ -23,21 +21,9 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
// requires main thread
|
// requires main thread
|
||||||
unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {
|
unsafe fn get_view_class() -> &'static Class {
|
||||||
static mut CLASSES: Option<HashMap<*const Class, &'static Class>> = None;
|
static mut CLASS: Option<&'static Class> = None;
|
||||||
static mut ID: usize = 0;
|
if CLASS.is_none() {
|
||||||
|
|
||||||
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`");
|
|
||||||
|
|
||||||
extern "C" fn draw_rect(object: &Object, _: Sel, rect: CGRect) {
|
extern "C" fn draw_rect(object: &Object, _: Sel, rect: CGRect) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let window: id = msg_send![object, window];
|
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`");
|
.expect("Failed to declare class `WinitUIView`");
|
||||||
ID += 1;
|
|
||||||
decl.add_method(sel!(drawRect:), draw_rect as extern "C" fn(_, _, _));
|
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(sel!(layoutSubviews), layout_subviews as extern "C" fn(_, _));
|
||||||
decl.add_method(
|
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(_, _, _, _),
|
handle_touches as extern "C" fn(_, _, _, _),
|
||||||
);
|
);
|
||||||
|
|
||||||
decl.register()
|
CLASS = Some(decl.register());
|
||||||
})
|
}
|
||||||
|
CLASS.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_class!(
|
declare_class!(
|
||||||
|
@ -382,7 +368,7 @@ pub(crate) unsafe fn create_view(
|
||||||
platform_attributes: &PlatformSpecificWindowBuilderAttributes,
|
platform_attributes: &PlatformSpecificWindowBuilderAttributes,
|
||||||
frame: CGRect,
|
frame: CGRect,
|
||||||
) -> id {
|
) -> id {
|
||||||
let class = get_view_class(platform_attributes.root_view_class);
|
let class = get_view_class();
|
||||||
|
|
||||||
let view: id = msg_send![class, alloc];
|
let view: id = msg_send![class, alloc];
|
||||||
assert!(!view.is_null(), "Failed to create `UIView` instance");
|
assert!(!view.is_null(), "Failed to create `UIView` instance");
|
||||||
|
|
|
@ -688,25 +688,11 @@ impl From<id> for WindowId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||||
pub root_view_class: &'static Class,
|
|
||||||
pub scale_factor: Option<f64>,
|
pub scale_factor: Option<f64>,
|
||||||
pub valid_orientations: ValidOrientations,
|
pub valid_orientations: ValidOrientations,
|
||||||
pub prefers_home_indicator_hidden: bool,
|
pub prefers_home_indicator_hidden: bool,
|
||||||
pub prefers_status_bar_hidden: bool,
|
pub prefers_status_bar_hidden: bool,
|
||||||
pub preferred_screen_edges_deferring_system_gestures: ScreenEdge,
|
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(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue