objc2-class-kit 0.3.2

Bindings to the ClassKit 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::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// CLSActivity represents user generated activity data for a given context.
    ///
    /// CLSActivity has three major components.
    ///
    /// (1) Progress, used to measure the amount of activity a user generates as a percentage.
    /// (2) Duration, used to measure the length of time a user spent on this activity. Use
    /// `-start`and
    /// `-stop`methods.
    /// (3) Activity Items, used to gather information about the activity generated by a user.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/classkit/clsactivity?language=objc)
    #[unsafe(super(CLSObject, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "CLSObject")]
    pub struct CLSActivity;
);

#[cfg(feature = "CLSObject")]
extern_conformance!(
    unsafe impl NSCoding for CLSActivity {}
);

#[cfg(feature = "CLSObject")]
extern_conformance!(
    unsafe impl NSObjectProtocol for CLSActivity {}
);

#[cfg(feature = "CLSObject")]
extern_conformance!(
    unsafe impl NSSecureCoding for CLSActivity {}
);

#[cfg(feature = "CLSObject")]
impl CLSActivity {
    extern_methods!(
        /// Current progress as a decimal representation of a percentage.
        ///
        /// Should be [0.0, 1.0].
        #[unsafe(method(progress))]
        #[unsafe(method_family = none)]
        pub unsafe fn progress(&self) -> c_double;

        /// Setter for [`progress`][Self::progress].
        #[unsafe(method(setProgress:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setProgress(&self, progress: c_double);

        /// Returns the total time tracked in this activity (excluding any previous activities).
        ///
        /// The time between calling
        /// `-start`and
        /// `-stop.`
        #[unsafe(method(duration))]
        #[unsafe(method_family = none)]
        pub unsafe fn duration(&self) -> NSTimeInterval;

        #[cfg(feature = "CLSActivityItem")]
        /// The primary activityItem to be reported on.
        ///
        /// This can be nil indicating
        /// `progress`property is the primary data instead of any activityItems.
        #[unsafe(method(primaryActivityItem))]
        #[unsafe(method_family = none)]
        pub unsafe fn primaryActivityItem(&self) -> Option<Retained<CLSActivityItem>>;

        #[cfg(feature = "CLSActivityItem")]
        /// Setter for [`primaryActivityItem`][Self::primaryActivityItem].
        #[unsafe(method(setPrimaryActivityItem:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPrimaryActivityItem(
            &self,
            primary_activity_item: Option<&CLSActivityItem>,
        );

        /// Adds progress to this activity.
        ///
        /// The progress should be a decimal representation of the start and ending percentage [0.0, 1.0].
        ///
        /// Parameter `start`: Starting percentage.
        ///
        /// Parameter `end`: Ending percentage.
        #[unsafe(method(addProgressRangeFromStart:toEnd:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addProgressRangeFromStart_toEnd(&self, start: c_double, end: c_double);

        #[cfg(feature = "CLSActivityItem")]
        /// Add an activity item to this CLSActivity.
        #[unsafe(method(addAdditionalActivityItem:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addAdditionalActivityItem(&self, activity_item: &CLSActivityItem);

        #[cfg(feature = "CLSActivityItem")]
        /// Array of all additional activity items on this CLSActivity.
        #[unsafe(method(additionalActivityItems))]
        #[unsafe(method_family = none)]
        pub unsafe fn additionalActivityItems(&self) -> Retained<NSArray<CLSActivityItem>>;
    );
}

/// Methods declared on superclass `CLSObject`.
#[cfg(feature = "CLSObject")]
impl CLSActivity {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

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

/// Activation.
#[cfg(feature = "CLSObject")]
impl CLSActivity {
    extern_methods!(
        /// Returns whether this Activity has been started or not.
        #[unsafe(method(isStarted))]
        #[unsafe(method_family = none)]
        pub unsafe fn isStarted(&self) -> bool;

        /// Start Activity.
        ///
        /// Starts the activity (or resumes if previously stopped).
        #[unsafe(method(start))]
        #[unsafe(method_family = none)]
        pub unsafe fn start(&self);

        /// Stop Activity.
        ///
        /// Stops or pauses the activity and ends the time being tracked on it.
        #[unsafe(method(stop))]
        #[unsafe(method_family = none)]
        pub unsafe fn stop(&self);

        /// Deletes all activity items.
        ///
        /// Convenience method to delete all activity items associated with the current activity.
        #[unsafe(method(removeAllActivityItems))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeAllActivityItems(&self);
    );
}

/// Activity.
#[cfg(all(feature = "CLSContext", feature = "CLSObject"))]
impl CLSContext {
    extern_methods!(
        /// Returns the current activity.
        ///
        /// Activity associated with a context.  If no activity was ever created this is nil. See:
        /// `-[CLSContext`createNewActivity]; for more details.
        #[unsafe(method(currentActivity))]
        #[unsafe(method_family = none)]
        pub unsafe fn currentActivity(&self) -> Option<Retained<CLSActivity>>;

        /// Creates a new activity
        ///
        /// Creates a new activity and sets it as the current activity.
        #[unsafe(method(createNewActivity))]
        #[unsafe(method_family = none)]
        pub unsafe fn createNewActivity(&self) -> Retained<CLSActivity>;
    );
}