diff --git a/firmware/application/ais_app.cpp b/firmware/application/ais_app.cpp index 872b986cc..fa2ff7ca6 100644 --- a/firmware/application/ais_app.cpp +++ b/firmware/application/ais_app.cpp @@ -274,19 +274,22 @@ typename RecentEntries::RangeType RecentEntries::r namespace ui { -AISRecentEntriesView::AISRecentEntriesView( - AISRecentEntries& recent +template +RecentEntriesView::RecentEntriesView( + Entries& recent ) : recent { recent } { flags.focusable = true; } -bool AISRecentEntriesView::on_encoder(const EncoderEvent event) { +template +bool RecentEntriesView::on_encoder(const EncoderEvent event) { advance(event); return true; } -bool AISRecentEntriesView::on_key(const ui::KeyEvent event) { +template +bool RecentEntriesView::on_key(const ui::KeyEvent event) { if( event == ui::KeyEvent::Select ) { if( on_select ) { const auto selected = recent.find(selected_key); @@ -299,8 +302,9 @@ bool AISRecentEntriesView::on_key(const ui::KeyEvent event) { return false; } -void AISRecentEntriesView::draw( - const AISRecentEntry& entry, +template<> +void RecentEntriesView::draw( + const Entry& entry, const Rect& target_rect, Painter& painter, const Style& style, @@ -319,7 +323,8 @@ void AISRecentEntriesView::draw( painter.draw_string(target_rect.pos, draw_style, line); } -void AISRecentEntriesView::paint(Painter& painter) { +template +void RecentEntriesView::paint(Painter& painter) { const auto r = screen_rect(); const auto& s = style(); @@ -341,11 +346,12 @@ void AISRecentEntriesView::paint(Painter& painter) { } } -void AISRecentEntriesView::advance(const int32_t amount) { +template +void RecentEntriesView::advance(const int32_t amount) { auto selected = recent.find(selected_key); if( selected == std::end(recent) ) { if( recent.empty() ) { - selected_key = invalid_key; + selected_key = Entry::invalid_key; } else { selected_key = recent.front().key(); } diff --git a/firmware/application/ais_app.hpp b/firmware/application/ais_app.hpp index 9a5589428..5dfd0f6bf 100644 --- a/firmware/application/ais_app.hpp +++ b/firmware/application/ais_app.hpp @@ -51,6 +51,8 @@ struct AISPosition { struct AISRecentEntry { using Key = ais::MMSI; + static constexpr Key invalid_key = 0xffffffff; + ais::MMSI mmsi; std::string name; std::string call_sign; @@ -83,6 +85,7 @@ struct AISRecentEntry { template class RecentEntries { public: + using EntryType = Entry; using Key = typename Entry::Key; using ContainerType = std::list; using const_reference = typename ContainerType::const_reference; @@ -132,11 +135,14 @@ private: namespace ui { -class AISRecentEntriesView : public View { +template +class RecentEntriesView : public View { public: - std::function on_select; + using Entry = typename Entries::EntryType; - AISRecentEntriesView(AISRecentEntries& recent); + std::function on_select; + + RecentEntriesView(Entries& recent); void paint(Painter& painter) override; @@ -144,16 +150,15 @@ public: bool on_key(const ui::KeyEvent event) override; private: - AISRecentEntries& recent; + Entries& recent; - using EntryKey = ais::MMSI; + using EntryKey = typename Entry::Key; EntryKey selected_key; - const EntryKey invalid_key = 0xffffffff; void advance(const int32_t amount); void draw( - const AISRecentEntry& entry, + const Entry& entry, const Rect& target_rect, Painter& painter, const Style& style, @@ -161,6 +166,8 @@ private: ); }; +using AISRecentEntriesView = RecentEntriesView; + class AISRecentEntryDetailView : public View { public: std::function on_close;