mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-07-28 01:05:58 -04:00
RecentEntriesView: Generalize draw_header() implementations.
This commit is contained in:
parent
2396d2d97a
commit
1e0d452f57
4 changed files with 50 additions and 79 deletions
|
@ -185,30 +185,6 @@ void AISRecentEntry::update(const ais::Packet& packet) {
|
||||||
|
|
||||||
namespace ui {
|
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<>
|
template<>
|
||||||
void RecentEntriesView<AISRecentEntries>::draw(
|
void RecentEntriesView<AISRecentEntries>::draw(
|
||||||
const Entry& entry,
|
const Entry& entry,
|
||||||
|
@ -303,6 +279,12 @@ AISAppView::AISAppView(NavigationView&) {
|
||||||
&recent_entry_detail_view,
|
&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);
|
recent_entry_detail_view.hidden(true);
|
||||||
|
|
||||||
target_frequency_ = initial_target_frequency;
|
target_frequency_ = initial_target_frequency;
|
||||||
|
|
|
@ -75,32 +75,6 @@ void ERTRecentEntry::update(const ert::Packet& packet) {
|
||||||
|
|
||||||
namespace ui {
|
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<>
|
template<>
|
||||||
void RecentEntriesView<ERTRecentEntries>::draw(
|
void RecentEntriesView<ERTRecentEntries>::draw(
|
||||||
const Entry& entry,
|
const Entry& entry,
|
||||||
|
@ -134,6 +108,14 @@ ERTAppView::ERTAppView(NavigationView&) {
|
||||||
&recent_entries_view,
|
&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({
|
radio::enable({
|
||||||
initial_target_frequency,
|
initial_target_frequency,
|
||||||
sampling_rate,
|
sampling_rate,
|
||||||
|
|
|
@ -118,6 +118,8 @@ private:
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
|
using RecentEntriesColumn = std::pair<std::string, size_t>;
|
||||||
|
|
||||||
template<class Entries>
|
template<class Entries>
|
||||||
class RecentEntriesView : public View {
|
class RecentEntriesView : public View {
|
||||||
public:
|
public:
|
||||||
|
@ -132,6 +134,16 @@ public:
|
||||||
set_focusable(true);
|
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 {
|
void paint(Painter& painter) override {
|
||||||
const auto r = screen_rect();
|
const auto r = screen_rect();
|
||||||
const auto& s = style();
|
const auto& s = style();
|
||||||
|
@ -192,6 +204,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Entries& recent;
|
Entries& recent;
|
||||||
|
std::vector<std::pair<std::string, size_t>> _columns;
|
||||||
|
|
||||||
using EntryKey = typename Entry::Key;
|
using EntryKey = typename Entry::Key;
|
||||||
EntryKey selected_key = Entry::invalid_key;
|
EntryKey selected_key = Entry::invalid_key;
|
||||||
|
@ -226,7 +239,19 @@ private:
|
||||||
const Rect& target_rect,
|
const Rect& target_rect,
|
||||||
Painter& painter,
|
Painter& painter,
|
||||||
const Style& style
|
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(
|
void draw(
|
||||||
const Entry& entry,
|
const Entry& entry,
|
||||||
|
|
|
@ -95,34 +95,6 @@ void TPMSRecentEntry::update(const tpms::Reading& reading) {
|
||||||
|
|
||||||
namespace ui {
|
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<>
|
template<>
|
||||||
void RecentEntriesView<TPMSRecentEntries>::draw(
|
void RecentEntriesView<TPMSRecentEntries>::draw(
|
||||||
const Entry& entry,
|
const Entry& entry,
|
||||||
|
@ -176,6 +148,16 @@ TPMSAppView::TPMSAppView(NavigationView&) {
|
||||||
&recent_entries_view,
|
&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({
|
radio::enable({
|
||||||
tuning_frequency(),
|
tuning_frequency(),
|
||||||
sampling_rate,
|
sampling_rate,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue