layer_shika_domain/value_objects/
anchor.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub struct AnchorEdges(u8);
15
16impl AnchorEdges {
17 const TOP: u8 = 1 << 0;
18 const BOTTOM: u8 = 1 << 1;
19 const LEFT: u8 = 1 << 2;
20 const RIGHT: u8 = 1 << 3;
21
22 #[must_use]
23 pub const fn new(bits: u8) -> Self {
24 Self(bits)
25 }
26
27 #[must_use]
28 pub const fn empty() -> Self {
29 Self(0)
30 }
31
32 #[must_use]
33 pub const fn all() -> Self {
34 Self(Self::TOP | Self::BOTTOM | Self::LEFT | Self::RIGHT)
35 }
36
37 #[must_use]
38 pub const fn top_bar() -> Self {
39 Self(Self::TOP | Self::LEFT | Self::RIGHT)
40 }
41
42 #[must_use]
43 pub const fn bottom_bar() -> Self {
44 Self(Self::BOTTOM | Self::LEFT | Self::RIGHT)
45 }
46
47 #[must_use]
48 pub const fn left_bar() -> Self {
49 Self(Self::LEFT | Self::TOP | Self::BOTTOM)
50 }
51
52 #[must_use]
53 pub const fn right_bar() -> Self {
54 Self(Self::RIGHT | Self::TOP | Self::BOTTOM)
55 }
56
57 #[must_use]
58 pub const fn with_top(mut self) -> Self {
59 self.0 |= Self::TOP;
60 self
61 }
62
63 #[must_use]
64 pub const fn with_bottom(mut self) -> Self {
65 self.0 |= Self::BOTTOM;
66 self
67 }
68
69 #[must_use]
70 pub const fn with_left(mut self) -> Self {
71 self.0 |= Self::LEFT;
72 self
73 }
74
75 #[must_use]
76 pub const fn with_right(mut self) -> Self {
77 self.0 |= Self::RIGHT;
78 self
79 }
80
81 #[must_use]
82 pub const fn has_top(&self) -> bool {
83 self.0 & Self::TOP != 0
84 }
85
86 #[must_use]
87 pub const fn has_bottom(&self) -> bool {
88 self.0 & Self::BOTTOM != 0
89 }
90
91 #[must_use]
92 pub const fn has_left(&self) -> bool {
93 self.0 & Self::LEFT != 0
94 }
95
96 #[must_use]
97 pub const fn has_right(&self) -> bool {
98 self.0 & Self::RIGHT != 0
99 }
100}
101
102impl Default for AnchorEdges {
103 fn default() -> Self {
104 Self::top_bar()
105 }
106}
107
108#[derive(Debug, Clone, Copy, PartialEq, Eq)]
109pub enum Anchor {
110 Top,
111 Bottom,
112 Left,
113 Right,
114}