Skip to main content

cranpose_text/
decoration.rs

1use cranpose_ui_graphics::Color;
2
3/// A set of lines drawn on text: none, an underline, a line through, or both.
4/// Combine values with [`TextDecoration::combine`]. Compose's `TextDecoration`.
5#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
6pub struct TextDecoration(u32);
7
8impl TextDecoration {
9    /// No line is drawn.
10    pub const NONE: Self = Self(0);
11    /// A line drawn below the text.
12    pub const UNDERLINE: Self = Self(1);
13    /// A line drawn through the middle of the text.
14    pub const LINE_THROUGH: Self = Self(2);
15
16    /// Returns true when every line set in `other` is also set in this value.
17    pub fn contains(&self, other: Self) -> bool {
18        (self.0 | other.0) == self.0
19    }
20
21    /// Returns a decoration that draws the lines of both `self` and `other`.
22    pub fn combine(self, other: Self) -> Self {
23        Self(self.0 | other.0)
24    }
25}
26
27impl Default for TextDecoration {
28    fn default() -> Self {
29        Self::NONE
30    }
31}
32
33#[cfg(test)]
34#[path = "tests/decoration_tests.rs"]
35mod tests;
36
37/// A shadow drawn behind text. Compose's `Shadow`.
38#[derive(Clone, Copy, Debug, PartialEq)]
39pub struct Shadow {
40    /// Color of the shadow, including its alpha.
41    pub color: Color,
42    /// Offset of the shadow from the text, in logical pixels.
43    pub offset: cranpose_ui_graphics::Point,
44    /// Blur radius of the shadow, in logical pixels. Zero gives a hard-edged shadow.
45    pub blur_radius: f32,
46}
47
48impl Default for Shadow {
49    fn default() -> Self {
50        Self {
51            color: Color(0.0, 0.0, 0.0, 1.0),
52            offset: cranpose_ui_graphics::Point::new(0.0, 0.0),
53            blur_radius: 0.0,
54        }
55    }
56}