mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-22 17:29:44 +00:00
Template AISRecentEntriesView.
More teasing apart, not sure where this will end...
This commit is contained in:
@@ -274,19 +274,22 @@ typename RecentEntries<Packet, Entry>::RangeType RecentEntries<Packet, Entry>::r
|
|||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
AISRecentEntriesView::AISRecentEntriesView(
|
template<class Entries>
|
||||||
AISRecentEntries& recent
|
RecentEntriesView<Entries>::RecentEntriesView(
|
||||||
|
Entries& recent
|
||||||
) : recent { recent }
|
) : recent { recent }
|
||||||
{
|
{
|
||||||
flags.focusable = true;
|
flags.focusable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AISRecentEntriesView::on_encoder(const EncoderEvent event) {
|
template<class Entries>
|
||||||
|
bool RecentEntriesView<Entries>::on_encoder(const EncoderEvent event) {
|
||||||
advance(event);
|
advance(event);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AISRecentEntriesView::on_key(const ui::KeyEvent event) {
|
template<class Entries>
|
||||||
|
bool RecentEntriesView<Entries>::on_key(const ui::KeyEvent event) {
|
||||||
if( event == ui::KeyEvent::Select ) {
|
if( event == ui::KeyEvent::Select ) {
|
||||||
if( on_select ) {
|
if( on_select ) {
|
||||||
const auto selected = recent.find(selected_key);
|
const auto selected = recent.find(selected_key);
|
||||||
@@ -299,8 +302,9 @@ bool AISRecentEntriesView::on_key(const ui::KeyEvent event) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AISRecentEntriesView::draw(
|
template<>
|
||||||
const AISRecentEntry& entry,
|
void RecentEntriesView<AISRecentEntries>::draw(
|
||||||
|
const Entry& entry,
|
||||||
const Rect& target_rect,
|
const Rect& target_rect,
|
||||||
Painter& painter,
|
Painter& painter,
|
||||||
const Style& style,
|
const Style& style,
|
||||||
@@ -319,7 +323,8 @@ void AISRecentEntriesView::draw(
|
|||||||
painter.draw_string(target_rect.pos, draw_style, line);
|
painter.draw_string(target_rect.pos, draw_style, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AISRecentEntriesView::paint(Painter& painter) {
|
template<class Entries>
|
||||||
|
void RecentEntriesView<Entries>::paint(Painter& painter) {
|
||||||
const auto r = screen_rect();
|
const auto r = screen_rect();
|
||||||
const auto& s = style();
|
const auto& s = style();
|
||||||
|
|
||||||
@@ -341,11 +346,12 @@ void AISRecentEntriesView::paint(Painter& painter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AISRecentEntriesView::advance(const int32_t amount) {
|
template<class Entries>
|
||||||
|
void RecentEntriesView<Entries>::advance(const int32_t amount) {
|
||||||
auto selected = recent.find(selected_key);
|
auto selected = recent.find(selected_key);
|
||||||
if( selected == std::end(recent) ) {
|
if( selected == std::end(recent) ) {
|
||||||
if( recent.empty() ) {
|
if( recent.empty() ) {
|
||||||
selected_key = invalid_key;
|
selected_key = Entry::invalid_key;
|
||||||
} else {
|
} else {
|
||||||
selected_key = recent.front().key();
|
selected_key = recent.front().key();
|
||||||
}
|
}
|
||||||
|
@@ -51,6 +51,8 @@ struct AISPosition {
|
|||||||
struct AISRecentEntry {
|
struct AISRecentEntry {
|
||||||
using Key = ais::MMSI;
|
using Key = ais::MMSI;
|
||||||
|
|
||||||
|
static constexpr Key invalid_key = 0xffffffff;
|
||||||
|
|
||||||
ais::MMSI mmsi;
|
ais::MMSI mmsi;
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string call_sign;
|
std::string call_sign;
|
||||||
@@ -83,6 +85,7 @@ struct AISRecentEntry {
|
|||||||
template<class Packet, class Entry>
|
template<class Packet, class Entry>
|
||||||
class RecentEntries {
|
class RecentEntries {
|
||||||
public:
|
public:
|
||||||
|
using EntryType = Entry;
|
||||||
using Key = typename Entry::Key;
|
using Key = typename Entry::Key;
|
||||||
using ContainerType = std::list<Entry>;
|
using ContainerType = std::list<Entry>;
|
||||||
using const_reference = typename ContainerType::const_reference;
|
using const_reference = typename ContainerType::const_reference;
|
||||||
@@ -132,11 +135,14 @@ private:
|
|||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
class AISRecentEntriesView : public View {
|
template<class Entries>
|
||||||
|
class RecentEntriesView : public View {
|
||||||
public:
|
public:
|
||||||
std::function<void(const AISRecentEntry& entry)> on_select;
|
using Entry = typename Entries::EntryType;
|
||||||
|
|
||||||
AISRecentEntriesView(AISRecentEntries& recent);
|
std::function<void(const Entry& entry)> on_select;
|
||||||
|
|
||||||
|
RecentEntriesView(Entries& recent);
|
||||||
|
|
||||||
void paint(Painter& painter) override;
|
void paint(Painter& painter) override;
|
||||||
|
|
||||||
@@ -144,16 +150,15 @@ public:
|
|||||||
bool on_key(const ui::KeyEvent event) override;
|
bool on_key(const ui::KeyEvent event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AISRecentEntries& recent;
|
Entries& recent;
|
||||||
|
|
||||||
using EntryKey = ais::MMSI;
|
using EntryKey = typename Entry::Key;
|
||||||
EntryKey selected_key;
|
EntryKey selected_key;
|
||||||
const EntryKey invalid_key = 0xffffffff;
|
|
||||||
|
|
||||||
void advance(const int32_t amount);
|
void advance(const int32_t amount);
|
||||||
|
|
||||||
void draw(
|
void draw(
|
||||||
const AISRecentEntry& entry,
|
const Entry& entry,
|
||||||
const Rect& target_rect,
|
const Rect& target_rect,
|
||||||
Painter& painter,
|
Painter& painter,
|
||||||
const Style& style,
|
const Style& style,
|
||||||
@@ -161,6 +166,8 @@ private:
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using AISRecentEntriesView = RecentEntriesView<AISRecentEntries>;
|
||||||
|
|
||||||
class AISRecentEntryDetailView : public View {
|
class AISRecentEntryDetailView : public View {
|
||||||
public:
|
public:
|
||||||
std::function<void(void)> on_close;
|
std::function<void(void)> on_close;
|
||||||
|
Reference in New Issue
Block a user