application: Store pace in the model and show it in its own view.
[gps-watch.git] / src / application / views.rs
index 1218532a6b4427e6c16506b3fe9e14eecd388d46..f29726f6c75b9af58e8b433ff2d38b38ab524d63 100644 (file)
@@ -95,3 +95,42 @@ impl DistanceView {
         true
     }
 }
+
+pub struct PaceView {
+    is_valid: bool,
+}
+
+impl PaceView {
+    pub fn new() -> PaceView {
+        PaceView {
+            is_valid: false,
+        }
+    }
+
+    pub fn invalidate(&mut self) {
+        self.is_valid = false;
+    }
+
+    pub fn draw(&mut self, screen: &mut screen::Screen,
+                model: &mut model::Model) -> bool {
+        if self.is_valid &&
+           !model.check_and_reset_is_dirty(model::Field::Pace(0)) {
+            return false;
+        }
+
+        let mut min_and_s = [b':'; 6];
+
+        common::fmt::fmt_u32_pad(&mut min_and_s[0..3], model.pace_s / 60,
+                                 3, b' ');
+
+        common::fmt::fmt_u32_pad(&mut min_and_s[4..6], model.pace_s % 60,
+                                 2, b'0');
+
+        screen.clear();
+        screen.draw_text(&min_and_s);
+
+        self.is_valid = true;
+
+        true
+    }
+}