objc2_ui_kit/
text.rs

1use objc2::encode::{Encode, Encoding, RefEncode};
2use objc2::ffi::NSInteger;
3
4/// (!TARGET_CPU_X86_64 || (TARGET_OS_IPHONE && !TARGET_OS_MACCATALYST))
5///
6/// <https://github.com/xamarin/xamarin-macios/issues/12111>
7// TODO: Make this work with mac catalyst
8const TARGET_ABI_USES_IOS_VALUES: bool =
9    !cfg!(any(target_arch = "x86", target_arch = "x86_64")) || cfg!(not(target_os = "macos"));
10
11// NS_ENUM
12#[repr(transparent)]
13#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
14pub struct NSTextAlignment(pub NSInteger);
15
16unsafe impl Encode for NSTextAlignment {
17    const ENCODING: Encoding = NSInteger::ENCODING;
18}
19
20unsafe impl RefEncode for NSTextAlignment {
21    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
22}
23
24#[allow(non_upper_case_globals)]
25#[allow(clippy::bool_to_int_with_if)]
26impl NSTextAlignment {
27    #[doc(alias = "NSTextAlignmentLeft")]
28    pub const Left: Self = Self(0);
29    #[doc(alias = "NSTextAlignmentRight")]
30    pub const Right: Self = Self(if TARGET_ABI_USES_IOS_VALUES { 2 } else { 1 });
31    #[doc(alias = "NSTextAlignmentCenter")]
32    pub const Center: Self = Self(if TARGET_ABI_USES_IOS_VALUES { 1 } else { 2 });
33    #[doc(alias = "NSTextAlignmentJustified")]
34    pub const Justified: Self = Self(3);
35    #[doc(alias = "NSTextAlignmentNatural")]
36    pub const Natural: Self = Self(4);
37}