use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;
#[cfg(feature = "objc2-core-graphics")]
use objc2_core_graphics::*;
use crate::*;
#[doc(alias = "CTRunDelegateRef")]
#[repr(C)]
pub struct CTRunDelegate {
inner: [u8; 0],
_p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}
cf_type!(
unsafe impl CTRunDelegate {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
unsafe impl RefEncode<"__CTRunDelegate"> for CTRunDelegate {}
);
unsafe impl ConcreteType for CTRunDelegate {
#[doc(alias = "CTRunDelegateGetTypeID")]
#[inline]
fn type_id() -> CFTypeID {
extern "C-unwind" {
fn CTRunDelegateGetTypeID() -> CFTypeID;
}
unsafe { CTRunDelegateGetTypeID() }
}
}
pub type CTRunDelegateDeallocateCallback = Option<unsafe extern "C-unwind" fn(NonNull<c_void>)>;
pub type CTRunDelegateGetAscentCallback =
Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> CGFloat>;
pub type CTRunDelegateGetDescentCallback =
Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> CGFloat>;
pub type CTRunDelegateGetWidthCallback =
Option<unsafe extern "C-unwind" fn(NonNull<c_void>) -> CGFloat>;
#[repr(C)]
#[allow(unpredictable_function_pointer_comparisons)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CTRunDelegateCallbacks {
pub version: CFIndex,
pub dealloc: CTRunDelegateDeallocateCallback,
pub getAscent: CTRunDelegateGetAscentCallback,
pub getDescent: CTRunDelegateGetDescentCallback,
pub getWidth: CTRunDelegateGetWidthCallback,
}
#[cfg(feature = "objc2")]
unsafe impl Encode for CTRunDelegateCallbacks {
const ENCODING: Encoding = Encoding::Struct(
"?",
&[
<CFIndex>::ENCODING,
<CTRunDelegateDeallocateCallback>::ENCODING,
<CTRunDelegateGetAscentCallback>::ENCODING,
<CTRunDelegateGetDescentCallback>::ENCODING,
<CTRunDelegateGetWidthCallback>::ENCODING,
],
);
}
#[cfg(feature = "objc2")]
unsafe impl RefEncode for CTRunDelegateCallbacks {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
pub const kCTRunDelegateVersion1: c_uint = 1;
pub const kCTRunDelegateCurrentVersion: c_uint = kCTRunDelegateVersion1;
impl CTRunDelegate {
#[doc(alias = "CTRunDelegateCreate")]
#[inline]
pub unsafe fn new(
callbacks: NonNull<CTRunDelegateCallbacks>,
ref_con: *mut c_void,
) -> Option<CFRetained<CTRunDelegate>> {
extern "C-unwind" {
fn CTRunDelegateCreate(
callbacks: NonNull<CTRunDelegateCallbacks>,
ref_con: *mut c_void,
) -> Option<NonNull<CTRunDelegate>>;
}
let ret = unsafe { CTRunDelegateCreate(callbacks, ref_con) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[doc(alias = "CTRunDelegateGetRefCon")]
#[inline]
pub unsafe fn ref_con(&self) -> NonNull<c_void> {
extern "C-unwind" {
fn CTRunDelegateGetRefCon(run_delegate: &CTRunDelegate) -> Option<NonNull<c_void>>;
}
let ret = unsafe { CTRunDelegateGetRefCon(self) };
ret.expect("function was marked as returning non-null, but actually returned NULL")
}
}
#[cfg(feature = "objc2")]
extern_protocol!(
#[cfg(feature = "objc2")]
pub unsafe trait CTAdaptiveImageProviding {
#[cfg(feature = "objc2-core-graphics")]
#[unsafe(method(imageForProposedSize:scaleFactor:imageOffset:imageSize:))]
#[unsafe(method_family = none)]
unsafe fn imageForProposedSize_scaleFactor_imageOffset_imageSize(
&self,
proposed_size: CGSize,
scale_factor: CGFloat,
out_image_offset: NonNull<CGPoint>,
out_image_size: NonNull<CGSize>,
) -> Option<Retained<CGImage>>;
}
);
#[deprecated = "renamed to `CTRunDelegate::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CTRunDelegateCreate(
callbacks: NonNull<CTRunDelegateCallbacks>,
ref_con: *mut c_void,
) -> Option<CFRetained<CTRunDelegate>> {
extern "C-unwind" {
fn CTRunDelegateCreate(
callbacks: NonNull<CTRunDelegateCallbacks>,
ref_con: *mut c_void,
) -> Option<NonNull<CTRunDelegate>>;
}
let ret = unsafe { CTRunDelegateCreate(callbacks, ref_con) };
ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
#[deprecated = "renamed to `CTRunDelegate::ref_con`"]
#[inline]
pub unsafe extern "C-unwind" fn CTRunDelegateGetRefCon(
run_delegate: &CTRunDelegate,
) -> NonNull<c_void> {
extern "C-unwind" {
fn CTRunDelegateGetRefCon(run_delegate: &CTRunDelegate) -> Option<NonNull<c_void>>;
}
let ret = unsafe { CTRunDelegateGetRefCon(run_delegate) };
ret.expect("function was marked as returning non-null, but actually returned NULL")
}