Skip to main content

polyhorn_ios_sys/polykit/
text_input_view.rs

1use objc::runtime::*;
2use objc::*;
3
4use super::PLYView;
5use crate::foundation::NSAttributedString;
6use crate::Raw;
7
8/// An object that displays an editable text area in your interface.
9pub struct PLYTextInputView {
10    pub(super) object: *mut Object,
11}
12
13impl PLYTextInputView {
14    /// Initializes a newly allocated text input view.
15    pub fn new() -> PLYTextInputView {
16        unsafe {
17            let mut object: *mut Object = msg_send![class!(PLYTextInputView), alloc];
18            object = msg_send![object, init];
19            PLYTextInputView { object }
20        }
21    }
22
23    /// Sets the styled string that displays when there is no other text in the
24    /// text field.
25    pub fn set_attributed_placeholder(&mut self, placeholder: &NSAttributedString) {
26        unsafe {
27            let _: () = msg_send![self.object, setAttributedPlaceholder: placeholder.as_raw()];
28        }
29    }
30
31    /// Upcasts this text input view to a UIView.
32    pub fn to_view(&self) -> PLYView {
33        unsafe { PLYView::from_raw_retain(self.object) }
34    }
35}
36
37impl Raw for PLYTextInputView {
38    unsafe fn from_raw(object: *mut Object) -> Self {
39        PLYTextInputView { object }
40    }
41
42    unsafe fn as_raw(&self) -> *mut Object {
43        self.object
44    }
45}
46
47impl Clone for PLYTextInputView {
48    fn clone(&self) -> Self {
49        unsafe { Self::from_raw_retain(self.as_raw()) }
50    }
51}
52
53impl Drop for PLYTextInputView {
54    fn drop(&mut self) {
55        unsafe { objc_release(self.object) }
56    }
57}