1use crate::models::Model;
4
5mod orientation;
6pub(crate) use orientation::MemoryMapping;
7pub use orientation::{InvalidAngleError, Orientation, Rotation};
8
9#[derive(Clone)]
12#[non_exhaustive]
13pub struct ModelOptions {
14 pub color_order: ColorOrder,
16 pub orientation: Orientation,
18 pub invert_colors: ColorInversion,
20 pub refresh_order: RefreshOrder,
22 pub display_size: (u16, u16),
24 pub display_offset: (u16, u16),
26}
27
28impl ModelOptions {
29 pub fn full_size<M: Model>() -> Self {
31 Self {
32 color_order: ColorOrder::default(),
33 orientation: Orientation::default(),
34 invert_colors: ColorInversion::default(),
35 refresh_order: RefreshOrder::default(),
36 display_size: M::FRAMEBUFFER_SIZE,
37 display_offset: (0, 0),
38 }
39 }
40
41 pub fn with_all(display_size: (u16, u16), display_offset: (u16, u16)) -> Self {
43 Self {
44 color_order: ColorOrder::default(),
45 orientation: Orientation::default(),
46 invert_colors: ColorInversion::default(),
47 refresh_order: RefreshOrder::default(),
48 display_size,
49 display_offset,
50 }
51 }
52
53 #[allow(dead_code)]
57 pub(crate) fn display_size(&self) -> (u16, u16) {
58 if self.orientation.rotation.is_horizontal() {
59 self.display_size
60 } else {
61 (self.display_size.1, self.display_size.0)
62 }
63 }
64}
65
66#[derive(Copy, Clone, Debug, PartialEq, Eq)]
68pub enum ColorInversion {
69 Normal,
71 Inverted,
73}
74
75impl Default for ColorInversion {
76 fn default() -> Self {
77 Self::Normal
78 }
79}
80
81#[derive(Copy, Clone, Debug, PartialEq, Eq)]
83pub enum VerticalRefreshOrder {
84 TopToBottom,
86 BottomToTop,
88}
89
90impl Default for VerticalRefreshOrder {
91 fn default() -> Self {
92 Self::TopToBottom
93 }
94}
95
96impl VerticalRefreshOrder {
97 #[must_use]
99 pub const fn flip(self) -> Self {
100 match self {
101 Self::TopToBottom => Self::BottomToTop,
102 Self::BottomToTop => Self::TopToBottom,
103 }
104 }
105}
106
107#[derive(Copy, Clone, Debug, PartialEq, Eq)]
109pub enum HorizontalRefreshOrder {
110 LeftToRight,
112 RightToLeft,
114}
115
116impl Default for HorizontalRefreshOrder {
117 fn default() -> Self {
118 Self::LeftToRight
119 }
120}
121
122impl HorizontalRefreshOrder {
123 #[must_use]
125 pub const fn flip(self) -> Self {
126 match self {
127 Self::LeftToRight => Self::RightToLeft,
128 Self::RightToLeft => Self::LeftToRight,
129 }
130 }
131}
132
133#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
137pub struct RefreshOrder {
138 pub vertical: VerticalRefreshOrder,
140 pub horizontal: HorizontalRefreshOrder,
142}
143
144impl RefreshOrder {
145 pub const fn new(vertical: VerticalRefreshOrder, horizontal: HorizontalRefreshOrder) -> Self {
147 Self {
148 vertical,
149 horizontal,
150 }
151 }
152
153 #[must_use]
155 pub const fn flip_vertical(self) -> Self {
156 Self {
157 vertical: self.vertical.flip(),
158 ..self
159 }
160 }
161
162 #[must_use]
164 pub const fn flip_horizontal(self) -> Self {
165 Self {
166 horizontal: self.horizontal.flip(),
167 ..self
168 }
169 }
170}
171
172#[derive(Copy, Clone, Debug, PartialEq, Eq)]
174pub enum TearingEffect {
175 Off,
177 Vertical,
179 HorizontalAndVertical,
181}
182
183#[derive(Debug, Clone, Copy, PartialEq, Eq)]
185pub enum ColorOrder {
186 Rgb,
188 Bgr,
190}
191
192impl Default for ColorOrder {
193 fn default() -> Self {
194 Self::Rgb
195 }
196}