--- /dev/null
+/*
+ * Copyright (c) 2020 Tilman Sauerbeck (tilman at code-monkey de)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+use common::time::Time;
+use common::screen;
+use model;
+
+pub struct TimeView {
+ is_valid: bool,
+}
+
+impl TimeView {
+ pub fn new() -> TimeView {
+ TimeView {
+ 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::UnixTime(0)) {
+ return false;
+ }
+
+ if let Some(tm) = Time::from_unix_time(model.unix_time) {
+ let mut time_s = [b' '; 8];
+ tm.fmt_time(&mut time_s);
+
+ screen.clear();
+ screen.draw_text(&time_s);
+ }
+
+ self.is_valid = true;
+
+ true
+ }
+}
+
+pub struct DistanceView {
+ is_valid: bool,
+}
+
+impl DistanceView {
+ pub fn new() -> DistanceView {
+ DistanceView {
+ 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::Distance(0)) {
+ return false;
+ }
+
+ let mut distance_m_s = [b' '; 8];
+
+ common::fmt::fmt_u32(&mut distance_m_s, model.distance_cm / 100);
+
+ screen.clear();
+ screen.draw_text(&distance_m_s);
+
+ self.is_valid = true;
+
+ true
+ }
+}