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        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
72extern_conformance!(
73    unsafe impl NSCopying for UIShape {}
74);
75
76unsafe impl CopyingHelper for UIShape {
77    type Result = Self;
78}
79
80extern_conformance!(
81    unsafe impl NSObjectProtocol for UIShape {}
82);
83
84extern_conformance!(
85    unsafe impl UIShapeProvider for UIShape {}
86);
87
88impl UIShape {
89    extern_methods!(
90        /// A rectangular shape.
91        #[unsafe(method(rectShape))]
92        #[unsafe(method_family = none)]
93        pub fn rectShape() -> Retained<UIShape>;
94
95        /// A capsule shape, equivalent to a rounded rectangle where the corner
96        /// radius is chosen as half the length of the rectangle’s smallest edge.
97        #[unsafe(method(capsuleShape))]
98        #[unsafe(method_family = none)]
99        pub fn capsuleShape() -> Retained<UIShape>;
100
101        /// A circular shape, with a radius equals half the length of the frame
102        /// rectangle’s smallest edge.
103        #[unsafe(method(circleShape))]
104        #[unsafe(method_family = none)]
105        pub fn circleShape() -> Retained<UIShape>;
106
107        #[cfg(feature = "objc2-core-foundation")]
108        /// A rectangular shape with rounded corners, aligned inside the frame of
109        /// in which it is contained.
110        #[unsafe(method(rectShapeWithCornerRadius:))]
111        #[unsafe(method_family = none)]
112        pub fn rectShapeWithCornerRadius(corner_radius: CGFloat) -> Retained<Self>;
113
114        #[cfg(feature = "objc2-core-foundation")]
115        /// A rectangular shape with rounded corners, aligned inside the frame of
116        /// in which it is contained.
117        #[unsafe(method(rectShapeWithCornerRadius:cornerCurve:))]
118        #[unsafe(method_family = none)]
119        pub fn rectShapeWithCornerRadius_cornerCurve(
120            corner_radius: CGFloat,
121            corner_curve: UICornerCurve,
122        ) -> Retained<Self>;
123
124        #[cfg(all(feature = "UIGeometry", feature = "objc2-core-foundation"))]
125        /// A rectangular shape with rounded corners, aligned inside the frame of
126        /// in which it is contained.
127        #[unsafe(method(rectShapeWithCornerRadius:cornerCurve:maskedCorners:))]
128        #[unsafe(method_family = none)]
129        pub fn rectShapeWithCornerRadius_cornerCurve_maskedCorners(
130            corner_radius: CGFloat,
131            corner_curve: UICornerCurve,
132            masked_corners: UIRectCorner,
133        ) -> Retained<Self>;
134
135        #[cfg(feature = "objc2-core-foundation")]
136        /// A fixed rectangle shape using `rect` as its shape, regardless of the
137        /// frame in which it is contained.
138        #[unsafe(method(fixedRectShapeWithRect:))]
139        #[unsafe(method_family = none)]
140        pub fn fixedRectShapeWithRect(rect: CGRect) -> Retained<Self>;
141
142        #[cfg(feature = "objc2-core-foundation")]
143        /// A fixed rectangle shape using `rect` as its shape, regardless of the
144        /// frame in which it is contained, with rounded corners using `cornerRadius`.
145        #[unsafe(method(fixedRectShapeWithRect:cornerRadius:))]
146        #[unsafe(method_family = none)]
147        pub fn fixedRectShapeWithRect_cornerRadius(
148            rect: CGRect,
149            corner_radius: CGFloat,
150        ) -> Retained<Self>;
151
152        #[cfg(all(feature = "UIGeometry", feature = "objc2-core-foundation"))]
153        /// A fixed rectangle shape using `rect` as its shape, regardless of the
154        /// frame in which it is contained, with rounded corners using `cornerRadius`.
155        #[unsafe(method(fixedRectShapeWithRect:cornerRadius:cornerCurve:maskedCorners:))]
156        #[unsafe(method_family = none)]
157        pub fn fixedRectShapeWithRect_cornerRadius_cornerCurve_maskedCorners(
158            rect: CGRect,
159            corner_radius: CGFloat,
160            corner_curve: UICornerCurve,
161            masked_corners: UIRectCorner,
162        ) -> Retained<Self>;
163
164        #[cfg(feature = "UIBezierPath")]
165        /// A shape with a custom bezier path.
166        #[unsafe(method(shapeWithBezierPath:))]
167        #[unsafe(method_family = none)]
168        pub fn shapeWithBezierPath(path: &UIBezierPath) -> Retained<Self>;
169
170        /// Creates a dynamic shape that can be resolved using the provided
171        /// `UIShapeProvider` based on context like its containing rect.
172        #[unsafe(method(shapeWithProvider:))]
173        #[unsafe(method_family = none)]
174        pub fn shapeWithProvider(provider: &ProtocolObject<dyn UIShapeProvider>) -> Retained<Self>;
175
176        #[cfg(all(feature = "UIGeometry", feature = "objc2-core-foundation"))]
177        /// Insets this shape by the provided `insets`, returning a new modified
178        /// shape.
179        ///
180        /// Negative values can be used to add inner padding to a shape. If this
181        /// shape is not insettable (e.g., if it is a custom path), this has no
182        /// effect. For some shapes like rounded rectangles, this can also modify
183        /// the corner radii of the shape to ensure the resulting corners are
184        /// concentric.
185        #[unsafe(method(shapeByApplyingInsets:))]
186        #[unsafe(method_family = none)]
187        pub fn shapeByApplyingInsets(&self, insets: UIEdgeInsets) -> Retained<UIShape>;
188
189        #[cfg(feature = "objc2-core-foundation")]
190        /// Insets this shape by the provided `inset`, returning a new modified
191        /// shape.
192        ///
193        /// Negative values can be used to add inner padding to a shape. If this
194        /// shape is not insettable (e.g., if it is a custom path), this has no
195        /// effect. For some shapes like rounded rectangles, this can also modify
196        /// the corner radii of the shape to ensure the resulting corners are
197        /// concentric.
198        #[unsafe(method(shapeByApplyingInset:))]
199        #[unsafe(method_family = none)]
200        pub fn shapeByApplyingInset(&self, inset: CGFloat) -> Retained<UIShape>;
201
202        /// Resolves this shape in the provided `context`.
203        #[unsafe(method(resolvedShapeInContext:))]
204        #[unsafe(method_family = none)]
205        pub fn resolvedShapeInContext(
206            &self,
207            context: &UIShapeResolutionContext,
208        ) -> Retained<UIResolvedShape>;
209
210        #[unsafe(method(init))]
211        #[unsafe(method_family = init)]
212        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
213
214        #[unsafe(method(new))]
215        #[unsafe(method_family = new)]
216        pub unsafe fn new() -> Retained<Self>;
217    );
218}
219
220extern_class!(
221    /// A shape that has been resolved based on a `ResolutionContext`.
222    ///
223    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uiresolvedshape?language=objc)
224    #[unsafe(super(NSObject))]
225    #[derive(Debug, PartialEq, Eq, Hash)]
226    pub struct UIResolvedShape;
227);
228
229extern_conformance!(
230    unsafe impl NSCopying for UIResolvedShape {}
231);
232
233unsafe impl CopyingHelper for UIResolvedShape {
234    type Result = Self;
235}
236
237extern_conformance!(
238    unsafe impl NSObjectProtocol for UIResolvedShape {}
239);
240
241impl UIResolvedShape {
242    extern_methods!(
243        /// The abstract shape that produced this resolved shape.
244        #[unsafe(method(shape))]
245        #[unsafe(method_family = none)]
246        pub fn shape(&self) -> Retained<UIShape>;
247
248        #[cfg(feature = "objc2-core-foundation")]
249        /// The bounding rect in which the shape is framed.
250        #[unsafe(method(boundingRect))]
251        #[unsafe(method_family = none)]
252        pub fn boundingRect(&self) -> CGRect;
253
254        #[cfg(feature = "UIBezierPath")]
255        /// The bezier path representing this shape.
256        #[unsafe(method(path))]
257        #[unsafe(method_family = none)]
258        pub fn path(&self) -> Retained<UIBezierPath>;
259
260        #[cfg(all(feature = "UIGeometry", feature = "objc2-core-foundation"))]
261        /// Insets this shape by the provided `insets`, returning a new modified
262        /// shape.
263        ///
264        /// Negative values can be used to add inner padding to a shape. If this
265        /// shape is not insettable (e.g., if it is a custom path), this has no
266        /// effect. For some shapes like rounded rectangles, this can also modify
267        /// the corner radii of the shape to ensure the resulting corners are
268        /// concentric.
269        #[unsafe(method(shapeByApplyingInsets:))]
270        #[unsafe(method_family = none)]
271        pub fn shapeByApplyingInsets(&self, insets: UIEdgeInsets) -> Retained<UIResolvedShape>;
272
273        #[cfg(feature = "objc2-core-foundation")]
274        /// Insets this shape by the provided `inset`, returning a new modified
275        /// shape.
276        ///
277        /// Negative values can be used to add inner padding to a shape. If this
278        /// shape is not insettable (e.g., if it is a custom path), this has no
279        /// effect. For some shapes like rounded rectangles, this can also modify
280        /// the corner radii of the shape to ensure the resulting corners are
281        /// concentric.
282        #[unsafe(method(shapeByApplyingInset:))]
283        #[unsafe(method_family = none)]
284        pub fn shapeByApplyingInset(&self, inset: CGFloat) -> Retained<UIResolvedShape>;
285
286        #[unsafe(method(init))]
287        #[unsafe(method_family = init)]
288        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
289
290        #[unsafe(method(new))]
291        #[unsafe(method_family = new)]
292        pub unsafe fn new() -> Retained<Self>;
293    );
294}
295
296extern_class!(
297    /// The context used for resolving a `dynamic` `UIShape`.
298    ///
299    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uishaperesolutioncontext?language=objc)
300    #[unsafe(super(NSObject))]
301    #[derive(Debug, PartialEq, Eq, Hash)]
302    pub struct UIShapeResolutionContext;
303);
304
305extern_conformance!(
306    unsafe impl NSObjectProtocol for UIShapeResolutionContext {}
307);
308
309impl UIShapeResolutionContext {
310    extern_methods!(
311        /// The resolved shape of the content to which this shape may be
312        /// applied. For example, if this shape will be used to apply an effect
313        /// to a button, the `contentShape` could represent the bounding shape
314        /// of that button's background. You should typically size a dynamic
315        /// shape relative to the bounding `rect` of the `contentShape`.
316        #[unsafe(method(contentShape))]
317        #[unsafe(method_family = none)]
318        pub fn contentShape(&self) -> Retained<UIResolvedShape>;
319
320        #[unsafe(method(init))]
321        #[unsafe(method_family = init)]
322        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
323
324        #[unsafe(method(new))]
325        #[unsafe(method_family = new)]
326        pub unsafe fn new() -> Retained<Self>;
327    );
328}