mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-28 08:49:45 -05:00
Template AISRecentEntriesView.
More teasing apart, not sure where this will end...
This commit is contained in:
parent
eda6e6a5be
commit
df3ce07c5c
@ -274,19 +274,22 @@ typename RecentEntries<Packet, Entry>::RangeType RecentEntries<Packet, Entry>::r
|
||||
|
||||
namespace ui {
|
||||
|
||||
AISRecentEntriesView::AISRecentEntriesView(
|
||||
AISRecentEntries& recent
|
||||
template<class Entries>
|
||||
RecentEntriesView<Entries>::RecentEntriesView(
|
||||
Entries& recent
|
||||
) : recent { recent }
|
||||
{
|
||||
flags.focusable = true;
|
||||
}
|
||||
|
||||
bool AISRecentEntriesView::on_encoder(const EncoderEvent event) {
|
||||
template<class Entries>
|
||||
bool RecentEntriesView<Entries>::on_encoder(const EncoderEvent event) {
|
||||
advance(event);
|
||||
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( 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<AISRecentEntries>::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<class Entries>
|
||||
void RecentEntriesView<Entries>::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<class Entries>
|
||||
void RecentEntriesView<Entries>::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();
|
||||
}
|
||||
|
@ -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 Packet, class Entry>
|
||||
class RecentEntries {
|
||||
public:
|
||||
using EntryType = Entry;
|
||||
using Key = typename Entry::Key;
|
||||
using ContainerType = std::list<Entry>;
|
||||
using const_reference = typename ContainerType::const_reference;
|
||||
@ -132,11 +135,14 @@ private:
|
||||
|
||||
namespace ui {
|
||||
|
||||
class AISRecentEntriesView : public View {
|
||||
template<class Entries>
|
||||
class RecentEntriesView : public View {
|
||||
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;
|
||||
|
||||
@ -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<AISRecentEntries>;
|
||||
|
||||
class AISRecentEntryDetailView : public View {
|
||||
public:
|
||||
std::function<void(void)> on_close;
|
||||
|
Loading…
Reference in New Issue
Block a user