X-Git-Url: http://git.code-monkey.de/?p=gps-watch.git;a=blobdiff_plain;f=src%2Fapplication%2Fviews.rs;fp=src%2Fapplication%2Fviews.rs;h=1218532a6b4427e6c16506b3fe9e14eecd388d46;hp=0000000000000000000000000000000000000000;hb=683135c35c05cd547f8a77b3602c2ddc78c1e887;hpb=70fb2fadd8688fdc11ba1d398661ac99aaa1b02a diff --git a/src/application/views.rs b/src/application/views.rs new file mode 100644 index 0000000..1218532 --- /dev/null +++ b/src/application/views.rs @@ -0,0 +1,97 @@ +/* + * 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 + } +}