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