RecentEntriesView: Extract duplicate focus+selection style code.

This commit is contained in:
Jared Boone 2016-09-02 22:44:40 -07:00
parent 1e0d452f57
commit c6f7d7f844
4 changed files with 9 additions and 18 deletions

View File

@ -190,11 +190,8 @@ void RecentEntriesView<AISRecentEntries>::draw(
const Entry& entry, const Entry& entry,
const Rect& target_rect, const Rect& target_rect,
Painter& painter, Painter& painter,
const Style& style, const Style& style
const bool is_selected
) { ) {
const auto& draw_style = is_selected ? style.invert() : style;
std::string line = ais::format::mmsi(entry.mmsi) + " "; std::string line = ais::format::mmsi(entry.mmsi) + " ";
if( !entry.name.empty() ) { if( !entry.name.empty() ) {
line += entry.name; line += entry.name;
@ -203,7 +200,7 @@ void RecentEntriesView<AISRecentEntries>::draw(
} }
line.resize(target_rect.width() / 8, ' '); line.resize(target_rect.width() / 8, ' ');
painter.draw_string(target_rect.pos, draw_style, line); painter.draw_string(target_rect.pos, style, line);
} }
AISRecentEntryDetailView::AISRecentEntryDetailView() { AISRecentEntryDetailView::AISRecentEntryDetailView() {

View File

@ -80,11 +80,8 @@ void RecentEntriesView<ERTRecentEntries>::draw(
const Entry& entry, const Entry& entry,
const Rect& target_rect, const Rect& target_rect,
Painter& painter, Painter& painter,
const Style& style, const Style& style
const bool is_selected
) { ) {
const auto& draw_style = is_selected ? style.invert() : style;
std::string line = ert::format::id(entry.id) + " " + ert::format::commodity_type(entry.commodity_type) + " " + ert::format::consumption(entry.last_consumption); std::string line = ert::format::id(entry.id) + " " + ert::format::commodity_type(entry.commodity_type) + " " + ert::format::consumption(entry.last_consumption);
if( entry.received_count > 999 ) { if( entry.received_count > 999 ) {
@ -94,7 +91,7 @@ void RecentEntriesView<ERTRecentEntries>::draw(
} }
line.resize(target_rect.width() / 8, ' '); line.resize(target_rect.width() / 8, ' ');
painter.draw_string(target_rect.pos, draw_style, line); painter.draw_string(target_rect.pos, style, line);
} }
ERTAppView::ERTAppView(NavigationView&) { ERTAppView::ERTAppView(NavigationView&) {

View File

@ -170,7 +170,8 @@ public:
for(auto p = range.first; p != range.second; p++) { for(auto p = range.first; p != range.second; p++) {
const auto& entry = *p; const auto& entry = *p;
const auto is_selected_key = (selected_key == entry.key()); const auto is_selected_key = (selected_key == entry.key());
draw(entry, target_rect, painter, s, (has_focus() && is_selected_key)); const auto item_style = (has_focus() && is_selected_key) ? s.invert() : s;
draw(entry, target_rect, painter, item_style);
target_rect.pos.y += target_rect.height(); target_rect.pos.y += target_rect.height();
} }
@ -257,8 +258,7 @@ private:
const Entry& entry, const Entry& entry,
const Rect& target_rect, const Rect& target_rect,
Painter& painter, Painter& painter,
const Style& style, const Style& style
const bool is_selected
); );
}; };

View File

@ -100,11 +100,8 @@ void RecentEntriesView<TPMSRecentEntries>::draw(
const Entry& entry, const Entry& entry,
const Rect& target_rect, const Rect& target_rect,
Painter& painter, Painter& painter,
const Style& style, const Style& style
const bool is_selected
) { ) {
const auto& draw_style = is_selected ? style.invert() : style;
std::string line = tpms::format::type(entry.type) + " " + tpms::format::id(entry.id); std::string line = tpms::format::type(entry.type) + " " + tpms::format::id(entry.id);
if( entry.last_pressure.is_valid() ) { if( entry.last_pressure.is_valid() ) {
@ -132,7 +129,7 @@ void RecentEntriesView<TPMSRecentEntries>::draw(
} }
line.resize(target_rect.width() / 8, ' '); line.resize(target_rect.width() / 8, ' ');
painter.draw_string(target_rect.pos, draw_style, line); painter.draw_string(target_rect.pos, style, line);
} }
TPMSAppView::TPMSAppView(NavigationView&) { TPMSAppView::TPMSAppView(NavigationView&) {