rust_macios/appkit/
ns_text_field.rs

1use objc::{msg_send, sel, sel_impl};
2
3use crate::{foundation::NSString, objective_c_runtime::traits::FromId, object};
4
5use super::{interface_impl,  INSControl, INSResponder, INSView};
6
7object! {
8    /// Text the user can select or edit to send an action message to a target when the user presses the Return key.
9    unsafe pub struct NSTextField;
10}
11
12impl INSResponder for NSTextField {}
13
14impl INSView for NSTextField {}
15
16impl INSControl for NSTextField {}
17
18#[interface_impl(NSControl)]
19impl NSTextField {
20    /* Creating Text Fields
21     */
22
23    /// Initializes a text field for use as a static label that uses the system default font, doesn’t wrap, and doesn’t have selectable text.
24    #[method]
25    pub fn label_with_string(string: NSString) -> Self
26    where
27        Self: Sized + FromId,
28    {
29        unsafe { Self::from_id(msg_send![Self::m_class(), labelWithString: string]) }
30    }
31
32    /// Initializes a single-line editable text field for user input using the system default font and standard visual appearance.
33    #[method]
34    pub fn text_field_with_string(string: NSString) -> Self
35    where
36        Self: Sized + FromId,
37    {
38        unsafe { Self::from_id(msg_send![Self::m_class(), textFieldWithString: string]) }
39    }
40
41    /// Initializes a text field for use as a multiline static label with selectable text that uses the system default font.
42    #[method]
43    pub fn text_view_with_string(string: NSString) -> Self
44    where
45        Self: Sized + FromId,
46    {
47        unsafe { Self::from_id(msg_send![Self::m_class(), textViewWithString: string]) }
48    }
49}