Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394use crate::bar::{component::Value, module::Data};
#[derive(Debug)]pub struct BarComponent { pub measure: String, pub min: f32, pub max: f32, pub value: f32, pub width: f32, pub height: f32, pub border_width: f32, pub padding: f32, pub direction: Direction, pub full_colour: [u8; 4], pub empty_colour: [u8; 4], pub border_colour: [u8; 4], pub offset: f32, tick: u64,}
impl Default for BarComponent { fn default() -> Self { Self { measure: String::new(), min: 0.0, max: 100.0, value: f32::NAN, width: 8.0, height: 16.0, border_width: 1.0, padding: 1.0, direction: Direction::BottomToTop, full_colour: [255, 255, 255, 255], empty_colour: [0, 0, 0, 0], border_colour: [255, 255, 255, 255], offset: 0.0, tick: 0, } }}
impl BarComponent { pub fn new( measure: String, min: f32, max: f32, width: f32, height: f32, border_width: f32, padding: f32, direction: Direction, full_colour: [u8; 4], empty_colour: [u8; 4], border_colour: [u8; 4], offset: f32, ) -> Self { BarComponent { measure, min, max, value: f32::NAN, width, height, border_width, padding, direction, full_colour, empty_colour, border_colour, offset, tick: 0, } } pub fn needs_update(&self, data: &Data) -> bool { data.get_tick(&self.measure).unwrap() > self.tick }
pub fn update(&mut self, data: &Data) { match data.get_value(&self.measure) { Some(Value::Num(n)) => self.value = *n, _ => todo!(), } }}
#[derive(Clone, Copy, Debug)]#[repr(u8)]pub enum Direction { LeftToRight = 0, RightToLeft = 1, TopToBottom = 2, BottomToTop = 3,}