use core_graphics::base::CGFloat;
use objc::runtime::{Class, Object};
use objc::{class, msg_send, sel, sel_impl};
use objc_id::ShareId;
use crate::color::Color;
use crate::foundation::{id, nil, NSUInteger, NO, YES};
use crate::layout::Layout;
use crate::objc_access::ObjcAccess;
use crate::utils::properties::ObjcProperty;
#[cfg(feature = "autolayout")]
use crate::layout::{LayoutAnchorDimension, LayoutAnchorX, LayoutAnchorY};
mod enums;
pub use enums::ProgressIndicatorStyle;
#[derive(Debug)]
pub struct ProgressIndicator {
pub objc: ObjcProperty,
#[cfg(feature = "autolayout")]
pub top: LayoutAnchorY,
#[cfg(feature = "autolayout")]
pub leading: LayoutAnchorX,
#[cfg(feature = "autolayout")]
pub left: LayoutAnchorX,
#[cfg(feature = "autolayout")]
pub trailing: LayoutAnchorX,
#[cfg(feature = "autolayout")]
pub right: LayoutAnchorX,
#[cfg(feature = "autolayout")]
pub bottom: LayoutAnchorY,
#[cfg(feature = "autolayout")]
pub width: LayoutAnchorDimension,
#[cfg(feature = "autolayout")]
pub height: LayoutAnchorDimension,
#[cfg(feature = "autolayout")]
pub center_x: LayoutAnchorX,
#[cfg(feature = "autolayout")]
pub center_y: LayoutAnchorY
}
impl Default for ProgressIndicator {
fn default() -> Self {
ProgressIndicator::new()
}
}
impl ProgressIndicator {
pub fn new() -> Self {
let view = unsafe {
#[cfg(feature = "appkit")]
let view: id = msg_send![class!(NSProgressIndicator), new];
#[cfg(feature = "autolayout")]
let _: () = msg_send![view, setTranslatesAutoresizingMaskIntoConstraints: NO];
#[cfg(feature = "appkit")]
let _: () = msg_send![view, setWantsLayer: YES];
view
};
ProgressIndicator {
#[cfg(feature = "autolayout")]
top: LayoutAnchorY::top(view),
#[cfg(feature = "autolayout")]
left: LayoutAnchorX::left(view),
#[cfg(feature = "autolayout")]
leading: LayoutAnchorX::leading(view),
#[cfg(feature = "autolayout")]
right: LayoutAnchorX::right(view),
#[cfg(feature = "autolayout")]
trailing: LayoutAnchorX::trailing(view),
#[cfg(feature = "autolayout")]
bottom: LayoutAnchorY::bottom(view),
#[cfg(feature = "autolayout")]
width: LayoutAnchorDimension::width(view),
#[cfg(feature = "autolayout")]
height: LayoutAnchorDimension::height(view),
#[cfg(feature = "autolayout")]
center_x: LayoutAnchorX::center(view),
#[cfg(feature = "autolayout")]
center_y: LayoutAnchorY::center(view),
objc: ObjcProperty::retain(view)
}
}
}
impl ProgressIndicator {
pub fn start_animation(&self) {
self.objc.with_mut(|obj| unsafe {
let _: () = msg_send![obj, startAnimation: nil];
});
}
pub fn stop_animation(&self) {
self.objc.with_mut(|obj| unsafe {
let _: () = msg_send![obj, stopAnimation: nil];
});
}
pub fn increment(&self, amount: f64) {
self.objc.with_mut(|obj| unsafe {
let _: () = msg_send![obj, incrementBy: amount];
});
}
pub fn set_style(&self, style: ProgressIndicatorStyle) {
let style = style as NSUInteger;
self.objc.with_mut(move |obj| unsafe {
let _: () = msg_send![obj, setStyle: style];
});
}
pub fn set_indeterminate(&self, is_indeterminate: bool) {
self.objc.with_mut(|obj| unsafe {
let _: () = msg_send![obj, setIndeterminate:match is_indeterminate {
true => YES,
false => NO
}];
});
}
pub fn set_value(&self, value: f64) {
let value = value as CGFloat;
self.objc.with_mut(|obj| unsafe {
let _: () = msg_send![obj, setDoubleValue: value];
});
}
pub fn set_hidden(&self, hidden: bool) {
self.objc.with_mut(|obj| unsafe {
let _: () = msg_send![obj, setHidden:match hidden {
true => YES,
false => NO
}];
});
}
}
impl ObjcAccess for ProgressIndicator {
fn with_backing_obj_mut<F: Fn(id)>(&self, handler: F) {
self.objc.with_mut(handler);
}
fn get_from_backing_obj<F: Fn(&Object) -> R, R>(&self, handler: F) -> R {
self.objc.get(handler)
}
}
impl Layout for ProgressIndicator {}
impl Drop for ProgressIndicator {
fn drop(&mut self) {
}
}