123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- use config::Config;
- use super::super::sensors;
- use super::super::sensors::Sensor;
- use ui::widget;
- const MARGIN: u16 = 7;
- pub struct Sensors {
- context: widget::DrawContext,
- sensors: Vec<Box<Sensor>>
- }
- impl Sensors {
- pub fn new(context: widget::DrawContext, config: &Config) -> Sensors {
- Sensors {
- context: context,
- sensors: sensors::sensor_list(config)
- }
- }
- }
- impl widget::Widget for Sensors {
- fn render(&mut self, x: u16) {
- let mut offset = x;
- for ref sensor in self.sensors.iter() {
- let icon_width = self.context.measure_text(&sensor.icon());
- let status_width = self.context.measure_text(&sensor.status());
- self.context.set_bg_color(0x6666, 0x6666, 0x6666, 0xFFFF);
- self.context.draw_bg(offset, icon_width + MARGIN * 2);
- self.context.draw_text(&sensor.icon(), offset + MARGIN);
- offset += icon_width + MARGIN * 2;
- self.context.set_bg_color(0x0, 0x0, 0x0, 0xFFFF);
- self.context.draw_text(&sensor.status(), offset + MARGIN);
- offset += status_width + MARGIN * 2;
- }
- }
- fn width(&mut self) -> u16 {
- let mut sum = 0;
- for ref sensor in self.sensors.iter() {
- let text = format!("{}{}", sensor.icon(), sensor.status());
- sum += self.context.measure_text(&text) + MARGIN * 4;
- }
- sum
- }
- fn handle_event(&mut self, event: &widget::Message) -> bool {
- match event {
- &widget::Message::Update =>
- for ref mut sensor in self.sensors.iter_mut() {
- sensor.process()
- },
- _ => {}
- }
- false
- }
- }
|