objc2_core_graphics/generated/
CGPattern.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpattern?language=objc)
14#[doc(alias = "CGPatternRef")]
15#[repr(C)]
16pub struct CGPattern {
17    inner: [u8; 0],
18    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
19}
20
21cf_type!(
22    unsafe impl CGPattern {}
23);
24#[cfg(feature = "objc2")]
25cf_objc2_type!(
26    unsafe impl RefEncode<"CGPattern"> for CGPattern {}
27);
28
29/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpatterntiling?language=objc)
30// NS_ENUM
31#[repr(transparent)]
32#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
33pub struct CGPatternTiling(pub i32);
34impl CGPatternTiling {
35    #[doc(alias = "kCGPatternTilingNoDistortion")]
36    pub const NoDistortion: Self = Self(0);
37    #[doc(alias = "kCGPatternTilingConstantSpacingMinimalDistortion")]
38    pub const ConstantSpacingMinimalDistortion: Self = Self(1);
39    #[doc(alias = "kCGPatternTilingConstantSpacing")]
40    pub const ConstantSpacing: Self = Self(2);
41}
42
43#[cfg(feature = "objc2")]
44unsafe impl Encode for CGPatternTiling {
45    const ENCODING: Encoding = i32::ENCODING;
46}
47
48#[cfg(feature = "objc2")]
49unsafe impl RefEncode for CGPatternTiling {
50    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
51}
52
53/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpatterndrawpatterncallback?language=objc)
54#[cfg(feature = "CGContext")]
55pub type CGPatternDrawPatternCallback =
56    Option<unsafe extern "C-unwind" fn(*mut c_void, *mut CGContext)>;
57
58/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpatternreleaseinfocallback?language=objc)
59pub type CGPatternReleaseInfoCallback = Option<unsafe extern "C-unwind" fn(*mut c_void)>;
60
61/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpatterncallbacks?language=objc)
62#[cfg(feature = "CGContext")]
63#[repr(C)]
64#[allow(unpredictable_function_pointer_comparisons)]
65#[derive(Clone, Copy, Debug, PartialEq)]
66pub struct CGPatternCallbacks {
67    pub version: c_uint,
68    pub drawPattern: CGPatternDrawPatternCallback,
69    pub releaseInfo: CGPatternReleaseInfoCallback,
70}
71
72#[cfg(all(feature = "CGContext", feature = "objc2"))]
73unsafe impl Encode for CGPatternCallbacks {
74    const ENCODING: Encoding = Encoding::Struct(
75        "CGPatternCallbacks",
76        &[
77            <c_uint>::ENCODING,
78            <CGPatternDrawPatternCallback>::ENCODING,
79            <CGPatternReleaseInfoCallback>::ENCODING,
80        ],
81    );
82}
83
84#[cfg(all(feature = "CGContext", feature = "objc2"))]
85unsafe impl RefEncode for CGPatternCallbacks {
86    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
87}
88
89unsafe impl ConcreteType for CGPattern {
90    #[doc(alias = "CGPatternGetTypeID")]
91    #[inline]
92    fn type_id() -> CFTypeID {
93        extern "C-unwind" {
94            fn CGPatternGetTypeID() -> CFTypeID;
95        }
96        unsafe { CGPatternGetTypeID() }
97    }
98}
99
100impl CGPattern {
101    /// # Safety
102    ///
103    /// - `info` must be a valid pointer or null.
104    /// - `callbacks` must be a valid pointer or null.
105    #[doc(alias = "CGPatternCreate")]
106    #[cfg(feature = "CGContext")]
107    #[inline]
108    pub unsafe fn new(
109        info: *mut c_void,
110        bounds: CGRect,
111        matrix: CGAffineTransform,
112        x_step: CGFloat,
113        y_step: CGFloat,
114        tiling: CGPatternTiling,
115        is_colored: bool,
116        callbacks: *const CGPatternCallbacks,
117    ) -> Option<CFRetained<CGPattern>> {
118        extern "C-unwind" {
119            fn CGPatternCreate(
120                info: *mut c_void,
121                bounds: CGRect,
122                matrix: CGAffineTransform,
123                x_step: CGFloat,
124                y_step: CGFloat,
125                tiling: CGPatternTiling,
126                is_colored: bool,
127                callbacks: *const CGPatternCallbacks,
128            ) -> Option<NonNull<CGPattern>>;
129        }
130        let ret = unsafe {
131            CGPatternCreate(
132                info, bounds, matrix, x_step, y_step, tiling, is_colored, callbacks,
133            )
134        };
135        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
136    }
137}
138
139#[cfg(feature = "CGContext")]
140#[deprecated = "renamed to `CGPattern::new`"]
141#[inline]
142pub unsafe extern "C-unwind" fn CGPatternCreate(
143    info: *mut c_void,
144    bounds: CGRect,
145    matrix: CGAffineTransform,
146    x_step: CGFloat,
147    y_step: CGFloat,
148    tiling: CGPatternTiling,
149    is_colored: bool,
150    callbacks: *const CGPatternCallbacks,
151) -> Option<CFRetained<CGPattern>> {
152    extern "C-unwind" {
153        fn CGPatternCreate(
154            info: *mut c_void,
155            bounds: CGRect,
156            matrix: CGAffineTransform,
157            x_step: CGFloat,
158            y_step: CGFloat,
159            tiling: CGPatternTiling,
160            is_colored: bool,
161            callbacks: *const CGPatternCallbacks,
162        ) -> Option<NonNull<CGPattern>>;
163    }
164    let ret = unsafe {
165        CGPatternCreate(
166            info, bounds, matrix, x_step, y_step, tiling, is_colored, callbacks,
167        )
168    };
169    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
170}