From c6f7d7f844f63fce33bd419d292d45ab8d803c86 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 2 Sep 2016 22:44:40 -0700 Subject: [PATCH] RecentEntriesView: Extract duplicate focus+selection style code. --- firmware/application/ais_app.cpp | 7 ++----- firmware/application/ert_app.cpp | 7 ++----- firmware/application/recent_entries.hpp | 6 +++--- firmware/application/tpms_app.cpp | 7 ++----- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/firmware/application/ais_app.cpp b/firmware/application/ais_app.cpp index 3d7ad098..cb9e1ef8 100644 --- a/firmware/application/ais_app.cpp +++ b/firmware/application/ais_app.cpp @@ -190,11 +190,8 @@ void RecentEntriesView::draw( const Entry& entry, const Rect& target_rect, Painter& painter, - const Style& style, - const bool is_selected + const Style& style ) { - const auto& draw_style = is_selected ? style.invert() : style; - std::string line = ais::format::mmsi(entry.mmsi) + " "; if( !entry.name.empty() ) { line += entry.name; @@ -203,7 +200,7 @@ void RecentEntriesView::draw( } line.resize(target_rect.width() / 8, ' '); - painter.draw_string(target_rect.pos, draw_style, line); + painter.draw_string(target_rect.pos, style, line); } AISRecentEntryDetailView::AISRecentEntryDetailView() { diff --git a/firmware/application/ert_app.cpp b/firmware/application/ert_app.cpp index fac65320..d02133c8 100644 --- a/firmware/application/ert_app.cpp +++ b/firmware/application/ert_app.cpp @@ -80,11 +80,8 @@ void RecentEntriesView::draw( const Entry& entry, const Rect& target_rect, Painter& painter, - const Style& style, - const bool is_selected + const Style& style ) { - const auto& draw_style = is_selected ? style.invert() : style; - std::string line = ert::format::id(entry.id) + " " + ert::format::commodity_type(entry.commodity_type) + " " + ert::format::consumption(entry.last_consumption); if( entry.received_count > 999 ) { @@ -94,7 +91,7 @@ void RecentEntriesView::draw( } line.resize(target_rect.width() / 8, ' '); - painter.draw_string(target_rect.pos, draw_style, line); + painter.draw_string(target_rect.pos, style, line); } ERTAppView::ERTAppView(NavigationView&) { diff --git a/firmware/application/recent_entries.hpp b/firmware/application/recent_entries.hpp index 30bf4a8d..c0118f77 100644 --- a/firmware/application/recent_entries.hpp +++ b/firmware/application/recent_entries.hpp @@ -170,7 +170,8 @@ public: for(auto p = range.first; p != range.second; p++) { const auto& entry = *p; const auto is_selected_key = (selected_key == entry.key()); - draw(entry, target_rect, painter, s, (has_focus() && is_selected_key)); + const auto item_style = (has_focus() && is_selected_key) ? s.invert() : s; + draw(entry, target_rect, painter, item_style); target_rect.pos.y += target_rect.height(); } @@ -257,8 +258,7 @@ private: const Entry& entry, const Rect& target_rect, Painter& painter, - const Style& style, - const bool is_selected + const Style& style ); }; diff --git a/firmware/application/tpms_app.cpp b/firmware/application/tpms_app.cpp index 25ad2420..9da4fce6 100644 --- a/firmware/application/tpms_app.cpp +++ b/firmware/application/tpms_app.cpp @@ -100,11 +100,8 @@ void RecentEntriesView::draw( const Entry& entry, const Rect& target_rect, Painter& painter, - const Style& style, - const bool is_selected + const Style& style ) { - const auto& draw_style = is_selected ? style.invert() : style; - std::string line = tpms::format::type(entry.type) + " " + tpms::format::id(entry.id); if( entry.last_pressure.is_valid() ) { @@ -132,7 +129,7 @@ void RecentEntriesView::draw( } line.resize(target_rect.width() / 8, ' '); - painter.draw_string(target_rect.pos, draw_style, line); + painter.draw_string(target_rect.pos, style, line); } TPMSAppView::TPMSAppView(NavigationView&) {