objc2_ui_kit/generated/
UIEditMenuInteraction.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uieditmenuarrowdirection?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct UIEditMenuArrowDirection(pub NSInteger);
17impl UIEditMenuArrowDirection {
18    #[doc(alias = "UIEditMenuArrowDirectionAutomatic")]
19    pub const Automatic: Self = Self(0);
20    #[doc(alias = "UIEditMenuArrowDirectionUp")]
21    pub const Up: Self = Self(1);
22    #[doc(alias = "UIEditMenuArrowDirectionDown")]
23    pub const Down: Self = Self(2);
24    #[doc(alias = "UIEditMenuArrowDirectionLeft")]
25    pub const Left: Self = Self(3);
26    #[doc(alias = "UIEditMenuArrowDirectionRight")]
27    pub const Right: Self = Self(4);
28}
29
30unsafe impl Encode for UIEditMenuArrowDirection {
31    const ENCODING: Encoding = NSInteger::ENCODING;
32}
33
34unsafe impl RefEncode for UIEditMenuArrowDirection {
35    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
36}
37
38extern_class!(
39    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uieditmenuconfiguration?language=objc)
40    #[unsafe(super(NSObject))]
41    #[thread_kind = MainThreadOnly]
42    #[derive(Debug, PartialEq, Eq, Hash)]
43    pub struct UIEditMenuConfiguration;
44);
45
46extern_conformance!(
47    unsafe impl NSObjectProtocol for UIEditMenuConfiguration {}
48);
49
50impl UIEditMenuConfiguration {
51    extern_methods!(
52        /// The unique identifier of the configuration.
53        #[unsafe(method(identifier))]
54        #[unsafe(method_family = none)]
55        pub fn identifier(&self) -> Retained<ProtocolObject<dyn NSCopying>>;
56
57        #[cfg(feature = "objc2-core-foundation")]
58        /// The source location of the menu. The suggested actions menu elements will be derived from this location in the interaction's view.
59        /// By default, the menu will be presented from this location. You can change the presentation source of the menu with the delegate
60        /// method
61        /// `editMenuInteraction:targetRectForConfiguration:`
62        #[unsafe(method(sourcePoint))]
63        #[unsafe(method_family = none)]
64        pub fn sourcePoint(&self) -> CGPoint;
65
66        /// The preferred arrow direction of the edit menu. Default is
67        /// `UIEditMenuArrowDirectionAutomatic`
68        #[unsafe(method(preferredArrowDirection))]
69        #[unsafe(method_family = none)]
70        pub fn preferredArrowDirection(&self) -> UIEditMenuArrowDirection;
71
72        /// Setter for [`preferredArrowDirection`][Self::preferredArrowDirection].
73        #[unsafe(method(setPreferredArrowDirection:))]
74        #[unsafe(method_family = none)]
75        pub fn setPreferredArrowDirection(
76            &self,
77            preferred_arrow_direction: UIEditMenuArrowDirection,
78        );
79
80        #[cfg(feature = "objc2-core-foundation")]
81        /// Creates a new configuration with the specified source location.
82        ///
83        /// # Safety
84        ///
85        /// `identifier` should be of the correct type.
86        #[unsafe(method(configurationWithIdentifier:sourcePoint:))]
87        #[unsafe(method_family = none)]
88        pub unsafe fn configurationWithIdentifier_sourcePoint(
89            identifier: Option<&ProtocolObject<dyn NSCopying>>,
90            source_point: CGPoint,
91            mtm: MainThreadMarker,
92        ) -> Retained<Self>;
93
94        #[unsafe(method(init))]
95        #[unsafe(method_family = init)]
96        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
97
98        #[unsafe(method(new))]
99        #[unsafe(method_family = new)]
100        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
101    );
102}
103
104extern_class!(
105    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uieditmenuinteraction?language=objc)
106    #[unsafe(super(NSObject))]
107    #[thread_kind = MainThreadOnly]
108    #[derive(Debug, PartialEq, Eq, Hash)]
109    pub struct UIEditMenuInteraction;
110);
111
112extern_conformance!(
113    unsafe impl NSObjectProtocol for UIEditMenuInteraction {}
114);
115
116#[cfg(feature = "UIInteraction")]
117extern_conformance!(
118    unsafe impl UIInteraction for UIEditMenuInteraction {}
119);
120
121impl UIEditMenuInteraction {
122    extern_methods!(
123        /// The object that defines the delegate of the interaction.
124        #[unsafe(method(delegate))]
125        #[unsafe(method_family = none)]
126        pub fn delegate(
127            &self,
128        ) -> Option<Retained<ProtocolObject<dyn UIEditMenuInteractionDelegate>>>;
129
130        /// Creates a new edit menu interaction with the specified delegate.
131        #[unsafe(method(initWithDelegate:))]
132        #[unsafe(method_family = init)]
133        pub fn initWithDelegate(
134            this: Allocated<Self>,
135            delegate: Option<&ProtocolObject<dyn UIEditMenuInteractionDelegate>>,
136        ) -> Retained<Self>;
137
138        /// Presents an edit menu with the specified
139        /// `configuration`object.
140        /// If a menu is already presented, it will be dismissed automatically before the new menu is presented.
141        ///
142        /// :
143        /// `presentEditMenuWithConfiguration:`is not supported on Mac Catalyst.
144        #[unsafe(method(presentEditMenuWithConfiguration:))]
145        #[unsafe(method_family = none)]
146        pub fn presentEditMenuWithConfiguration(&self, configuration: &UIEditMenuConfiguration);
147
148        /// Dismiss the currently active menu if one is currently presented.
149        #[unsafe(method(dismissMenu))]
150        #[unsafe(method_family = none)]
151        pub fn dismissMenu(&self);
152
153        /// Reloads the visible menu. This menu has no effect if there is no menu presented. This method will query
154        /// the menu again from the delegate method
155        /// `editMenuInteraction:menuForConfiguration:suggestedActions:`and refresh the UI with the updated menu.
156        #[unsafe(method(reloadVisibleMenu))]
157        #[unsafe(method_family = none)]
158        pub fn reloadVisibleMenu(&self);
159
160        /// Updates the position of the currently visible menu, with an option to animate the action. This method
161        /// has no effect if no menu is presented. This method will query the position from the delegate method
162        /// `editMenuInteraction:targetRectForConfiguration:`if it is implemented.
163        #[unsafe(method(updateVisibleMenuPositionAnimated:))]
164        #[unsafe(method_family = none)]
165        pub fn updateVisibleMenuPositionAnimated(&self, animated: bool);
166
167        #[cfg(all(
168            feature = "UIResponder",
169            feature = "UIView",
170            feature = "objc2-core-foundation"
171        ))]
172        /// Returns the interaction's location within the given view.
173        #[unsafe(method(locationInView:))]
174        #[unsafe(method_family = none)]
175        pub fn locationInView(&self, view: Option<&UIView>) -> CGPoint;
176
177        #[unsafe(method(init))]
178        #[unsafe(method_family = init)]
179        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
180
181        #[unsafe(method(new))]
182        #[unsafe(method_family = new)]
183        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
184    );
185}
186
187extern_protocol!(
188    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uieditmenuinteractionanimating?language=objc)
189    pub unsafe trait UIEditMenuInteractionAnimating:
190        NSObjectProtocol + MainThreadOnly
191    {
192        #[cfg(feature = "block2")]
193        #[unsafe(method(addAnimations:))]
194        #[unsafe(method_family = none)]
195        fn addAnimations(&self, animations: &block2::DynBlock<dyn Fn()>);
196
197        #[cfg(feature = "block2")]
198        #[unsafe(method(addCompletion:))]
199        #[unsafe(method_family = none)]
200        fn addCompletion(&self, completion: &block2::DynBlock<dyn Fn()>);
201    }
202);
203
204extern_protocol!(
205    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uieditmenuinteractiondelegate?language=objc)
206    pub unsafe trait UIEditMenuInteractionDelegate: NSObjectProtocol {
207        #[cfg(all(feature = "UIMenu", feature = "UIMenuElement"))]
208        /// Called when the interaction begins.
209        ///
210        ///
211        /// Parameter `interaction`: The UIEditMenuInteraction.
212        ///
213        /// Parameter `configuration`: The UIEditMenuConfiguration object used to present the menu.
214        ///
215        /// Parameter `suggestedActions`: An array of suggested actions gathered from the UIResponder chain. You may
216        /// include these actions in the hierarchy to display them in the resulting menu.
217        ///
218        ///
219        /// Returns: Return a UIMenu describing the desired menu hierarchy. Return
220        /// `nil`to present the default system menu.
221        #[optional]
222        #[unsafe(method(editMenuInteraction:menuForConfiguration:suggestedActions:))]
223        #[unsafe(method_family = none)]
224        fn editMenuInteraction_menuForConfiguration_suggestedActions(
225            &self,
226            interaction: &UIEditMenuInteraction,
227            configuration: &UIEditMenuConfiguration,
228            suggested_actions: &NSArray<UIMenuElement>,
229        ) -> Option<Retained<UIMenu>>;
230
231        #[cfg(feature = "objc2-core-foundation")]
232        /// Called when the interaction begins, or when
233        /// `updateVisibleMenuPosition(animated:)`is called.
234        ///
235        ///
236        /// Parameter `interaction`: The UIEditMenuInteraction.
237        ///
238        /// Parameter `configuration`: The UIEditMenuConfiguration object used to present the menu.
239        ///
240        ///
241        /// Returns: Return a rectangle relative to the interaction's view. The menu will be displayed around
242        /// target rect, space permitting, with the arrow pointing at the edge of the target rectangle
243        /// for the specified arrow direction of the configuration. By default, an empty-sized rectangle
244        /// centered at
245        /// `configuration.sourcePoint`will be used if this method is not implemented. Return
246        /// `CGRectNull`to use the default rect.
247        #[optional]
248        #[unsafe(method(editMenuInteraction:targetRectForConfiguration:))]
249        #[unsafe(method_family = none)]
250        fn editMenuInteraction_targetRectForConfiguration(
251            &self,
252            interaction: &UIEditMenuInteraction,
253            configuration: &UIEditMenuConfiguration,
254        ) -> CGRect;
255
256        /// Called when the interaction is about to present the menu.
257        ///
258        ///
259        /// Parameter `interaction`: The UIEditMenuInteraction.
260        ///
261        /// Parameter `configuration`: The configuration object of the menu about to be presented by this interaction.
262        ///
263        /// Parameter `animator`: Appearance animator. Add animations to this object to run them alongside the appearance transition.
264        #[optional]
265        #[unsafe(method(editMenuInteraction:willPresentMenuForConfiguration:animator:))]
266        #[unsafe(method_family = none)]
267        fn editMenuInteraction_willPresentMenuForConfiguration_animator(
268            &self,
269            interaction: &UIEditMenuInteraction,
270            configuration: &UIEditMenuConfiguration,
271            animator: &ProtocolObject<dyn UIEditMenuInteractionAnimating>,
272        );
273
274        /// Called when the interaction is about to dismiss the menu.
275        ///
276        ///
277        /// Parameter `interaction`: The UIEditMenuInteraction.
278        ///
279        /// Parameter `configuration`: The configuration object of the menu about to be dismissed by this interaction.
280        ///
281        /// Parameter `animator`: Dismiss animator. Add animations to this object to run them alongside the dismiss transition.
282        #[optional]
283        #[unsafe(method(editMenuInteraction:willDismissMenuForConfiguration:animator:))]
284        #[unsafe(method_family = none)]
285        fn editMenuInteraction_willDismissMenuForConfiguration_animator(
286            &self,
287            interaction: &UIEditMenuInteraction,
288            configuration: &UIEditMenuConfiguration,
289            animator: &ProtocolObject<dyn UIEditMenuInteractionAnimating>,
290        );
291    }
292);