objc2-ui-kit 0.3.2

Bindings to the UIKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/uikit/uigesturerecognizerstate?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct UIGestureRecognizerState(pub NSInteger);
impl UIGestureRecognizerState {
    #[doc(alias = "UIGestureRecognizerStatePossible")]
    pub const Possible: Self = Self(0);
    #[doc(alias = "UIGestureRecognizerStateBegan")]
    pub const Began: Self = Self(1);
    #[doc(alias = "UIGestureRecognizerStateChanged")]
    pub const Changed: Self = Self(2);
    #[doc(alias = "UIGestureRecognizerStateEnded")]
    pub const Ended: Self = Self(3);
    #[doc(alias = "UIGestureRecognizerStateCancelled")]
    pub const Cancelled: Self = Self(4);
    #[doc(alias = "UIGestureRecognizerStateFailed")]
    pub const Failed: Self = Self(5);
    #[doc(alias = "UIGestureRecognizerStateRecognized")]
    pub const Recognized: Self = Self(UIGestureRecognizerState::Ended.0);
}

unsafe impl Encode for UIGestureRecognizerState {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for UIGestureRecognizerState {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uigesturerecognizer?language=objc)
    #[unsafe(super(NSObject))]
    #[thread_kind = MainThreadOnly]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct UIGestureRecognizer;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for UIGestureRecognizer {}
);

impl UIGestureRecognizer {
    extern_methods!(
        /// # Safety
        ///
        /// - `target` should be of the correct type.
        /// - `action` must be a valid selector.
        #[unsafe(method(initWithTarget:action:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithTarget_action(
            this: Allocated<Self>,
            target: Option<&AnyObject>,
            action: Option<Sel>,
        ) -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        /// # Safety
        ///
        /// `coder` possibly has further requirements.
        #[unsafe(method(initWithCoder:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoder(
            this: Allocated<Self>,
            coder: &NSCoder,
        ) -> Option<Retained<Self>>;

        /// # Safety
        ///
        /// - `target` should be of the correct type.
        /// - `action` must be a valid selector.
        #[unsafe(method(addTarget:action:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addTarget_action(&self, target: &AnyObject, action: Sel);

        /// # Safety
        ///
        /// - `target` should be of the correct type.
        /// - `action` must be a valid selector.
        #[unsafe(method(removeTarget:action:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeTarget_action(&self, target: Option<&AnyObject>, action: Option<Sel>);

        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub fn delegate(&self)
            -> Option<Retained<ProtocolObject<dyn UIGestureRecognizerDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn UIGestureRecognizerDelegate>>,
        );

        #[unsafe(method(isEnabled))]
        #[unsafe(method_family = none)]
        pub fn isEnabled(&self) -> bool;

        /// Setter for [`isEnabled`][Self::isEnabled].
        #[unsafe(method(setEnabled:))]
        #[unsafe(method_family = none)]
        pub fn setEnabled(&self, enabled: bool);

        #[cfg(all(feature = "UIResponder", feature = "UIView"))]
        #[unsafe(method(view))]
        #[unsafe(method_family = none)]
        pub fn view(&self) -> Option<Retained<UIView>>;

        #[unsafe(method(cancelsTouchesInView))]
        #[unsafe(method_family = none)]
        pub fn cancelsTouchesInView(&self) -> bool;

        /// Setter for [`cancelsTouchesInView`][Self::cancelsTouchesInView].
        #[unsafe(method(setCancelsTouchesInView:))]
        #[unsafe(method_family = none)]
        pub fn setCancelsTouchesInView(&self, cancels_touches_in_view: bool);

        #[unsafe(method(delaysTouchesBegan))]
        #[unsafe(method_family = none)]
        pub fn delaysTouchesBegan(&self) -> bool;

        /// Setter for [`delaysTouchesBegan`][Self::delaysTouchesBegan].
        #[unsafe(method(setDelaysTouchesBegan:))]
        #[unsafe(method_family = none)]
        pub fn setDelaysTouchesBegan(&self, delays_touches_began: bool);

        #[unsafe(method(delaysTouchesEnded))]
        #[unsafe(method_family = none)]
        pub fn delaysTouchesEnded(&self) -> bool;

        /// Setter for [`delaysTouchesEnded`][Self::delaysTouchesEnded].
        #[unsafe(method(setDelaysTouchesEnded:))]
        #[unsafe(method_family = none)]
        pub fn setDelaysTouchesEnded(&self, delays_touches_ended: bool);

        #[unsafe(method(allowedTouchTypes))]
        #[unsafe(method_family = none)]
        pub fn allowedTouchTypes(&self) -> Retained<NSArray<NSNumber>>;

        /// Setter for [`allowedTouchTypes`][Self::allowedTouchTypes].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setAllowedTouchTypes:))]
        #[unsafe(method_family = none)]
        pub fn setAllowedTouchTypes(&self, allowed_touch_types: &NSArray<NSNumber>);

        #[unsafe(method(allowedPressTypes))]
        #[unsafe(method_family = none)]
        pub fn allowedPressTypes(&self) -> Retained<NSArray<NSNumber>>;

        /// Setter for [`allowedPressTypes`][Self::allowedPressTypes].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setAllowedPressTypes:))]
        #[unsafe(method_family = none)]
        pub fn setAllowedPressTypes(&self, allowed_press_types: &NSArray<NSNumber>);

        #[unsafe(method(requiresExclusiveTouchType))]
        #[unsafe(method_family = none)]
        pub fn requiresExclusiveTouchType(&self) -> bool;

        /// Setter for [`requiresExclusiveTouchType`][Self::requiresExclusiveTouchType].
        #[unsafe(method(setRequiresExclusiveTouchType:))]
        #[unsafe(method_family = none)]
        pub fn setRequiresExclusiveTouchType(&self, requires_exclusive_touch_type: bool);

        #[unsafe(method(requireGestureRecognizerToFail:))]
        #[unsafe(method_family = none)]
        pub fn requireGestureRecognizerToFail(
            &self,
            other_gesture_recognizer: &UIGestureRecognizer,
        );

        #[cfg(all(
            feature = "UIResponder",
            feature = "UIView",
            feature = "objc2-core-foundation"
        ))]
        #[unsafe(method(locationInView:))]
        #[unsafe(method_family = none)]
        pub fn locationInView(&self, view: Option<&UIView>) -> CGPoint;

        #[unsafe(method(numberOfTouches))]
        #[unsafe(method_family = none)]
        pub fn numberOfTouches(&self) -> NSUInteger;

        #[cfg(all(
            feature = "UIResponder",
            feature = "UIView",
            feature = "objc2-core-foundation"
        ))]
        #[unsafe(method(locationOfTouch:inView:))]
        #[unsafe(method_family = none)]
        pub fn locationOfTouch_inView(
            &self,
            touch_index: NSUInteger,
            view: Option<&UIView>,
        ) -> CGPoint;

        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        pub fn name(&self) -> Option<Retained<NSString>>;

        /// Setter for [`name`][Self::name].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setName:))]
        #[unsafe(method_family = none)]
        pub fn setName(&self, name: Option<&NSString>);

        #[cfg(feature = "UICommand")]
        #[unsafe(method(modifierFlags))]
        #[unsafe(method_family = none)]
        pub fn modifierFlags(&self) -> UIKeyModifierFlags;

        #[cfg(feature = "UIEvent")]
        #[unsafe(method(buttonMask))]
        #[unsafe(method_family = none)]
        pub fn buttonMask(&self) -> UIEventButtonMask;
    );
}

/// Methods declared on superclass `NSObject`.
impl UIGestureRecognizer {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
    );
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/uikit/uigesturerecognizerdelegate?language=objc)
    pub unsafe trait UIGestureRecognizerDelegate: NSObjectProtocol + MainThreadOnly {
        #[optional]
        #[unsafe(method(gestureRecognizerShouldBegin:))]
        #[unsafe(method_family = none)]
        fn gestureRecognizerShouldBegin(&self, gesture_recognizer: &UIGestureRecognizer) -> bool;

        #[optional]
        #[unsafe(method(gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:))]
        #[unsafe(method_family = none)]
        fn gestureRecognizer_shouldRecognizeSimultaneouslyWithGestureRecognizer(
            &self,
            gesture_recognizer: &UIGestureRecognizer,
            other_gesture_recognizer: &UIGestureRecognizer,
        ) -> bool;

        #[optional]
        #[unsafe(method(gestureRecognizer:shouldRequireFailureOfGestureRecognizer:))]
        #[unsafe(method_family = none)]
        fn gestureRecognizer_shouldRequireFailureOfGestureRecognizer(
            &self,
            gesture_recognizer: &UIGestureRecognizer,
            other_gesture_recognizer: &UIGestureRecognizer,
        ) -> bool;

        #[optional]
        #[unsafe(method(gestureRecognizer:shouldBeRequiredToFailByGestureRecognizer:))]
        #[unsafe(method_family = none)]
        fn gestureRecognizer_shouldBeRequiredToFailByGestureRecognizer(
            &self,
            gesture_recognizer: &UIGestureRecognizer,
            other_gesture_recognizer: &UIGestureRecognizer,
        ) -> bool;

        #[cfg(feature = "UITouch")]
        #[optional]
        #[unsafe(method(gestureRecognizer:shouldReceiveTouch:))]
        #[unsafe(method_family = none)]
        fn gestureRecognizer_shouldReceiveTouch(
            &self,
            gesture_recognizer: &UIGestureRecognizer,
            touch: &UITouch,
        ) -> bool;

        #[cfg(feature = "UIPress")]
        #[optional]
        #[unsafe(method(gestureRecognizer:shouldReceivePress:))]
        #[unsafe(method_family = none)]
        fn gestureRecognizer_shouldReceivePress(
            &self,
            gesture_recognizer: &UIGestureRecognizer,
            press: &UIPress,
        ) -> bool;

        #[cfg(feature = "UIEvent")]
        #[optional]
        #[unsafe(method(gestureRecognizer:shouldReceiveEvent:))]
        #[unsafe(method_family = none)]
        fn gestureRecognizer_shouldReceiveEvent(
            &self,
            gesture_recognizer: &UIGestureRecognizer,
            event: &UIEvent,
        ) -> bool;
    }
);