Add AIS detail view.

This commit is contained in:
Jared Boone 2016-01-14 22:39:58 -08:00
parent b1707298b7
commit aa249cbad4
2 changed files with 87 additions and 0 deletions

View File

@ -197,6 +197,19 @@ bool AISRecentEntriesView::on_encoder(const EncoderEvent event) {
return true;
}
bool AISRecentEntriesView::on_key(const ui::KeyEvent event) {
if( event == ui::KeyEvent::Select ) {
if( on_select ) {
const auto selected = recent.find_by_mmsi(selected_key);
if( selected != std::end(recent) ) {
on_select(*selected);
return true;
}
}
}
return false;
}
static void ais_list_item_draw(
const AISRecentEntry& entry,
const Rect& target_rect,
@ -265,11 +278,34 @@ void AISRecentEntriesView::advance(const int32_t amount) {
set_dirty();
}
AISRecentEntryDetailView::AISRecentEntryDetailView() {
add_children({ {
&button_done,
} });
button_done.on_select = [this](const ui::Button&) {
if( this->on_close ) {
this->on_close();
}
};
}
void AISRecentEntryDetailView::focus() {
button_done.focus();
}
void AISRecentEntryDetailView::set_entry(const AISRecentEntry& new_entry) {
entry = new_entry;
}
AISAppView::AISAppView() {
add_children({ {
&recent_entries_view,
&recent_entry_detail_view,
} });
recent_entry_detail_view.hidden(true);
EventDispatcher::message_map().register_handler(Message::ID::AISPacket,
[this](Message* const p) {
const auto message = static_cast<const AISPacketMessage*>(p);
@ -286,6 +322,13 @@ AISAppView::AISAppView() {
.decimation_factor = 1,
});
receiver_model.set_baseband_bandwidth(1750000);
recent_entries_view.on_select = [this](const AISRecentEntry& entry) {
this->on_show_detail(entry);
};
recent_entry_detail_view.on_close = [this]() {
this->on_show_list();
};
}
AISAppView::~AISAppView() {
@ -295,6 +338,7 @@ AISAppView::~AISAppView() {
void AISAppView::set_parent_rect(const Rect new_parent_rect) {
View::set_parent_rect(new_parent_rect);
recent_entries_view.set_parent_rect({ 0, 0, new_parent_rect.width(), new_parent_rect.height() });
recent_entry_detail_view.set_parent_rect({ 0, 0, new_parent_rect.width(), new_parent_rect.height() });
}
void AISAppView::on_packet(const ais::Packet& packet) {
@ -303,4 +347,17 @@ void AISAppView::on_packet(const ais::Packet& packet) {
recent_entries_view.set_dirty();
}
void AISAppView::on_show_list() {
recent_entries_view.hidden(false);
recent_entry_detail_view.hidden(true);
recent_entries_view.focus();
}
void AISAppView::on_show_detail(const AISRecentEntry& entry) {
recent_entries_view.hidden(true);
recent_entry_detail_view.hidden(false);
recent_entry_detail_view.set_entry(entry);
recent_entry_detail_view.focus();
}
} /* namespace ui */

View File

@ -53,6 +53,11 @@ struct AISRecentEntry {
size_t received_count;
int8_t navigational_status;
AISRecentEntry(
) : AISRecentEntry { 0 }
{
}
AISRecentEntry(
const ais::MMSI& mmsi
) : mmsi { mmsi },
@ -113,11 +118,14 @@ namespace ui {
class AISRecentEntriesView : public View {
public:
std::function<void(const AISRecentEntry& entry)> on_select;
AISRecentEntriesView(AISRecentEntries& recent);
void paint(Painter& painter) override;
bool on_encoder(const EncoderEvent event) override;
bool on_key(const ui::KeyEvent event) override;
private:
AISRecentEntries& recent;
@ -129,6 +137,25 @@ private:
void advance(const int32_t amount);
};
class AISRecentEntryDetailView : public View {
public:
std::function<void(void)> on_close;
AISRecentEntryDetailView();
void set_entry(const AISRecentEntry& new_entry);
void focus() override;
private:
AISRecentEntry entry;
Button button_done {
{ 72, 192, 96, 24 },
"Done"
};
};
class AISAppView : public View {
public:
AISAppView();
@ -145,8 +172,11 @@ private:
AISLogger logger;
AISRecentEntriesView recent_entries_view { recent };
AISRecentEntryDetailView recent_entry_detail_view;
void on_packet(const ais::Packet& packet);
void on_show_list();
void on_show_detail(const AISRecentEntry& entry);
};
} /* namespace ui */