diff --git a/logicworld-subassembly/src/lw.rs b/logicworld-subassembly/src/lw.rs index 4a3fb17..2148cf3 100644 --- a/logicworld-subassembly/src/lw.rs +++ b/logicworld-subassembly/src/lw.rs @@ -145,6 +145,85 @@ impl CircuitBoard { return custom_data; } } +pub struct Label<'a> { + text: &'a str, + color: Vec, + size: Float, + mono: bool, + width: Int, + height: Int, + horizontal_align: HorizontalAlign, + vertical_align: VerticalAlign, +} +#[repr(i32)] +#[derive(Copy, Clone)] +pub enum HorizontalAlign { + Left = 0, + Middle = 1, + Right = 2, +} +#[repr(i32)] +#[derive(Copy, Clone)] +pub enum VerticalAlign { + Top = 0, + Middle = 1, + Bottom = 2, +} +impl<'a> Label<'a> { + pub fn new(text: &'a str) -> Self { + Self { + text, + color: vec![51, 51, 51], + size: 0.8, + mono: false, + width: 1, + height: 1, + horizontal_align: HorizontalAlign::Middle, + vertical_align: VerticalAlign::Middle, + } + } + pub fn mono(&mut self) -> &mut Self { + self.mono = true; + return self; + } + pub fn with_color(&mut self, r: u8, g: u8, b: u8) -> &mut Self { + self.color[0] = r; + self.color[1] = g; + self.color[2] = b; + return self; + } + pub fn with_size(&mut self, size: Float) -> &mut Self { + self.size = size; + return self; + } + pub fn with_dimensions(&mut self, width: Int, height: Int) -> &mut Self { + self.width = width; + self.height = height; + return self; + } + pub fn with_align( + &mut self, + horizontal: HorizontalAlign, + vertical: VerticalAlign, + ) -> &mut Self { + self.horizontal_align = horizontal; + self.vertical_align = vertical; + return self; + } + pub fn custom_data(&self) -> Vec { + let mut custom_data = Vec::with_capacity(33); + custom_data.extend(&(self.horizontal_align as Int).to_le_bytes()); + custom_data.extend(&self.color); + custom_data.extend(&self.size.to_le_bytes()); + custom_data.extend(&[self.mono as u8]); + custom_data.extend(&(self.text.len() as Int).to_le_bytes()); + custom_data.extend(self.text.as_bytes()); + custom_data.extend(&self.width.to_le_bytes()); + custom_data.extend(&self.height.to_le_bytes()); + custom_data.extend(&(self.vertical_align as Int).to_le_bytes()); + return custom_data; + } +} impl BinarySerializable for Vec { fn write_to(&self, writer: &mut W) -> io::Result<()> {