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 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 fn menuAppearance(&self) -> UIContextMenuInteractionAppearance;
85
86        #[unsafe(method(initWithDelegate:))]
87        #[unsafe(method_family = init)]
88        pub 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 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        ///
130        /// # Safety
131        ///
132        /// `block` block's return must be a valid pointer.
133        #[unsafe(method(updateVisibleMenuWithBlock:))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn updateVisibleMenuWithBlock(
136            &self,
137            block: &block2::DynBlock<dyn Fn(NonNull<UIMenu>) -> NonNull<UIMenu> + '_>,
138        );
139
140        /// Dismisses the currently presented menu (if there is one).
141        #[unsafe(method(dismissMenu))]
142        #[unsafe(method_family = none)]
143        pub fn dismissMenu(&self);
144    );
145}
146
147extern_protocol!(
148    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenuinteractionanimating?language=objc)
149    pub unsafe trait UIContextMenuInteractionAnimating:
150        NSObjectProtocol + MainThreadOnly
151    {
152        #[cfg(all(feature = "UIResponder", feature = "UIViewController"))]
153        /// Displayed preview view controller.
154        #[unsafe(method(previewViewController))]
155        #[unsafe(method_family = none)]
156        fn previewViewController(&self) -> Option<Retained<UIViewController>>;
157
158        #[cfg(feature = "block2")]
159        #[unsafe(method(addAnimations:))]
160        #[unsafe(method_family = none)]
161        fn addAnimations(&self, animations: &block2::DynBlock<dyn Fn()>);
162
163        #[cfg(feature = "block2")]
164        #[unsafe(method(addCompletion:))]
165        #[unsafe(method_family = none)]
166        fn addCompletion(&self, completion: &block2::DynBlock<dyn Fn()>);
167    }
168);
169
170extern_protocol!(
171    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenuinteractioncommitanimating?language=objc)
172    pub unsafe trait UIContextMenuInteractionCommitAnimating:
173        UIContextMenuInteractionAnimating + MainThreadOnly
174    {
175        /// Preferred animation style for the menu's commit action. Triggered when the user taps the preview.
176        #[unsafe(method(preferredCommitStyle))]
177        #[unsafe(method_family = none)]
178        fn preferredCommitStyle(&self) -> UIContextMenuInteractionCommitStyle;
179
180        /// Setter for [`preferredCommitStyle`][Self::preferredCommitStyle].
181        #[unsafe(method(setPreferredCommitStyle:))]
182        #[unsafe(method_family = none)]
183        fn setPreferredCommitStyle(
184            &self,
185            preferred_commit_style: UIContextMenuInteractionCommitStyle,
186        );
187    }
188);
189
190extern_protocol!(
191    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenuinteractiondelegate?language=objc)
192    pub unsafe trait UIContextMenuInteractionDelegate:
193        NSObjectProtocol + MainThreadOnly
194    {
195        #[cfg(all(
196            feature = "UIContextMenuConfiguration",
197            feature = "objc2-core-foundation"
198        ))]
199        /// Called when the interaction begins.
200        ///
201        ///
202        /// Parameter `interaction`: The UIContextMenuInteraction.
203        ///
204        /// Parameter `location`: The location of the interaction in its view.
205        ///
206        ///
207        /// Returns: A UIContextMenuConfiguration describing the menu to be presented. Return nil to prevent the interaction from beginning.
208        /// Returning an empty configuration causes the interaction to begin then fail with a cancellation effect. You might use this
209        /// to indicate to users that it's possible for a menu to be presented from this view, but that there are no actions to
210        /// present at this particular time.
211        #[unsafe(method(contextMenuInteraction:configurationForMenuAtLocation:))]
212        #[unsafe(method_family = none)]
213        fn contextMenuInteraction_configurationForMenuAtLocation(
214            &self,
215            interaction: &UIContextMenuInteraction,
216            location: CGPoint,
217        ) -> Option<Retained<UIContextMenuConfiguration>>;
218
219        #[cfg(all(feature = "UIContextMenuConfiguration", feature = "UITargetedPreview"))]
220        /// Called when a context menu interaction begins. Return a UITargetedPreview corresponding to the item with the given identifier.
221        ///
222        ///
223        /// Parameter `interaction`: The UIContextMenuInteraction.
224        ///
225        /// Parameter `configuration`: Configuration of the menu that will be presented if the interaction proceeds.
226        ///
227        /// Parameter `identifier`: Identifier for the item whose preview is being requested.
228        ///
229        /// # Safety
230        ///
231        /// `identifier` should be of the correct type.
232        #[optional]
233        #[unsafe(method(contextMenuInteraction:configuration:highlightPreviewForItemWithIdentifier:))]
234        #[unsafe(method_family = none)]
235        unsafe fn contextMenuInteraction_configuration_highlightPreviewForItemWithIdentifier(
236            &self,
237            interaction: &UIContextMenuInteraction,
238            configuration: &UIContextMenuConfiguration,
239            identifier: &ProtocolObject<dyn NSCopying>,
240        ) -> Option<Retained<UITargetedPreview>>;
241
242        #[cfg(all(feature = "UIContextMenuConfiguration", feature = "UITargetedPreview"))]
243        /// Called when a context menu is dismissed. Return a UITargetedPreview corresponding to the item with the given identifier.
244        ///
245        ///
246        /// Parameter `interaction`: The UIContextMenuInteraction.
247        ///
248        /// Parameter `configuration`: Configuration of the menu being dismissed.
249        ///
250        /// Parameter `identifier`: Identifier for the item whose preview is being requested.
251        ///
252        /// # Safety
253        ///
254        /// `identifier` should be of the correct type.
255        #[optional]
256        #[unsafe(method(contextMenuInteraction:configuration:dismissalPreviewForItemWithIdentifier:))]
257        #[unsafe(method_family = none)]
258        unsafe fn contextMenuInteraction_configuration_dismissalPreviewForItemWithIdentifier(
259            &self,
260            interaction: &UIContextMenuInteraction,
261            configuration: &UIContextMenuConfiguration,
262            identifier: &ProtocolObject<dyn NSCopying>,
263        ) -> Option<Retained<UITargetedPreview>>;
264
265        #[cfg(feature = "UIContextMenuConfiguration")]
266        /// Called when the interaction is about to "commit" in response to the user tapping the preview.
267        ///
268        ///
269        /// Parameter `interaction`: The UIContextMenuInteraction.
270        ///
271        /// Parameter `configuration`: Configuration of the currently displayed menu.
272        ///
273        /// Parameter `animator`: Commit animator. Add animations to this object to run them alongside the commit transition.
274        #[optional]
275        #[unsafe(method(contextMenuInteraction:willPerformPreviewActionForMenuWithConfiguration:animator:))]
276        #[unsafe(method_family = none)]
277        fn contextMenuInteraction_willPerformPreviewActionForMenuWithConfiguration_animator(
278            &self,
279            interaction: &UIContextMenuInteraction,
280            configuration: &UIContextMenuConfiguration,
281            animator: &ProtocolObject<dyn UIContextMenuInteractionCommitAnimating>,
282        );
283
284        #[cfg(feature = "UIContextMenuConfiguration")]
285        /// Called when the interaction is about to display a menu.
286        ///
287        ///
288        /// Parameter `interaction`: The UIContextMenuInteraction.
289        ///
290        /// Parameter `configuration`: The configuration of the menu about to be displayed by this interaction.
291        ///
292        /// Parameter `animator`: Appearance animator. Add animations to run them alongside the appearance transition.
293        #[optional]
294        #[unsafe(method(contextMenuInteraction:willDisplayMenuForConfiguration:animator:))]
295        #[unsafe(method_family = none)]
296        fn contextMenuInteraction_willDisplayMenuForConfiguration_animator(
297            &self,
298            interaction: &UIContextMenuInteraction,
299            configuration: &UIContextMenuConfiguration,
300            animator: Option<&ProtocolObject<dyn UIContextMenuInteractionAnimating>>,
301        );
302
303        #[cfg(feature = "UIContextMenuConfiguration")]
304        /// Called when the interaction is about to end.
305        ///
306        ///
307        /// Parameter `interaction`: The UIContextMenuInteraction.
308        ///
309        /// Parameter `configuration`: Ending configuration.
310        ///
311        /// Parameter `animator`: Disappearance animator. Add animations to run them alongside the disappearance transition.
312        #[optional]
313        #[unsafe(method(contextMenuInteraction:willEndForConfiguration:animator:))]
314        #[unsafe(method_family = none)]
315        fn contextMenuInteraction_willEndForConfiguration_animator(
316            &self,
317            interaction: &UIContextMenuInteraction,
318            configuration: &UIContextMenuConfiguration,
319            animator: Option<&ProtocolObject<dyn UIContextMenuInteractionAnimating>>,
320        );
321
322        #[cfg(all(feature = "UIContextMenuConfiguration", feature = "UITargetedPreview"))]
323        /// Called when the interaction begins. Return a UITargetedPreview describing the desired highlight preview.
324        ///
325        ///
326        /// Parameter `interaction`: The UIContextMenuInteraction requesting a highlighting preview.
327        ///
328        /// Parameter `configuration`: The configuration of the menu about to be displayed by this interaction.
329        #[deprecated]
330        #[optional]
331        #[unsafe(method(contextMenuInteraction:previewForHighlightingMenuWithConfiguration:))]
332        #[unsafe(method_family = none)]
333        fn contextMenuInteraction_previewForHighlightingMenuWithConfiguration(
334            &self,
335            interaction: &UIContextMenuInteraction,
336            configuration: &UIContextMenuConfiguration,
337        ) -> Option<Retained<UITargetedPreview>>;
338
339        #[cfg(all(feature = "UIContextMenuConfiguration", feature = "UITargetedPreview"))]
340        /// Called when the interaction is about to dismiss. Return a UITargetedPreview describing the desired dismissal target.
341        /// The interaction will animate the presented menu to the target. Use this to customize the dismissal animation.
342        ///
343        ///
344        /// Parameter `interaction`: The UIContextMenuInteraction requesting a dismissal preview.
345        ///
346        /// Parameter `configuration`: The configuration of the menu displayed by this interaction.
347        ///
348        ///
349        /// Returns: Return a UITargetedPreview describing the desired dismissal target. Return nil to cause the menu to
350        /// animate away without morphing into a specific view.
351        #[deprecated]
352        #[optional]
353        #[unsafe(method(contextMenuInteraction:previewForDismissingMenuWithConfiguration:))]
354        #[unsafe(method_family = none)]
355        fn contextMenuInteraction_previewForDismissingMenuWithConfiguration(
356            &self,
357            interaction: &UIContextMenuInteraction,
358            configuration: &UIContextMenuConfiguration,
359        ) -> Option<Retained<UITargetedPreview>>;
360    }
361);