objc2_ui_kit/generated/
UISpringLoadedInteraction.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::*;
8
9use crate::*;
10
11/// An object conforming to UISpringLoadedInteractionEffect uses UISpringLoadedInteractionEffectState
12/// to style the interaction view for the current springloading state.
13///
14/// - UISpringLoadedInteractionEffectStateInactive: the view is not engaged in springloading and should be displayed with its default style.
15/// - UISpringLoadedInteractionEffectStatePossible: the view may springload and should provide a visual cue to the user. The default effect highlights the view.
16/// - UISpringLoadedInteractionEffectStateActivating: the view is about to springload. The default effect will briefly flash while in this state.
17/// - UISpringLoadedInteractionEffectStateActivated: the view springloaded and the activation handler is called. The default effect will restore the view to its original appearance.
18///
19/// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uispringloadedinteractioneffectstate?language=objc)
20// NS_ENUM
21#[repr(transparent)]
22#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
23pub struct UISpringLoadedInteractionEffectState(pub NSInteger);
24impl UISpringLoadedInteractionEffectState {
25    #[doc(alias = "UISpringLoadedInteractionEffectStateInactive")]
26    pub const Inactive: Self = Self(0);
27    #[doc(alias = "UISpringLoadedInteractionEffectStatePossible")]
28    pub const Possible: Self = Self(1);
29    #[doc(alias = "UISpringLoadedInteractionEffectStateActivating")]
30    pub const Activating: Self = Self(2);
31    #[doc(alias = "UISpringLoadedInteractionEffectStateActivated")]
32    pub const Activated: Self = Self(3);
33}
34
35unsafe impl Encode for UISpringLoadedInteractionEffectState {
36    const ENCODING: Encoding = NSInteger::ENCODING;
37}
38
39unsafe impl RefEncode for UISpringLoadedInteractionEffectState {
40    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
41}
42
43extern_class!(
44    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uispringloadedinteraction?language=objc)
45    #[unsafe(super(NSObject))]
46    #[thread_kind = MainThreadOnly]
47    #[derive(Debug, PartialEq, Eq, Hash)]
48    pub struct UISpringLoadedInteraction;
49);
50
51unsafe impl NSObjectProtocol for UISpringLoadedInteraction {}
52
53#[cfg(feature = "UIInteraction")]
54unsafe impl UIInteraction for UISpringLoadedInteraction {}
55
56impl UISpringLoadedInteraction {
57    extern_methods!(
58        #[unsafe(method(new))]
59        #[unsafe(method_family = new)]
60        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
61
62        #[unsafe(method(init))]
63        #[unsafe(method_family = init)]
64        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
65
66        #[cfg(feature = "block2")]
67        /// The designated `UISpringLoadedInteraction` initializer.
68        ///
69        ///
70        /// Parameter `interactionBehavior`: The interaction behavior object controlling the springloaded interaction activation. If nil, the default behavior will be used.
71        ///
72        /// Parameter `interactionEffect`: The interaction effect object styling the interaction's view. If nil, the default effect will be used.
73        ///
74        /// Parameter `handler`: The handler to be performed when springloading is activated.
75        ///
76        /// Returns: An initialized springloaded interaction object or `nil` if the springloaded interaction could not be initialized.
77        #[unsafe(method(initWithInteractionBehavior:interactionEffect:activationHandler:))]
78        #[unsafe(method_family = init)]
79        pub unsafe fn initWithInteractionBehavior_interactionEffect_activationHandler(
80            this: Allocated<Self>,
81            interaction_behavior: Option<&ProtocolObject<dyn UISpringLoadedInteractionBehavior>>,
82            interaction_effect: Option<&ProtocolObject<dyn UISpringLoadedInteractionEffect>>,
83            handler: &block2::Block<
84                dyn Fn(
85                    NonNull<UISpringLoadedInteraction>,
86                    NonNull<ProtocolObject<dyn UISpringLoadedInteractionContext>>,
87                ),
88            >,
89        ) -> Retained<Self>;
90
91        #[cfg(feature = "block2")]
92        /// A springloaded interaction with the default interaction behavior and effect.
93        ///
94        ///
95        /// Parameter `handler`: The handler to be performed when springloading is activated.
96        ///
97        /// Returns: An initialized springloaded interaction object or `nil` if the springloaded interaction could not be initialized.
98        #[unsafe(method(initWithActivationHandler:))]
99        #[unsafe(method_family = init)]
100        pub unsafe fn initWithActivationHandler(
101            this: Allocated<Self>,
102            handler: &block2::Block<
103                dyn Fn(
104                    NonNull<UISpringLoadedInteraction>,
105                    NonNull<ProtocolObject<dyn UISpringLoadedInteractionContext>>,
106                ),
107            >,
108        ) -> Retained<Self>;
109
110        #[unsafe(method(interactionBehavior))]
111        #[unsafe(method_family = none)]
112        pub unsafe fn interactionBehavior(
113            &self,
114        ) -> Retained<ProtocolObject<dyn UISpringLoadedInteractionBehavior>>;
115
116        #[unsafe(method(interactionEffect))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn interactionEffect(
119            &self,
120        ) -> Retained<ProtocolObject<dyn UISpringLoadedInteractionEffect>>;
121    );
122}
123
124extern_protocol!(
125    /// The interaction behavior of a `UISpringLoadedInteraction` object must adopt the `UISpringLoadedInteractionBehavior` protocol.
126    ///
127    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uispringloadedinteractionbehavior?language=objc)
128    pub unsafe trait UISpringLoadedInteractionBehavior:
129        NSObjectProtocol + MainThreadOnly
130    {
131        /// Returns whether springloading should begin or continue for a given interaction.
132        ///
133        ///
134        /// Parameter `interaction`: The springloaded interaction object requesting this information
135        ///
136        /// Parameter `context`: An object that provides information about the current drag.
137        ///
138        /// Returns: true if the interaction should begin or continue springloading.
139        #[unsafe(method(shouldAllowInteraction:withContext:))]
140        #[unsafe(method_family = none)]
141        unsafe fn shouldAllowInteraction_withContext(
142            &self,
143            interaction: &UISpringLoadedInteraction,
144            context: &ProtocolObject<dyn UISpringLoadedInteractionContext>,
145        ) -> bool;
146
147        /// Informs the behavior that springloading for a given interaction was cancelled or activated.
148        ///
149        ///
150        /// Parameter `interaction`: The springloaded interaction object providing this information.
151        #[optional]
152        #[unsafe(method(interactionDidFinish:))]
153        #[unsafe(method_family = none)]
154        unsafe fn interactionDidFinish(&self, interaction: &UISpringLoadedInteraction);
155    }
156);
157
158extern_protocol!(
159    /// The interaction effect of a `UISpringLoadedInteraction` object must adopt the `UISpringLoadedInteractionEffect` protocol.
160    /// It is responsible for styling the interaction view according to the current springloading state.
161    ///
162    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uispringloadedinteractioneffect?language=objc)
163    pub unsafe trait UISpringLoadedInteractionEffect:
164        NSObjectProtocol + MainThreadOnly
165    {
166        /// Informs the effect that the springloading state changed.
167        ///
168        ///
169        /// Parameter `interaction`: The springloaded interaction providing this information.
170        ///
171        /// Parameter `context`: An object that provides information about the current springloading state.
172        #[unsafe(method(interaction:didChangeWithContext:))]
173        #[unsafe(method_family = none)]
174        unsafe fn interaction_didChangeWithContext(
175            &self,
176            interaction: &UISpringLoadedInteraction,
177            context: &ProtocolObject<dyn UISpringLoadedInteractionContext>,
178        );
179    }
180);
181
182extern_protocol!(
183    /// UISpringLoadedContext supplies information about the springloading state and current drag.
184    ///
185    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uispringloadedinteractioncontext?language=objc)
186    pub unsafe trait UISpringLoadedInteractionContext:
187        NSObjectProtocol + MainThreadOnly
188    {
189        /// The state that describes the current springloading style.
190        #[unsafe(method(state))]
191        #[unsafe(method_family = none)]
192        unsafe fn state(&self) -> UISpringLoadedInteractionEffectState;
193
194        #[cfg(all(feature = "UIResponder", feature = "UIView"))]
195        /// The view to which the interaction effect is applied. Defaults to the interaction's view.
196        #[unsafe(method(targetView))]
197        #[unsafe(method_family = none)]
198        unsafe fn targetView(&self) -> Option<Retained<UIView>>;
199
200        #[cfg(all(feature = "UIResponder", feature = "UIView"))]
201        /// Setter for [`targetView`][Self::targetView].
202        #[unsafe(method(setTargetView:))]
203        #[unsafe(method_family = none)]
204        unsafe fn setTargetView(&self, target_view: Option<&UIView>);
205
206        /// The `targetItem` allows to distinguish a region of the view on which the interaction is installed.
207        /// It is convenient to set this property to a model object associated to `targetView`.
208        #[unsafe(method(targetItem))]
209        #[unsafe(method_family = none)]
210        unsafe fn targetItem(&self) -> Option<Retained<AnyObject>>;
211
212        /// Setter for [`targetItem`][Self::targetItem].
213        #[unsafe(method(setTargetItem:))]
214        #[unsafe(method_family = none)]
215        unsafe fn setTargetItem(&self, target_item: Option<&AnyObject>);
216
217        #[cfg(all(
218            feature = "UIResponder",
219            feature = "UIView",
220            feature = "objc2-core-foundation"
221        ))]
222        /// Returns the point computed as the location of the current drag in a given view.
223        ///
224        ///
225        /// Parameter `view`: A view on which the drag is taking place. Specify nil to indicate the window.
226        ///
227        /// Returns: A point in the local coordinate system of `view`.
228        #[unsafe(method(locationInView:))]
229        #[unsafe(method_family = none)]
230        unsafe fn locationInView(&self, view: Option<&UIView>) -> CGPoint;
231    }
232);