RecentEntriesView: Generalize draw_header() implementations.

This commit is contained in:
Jared Boone 2016-09-02 22:22:30 -07:00
parent 2396d2d97a
commit 1e0d452f57
4 changed files with 50 additions and 79 deletions

View File

@ -185,30 +185,6 @@ void AISRecentEntry::update(const ais::Packet& packet) {
namespace ui {
static const std::array<std::pair<std::string, size_t>, 2> ais_columns { {
{ "MMSI", 9 },
{ "Name/Call", 20 },
} };
template<>
void RecentEntriesView<AISRecentEntries>::draw_header(
const Rect& target_rect,
Painter& painter,
const Style& style
) {
auto x = 0;
for(const auto& column : ais_columns) {
const auto width = column.second;
auto text = column.first;
if( width > text.length() ) {
text.append(width - text.length(), ' ');
}
painter.draw_string({ x, target_rect.pos.y }, style, text);
x += (width * 8) + 8;
}
}
template<>
void RecentEntriesView<AISRecentEntries>::draw(
const Entry& entry,
@ -303,6 +279,12 @@ AISAppView::AISAppView(NavigationView&) {
&recent_entry_detail_view,
} });
const std::array<RecentEntriesColumn, 2> columns { {
{ "MMSI", 9 },
{ "Name/Call", 20 },
} };
recent_entries_view.set_columns(columns);
recent_entry_detail_view.hidden(true);
target_frequency_ = initial_target_frequency;

View File

@ -75,32 +75,6 @@ void ERTRecentEntry::update(const ert::Packet& packet) {
namespace ui {
static const std::array<std::pair<std::string, size_t>, 4> ert_columns { {
{ "ID", 10 },
{ "Tp", 2 },
{ "Consumpt", 10 },
{ "Cnt", 3 },
} };
template<>
void RecentEntriesView<ERTRecentEntries>::draw_header(
const Rect& target_rect,
Painter& painter,
const Style& style
) {
auto x = 0;
for(const auto& column : ert_columns) {
const auto width = column.second;
auto text = column.first;
if( width > text.length() ) {
text.append(width - text.length(), ' ');
}
painter.draw_string({ x, target_rect.pos.y }, style, text);
x += (width * 8) + 8;
}
}
template<>
void RecentEntriesView<ERTRecentEntries>::draw(
const Entry& entry,
@ -134,6 +108,14 @@ ERTAppView::ERTAppView(NavigationView&) {
&recent_entries_view,
} });
const std::array<RecentEntriesColumn, 4> columns { {
{ "ID", 10 },
{ "Tp", 2 },
{ "Consumpt", 10 },
{ "Cnt", 3 },
} };
recent_entries_view.set_columns(columns);
radio::enable({
initial_target_frequency,
sampling_rate,

View File

@ -118,6 +118,8 @@ private:
namespace ui {
using RecentEntriesColumn = std::pair<std::string, size_t>;
template<class Entries>
class RecentEntriesView : public View {
public:
@ -132,6 +134,16 @@ public:
set_focusable(true);
}
template<size_t ColumnCount>
void set_columns(
const std::array<RecentEntriesColumn, ColumnCount>& columns
) {
_columns.clear();
for(const auto& column : columns) {
_columns.emplace_back(column);
}
}
void paint(Painter& painter) override {
const auto r = screen_rect();
const auto& s = style();
@ -192,6 +204,7 @@ public:
private:
Entries& recent;
std::vector<std::pair<std::string, size_t>> _columns;
using EntryKey = typename Entry::Key;
EntryKey selected_key = Entry::invalid_key;
@ -226,7 +239,19 @@ private:
const Rect& target_rect,
Painter& painter,
const Style& style
);
) {
auto x = 0;
for(const auto& column : _columns) {
const auto width = column.second;
auto text = column.first;
if( width > text.length() ) {
text.append(width - text.length(), ' ');
}
painter.draw_string({ x, target_rect.pos.y }, style, text);
x += (width * 8) + 8;
}
}
void draw(
const Entry& entry,

View File

@ -95,34 +95,6 @@ void TPMSRecentEntry::update(const tpms::Reading& reading) {
namespace ui {
static const std::array<std::pair<std::string, size_t>, 6> tpms_columns { {
{ "Tp", 2 },
{ "ID", 8 },
{ "kPa", 3 },
{ "C", 3 },
{ "Cnt", 3 },
{ "Fl", 2 },
} };
template<>
void RecentEntriesView<TPMSRecentEntries>::draw_header(
const Rect& target_rect,
Painter& painter,
const Style& style
) {
auto x = 0;
for(const auto& column : tpms_columns) {
const auto width = column.second;
auto text = column.first;
if( width > text.length() ) {
text.append(width - text.length(), ' ');
}
painter.draw_string({ x, target_rect.pos.y }, style, text);
x += (width * 8) + 8;
}
}
template<>
void RecentEntriesView<TPMSRecentEntries>::draw(
const Entry& entry,
@ -176,6 +148,16 @@ TPMSAppView::TPMSAppView(NavigationView&) {
&recent_entries_view,
} });
const std::array<RecentEntriesColumn, 6> columns { {
{ "Tp", 2 },
{ "ID", 8 },
{ "kPa", 3 },
{ "C", 3 },
{ "Cnt", 3 },
{ "Fl", 2 },
} };
recent_entries_view.set_columns(columns);
radio::enable({
tuning_frequency(),
sampling_rate,