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
51extern_conformance!(
52    unsafe impl NSObjectProtocol for UISpringLoadedInteraction {}
53);
54
55#[cfg(feature = "UIInteraction")]
56extern_conformance!(
57    unsafe impl UIInteraction for UISpringLoadedInteraction {}
58);
59
60impl UISpringLoadedInteraction {
61    extern_methods!(
62        #[unsafe(method(new))]
63        #[unsafe(method_family = new)]
64        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
65
66        #[unsafe(method(init))]
67        #[unsafe(method_family = init)]
68        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
69
70        #[cfg(feature = "block2")]
71        /// The designated `UISpringLoadedInteraction` initializer.
72        ///
73        ///
74        /// Parameter `interactionBehavior`: The interaction behavior object controlling the springloaded interaction activation. If nil, the default behavior will be used.
75        ///
76        /// Parameter `interactionEffect`: The interaction effect object styling the interaction's view. If nil, the default effect will be used.
77        ///
78        /// Parameter `handler`: The handler to be performed when springloading is activated.
79        ///
80        /// Returns: An initialized springloaded interaction object or `nil` if the springloaded interaction could not be initialized.
81        #[unsafe(method(initWithInteractionBehavior:interactionEffect:activationHandler:))]
82        #[unsafe(method_family = init)]
83        pub fn initWithInteractionBehavior_interactionEffect_activationHandler(
84            this: Allocated<Self>,
85            interaction_behavior: Option<&ProtocolObject<dyn UISpringLoadedInteractionBehavior>>,
86            interaction_effect: Option<&ProtocolObject<dyn UISpringLoadedInteractionEffect>>,
87            handler: &block2::DynBlock<
88                dyn Fn(
89                    NonNull<UISpringLoadedInteraction>,
90                    NonNull<ProtocolObject<dyn UISpringLoadedInteractionContext>>,
91                ),
92            >,
93        ) -> Retained<Self>;
94
95        #[cfg(feature = "block2")]
96        /// A springloaded interaction with the default interaction behavior and effect.
97        ///
98        ///
99        /// Parameter `handler`: The handler to be performed when springloading is activated.
100        ///
101        /// Returns: An initialized springloaded interaction object or `nil` if the springloaded interaction could not be initialized.
102        #[unsafe(method(initWithActivationHandler:))]
103        #[unsafe(method_family = init)]
104        pub fn initWithActivationHandler(
105            this: Allocated<Self>,
106            handler: &block2::DynBlock<
107                dyn Fn(
108                    NonNull<UISpringLoadedInteraction>,
109                    NonNull<ProtocolObject<dyn UISpringLoadedInteractionContext>>,
110                ),
111            >,
112        ) -> Retained<Self>;
113
114        #[unsafe(method(interactionBehavior))]
115        #[unsafe(method_family = none)]
116        pub fn interactionBehavior(
117            &self,
118        ) -> Retained<ProtocolObject<dyn UISpringLoadedInteractionBehavior>>;
119
120        #[unsafe(method(interactionEffect))]
121        #[unsafe(method_family = none)]
122        pub fn interactionEffect(
123            &self,
124        ) -> Retained<ProtocolObject<dyn UISpringLoadedInteractionEffect>>;
125    );
126}
127
128extern_protocol!(
129    /// The interaction behavior of a `UISpringLoadedInteraction` object must adopt the `UISpringLoadedInteractionBehavior` protocol.
130    ///
131    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uispringloadedinteractionbehavior?language=objc)
132    pub unsafe trait UISpringLoadedInteractionBehavior:
133        NSObjectProtocol + MainThreadOnly
134    {
135        /// Returns whether springloading should begin or continue for a given interaction.
136        ///
137        ///
138        /// Parameter `interaction`: The springloaded interaction object requesting this information
139        ///
140        /// Parameter `context`: An object that provides information about the current drag.
141        ///
142        /// Returns: true if the interaction should begin or continue springloading.
143        #[unsafe(method(shouldAllowInteraction:withContext:))]
144        #[unsafe(method_family = none)]
145        fn shouldAllowInteraction_withContext(
146            &self,
147            interaction: &UISpringLoadedInteraction,
148            context: &ProtocolObject<dyn UISpringLoadedInteractionContext>,
149        ) -> bool;
150
151        /// Informs the behavior that springloading for a given interaction was cancelled or activated.
152        ///
153        ///
154        /// Parameter `interaction`: The springloaded interaction object providing this information.
155        #[optional]
156        #[unsafe(method(interactionDidFinish:))]
157        #[unsafe(method_family = none)]
158        fn interactionDidFinish(&self, interaction: &UISpringLoadedInteraction);
159    }
160);
161
162extern_protocol!(
163    /// The interaction effect of a `UISpringLoadedInteraction` object must adopt the `UISpringLoadedInteractionEffect` protocol.
164    /// It is responsible for styling the interaction view according to the current springloading state.
165    ///
166    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uispringloadedinteractioneffect?language=objc)
167    pub unsafe trait UISpringLoadedInteractionEffect:
168        NSObjectProtocol + MainThreadOnly
169    {
170        /// Informs the effect that the springloading state changed.
171        ///
172        ///
173        /// Parameter `interaction`: The springloaded interaction providing this information.
174        ///
175        /// Parameter `context`: An object that provides information about the current springloading state.
176        #[unsafe(method(interaction:didChangeWithContext:))]
177        #[unsafe(method_family = none)]
178        fn interaction_didChangeWithContext(
179            &self,
180            interaction: &UISpringLoadedInteraction,
181            context: &ProtocolObject<dyn UISpringLoadedInteractionContext>,
182        );
183    }
184);
185
186extern_protocol!(
187    /// UISpringLoadedContext supplies information about the springloading state and current drag.
188    ///
189    /// See also [Apple's documentation](https://developer.apple.com/documentation/uikit/uispringloadedinteractioncontext?language=objc)
190    pub unsafe trait UISpringLoadedInteractionContext:
191        NSObjectProtocol + MainThreadOnly
192    {
193        /// The state that describes the current springloading style.
194        #[unsafe(method(state))]
195        #[unsafe(method_family = none)]
196        fn state(&self) -> UISpringLoadedInteractionEffectState;
197
198        #[cfg(all(feature = "UIResponder", feature = "UIView"))]
199        /// The view to which the interaction effect is applied. Defaults to the interaction's view.
200        #[unsafe(method(targetView))]
201        #[unsafe(method_family = none)]
202        fn targetView(&self) -> Option<Retained<UIView>>;
203
204        #[cfg(all(feature = "UIResponder", feature = "UIView"))]
205        /// Setter for [`targetView`][Self::targetView].
206        #[unsafe(method(setTargetView:))]
207        #[unsafe(method_family = none)]
208        fn setTargetView(&self, target_view: Option<&UIView>);
209
210        /// The `targetItem` allows to distinguish a region of the view on which the interaction is installed.
211        /// It is convenient to set this property to a model object associated to `targetView`.
212        #[unsafe(method(targetItem))]
213        #[unsafe(method_family = none)]
214        fn targetItem(&self) -> Option<Retained<AnyObject>>;
215
216        /// Setter for [`targetItem`][Self::targetItem].
217        ///
218        /// # Safety
219        ///
220        /// `target_item` should be of the correct type.
221        #[unsafe(method(setTargetItem:))]
222        #[unsafe(method_family = none)]
223        unsafe fn setTargetItem(&self, target_item: Option<&AnyObject>);
224
225        #[cfg(all(
226            feature = "UIResponder",
227            feature = "UIView",
228            feature = "objc2-core-foundation"
229        ))]
230        /// Returns the point computed as the location of the current drag in a given view.
231        ///
232        ///
233        /// Parameter `view`: A view on which the drag is taking place. Specify nil to indicate the window.
234        ///
235        /// Returns: A point in the local coordinate system of `view`.
236        #[unsafe(method(locationInView:))]
237        #[unsafe(method_family = none)]
238        fn locationInView(&self, view: Option<&UIView>) -> CGPoint;
239    }
240);