1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::foundation::{NSInteger, NSUInteger};

/// Specifies how text should align for a supported control.
#[derive(Copy, Clone, Debug)]
pub enum TextAlign {
    /// Align text to the left.
    Left,

    /// Align text to the right.
    Right,

    /// Center-align text.
    Center,

    /// Justify text.
    Justified,

    /// Natural.
    Natural
}

impl From<TextAlign> for NSInteger {
    fn from(alignment: TextAlign) -> Self {
        match alignment {
            TextAlign::Left => 0,
            TextAlign::Center => 1,
            TextAlign::Right => 2,
            TextAlign::Justified => 3,
            TextAlign::Natural => 4
        }
    }
}

/// Instructs text controls how to optimize line breaks.
#[derive(Copy, Clone, Debug)]
pub enum LineBreakMode {
    /// Wrap at word boundaries (the default)
    WrapWords,

    /// Wrap at character boundaries
    WrapChars,

    /// Clip with no regard
    Clip,

    /// Truncate the start, e.g, ...my sentence
    TruncateHead,

    /// Truncate the end, e.g, my sentenc...
    TruncateTail,

    /// Truncate the middle, e.g, my se...ce
    TruncateMiddle
}

impl Into<NSUInteger> for LineBreakMode {
    fn into(self) -> NSUInteger {
        match self {
            LineBreakMode::WrapWords => 0,
            LineBreakMode::WrapChars => 1,
            LineBreakMode::Clip => 2,
            LineBreakMode::TruncateHead => 3,
            LineBreakMode::TruncateTail => 4,
            LineBreakMode::TruncateMiddle => 5
        }
    }
}