objc2_ui_kit/generated/
UIContextMenuInteraction.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/uicontextmenuinteractioncommitstyle?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct UIContextMenuInteractionCommitStyle(pub NSInteger);
17impl UIContextMenuInteractionCommitStyle {
18    #[doc(alias = "UIContextMenuInteractionCommitStyleDismiss")]
19    pub const Dismiss: Self = Self(0);
20    #[doc(alias = "UIContextMenuInteractionCommitStylePop")]
21    pub const Pop: Self = Self(1);
22}
23
24unsafe impl Encode for UIContextMenuInteractionCommitStyle {
25    const ENCODING: Encoding = NSInteger::ENCODING;
26}
27
28unsafe impl RefEncode for UIContextMenuInteractionCommitStyle {
29    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
30}
31
32/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenuinteractionappearance?language=objc)
33// NS_ENUM
34#[repr(transparent)]
35#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
36pub struct UIContextMenuInteractionAppearance(pub NSInteger);
37impl UIContextMenuInteractionAppearance {
38    #[doc(alias = "UIContextMenuInteractionAppearanceUnknown")]
39    pub const Unknown: Self = Self(0);
40    #[doc(alias = "UIContextMenuInteractionAppearanceRich")]
41    pub const Rich: Self = Self(1);
42    #[doc(alias = "UIContextMenuInteractionAppearanceCompact")]
43    pub const Compact: Self = Self(2);
44}
45
46unsafe impl Encode for UIContextMenuInteractionAppearance {
47    const ENCODING: Encoding = NSInteger::ENCODING;
48}
49
50unsafe impl RefEncode for UIContextMenuInteractionAppearance {
51    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
52}
53
54extern_class!(
55    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenuinteraction?language=objc)
56    #[unsafe(super(NSObject))]
57    #[thread_kind = MainThreadOnly]
58    #[derive(Debug, PartialEq, Eq, Hash)]
59    pub struct UIContextMenuInteraction;
60);
61
62extern_conformance!(
63    unsafe impl NSObjectProtocol for UIContextMenuInteraction {}
64);
65
66#[cfg(feature = "UIInteraction")]
67extern_conformance!(
68    unsafe impl UIInteraction for UIContextMenuInteraction {}
69);
70
71impl UIContextMenuInteraction {
72    extern_methods!(
73        /// The interaction's delegate.
74        #[unsafe(method(delegate))]
75        #[unsafe(method_family = none)]
76        pub unsafe fn delegate(
77            &self,
78        ) -> Option<Retained<ProtocolObject<dyn UIContextMenuInteractionDelegate>>>;
79
80        /// Appearance of the menu this interaction has presented or is about to present. Since it may be
81        /// dependent on the user's input method, the appearance is only known while the interaction is active.
82        #[unsafe(method(menuAppearance))]
83        #[unsafe(method_family = none)]
84        pub unsafe fn menuAppearance(&self) -> UIContextMenuInteractionAppearance;
85
86        #[unsafe(method(initWithDelegate:))]
87        #[unsafe(method_family = init)]
88        pub unsafe fn initWithDelegate(
89            this: Allocated<Self>,
90            delegate: &ProtocolObject<dyn UIContextMenuInteractionDelegate>,
91        ) -> Retained<Self>;
92
93        #[unsafe(method(init))]
94        #[unsafe(method_family = init)]
95        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
96
97        #[unsafe(method(new))]
98        #[unsafe(method_family = new)]
99        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
100
101        #[cfg(all(
102            feature = "UIResponder",
103            feature = "UIView",
104            feature = "objc2-core-foundation"
105        ))]
106        /// Returns the interaction's location within the given view.
107        ///
108        ///
109        /// Parameter `view`: The view in which to locate the interaction.
110        #[unsafe(method(locationInView:))]
111        #[unsafe(method_family = none)]
112        pub unsafe fn locationInView(&self, view: Option<&UIView>) -> CGPoint;
113
114        #[cfg(all(feature = "UIMenu", feature = "UIMenuElement", feature = "block2"))]
115        /// Call to update the currently visible menu. This method does nothing if called before a menu is presented.
116        ///
117        ///
118        /// Parameter `block`: Called with a mutable copy of the currently visible menu. Modify and return this menu (or an entirely
119        /// new one) to change the currently visible menu items. Starting in iOS 15, this block is called once for
120        /// every visible submenu. For example, in the following hierarchy:
121        ///
122        /// *- Root Menu
123        /// *- Submenu A
124        /// *- Submenu B
125        /// *- Submenu C
126        ///
127        /// If Submenu A is visible, the block is called twice (once for the Root Menu and once for Submenu A).
128        /// If both A and B are visible, it's called 3 times (for the Root Menu, A, and B).
129        #[unsafe(method(updateVisibleMenuWithBlock:))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn updateVisibleMenuWithBlock(
132            &self,
133            block: &block2::DynBlock<dyn Fn(NonNull<UIMenu>) -> NonNull<UIMenu> + '_>,
134        );
135
136        /// Dismisses the currently presented menu (if there is one).
137        #[unsafe(method(dismissMenu))]
138        #[unsafe(method_family = none)]
139        pub unsafe fn dismissMenu(&self);
140    );
141}
142
143extern_protocol!(
144    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenuinteractionanimating?language=objc)
145    pub unsafe trait UIContextMenuInteractionAnimating:
146        NSObjectProtocol + MainThreadOnly
147    {
148        #[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
149        /// Displayed preview view controller.
150        #[unsafe(method(previewViewController))]
151        #[unsafe(method_family = none)]
152        unsafe fn previewViewController(&self) -> Option<Retained<UIViewController>>;
153
154        #[cfg(feature = "block2")]
155        #[unsafe(method(addAnimations:))]
156        #[unsafe(method_family = none)]
157        unsafe fn addAnimations(&self, animations: &block2::DynBlock<dyn Fn()>);
158
159        #[cfg(feature = "block2")]
160        #[unsafe(method(addCompletion:))]
161        #[unsafe(method_family = none)]
162        unsafe fn addCompletion(&self, completion: &block2::DynBlock<dyn Fn()>);
163    }
164);
165
166extern_protocol!(
167    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenuinteractioncommitanimating?language=objc)
168    pub unsafe trait UIContextMenuInteractionCommitAnimating:
169        UIContextMenuInteractionAnimating + MainThreadOnly
170    {
171        /// Preferred animation style for the menu's commit action. Triggered when the user taps the preview.
172        #[unsafe(method(preferredCommitStyle))]
173        #[unsafe(method_family = none)]
174        unsafe fn preferredCommitStyle(&self) -> UIContextMenuInteractionCommitStyle;
175
176        /// Setter for [`preferredCommitStyle`][Self::preferredCommitStyle].
177        #[unsafe(method(setPreferredCommitStyle:))]
178        #[unsafe(method_family = none)]
179        unsafe fn setPreferredCommitStyle(
180            &self,
181            preferred_commit_style: UIContextMenuInteractionCommitStyle,
182        );
183    }
184);
185
186extern_protocol!(
187    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenuinteractiondelegate?language=objc)
188    pub unsafe trait UIContextMenuInteractionDelegate:
189        NSObjectProtocol + MainThreadOnly
190    {
191        #[cfg(all(
192            feature = "UIContextMenuConfiguration",
193            feature = "objc2-core-foundation"
194        ))]
195        /// Called when the interaction begins.
196        ///
197        ///
198        /// Parameter `interaction`: The UIContextMenuInteraction.
199        ///
200        /// Parameter `location`: The location of the interaction in its view.
201        ///
202        ///
203        /// Returns: A UIContextMenuConfiguration describing the menu to be presented. Return nil to prevent the interaction from beginning.
204        /// Returning an empty configuration causes the interaction to begin then fail with a cancellation effect. You might use this
205        /// to indicate to users that it's possible for a menu to be presented from this view, but that there are no actions to
206        /// present at this particular time.
207        #[unsafe(method(contextMenuInteraction:configurationForMenuAtLocation:))]
208        #[unsafe(method_family = none)]
209        unsafe fn contextMenuInteraction_configurationForMenuAtLocation(
210            &self,
211            interaction: &UIContextMenuInteraction,
212            location: CGPoint,
213        ) -> Option<Retained<UIContextMenuConfiguration>>;
214
215        #[cfg(all(feature = "UIContextMenuConfiguration", feature = "UITargetedPreview"))]
216        /// Called when a context menu interaction begins. Return a UITargetedPreview corresponding to the item with the given identifier.
217        ///
218        ///
219        /// Parameter `interaction`: The UIContextMenuInteraction.
220        ///
221        /// Parameter `configuration`: Configuration of the menu that will be presented if the interaction proceeds.
222        ///
223        /// Parameter `identifier`: Identifier for the item whose preview is being requested.
224        #[optional]
225        #[unsafe(method(contextMenuInteraction:configuration:highlightPreviewForItemWithIdentifier:))]
226        #[unsafe(method_family = none)]
227        unsafe fn contextMenuInteraction_configuration_highlightPreviewForItemWithIdentifier(
228            &self,
229            interaction: &UIContextMenuInteraction,
230            configuration: &UIContextMenuConfiguration,
231            identifier: &ProtocolObject<dyn NSCopying>,
232        ) -> Option<Retained<UITargetedPreview>>;
233
234        #[cfg(all(feature = "UIContextMenuConfiguration", feature = "UITargetedPreview"))]
235        /// Called when a context menu is dismissed. Return a UITargetedPreview corresponding to the item with the given identifier.
236        ///
237        ///
238        /// Parameter `interaction`: The UIContextMenuInteraction.
239        ///
240        /// Parameter `configuration`: Configuration of the menu being dismissed.
241        ///
242        /// Parameter `identifier`: Identifier for the item whose preview is being requested.
243        #[optional]
244        #[unsafe(method(contextMenuInteraction:configuration:dismissalPreviewForItemWithIdentifier:))]
245        #[unsafe(method_family = none)]
246        unsafe fn contextMenuInteraction_configuration_dismissalPreviewForItemWithIdentifier(
247            &self,
248            interaction: &UIContextMenuInteraction,
249            configuration: &UIContextMenuConfiguration,
250            identifier: &ProtocolObject<dyn NSCopying>,
251        ) -> Option<Retained<UITargetedPreview>>;
252
253        #[cfg(feature = "UIContextMenuConfiguration")]
254        /// Called when the interaction is about to "commit" in response to the user tapping the preview.
255        ///
256        ///
257        /// Parameter `interaction`: The UIContextMenuInteraction.
258        ///
259        /// Parameter `configuration`: Configuration of the currently displayed menu.
260        ///
261        /// Parameter `animator`: Commit animator. Add animations to this object to run them alongside the commit transition.
262        #[optional]
263        #[unsafe(method(contextMenuInteraction:willPerformPreviewActionForMenuWithConfiguration:animator:))]
264        #[unsafe(method_family = none)]
265        unsafe fn contextMenuInteraction_willPerformPreviewActionForMenuWithConfiguration_animator(
266            &self,
267            interaction: &UIContextMenuInteraction,
268            configuration: &UIContextMenuConfiguration,
269            animator: &ProtocolObject<dyn UIContextMenuInteractionCommitAnimating>,
270        );
271
272        #[cfg(feature = "UIContextMenuConfiguration")]
273        /// Called when the interaction is about to display a menu.
274        ///
275        ///
276        /// Parameter `interaction`: The UIContextMenuInteraction.
277        ///
278        /// Parameter `configuration`: The configuration of the menu about to be displayed by this interaction.
279        ///
280        /// Parameter `animator`: Appearance animator. Add animations to run them alongside the appearance transition.
281        #[optional]
282        #[unsafe(method(contextMenuInteraction:willDisplayMenuForConfiguration:animator:))]
283        #[unsafe(method_family = none)]
284        unsafe fn contextMenuInteraction_willDisplayMenuForConfiguration_animator(
285            &self,
286            interaction: &UIContextMenuInteraction,
287            configuration: &UIContextMenuConfiguration,
288            animator: Option<&ProtocolObject<dyn UIContextMenuInteractionAnimating>>,
289        );
290
291        #[cfg(feature = "UIContextMenuConfiguration")]
292        /// Called when the interaction is about to end.
293        ///
294        ///
295        /// Parameter `interaction`: The UIContextMenuInteraction.
296        ///
297        /// Parameter `configuration`: Ending configuration.
298        ///
299        /// Parameter `animator`: Disappearance animator. Add animations to run them alongside the disappearance transition.
300        #[optional]
301        #[unsafe(method(contextMenuInteraction:willEndForConfiguration:animator:))]
302        #[unsafe(method_family = none)]
303        unsafe fn contextMenuInteraction_willEndForConfiguration_animator(
304            &self,
305            interaction: &UIContextMenuInteraction,
306            configuration: &UIContextMenuConfiguration,
307            animator: Option<&ProtocolObject<dyn UIContextMenuInteractionAnimating>>,
308        );
309
310        #[cfg(all(feature = "UIContextMenuConfiguration", feature = "UITargetedPreview"))]
311        /// Called when the interaction begins. Return a UITargetedPreview describing the desired highlight preview.
312        ///
313        ///
314        /// Parameter `interaction`: The UIContextMenuInteraction requesting a highlighting preview.
315        ///
316        /// Parameter `configuration`: The configuration of the menu about to be displayed by this interaction.
317        #[deprecated]
318        #[optional]
319        #[unsafe(method(contextMenuInteraction:previewForHighlightingMenuWithConfiguration:))]
320        #[unsafe(method_family = none)]
321        unsafe fn contextMenuInteraction_previewForHighlightingMenuWithConfiguration(
322            &self,
323            interaction: &UIContextMenuInteraction,
324            configuration: &UIContextMenuConfiguration,
325        ) -> Option<Retained<UITargetedPreview>>;
326
327        #[cfg(all(feature = "UIContextMenuConfiguration", feature = "UITargetedPreview"))]
328        /// Called when the interaction is about to dismiss. Return a UITargetedPreview describing the desired dismissal target.
329        /// The interaction will animate the presented menu to the target. Use this to customize the dismissal animation.
330        ///
331        ///
332        /// Parameter `interaction`: The UIContextMenuInteraction requesting a dismissal preview.
333        ///
334        /// Parameter `configuration`: The configuration of the menu displayed by this interaction.
335        ///
336        ///
337        /// Returns: Return a UITargetedPreview describing the desired dismissal target. Return nil to cause the menu to
338        /// animate away without morphing into a specific view.
339        #[deprecated]
340        #[optional]
341        #[unsafe(method(contextMenuInteraction:previewForDismissingMenuWithConfiguration:))]
342        #[unsafe(method_family = none)]
343        unsafe fn contextMenuInteraction_previewForDismissingMenuWithConfiguration(
344            &self,
345            interaction: &UIContextMenuInteraction,
346            configuration: &UIContextMenuConfiguration,
347        ) -> Option<Retained<UITargetedPreview>>;
348    }
349);