1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use objc::{msg_send, sel, sel_impl};
use crate::{
core_graphics::CGFloat,
object,
objective_c_runtime::{
nil,
traits::{FromId, PNSObject},
},
utils::to_bool,
};
use super::{interface_impl, NSMenu, NSStatusBar, NSStatusBarButton, NSStatusItemBehavior};
object! {
/// An individual element displayed in the system menu bar.
unsafe pub struct NSStatusItem;
}
impl NSStatusItem {
/// A status item length that is equal to the status bar’s thickness.
pub const NSSQUARE_STATUS_ITEM_LENGTH: CGFloat = -2.0;
/// A status item length that dynamically adjusts to the width of its contents.
pub const NSVARIABLE_STATUS_ITEM_LENGTH: CGFloat = -1.0;
/// Creates a new status item.
pub fn new() -> Self {
unsafe { Self::from_id(msg_send![NSStatusItem::m_class(), alloc]) }
}
}
impl Default for NSStatusItem {
fn default() -> Self {
Self::new()
}
}
#[interface_impl(NSObject)]
impl NSStatusItem {
/* Getting the Item’s Status Bar
*/
/// The status bar that displays the status item.
#[property]
pub fn status_bar(&self) -> NSStatusBar {
unsafe { NSStatusBar::from_id(msg_send![self.m_self(), statusBar]) }
}
/* Managing the Status Item’s Behavior
*/
/// The set of allowed behaviors for the status item.
#[property]
pub fn behavior(&self) -> NSStatusItemBehavior {
unsafe { msg_send![self.m_self(), behavior] }
}
/// The button displayed in the status bar.
#[property]
pub fn button(&self) -> Option<NSStatusBarButton> {
unsafe {
let id = msg_send![self.m_self(), button];
if id == nil {
None
} else {
Some(NSStatusBarButton::from_id(id))
}
}
}
/// The pull-down menu displayed when the user clicks the status item.
#[property]
pub fn menu(&self) -> NSMenu {
unsafe { NSMenu::from_id(msg_send![self.m_self(), menu]) }
}
/* Configuring the Status Item’s Appearance
*/
/// A Boolean value indicating if the menu bar currently displays the status item.
#[property]
pub fn visible(&self) -> bool {
unsafe { to_bool(msg_send![self.m_self(), isVisible]) }
}
/// The amount of space in the status bar that should be allocated to the status item.
#[property]
pub fn length(&self) -> CGFloat {
unsafe { msg_send![self.m_self(), length] }
}
}