mini_oled/screen/properties.rs
1//! Properties of the display, such as dimensions and rotation.
2//!
3//! This struct is typically used internally by the `Sh1106` driver, but can be interacted with
4//! via methods like `set_rotation` on the driver or canvas.
5//!
6//! ```rust
7//! use mini_oled::screen::properties::{DisplayProperties, DisplayRotation};
8//!
9//! // DisplayProperties is used internally but can be default initialized.
10//! // The generic parameters are Width, Height, and Offset.
11//! let properties: DisplayProperties<128, 64, 2> = DisplayProperties::default();
12//!
13//! // DisplayRotation is used to configure the screen orientation.
14//! let rotation = DisplayRotation::Rotate90;
15//! ```
16
17/// Properties of the display, such as dimensions and rotation.
18///
19/// This struct is typically used internally by the `Sh1106` driver, but can be interacted with
20/// via methods like `set_rotation` on the driver or canvas.
21///
22/// ```rust
23/// use mini_oled::screen::properties::{DisplayProperties, DisplayRotation};
24///
25/// // DisplayProperties is used internally but can be default initialized.
26/// // The generic parameters are Width, Height, and Offset.
27/// let properties: DisplayProperties<128, 64, 2> = DisplayProperties::default();
28///
29/// // DisplayRotation is used to configure the screen orientation.
30/// let rotation = DisplayRotation::Rotate90;
31/// ```
32pub struct DisplayProperties<const W: u32, const H: u32, const O: u8> {
33 display_rotation: DisplayRotation,
34}
35
36impl<const W: u32, const H: u32, const O: u8> DisplayProperties<W, H, O> {
37 pub(crate) fn new(display_rotation: DisplayRotation) -> Self {
38 DisplayProperties { display_rotation }
39 }
40
41 pub(crate) fn set_rotation(&mut self, display_rotation: DisplayRotation) {
42 self.display_rotation = display_rotation;
43 }
44
45 pub(crate) fn get_column_offset(&self) -> u8 {
46 O
47 }
48
49 pub(crate) fn get_rotation(&self) -> &DisplayRotation {
50 &self.display_rotation
51 }
52
53 pub(crate) const fn get_display_size(&self) -> (u32, u32) {
54 (W, H)
55 }
56}
57
58impl<const W: u32, const H: u32, const O: u8> Default for DisplayProperties<W, H, O> {
59 fn default() -> Self {
60 Self {
61 display_rotation: DisplayRotation::Rotate0,
62 }
63 }
64}
65
66/// Display rotation configuration.
67///
68/// # Example
69///
70/// ```rust
71/// use mini_oled::screen::properties::DisplayRotation;
72///
73/// let rotation = DisplayRotation::Rotate90;
74/// ```
75#[derive(Clone, Copy)]
76pub enum DisplayRotation {
77 /// No rotation, normal display
78 Rotate0,
79 /// Rotate by 90 degress clockwise
80 Rotate90,
81 /// Rotate by 180 degress clockwise
82 Rotate180,
83 /// Rotate 270 degress clockwise
84 Rotate270,
85}