objc2_ui_kit/generated/
UIContextMenuConfiguration.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenuconfigurationelementorder?language=objc)
11// NS_ENUM
12#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct UIContextMenuConfigurationElementOrder(pub NSInteger);
15impl UIContextMenuConfigurationElementOrder {
16    #[doc(alias = "UIContextMenuConfigurationElementOrderAutomatic")]
17    pub const Automatic: Self = Self(0);
18    /// Allows the system to choose the appropriate ordering strategy for the current context.
19    #[doc(alias = "UIContextMenuConfigurationElementOrderPriority")]
20    pub const Priority: Self = Self(1);
21    /// Order menu elements according to priority. Keeping the first element in the UIMenu closest to user's interaction point.
22    #[doc(alias = "UIContextMenuConfigurationElementOrderFixed")]
23    pub const Fixed: Self = Self(2);
24}
25
26unsafe impl Encode for UIContextMenuConfigurationElementOrder {
27    const ENCODING: Encoding = NSInteger::ENCODING;
28}
29
30unsafe impl RefEncode for UIContextMenuConfigurationElementOrder {
31    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
32}
33
34/// Return a UIAction-based UIMenu describing the desired action hierarchy.
35///
36///
37/// Parameter `suggestedActions`: An array of suggested actions gathered from the UIResponder chain. You may choose to include
38/// some of these actions in the hierarchy returned from this block to display them in the resulting menu.
39///
40/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenuactionprovider?language=objc)
41#[cfg(all(feature = "UIMenu", feature = "UIMenuElement", feature = "block2"))]
42pub type UIContextMenuActionProvider =
43    *mut block2::DynBlock<dyn Fn(NonNull<NSArray<UIMenuElement>>) -> *mut UIMenu>;
44
45/// Return a UIViewController to be displayed as this menu's preview component.
46///
47/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenucontentpreviewprovider?language=objc)
48#[cfg(all(
49    feature = "UIResponder",
50    feature = "UIViewController",
51    feature = "block2"
52))]
53pub type UIContextMenuContentPreviewProvider =
54    *mut block2::DynBlock<dyn Fn() -> *mut UIViewController>;
55
56extern_class!(
57    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uicontextmenuconfiguration?language=objc)
58    #[unsafe(super(NSObject))]
59    #[thread_kind = MainThreadOnly]
60    #[derive(Debug, PartialEq, Eq, Hash)]
61    pub struct UIContextMenuConfiguration;
62);
63
64extern_conformance!(
65    unsafe impl NSObjectProtocol for UIContextMenuConfiguration {}
66);
67
68impl UIContextMenuConfiguration {
69    extern_methods!(
70        /// This configuration's identifier. When representing multiple items in your app, this identifier
71        /// corresponds to the primary item (i.e. the one with which the user interacted when invoking the menu).
72        #[unsafe(method(identifier))]
73        #[unsafe(method_family = none)]
74        pub fn identifier(&self) -> Retained<ProtocolObject<dyn NSCopying>>;
75
76        /// When this menu acts on multiple items, you may include the identifiers of secondary items to display a multi-item menu.
77        #[unsafe(method(secondaryItemIdentifiers))]
78        #[unsafe(method_family = none)]
79        pub fn secondaryItemIdentifiers(&self) -> Retained<NSSet<ProtocolObject<dyn NSCopying>>>;
80
81        /// Setter for [`secondaryItemIdentifiers`][Self::secondaryItemIdentifiers].
82        ///
83        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
84        ///
85        /// # Safety
86        ///
87        /// `secondary_item_identifiers` generic should be of the correct type.
88        #[unsafe(method(setSecondaryItemIdentifiers:))]
89        #[unsafe(method_family = none)]
90        pub unsafe fn setSecondaryItemIdentifiers(
91            &self,
92            secondary_item_identifiers: &NSSet<ProtocolObject<dyn NSCopying>>,
93        );
94
95        /// Number of items on which this menu acts. Used to badge a multi-item menu's preview stack.
96        /// When unset, this value is determined automatically by the system. Values lower than 2 hide the badge.
97        #[unsafe(method(badgeCount))]
98        #[unsafe(method_family = none)]
99        pub fn badgeCount(&self) -> NSInteger;
100
101        /// Setter for [`badgeCount`][Self::badgeCount].
102        #[unsafe(method(setBadgeCount:))]
103        #[unsafe(method_family = none)]
104        pub fn setBadgeCount(&self, badge_count: NSInteger);
105
106        /// Preferred menu element ordering strategy for this menu.
107        #[unsafe(method(preferredMenuElementOrder))]
108        #[unsafe(method_family = none)]
109        pub fn preferredMenuElementOrder(&self) -> UIContextMenuConfigurationElementOrder;
110
111        /// Setter for [`preferredMenuElementOrder`][Self::preferredMenuElementOrder].
112        #[unsafe(method(setPreferredMenuElementOrder:))]
113        #[unsafe(method_family = none)]
114        pub fn setPreferredMenuElementOrder(
115            &self,
116            preferred_menu_element_order: UIContextMenuConfigurationElementOrder,
117        );
118
119        #[cfg(all(
120            feature = "UIMenu",
121            feature = "UIMenuElement",
122            feature = "UIResponder",
123            feature = "UIViewController",
124            feature = "block2"
125        ))]
126        /// Returns a UIContextMenuConfiguration.
127        ///
128        ///
129        /// Parameter `identifier`: Optional unique identifier. If omitted, an NSUUID will be generated. May be used to
130        /// identify this configuration throughout the interaction's lifecycle.
131        ///
132        /// Parameter `previewProvider`: Optional preview view controller provider block, called when the menu is about to be presented.
133        ///
134        /// Parameter `actionProvider`: Optional action provider block, called when the menu is about to be presented.
135        ///
136        /// # Safety
137        ///
138        /// - `identifier` should be of the correct type.
139        /// - `preview_provider` must be a valid pointer or null.
140        /// - `action_provider` must be a valid pointer or null.
141        #[unsafe(method(configurationWithIdentifier:previewProvider:actionProvider:))]
142        #[unsafe(method_family = none)]
143        pub unsafe fn configurationWithIdentifier_previewProvider_actionProvider(
144            identifier: Option<&ProtocolObject<dyn NSCopying>>,
145            preview_provider: UIContextMenuContentPreviewProvider,
146            action_provider: UIContextMenuActionProvider,
147            mtm: MainThreadMarker,
148        ) -> Retained<Self>;
149    );
150}
151
152/// Methods declared on superclass `NSObject`.
153impl UIContextMenuConfiguration {
154    extern_methods!(
155        #[unsafe(method(init))]
156        #[unsafe(method_family = init)]
157        pub fn init(this: Allocated<Self>) -> Retained<Self>;
158
159        #[unsafe(method(new))]
160        #[unsafe(method_family = new)]
161        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
162    );
163}