rust_macios/appkit/
ns_status_item.rs1use objc::{msg_send, sel, sel_impl};
2
3use crate::{
4 core_graphics::CGFloat,
5 object,
6 objective_c_runtime::{
7 nil,
8 traits::{FromId, PNSObject},
9 },
10 utils::to_bool,
11};
12
13use super::{interface_impl, NSMenu, NSStatusBar, NSStatusBarButton, NSStatusItemBehavior};
14
15object! {
16 unsafe pub struct NSStatusItem;
18}
19
20impl NSStatusItem {
21 pub const NSSQUARE_STATUS_ITEM_LENGTH: CGFloat = -2.0;
23
24 pub const NSVARIABLE_STATUS_ITEM_LENGTH: CGFloat = -1.0;
26
27 pub fn new() -> Self {
29 unsafe { Self::from_id(msg_send![NSStatusItem::m_class(), alloc]) }
30 }
31}
32
33impl Default for NSStatusItem {
34 fn default() -> Self {
35 Self::new()
36 }
37}
38
39#[interface_impl(NSObject)]
40impl NSStatusItem {
41 #[property]
46 pub fn status_bar(&self) -> NSStatusBar {
47 unsafe { NSStatusBar::from_id(msg_send![self.m_self(), statusBar]) }
48 }
49
50 #[property]
55 pub fn behavior(&self) -> NSStatusItemBehavior {
56 unsafe { msg_send![self.m_self(), behavior] }
57 }
58
59 #[property]
61 pub fn button(&self) -> Option<NSStatusBarButton> {
62 unsafe {
63 let id = msg_send![self.m_self(), button];
64 if id == nil {
65 None
66 } else {
67 Some(NSStatusBarButton::from_id(id))
68 }
69 }
70 }
71
72 #[property]
74 pub fn menu(&self) -> NSMenu {
75 unsafe { NSMenu::from_id(msg_send![self.m_self(), menu]) }
76 }
77
78 #[property]
83 pub fn visible(&self) -> bool {
84 unsafe { to_bool(msg_send![self.m_self(), isVisible]) }
85 }
86
87 #[property]
89 pub fn length(&self) -> CGFloat {
90 unsafe { msg_send![self.m_self(), length] }
91 }
92}