rust_macios/appkit/
ns_control.rs

1use objc::{msg_send, runtime::Sel, sel, sel_impl};
2
3use crate::{appkit::INSView, object};
4
5use super::{interface_impl, INSResponder};
6
7object! {
8    /// A specialized view, such as a button or text field, that notifies your app of relevant events using the target-action design pattern.
9    unsafe pub struct NSControl;
10}
11
12impl INSResponder for NSControl {}
13
14impl INSView for NSControl {}
15
16#[interface_impl(NSView)]
17impl NSControl {
18    /*  Implementing the Target-Action Mechanism */
19
20    /// The default action-message selector associated with the control.
21    #[property]
22    pub fn action(&self) -> Sel {
23        unsafe { msg_send![self.m_self(), action] }
24    }
25
26    /// Sets the default action-message selector associated with the control.
27    ///
28    /// # Arguments
29    ///
30    /// * `action` - The new action-message selector.
31    #[property]
32    pub fn set_action(&self, action: Sel) {
33        unsafe { msg_send![self.m_self(), setAction: action] }
34    }
35}