1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use std::ops::{Deref, DerefMut};

use nbt_lib::datatypes::TextComponent;

use crate::datatypes::Mask;

use super::Display;

/// An enum of the different attributes that an text display can have
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum TextDisplayMaskData {
    /// Whether it has a shadow or not
    HasShadow = 0x01,
    /// Whether it is see through or not
    IsSeeThrough = 0x02,
    /// Whether to use the default background color or not
    UseDefaultBackgroundColor = 0x04,
    /// Aligned centered
    AlignCenter = 0x08,
    /// Aligned left
    AlignLeft = 0x08 + 0x01, // or + 0x03,
    /// Aligned right
    AlignRight = 0x08 + 0x02,
}
impl Into<u8> for TextDisplayMaskData {
    fn into(self) -> u8 {
        self as u8
    }
}
/// An instance of a text display
pub struct TextDisplay {
    display: Display,
    /// The text of the display
    pub text: TextComponent,
    /// the line width
    pub line_width: i32,
    /// The background color
    ///
    /// # Note
    ///
    /// The color is decoded as RGB / ARGB
    /// where:
    /// - B: & 0xFF
    /// - G: & 0xFF00 >> 8
    /// - R: & 0xFF0000 >> 16
    /// - A: & 0xFF000000 >> 24
    pub background_color: i32,
    /// the text opacity ranging from 0 to 255
    pub text_opacity: i8,
    /// The mask of all text display options
    pub options: Mask<TextDisplayMaskData>,
}
impl Deref for TextDisplay {
    type Target = Display;

    fn deref(&self) -> &Self::Target {
        &self.display
    }
}
impl DerefMut for TextDisplay {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.display
    }
}
impl Default for TextDisplay {
    fn default() -> Self {
        Self {
            display: Display::default(),
            text: TextComponent::from("".to_string()),
            line_width: 200,
            background_color: 0x40000000,
            text_opacity: -1,
            options: Mask::default()
        }
    }
}