RecentEntries: Extract Columns model.

This commit is contained in:
Jared Boone 2016-09-05 12:34:41 -07:00
parent 61f0d97c39
commit 298324d6e4
7 changed files with 46 additions and 45 deletions

View File

@ -276,12 +276,6 @@ 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

@ -161,7 +161,11 @@ private:
AISRecentEntries recent;
std::unique_ptr<AISLogger> logger;
AISRecentEntriesView recent_entries_view { recent };
const RecentEntriesColumns columns { {
{ "MMSI", 9 },
{ "Name/Call", 20 },
} };
AISRecentEntriesView recent_entries_view { columns, recent };
AISRecentEntryDetailView recent_entry_detail_view;
static constexpr auto header_height = 1 * 16;

View File

@ -105,14 +105,6 @@ 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

@ -129,7 +129,13 @@ private:
ERTRecentEntries recent;
std::unique_ptr<ERTLogger> logger;
ERTRecentEntriesView recent_entries_view { recent };
const RecentEntriesColumns columns { {
{ "ID", 10 },
{ "Tp", 2 },
{ "Consumpt", 10 },
{ "Cnt", 3 },
} };
ERTRecentEntriesView recent_entries_view { columns, recent };
static constexpr auto header_height = 1 * 16;

View File

@ -95,17 +95,29 @@ namespace ui {
using RecentEntriesColumn = std::pair<std::string, size_t>;
class RecentEntriesColumns {
public:
using ContainerType = std::vector<RecentEntriesColumn>;
RecentEntriesColumns(
const std::initializer_list<RecentEntriesColumn> columns
) : _columns { columns }
{
}
ContainerType::const_iterator begin() const { return std::begin(_columns); }
ContainerType::const_iterator end() const { return std::end(_columns); }
private:
const ContainerType _columns;
};
class RecentEntriesHeader : public Widget {
public:
template<size_t ColumnCount>
void set_columns(
const std::array<RecentEntriesColumn, ColumnCount>& columns
) {
_columns.clear();
for(const auto& column : columns) {
_columns.emplace_back(column);
}
RecentEntriesHeader(
const RecentEntriesColumns& columns
) : _columns { columns }
{
}
void paint(Painter& painter) override {
@ -132,7 +144,7 @@ public:
}
private:
std::vector<RecentEntriesColumn> _columns;
const RecentEntriesColumns& _columns;
};
template<class Entries>
@ -247,8 +259,10 @@ public:
std::function<void(const Entry& entry)> on_select;
RecentEntriesView(
const RecentEntriesColumns& columns,
Entries& recent
) : _table { recent }
) : _header { columns },
_table { recent }
{
add_children({ {
&_header,
@ -258,13 +272,6 @@ public:
_table.on_select = [this](const Entry& entry) { if( this->on_select ) { this->on_select(entry); } };
}
template<size_t ColumnCount>
void set_columns(
const std::array<RecentEntriesColumn, ColumnCount>& columns
) {
_header.set_columns(columns);
}
void set_parent_rect(const Rect new_parent_rect) override {
constexpr Dim scale_height = 16;

View File

@ -145,16 +145,6 @@ 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,

View File

@ -153,7 +153,15 @@ private:
TPMSRecentEntries recent;
std::unique_ptr<TPMSLogger> logger;
TPMSRecentEntriesView recent_entries_view { recent };
const RecentEntriesColumns columns { {
{ "Tp", 2 },
{ "ID", 8 },
{ "kPa", 3 },
{ "C", 3 },
{ "Cnt", 3 },
{ "Fl", 2 },
} };
TPMSRecentEntriesView recent_entries_view { columns, recent };
uint32_t target_frequency_ = initial_target_frequency;