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,12 +424,12 @@ bool AISView::on_encoder(const EncoderEvent event) {
return true;
}
void AISView::paint(Painter& painter) {
const auto r = screen_rect();
const auto& s = style();
auto p = r.pos;
for(const auto entry : recent) {
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;
@ -437,17 +437,29 @@ void AISView::paint(Painter& painter) {
line += entry.call_sign;
}
line.resize(r.width() / 8, ' ');
line.resize(target_rect.width() / 8, ' ');
if( has_focus && (selected_key == entry.mmsi) ) {
painter.draw_string(p, s.invert(), line);
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(p, s, line);
painter.draw_string(target_rect.pos, s, line);
}
p.y += s.font.line_height();
return is_selected_key;
}
if( p.y >= r.bottom() ) {
void AISView::paint(Painter& painter) {
const auto r = screen_rect();
const auto& s = style();
Rect target_rect { r.pos, { r.width(), s.font.line_height() }};
for(const auto entry : recent) {
draw_entry(entry, target_rect, painter, s);
target_rect.pos.y += target_rect.height();
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();