polyhorn_ios_sys/polykit/
label.rs1use objc::runtime::*;
2use objc::*;
3
4use super::PLYView;
5use crate::foundation::NSAttributedString;
6use crate::Raw;
7
8pub struct PLYLabel {
10 pub(super) object: *mut Object,
11}
12
13impl PLYLabel {
14 pub fn new() -> PLYLabel {
16 unsafe {
17 let mut object: *mut Object = msg_send![class!(PLYLabel), alloc];
18 object = msg_send![object, init];
19 PLYLabel { object }
20 }
21 }
22
23 pub fn set_attributed_text(&mut self, string: &NSAttributedString) {
25 unsafe {
26 let _: () = msg_send![self.object, setAttributedText: string.as_raw()];
27 }
28 }
29
30 pub fn to_view(&self) -> PLYView {
32 unsafe { PLYView::from_raw_retain(self.object) }
33 }
34}
35
36impl Raw for PLYLabel {
37 unsafe fn from_raw(object: *mut Object) -> Self {
38 PLYLabel { object }
39 }
40
41 unsafe fn as_raw(&self) -> *mut Object {
42 self.object
43 }
44}
45
46impl Clone for PLYLabel {
47 fn clone(&self) -> Self {
48 unsafe { Self::from_raw_retain(self.as_raw()) }
49 }
50}
51
52impl Drop for PLYLabel {
53 fn drop(&mut self) {
54 unsafe { objc_release(self.object) }
55 }
56}