notcurses/visual/
scale.rs

1// notcurses::visual::scale
2//
3//!
4//
5
6/// Indicates how to scale a [`Visual`][super::Visual] during rendering.
7#[derive(Clone, Copy, PartialEq, Eq)]
8pub enum Scale {
9    /// Maintains the original size. Will Apply no scaling.
10    ///
11    /// This is the default.
12    None,
13
14    /// Maintains the aspect ratio.
15    ///
16    /// Scales a `Visual` to the `Plane`'s size without stretching.
17    Scale,
18
19    /// Like `None`, maintains the original size, while admitting
20    /// high-resolution blitters that don't preserve the aspect ratio.
21    NoneHiRes,
22
23    /// Like `Scale`, maintains the aspect ratio, while admitting
24    /// high-resolution blitters that don't preserve the aspect ratio.
25    ScaleHiRes,
26
27    /// Throws away aspect ratio.
28    ///
29    /// Stretches and scales the `Visual` in an attempt to fill the entirety
30    /// of the `Plane`.
31    Stretch,
32}
33
34mod core_impls {
35    use super::Scale;
36    use crate::sys::{c_api::NcScale_u32, NcScale};
37    use core::fmt;
38
39    impl Default for Scale {
40        fn default() -> Self {
41            Self::None
42        }
43    }
44
45    impl fmt::Display for Scale {
46        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47            write!(
48                f,
49                "{}",
50                match self {
51                    Scale::None => "None",
52                    Scale::Scale => "Scale",
53                    Scale::NoneHiRes => "NoneHiRes",
54                    Scale::ScaleHiRes => "ScaleHiRes",
55                    Scale::Stretch => "Stretch",
56                }
57            )
58        }
59    }
60
61    impl fmt::Debug for Scale {
62        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63            write!(f, "Scale {{ {} }}", self)
64        }
65    }
66
67    //
68
69    impl From<NcScale> for Scale {
70        fn from(nc: NcScale) -> Scale {
71            match nc {
72                NcScale::None => Scale::None,
73                NcScale::Scale => Scale::Scale,
74                NcScale::NoneHiRes => Scale::NoneHiRes,
75                NcScale::ScaleHiRes => Scale::ScaleHiRes,
76                NcScale::Stretch => Scale::Stretch,
77                _ => Self::default(),
78            }
79        }
80    }
81    impl From<Scale> for NcScale {
82        fn from(scale: Scale) -> NcScale {
83            match scale {
84                Scale::None => NcScale::None,
85                Scale::Scale => NcScale::Scale,
86                Scale::NoneHiRes => NcScale::NoneHiRes,
87                Scale::ScaleHiRes => NcScale::ScaleHiRes,
88                Scale::Stretch => NcScale::Stretch,
89            }
90        }
91    }
92
93    impl From<NcScale_u32> for Scale {
94        fn from(ncu: NcScale_u32) -> Scale {
95            NcScale::from(ncu).into()
96        }
97    }
98    impl From<Scale> for NcScale_u32 {
99        fn from(scale: Scale) -> NcScale_u32 {
100            NcScale::from(scale).into()
101        }
102    }
103}