Skip to main content

ferroui_base/media/immutable/
immutable_text_decoration.rs

1use crate::media::immutable::ImmutablePen;
2use crate::media::{TextDecorationLocation, TextDecorationUnit};
3
4/// An immutable representation of a text decoration.
5#[derive(Clone, Debug)]
6pub struct ImmutableTextDecoration {
7    location: TextDecorationLocation,
8    pen: ImmutablePen,
9    pen_thickness_unit: TextDecorationUnit,
10    pen_offset: f64,
11    pen_offset_unit: TextDecorationUnit,
12}
13
14impl ImmutableTextDecoration {
15    /// Creates a text decoration.
16    pub fn new(
17        location: TextDecorationLocation,
18        pen: ImmutablePen,
19        pen_thickness_unit: TextDecorationUnit,
20        pen_offset: f64,
21        pen_offset_unit: TextDecorationUnit,
22    ) -> ImmutableTextDecoration {
23        ImmutableTextDecoration { location, pen, pen_thickness_unit, pen_offset, pen_offset_unit }
24    }
25
26    /// Gets the location.
27    pub fn location(&self) -> TextDecorationLocation {
28        self.location
29    }
30
31    /// Gets the pen.
32    pub fn pen(&self) -> &ImmutablePen {
33        &self.pen
34    }
35
36    /// Gets the units in which the thickness of the pen is expressed.
37    pub fn pen_thickness_unit(&self) -> TextDecorationUnit {
38        self.pen_thickness_unit
39    }
40
41    /// Gets the pen offset.
42    pub fn pen_offset(&self) -> f64 {
43        self.pen_offset
44    }
45
46    /// Gets the units in which the pen offset is expressed.
47    pub fn pen_offset_unit(&self) -> TextDecorationUnit {
48        self.pen_offset_unit
49    }
50}
51
52// Not an upstream test: the class has none.
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn the_constructor_keeps_its_arguments() {
59        let decoration = ImmutableTextDecoration::new(
60            TextDecorationLocation::Strikethrough,
61            ImmutablePen::from_uint32(0xFF00_0000, 2.0),
62            TextDecorationUnit::FontRecommended,
63            3.0,
64            TextDecorationUnit::Pixel,
65        );
66
67        assert_eq!(TextDecorationLocation::Strikethrough, decoration.location());
68        assert_eq!(2.0, decoration.pen().thickness());
69        assert_eq!(TextDecorationUnit::FontRecommended, decoration.pen_thickness_unit());
70        assert_eq!(3.0, decoration.pen_offset());
71        assert_eq!(TextDecorationUnit::Pixel, decoration.pen_offset_unit());
72    }
73}