rust_macios/appkit/
ns_button.rs

1use objc::{msg_send, sel, sel_impl};
2
3use crate::{foundation::NSString, objective_c_runtime::traits::FromId};
4pub(crate) use crate::{object, objective_c_runtime::macros::interface_impl};
5
6use super::{INSControl, INSResponder, INSView, NSImage};
7
8object! {
9    /// A control that defines an area on the screen that a user clicks to trigger an action.
10    unsafe pub struct NSButton;
11}
12
13impl INSResponder for NSButton {}
14
15impl INSView for NSButton {}
16
17impl INSControl for NSButton {}
18
19#[interface_impl(NSControl)]
20impl NSButton {
21    /* Configuring Buttons
22     */
23
24    /// The title displayed on the button when it’s in an off state.
25    #[property]
26    pub fn title(&self) -> NSString {
27        unsafe { msg_send![self.m_self(), title] }
28    }
29
30    /// Sets the title displayed on the button when it’s in an off state.
31    #[property]
32    pub fn set_title(&self, title: NSString) {
33        unsafe { msg_send![self.m_self(), setTitle: title] }
34    }
35
36    /* Configuring Button Images
37     */
38
39    /// The image that appears on the button when it’s in an off state, or nil if there is no such image.
40    #[property]
41    pub fn image(&self) -> NSImage {
42        unsafe { NSImage::from_id(msg_send![self.m_self(), image]) }
43    }
44
45    /// Sets the image that appears on the button when it’s in an off state, or nil if there is no such image.
46    ///
47    /// # Arguments
48    ///
49    /// * `image` - The new image.
50    #[property]
51    pub fn set_image(&self, image: NSImage) {
52        unsafe { msg_send![self.m_self(), setImage: image] }
53    }
54}