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
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue