gooey/interface/controller/
alignment.rs1#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2pub struct Alignment {
3 pub horizontal : Horizontal,
4 pub vertical : Vertical
5}
6
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8pub enum Horizontal {
9 Left,
10 Center,
11 Right
12}
13
14#[derive(Clone, Copy, Debug, Eq, PartialEq)]
15pub enum Vertical {
16 Top,
17 Middle,
18 Bottom
19}
20
21impl Alignment {
22 #[inline]
24 pub const fn tile() -> Self {
25 Alignment {
26 horizontal: Horizontal::Left,
27 vertical: Vertical::Top
28 }
29 }
30 #[inline]
32 pub const fn pixel() -> Self {
33 Alignment {
34 horizontal: Horizontal::Left,
35 vertical: Vertical::Bottom
36 }
37 }
38 #[inline]
40 pub const fn middle_center() -> Self {
41 Alignment {
42 horizontal: Horizontal::Center,
43 vertical: Vertical::Middle
44 }
45 }
46
47 #[inline]
48 pub const fn new (horizontal : Horizontal, vertical : Vertical) -> Self {
49 Alignment { horizontal, vertical }
50 }
51}
52
53impl Default for Alignment {
54 fn default() -> Self {
55 Self::tile()
56 }
57}
58
59impl Horizontal {
60 #[inline]
61 pub fn right_sign (&self) -> i32 {
62 match self {
63 Horizontal::Left | Horizontal::Center => 1,
64 Horizontal::Right => -1
65 }
66 }
67 #[inline]
68 pub fn left_sign (&self) -> i32 {
69 match self {
70 Horizontal::Left | Horizontal::Center => -1,
71 Horizontal::Right => 1
72 }
73 }
74}
75impl Vertical {
76 #[inline]
77 pub fn up_sign (&self) -> i32 {
78 match self {
79 Vertical::Bottom | Vertical::Middle => 1,
80 Vertical::Top => -1
81 }
82 }
83 #[inline]
84 pub fn down_sign (&self) -> i32 {
85 match self {
86 Vertical::Bottom | Vertical::Middle => -1,
87 Vertical::Top => 1
88 }
89 }
90}