objc2_ui_kit/generated/
UIShape.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5#[cfg(feature = "objc2-core-foundation")]
6use objc2_core_foundation::*;
7use objc2_foundation::*;
8
9use crate::*;
10
11/// The corner curve to apply to a view.
12///
13/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uicornercurve?language=objc)
14// NS_ENUM
15#[repr(transparent)]
16#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
17pub struct UICornerCurve(pub NSInteger);
18impl UICornerCurve {
19    /// Select the corner style automatically.
20    #[doc(alias = "UICornerCurveAutomatic")]
21    pub const Automatic: Self = Self(0);
22    /// Always use a circular corner style.
23    #[doc(alias = "UICornerCurveCircular")]
24    pub const Circular: Self = Self(1);
25    /// Always use a continuous corner style.
26    #[doc(alias = "UICornerCurveContinuous")]
27    pub const Continuous: Self = Self(2);
28}
29
30unsafe impl Encode for UICornerCurve {
31    const ENCODING: Encoding = NSInteger::ENCODING;
32}
33
34unsafe impl RefEncode for UICornerCurve {
35    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
36}
37
38extern_protocol!(
39    /// A type that can provide a custom `UIShape`, resolved dynamically based on
40    /// context.
41    ///
42    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uishapeprovider?language=objc)
43    pub unsafe trait UIShapeProvider: NSObjectProtocol {
44        /// Resolves this shape in the provided `context`.
45        #[unsafe(method(resolvedShapeInContext:))]
46        #[unsafe(method_family = none)]
47        unsafe fn resolvedShapeInContext(
48            &self,
49            context: &UIShapeResolutionContext,
50        ) -> Retained<UIResolvedShape>;
51    }
52);
53
54extern_class!(
55    /// An abstract representation of a shape.
56    ///
57    /// A `UIShape` can represent a simple shape such as a rectangle or circle that
58    /// are later "resolved" into a concrete shape based on context like a size and
59    /// position for the shape. A `UIShape` can also represent more complex shapes
60    /// like paths and even "dynamic" shapes that are resolved using a custom
61    /// closure.
62    ///
63    /// You typically use a `UIShape` with APIs like `UIHoverStyle` to represent the
64    /// shape of an effect.
65    ///
66    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uishape?language=objc)
67    #[unsafe(super(NSObject))]
68    #[derive(Debug, PartialEq, Eq, Hash)]
69    pub struct UIShape;
70);
71
72unsafe impl NSCopying for UIShape {}
73
74unsafe impl CopyingHelper for UIShape {
75    type Result = Self;
76}
77
78unsafe impl NSObjectProtocol for UIShape {}
79
80unsafe impl UIShapeProvider for UIShape {}
81
82impl UIShape {
83    extern_methods!(
84        /// A rectangular shape.
85        #[unsafe(method(rectShape))]
86        #[unsafe(method_family = none)]
87        pub unsafe fn rectShape() -> Retained<UIShape>;
88
89        /// A capsule shape, equivalent to a rounded rectangle where the corner
90        /// radius is chosen as half the length of the rectangle’s smallest edge.
91        #[unsafe(method(capsuleShape))]
92        #[unsafe(method_family = none)]
93        pub unsafe fn capsuleShape() -> Retained<UIShape>;
94
95        /// A circular shape, with a radius equals half the length of the frame
96        /// rectangle’s smallest edge.
97        #[unsafe(method(circleShape))]
98        #[unsafe(method_family = none)]
99        pub unsafe fn circleShape() -> Retained<UIShape>;
100
101        #[cfg(feature = "objc2-core-foundation")]
102        /// A rectangular shape with rounded corners, aligned inside the frame of
103        /// in which it is contained.
104        #[unsafe(method(rectShapeWithCornerRadius:))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn rectShapeWithCornerRadius(corner_radius: CGFloat) -> Retained<Self>;
107
108        #[cfg(feature = "objc2-core-foundation")]
109        /// A rectangular shape with rounded corners, aligned inside the frame of
110        /// in which it is contained.
111        #[unsafe(method(rectShapeWithCornerRadius:cornerCurve:))]
112        #[unsafe(method_family = none)]
113        pub unsafe fn rectShapeWithCornerRadius_cornerCurve(
114            corner_radius: CGFloat,
115            corner_curve: UICornerCurve,
116        ) -> Retained<Self>;
117
118        #[cfg(all(feature = "UIGeometry", feature = "objc2-core-foundation"))]
119        /// A rectangular shape with rounded corners, aligned inside the frame of
120        /// in which it is contained.
121        #[unsafe(method(rectShapeWithCornerRadius:cornerCurve:maskedCorners:))]
122        #[unsafe(method_family = none)]
123        pub unsafe fn rectShapeWithCornerRadius_cornerCurve_maskedCorners(
124            corner_radius: CGFloat,
125            corner_curve: UICornerCurve,
126            masked_corners: UIRectCorner,
127        ) -> Retained<Self>;
128
129        #[cfg(feature = "objc2-core-foundation")]
130        /// A fixed rectangle shape using `rect` as its shape, regardless of the
131        /// frame in which it is contained.
132        #[unsafe(method(fixedRectShapeWithRect:))]
133        #[unsafe(method_family = none)]
134        pub unsafe fn fixedRectShapeWithRect(rect: CGRect) -> Retained<Self>;
135
136        #[cfg(feature = "objc2-core-foundation")]
137        /// A fixed rectangle shape using `rect` as its shape, regardless of the
138        /// frame in which it is contained, with rounded corners using `cornerRadius`.
139        #[unsafe(method(fixedRectShapeWithRect:cornerRadius:))]
140        #[unsafe(method_family = none)]
141        pub unsafe fn fixedRectShapeWithRect_cornerRadius(
142            rect: CGRect,
143            corner_radius: CGFloat,
144        ) -> Retained<Self>;
145
146        #[cfg(all(feature = "UIGeometry", feature = "objc2-core-foundation"))]
147        /// A fixed rectangle shape using `rect` as its shape, regardless of the
148        /// frame in which it is contained, with rounded corners using `cornerRadius`.
149        #[unsafe(method(fixedRectShapeWithRect:cornerRadius:cornerCurve:maskedCorners:))]
150        #[unsafe(method_family = none)]
151        pub unsafe fn fixedRectShapeWithRect_cornerRadius_cornerCurve_maskedCorners(
152            rect: CGRect,
153            corner_radius: CGFloat,
154            corner_curve: UICornerCurve,
155            masked_corners: UIRectCorner,
156        ) -> Retained<Self>;
157
158        #[cfg(feature = "UIBezierPath")]
159        /// A shape with a custom bezier path.
160        #[unsafe(method(shapeWithBezierPath:))]
161        #[unsafe(method_family = none)]
162        pub unsafe fn shapeWithBezierPath(path: &UIBezierPath) -> Retained<Self>;
163
164        /// Creates a dynamic shape that can be resolved using the provided
165        /// `UIShapeProvider` based on context like its containing rect.
166        #[unsafe(method(shapeWithProvider:))]
167        #[unsafe(method_family = none)]
168        pub unsafe fn shapeWithProvider(
169            provider: &ProtocolObject<dyn UIShapeProvider>,
170        ) -> Retained<Self>;
171
172        #[cfg(all(feature = "UIGeometry", feature = "objc2-core-foundation"))]
173        /// Insets this shape by the provided `insets`, returning a new modified
174        /// shape.
175        ///
176        /// Negative values can be used to add inner padding to a shape. If this
177        /// shape is not insettable (e.g., if it is a custom path), this has no
178        /// effect. For some shapes like rounded rectangles, this can also modify
179        /// the corner radii of the shape to ensure the resulting corners are
180        /// concentric.
181        #[unsafe(method(shapeByApplyingInsets:))]
182        #[unsafe(method_family = none)]
183        pub unsafe fn shapeByApplyingInsets(&self, insets: UIEdgeInsets) -> Retained<UIShape>;
184
185        #[cfg(feature = "objc2-core-foundation")]
186        /// Insets this shape by the provided `inset`, returning a new modified
187        /// shape.
188        ///
189        /// Negative values can be used to add inner padding to a shape. If this
190        /// shape is not insettable (e.g., if it is a custom path), this has no
191        /// effect. For some shapes like rounded rectangles, this can also modify
192        /// the corner radii of the shape to ensure the resulting corners are
193        /// concentric.
194        #[unsafe(method(shapeByApplyingInset:))]
195        #[unsafe(method_family = none)]
196        pub unsafe fn shapeByApplyingInset(&self, inset: CGFloat) -> Retained<UIShape>;
197
198        /// Resolves this shape in the provided `context`.
199        #[unsafe(method(resolvedShapeInContext:))]
200        #[unsafe(method_family = none)]
201        pub unsafe fn resolvedShapeInContext(
202            &self,
203            context: &UIShapeResolutionContext,
204        ) -> Retained<UIResolvedShape>;
205
206        #[unsafe(method(init))]
207        #[unsafe(method_family = init)]
208        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
209
210        #[unsafe(method(new))]
211        #[unsafe(method_family = new)]
212        pub unsafe fn new() -> Retained<Self>;
213    );
214}
215
216extern_class!(
217    /// A shape that has been resolved based on a `ResolutionContext`.
218    ///
219    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiresolvedshape?language=objc)
220    #[unsafe(super(NSObject))]
221    #[derive(Debug, PartialEq, Eq, Hash)]
222    pub struct UIResolvedShape;
223);
224
225unsafe impl NSCopying for UIResolvedShape {}
226
227unsafe impl CopyingHelper for UIResolvedShape {
228    type Result = Self;
229}
230
231unsafe impl NSObjectProtocol for UIResolvedShape {}
232
233impl UIResolvedShape {
234    extern_methods!(
235        /// The abstract shape that produced this resolved shape.
236        #[unsafe(method(shape))]
237        #[unsafe(method_family = none)]
238        pub unsafe fn shape(&self) -> Retained<UIShape>;
239
240        #[cfg(feature = "objc2-core-foundation")]
241        /// The bounding rect in which the shape is framed.
242        #[unsafe(method(boundingRect))]
243        #[unsafe(method_family = none)]
244        pub unsafe fn boundingRect(&self) -> CGRect;
245
246        #[cfg(feature = "UIBezierPath")]
247        /// The bezier path representing this shape.
248        #[unsafe(method(path))]
249        #[unsafe(method_family = none)]
250        pub unsafe fn path(&self) -> Retained<UIBezierPath>;
251
252        #[cfg(all(feature = "UIGeometry", feature = "objc2-core-foundation"))]
253        /// Insets this shape by the provided `insets`, returning a new modified
254        /// shape.
255        ///
256        /// Negative values can be used to add inner padding to a shape. If this
257        /// shape is not insettable (e.g., if it is a custom path), this has no
258        /// effect. For some shapes like rounded rectangles, this can also modify
259        /// the corner radii of the shape to ensure the resulting corners are
260        /// concentric.
261        #[unsafe(method(shapeByApplyingInsets:))]
262        #[unsafe(method_family = none)]
263        pub unsafe fn shapeByApplyingInsets(
264            &self,
265            insets: UIEdgeInsets,
266        ) -> Retained<UIResolvedShape>;
267
268        #[cfg(feature = "objc2-core-foundation")]
269        /// Insets this shape by the provided `inset`, returning a new modified
270        /// shape.
271        ///
272        /// Negative values can be used to add inner padding to a shape. If this
273        /// shape is not insettable (e.g., if it is a custom path), this has no
274        /// effect. For some shapes like rounded rectangles, this can also modify
275        /// the corner radii of the shape to ensure the resulting corners are
276        /// concentric.
277        #[unsafe(method(shapeByApplyingInset:))]
278        #[unsafe(method_family = none)]
279        pub unsafe fn shapeByApplyingInset(&self, inset: CGFloat) -> Retained<UIResolvedShape>;
280
281        #[unsafe(method(init))]
282        #[unsafe(method_family = init)]
283        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
284
285        #[unsafe(method(new))]
286        #[unsafe(method_family = new)]
287        pub unsafe fn new() -> Retained<Self>;
288    );
289}
290
291extern_class!(
292    /// The context used for resolving a `dynamic` `UIShape`.
293    ///
294    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uishaperesolutioncontext?language=objc)
295    #[unsafe(super(NSObject))]
296    #[derive(Debug, PartialEq, Eq, Hash)]
297    pub struct UIShapeResolutionContext;
298);
299
300unsafe impl NSObjectProtocol for UIShapeResolutionContext {}
301
302impl UIShapeResolutionContext {
303    extern_methods!(
304        /// The resolved shape of the content to which this shape may be
305        /// applied. For example, if this shape will be used to apply an effect
306        /// to a button, the `contentShape` could represent the bounding shape
307        /// of that button's background. You should typically size a dynamic
308        /// shape relative to the bounding `rect` of the `contentShape`.
309        #[unsafe(method(contentShape))]
310        #[unsafe(method_family = none)]
311        pub unsafe fn contentShape(&self) -> Retained<UIResolvedShape>;
312
313        #[unsafe(method(init))]
314        #[unsafe(method_family = init)]
315        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
316
317        #[unsafe(method(new))]
318        #[unsafe(method_family = new)]
319        pub unsafe fn new() -> Retained<Self>;
320    );
321}