AISView RecentEntry UI selection by encoder.

This commit is contained in:
Jared Boone 2015-12-05 14:24:41 -08:00
parent 27684069c5
commit 9791d64b50
2 changed files with 56 additions and 2 deletions

View File

@ -415,6 +415,11 @@ void AISView::on_blur() {
set_dirty();
}
bool AISView::on_encoder(const EncoderEvent event) {
advance(event);
return true;
}
void AISView::paint(Painter& painter) {
const auto r = screen_rect();
const auto& s = style();
@ -430,7 +435,12 @@ void AISView::paint(Painter& painter) {
line.resize(r.width() / 8, ' ');
painter.draw_string(p, s, line);
if( has_focus && (selected_key == entry.mmsi) ) {
painter.draw_string(p, s.invert(), line);
} else {
painter.draw_string(p, s, line);
}
p.y += s.font.line_height();
if( p.y >= r.bottom() ) {
@ -439,4 +449,35 @@ void AISView::paint(Painter& painter) {
}
}
AISView::RecentEntries::iterator AISView::selected_entry() {
const auto key = selected_key;
return std::find_if(std::begin(recent), std::end(recent), [key](const RecentEntry& e) { return e.mmsi == key; });
}
void AISView::advance(const int32_t amount) {
auto selected = selected_entry();
if( selected == std::end(recent) ) {
if( recent.empty() ) {
selected_key = invalid_key;
} else {
selected_key = recent.front().mmsi;
}
} else {
if( amount < 0 ) {
if( selected != std::begin(recent) ) {
std::advance(selected, -1);
}
}
if( amount > 0 ) {
std::advance(selected, 1);
if( selected == std::end(recent) ) {
return;
}
}
selected_key = selected->mmsi;
}
set_dirty();
}
} /* namespace ui */

View File

@ -37,6 +37,8 @@ using namespace lpc43xx;
#include <list>
#include <utility>
#include <iterator>
namespace baseband {
namespace ais {
@ -130,9 +132,15 @@ public:
void on_focus() override;
void on_blur() override;
bool on_encoder(const EncoderEvent event) override;
private:
AISModel model;
using EntryKey = baseband::ais::MMSI;
EntryKey selected_key;
const EntryKey invalid_key = 0xffffffff;
bool has_focus = false;
struct Position {
@ -160,9 +168,14 @@ private:
}
};
std::list<RecentEntry> recent;
using RecentEntries = std::list<RecentEntry>;
RecentEntries recent;
void on_packet(const baseband::ais::Packet& packet);
RecentEntries::iterator selected_entry();
void advance(const int32_t amount);
};
} /* namespace ui */