use std::rc::Rc; use std::{cell::RefCell, ops::Deref}; use objc2::rc::Id; use objc2_app_kit::{NSView, NSWindow}; use objc2_foundation::NSMutableAttributedString; use super::Platform; #[derive(Clone, Copy)] pub struct WinRef<'a>(pub &'a NSWindow, pub &'a NSView); impl<'a> Deref for WinRef<'a> { type Target = NSWindow; fn deref(&self) -> &Self::Target { self.0 } } impl<'a> AsRef for WinRef<'a> { fn as_ref(&self) -> &NSView { self.1 } } impl<'a> types::WinRef for WinRef<'a> { fn raw(&self) -> Option { use core::ffi::c_void; if let Some(view) = self.contentView() { let view = &*view as *const NSView; let view = view as *const c_void; let view = view as *mut c_void; return Some(WinRaw::from(view)); } None } fn show(&self) { let window = self.0; window.makeKeyAndOrderFront(Some(&window)); } fn close(&self) { let window = self.0; window.close() } fn fresh(&self, _: &str) { let view = self.1; unsafe { view.setNeedsDisplay(true) }; } fn size(&self) -> (u32, u32) { let factor: Factor = self.0.into(); let frame = self.1.frame(); let ret = (factor.to_u32(frame.size.width), factor.to_u32(frame.size.height)); ret } fn density(&self) -> f32 { Factor::from(self.0).as_f32() } } #[derive(Debug)] pub struct WinHandle(pub Id); impl types::WinHandle for WinHandle { fn with(&self, mut fun: impl FnMut(WinRef<'_>)) { if let Some(view) = self.0.contentView() { fun(WinRef(&self.0, &view)); } } } #[derive(Clone)] pub struct Vars { delegate: Rc>, marked_text: Rc>>, } mod event; pub use event::*; mod win; pub use win::*; mod view; pub use view::*; mod raw; pub use raw::*; mod factor; pub use factor::*;