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