Extract AIS RecentEntry painting into separate method.

Small steps in a larger refactor, and better selected-item-scrolls-off-the-bottom behavior.
This commit is contained in:
Jared Boone 2015-12-05 20:15:30 -08:00
parent 8fce9378cc
commit c4ad2ffe1b
2 changed files with 36 additions and 17 deletions

View File

@ -424,30 +424,42 @@ bool AISView::on_encoder(const EncoderEvent event) {
return true;
}
bool AISView::draw_entry(
const RecentEntry& entry,
const Rect& target_rect,
Painter& painter,
const Style& s
) {
std::string line = baseband::ais::format_mmsi(entry.mmsi) + " ";
if( !entry.name.empty() ) {
line += entry.name;
} else {
line += entry.call_sign;
}
line.resize(target_rect.width() / 8, ' ');
const bool is_selected_key = (selected_key == entry.mmsi);
if( has_focus && is_selected_key ) {
painter.draw_string(target_rect.pos, s.invert(), line);
} else {
painter.draw_string(target_rect.pos, s, line);
}
return is_selected_key;
}
void AISView::paint(Painter& painter) {
const auto r = screen_rect();
const auto& s = style();
auto p = r.pos;
Rect target_rect { r.pos, { r.width(), s.font.line_height() }};
for(const auto entry : recent) {
std::string line = baseband::ais::format_mmsi(entry.mmsi) + " ";
if( !entry.name.empty() ) {
line += entry.name;
} else {
line += entry.call_sign;
}
draw_entry(entry, target_rect, painter, s);
line.resize(r.width() / 8, ' ');
target_rect.pos.y += target_rect.height();
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() ) {
if( target_rect.pos.y >= r.bottom() ) {
break;
}
}

View File

@ -173,6 +173,13 @@ private:
void on_packet(const baseband::ais::Packet& packet);
bool draw_entry(
const RecentEntry& entry,
const Rect& target_rect,
Painter& painter,
const Style& s
);
void truncate_entries();
RecentEntries::iterator selected_entry();