use super::types::{MacOSObjc2Platform, MacObjc2HandleKind};
use crate::core::PlatformFamily;
use crate::platform::Platform;
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;
impl Platform for MacOSObjc2Platform {
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn backend_name(&self) -> &'static str {
"macos-objc2-preview"
}
fn family(&self) -> PlatformFamily {
PlatformFamily::Desktop
}
fn init(&self) {
let _ = self.objc2_runtime_marker();
self.runtime.initialized.store(true, Ordering::SeqCst);
}
fn run(&self) {
if !self.runtime.initialized.load(Ordering::SeqCst) {
self.init();
}
self.runtime.running.store(true, Ordering::SeqCst);
while self.runtime.running.load(Ordering::SeqCst) {
thread::sleep(Duration::from_millis(16));
}
}
fn quit(&self) {
self.runtime.running.store(false, Ordering::SeqCst);
}
fn create_window(&self, title: &str, x: i32, y: i32, width: u32, height: u32) -> u64 {
let id = self.insert_widget(MacObjc2HandleKind::Window, title, x, y, width, height);
#[cfg(all(target_os = "macos", feature = "objc2-macos"))]
if let Some(mtm) = objc2::MainThreadMarker::new() {
let window = super::native::create_ns_window(mtm, title, x, y, width, height);
super::native::store_native_view(id, &*window as *const _ as *mut std::ffi::c_void);
}
id
}
}