polyhorn_ios_sys/foundation/
paragraph_style.rs1use objc::runtime::*;
2use objc::*;
3
4use crate::Raw;
5
6#[repr(usize)]
8pub enum NSTextAlignment {
9 Left = 0,
11
12 #[cfg(target_os = "ios")]
13 Center = 1,
15
16 #[cfg(not(target_os = "ios"))]
17 Right = 1,
19
20 #[cfg(target_os = "ios")]
21 Right = 2,
23
24 #[cfg(not(target_os = "ios"))]
25 Center = 2,
27}
28
29pub struct NSParagraphStyle {
31 object: *mut Object,
32}
33
34pub struct NSMutableParagraphStyle {
37 object: *mut Object,
38}
39
40impl NSMutableParagraphStyle {
41 pub fn new() -> NSMutableParagraphStyle {
43 unsafe {
44 let mut object: *mut Object = msg_send![class!(NSMutableParagraphStyle), alloc];
45 object = msg_send![object, init];
46 NSMutableParagraphStyle { object }
47 }
48 }
49
50 pub fn set_alignment(&mut self, alignment: NSTextAlignment) {
52 unsafe {
53 let _: () = msg_send![self.object, setAlignment: alignment];
54 }
55 }
56}
57
58impl Raw for NSMutableParagraphStyle {
59 unsafe fn from_raw(object: *mut Object) -> Self {
60 NSMutableParagraphStyle { object }
61 }
62
63 unsafe fn as_raw(&self) -> *mut Object {
64 self.object
65 }
66}
67
68impl Drop for NSMutableParagraphStyle {
69 fn drop(&mut self) {
70 unsafe {
71 objc_release(self.object);
72 }
73 }
74}
75
76impl Into<NSParagraphStyle> for NSMutableParagraphStyle {
77 fn into(self) -> NSParagraphStyle {
78 unsafe { NSParagraphStyle::from_raw_retain(self.as_raw()) }
79 }
80}
81
82impl Raw for NSParagraphStyle {
83 unsafe fn from_raw(object: *mut Object) -> Self {
84 NSParagraphStyle { object }
85 }
86
87 unsafe fn as_raw(&self) -> *mut Object {
88 self.object
89 }
90}
91
92impl Clone for NSParagraphStyle {
93 fn clone(&self) -> Self {
94 unsafe { Self::from_raw_retain(self.as_raw()) }
95 }
96}
97
98impl Drop for NSParagraphStyle {
99 fn drop(&mut self) {
100 unsafe { objc_release(self.object) }
101 }
102}