View::add_children: Use std::list_initializer as argument.

Improvement in code size -- 944 bytes.

Some day I will understand C++11 well enough to do the right thing the first time.
This commit is contained in:
Jared Boone 2016-09-05 14:53:04 -07:00
parent 298324d6e4
commit 8a69b0523e
16 changed files with 57 additions and 55 deletions

View File

@ -204,9 +204,9 @@ void RecentEntriesTable<AISRecentEntries>::draw(
} }
AISRecentEntryDetailView::AISRecentEntryDetailView() { AISRecentEntryDetailView::AISRecentEntryDetailView() {
add_children({ { add_children({
&button_done, &button_done,
} }); });
button_done.on_select = [this](const ui::Button&) { button_done.on_select = [this](const ui::Button&) {
if( this->on_close ) { if( this->on_close ) {
@ -264,7 +264,7 @@ void AISRecentEntryDetailView::set_entry(const AISRecentEntry& entry) {
AISAppView::AISAppView(NavigationView&) { AISAppView::AISAppView(NavigationView&) {
baseband::run_image(portapack::spi_flash::image_tag_ais); baseband::run_image(portapack::spi_flash::image_tag_ais);
add_children({ { add_children({
&label_channel, &label_channel,
&options_channel, &options_channel,
&field_rf_amp, &field_rf_amp,
@ -274,7 +274,7 @@ AISAppView::AISAppView(NavigationView&) {
&channel, &channel,
&recent_entries_view, &recent_entries_view,
&recent_entry_detail_view, &recent_entry_detail_view,
} }); });
recent_entry_detail_view.hidden(true); recent_entry_detail_view.hidden(true);

View File

@ -44,10 +44,10 @@ AMOptionsView::AMOptionsView(
{ {
set_style(style); set_style(style);
add_children({ { add_children({
&label_config, &label_config,
&options_config, &options_config,
} }); });
options_config.set_selected_index(receiver_model.am_configuration()); options_config.set_selected_index(receiver_model.am_configuration());
options_config.on_change = [this](size_t n, OptionsField::value_t) { options_config.on_change = [this](size_t n, OptionsField::value_t) {
@ -63,10 +63,10 @@ NBFMOptionsView::NBFMOptionsView(
{ {
set_style(style); set_style(style);
add_children({ { add_children({
&label_config, &label_config,
&options_config, &options_config,
} }); });
options_config.set_selected_index(receiver_model.nbfm_configuration()); options_config.set_selected_index(receiver_model.nbfm_configuration());
options_config.on_change = [this](size_t n, OptionsField::value_t) { options_config.on_change = [this](size_t n, OptionsField::value_t) {
@ -79,7 +79,7 @@ NBFMOptionsView::NBFMOptionsView(
AnalogAudioView::AnalogAudioView( AnalogAudioView::AnalogAudioView(
NavigationView& nav NavigationView& nav
) { ) {
add_children({ { add_children({
&rssi, &rssi,
&channel, &channel,
&audio, &audio,
@ -90,7 +90,7 @@ AnalogAudioView::AnalogAudioView(
&field_volume, &field_volume,
&record_view, &record_view,
&waterfall, &waterfall,
} }); });
field_frequency.set_value(receiver_model.tuning_frequency()); field_frequency.set_value(receiver_model.tuning_frequency());
field_frequency.set_step(receiver_model.frequency_step()); field_frequency.set_step(receiver_model.frequency_step());

View File

@ -34,7 +34,7 @@ namespace ui {
CaptureAppView::CaptureAppView(NavigationView& nav) { CaptureAppView::CaptureAppView(NavigationView& nav) {
baseband::run_image(portapack::spi_flash::image_tag_capture); baseband::run_image(portapack::spi_flash::image_tag_capture);
add_children({ { add_children({
&rssi, &rssi,
&channel, &channel,
&field_frequency, &field_frequency,
@ -44,7 +44,7 @@ CaptureAppView::CaptureAppView(NavigationView& nav) {
&field_vga, &field_vga,
&record_view, &record_view,
&waterfall, &waterfall,
} }); });
field_frequency.set_value(target_frequency()); field_frequency.set_value(target_frequency());
field_frequency.set_step(receiver_model.frequency_step()); field_frequency.set_step(receiver_model.frequency_step());

View File

@ -97,13 +97,13 @@ void RecentEntriesTable<ERTRecentEntries>::draw(
ERTAppView::ERTAppView(NavigationView&) { ERTAppView::ERTAppView(NavigationView&) {
baseband::run_image(portapack::spi_flash::image_tag_ert); baseband::run_image(portapack::spi_flash::image_tag_ert);
add_children({ { add_children({
&field_rf_amp, &field_rf_amp,
&field_lna, &field_lna,
&field_vga, &field_vga,
&rssi, &rssi,
&recent_entries_view, &recent_entries_view,
} }); });
radio::enable({ radio::enable({
initial_target_frequency, initial_target_frequency,

View File

@ -264,10 +264,10 @@ public:
) : _header { columns }, ) : _header { columns },
_table { recent } _table { recent }
{ {
add_children({ { add_children({
&_header, &_header,
&_table, &_table,
} }); });
_table.on_select = [this](const Entry& entry) { if( this->on_select ) { this->on_select(entry); } }; _table.on_select = [this](const Entry& entry) { if( this->on_select ) { this->on_select(entry); } };
} }

View File

@ -135,7 +135,7 @@ void RecentEntriesTable<TPMSRecentEntries>::draw(
TPMSAppView::TPMSAppView(NavigationView&) { TPMSAppView::TPMSAppView(NavigationView&) {
baseband::run_image(portapack::spi_flash::image_tag_tpms); baseband::run_image(portapack::spi_flash::image_tag_tpms);
add_children({ { add_children({
&rssi, &rssi,
&channel, &channel,
&options_band, &options_band,
@ -143,7 +143,7 @@ TPMSAppView::TPMSAppView(NavigationView&) {
&field_lna, &field_lna,
&field_vga, &field_vga,
&recent_entries_view, &recent_entries_view,
} }); });
radio::enable({ radio::enable({
tuning_frequency(), tuning_frequency(),

View File

@ -34,9 +34,9 @@ namespace ui {
/* BasebandStatsView *****************************************************/ /* BasebandStatsView *****************************************************/
BasebandStatsView::BasebandStatsView() { BasebandStatsView::BasebandStatsView() {
add_children({ { add_children({
&text_stats, &text_stats,
} }); });
} }
static std::string ticks_to_percent_string(const uint32_t ticks) { static std::string ticks_to_percent_string(const uint32_t ticks) {

View File

@ -35,7 +35,7 @@ namespace ui {
/* DebugMemoryView *******************************************************/ /* DebugMemoryView *******************************************************/
DebugMemoryView::DebugMemoryView(NavigationView& nav) { DebugMemoryView::DebugMemoryView(NavigationView& nav) {
add_children({ { add_children({
&text_title, &text_title,
&text_label_m0_core_free, &text_label_m0_core_free,
&text_label_m0_core_free_value, &text_label_m0_core_free_value,
@ -44,7 +44,7 @@ DebugMemoryView::DebugMemoryView(NavigationView& nav) {
&text_label_m0_heap_fragments, &text_label_m0_heap_fragments,
&text_label_m0_heap_fragments_value, &text_label_m0_heap_fragments_value,
&button_done &button_done
} }); });
const auto m0_core_free = chCoreStatus(); const auto m0_core_free = chCoreStatus();
text_label_m0_core_free_value.set(to_string_dec_uint(m0_core_free, 5)); text_label_m0_core_free_value.set(to_string_dec_uint(m0_core_free, 5));
@ -135,11 +135,11 @@ Coord TemperatureWidget::screen_y(
/* TemperatureView *******************************************************/ /* TemperatureView *******************************************************/
TemperatureView::TemperatureView(NavigationView& nav) { TemperatureView::TemperatureView(NavigationView& nav) {
add_children({ { add_children({
&text_title, &text_title,
&temperature_widget, &temperature_widget,
&button_done, &button_done,
} }); });
button_done.on_select = [&nav](Button&){ nav.pop(); }; button_done.on_select = [&nav](Button&){ nav.pop(); };
} }
@ -219,12 +219,12 @@ RegistersView::RegistersView(
std::function<uint32_t(const size_t register_number)>&& reader std::function<uint32_t(const size_t register_number)>&& reader
) : registers_widget { std::move(config), std::move(reader) } ) : registers_widget { std::move(config), std::move(reader) }
{ {
add_children({ { add_children({
&text_title, &text_title,
&registers_widget, &registers_widget,
&button_update, &button_update,
&button_done, &button_done,
} }); });
button_update.on_select = [this](Button&){ button_update.on_select = [this](Button&){
this->registers_widget.update(); this->registers_widget.update();

View File

@ -43,13 +43,13 @@ namespace ui {
/* SystemStatusView ******************************************************/ /* SystemStatusView ******************************************************/
SystemStatusView::SystemStatusView() { SystemStatusView::SystemStatusView() {
add_children({ { add_children({
&button_back, &button_back,
&title, &title,
&button_camera, &button_camera,
&button_sleep, &button_sleep,
&sd_card_status_view, &sd_card_status_view,
} }); });
button_back.on_select = [this](Button&){ button_back.on_select = [this](Button&){
if( this->on_back ) { if( this->on_back ) {
@ -259,7 +259,7 @@ HackRFFirmwareView::HackRFFirmwareView(NavigationView& nav) {
nav.pop(); nav.pop();
}; };
add_children({ { add_children({
&text_title, &text_title,
&text_description_1, &text_description_1,
&text_description_2, &text_description_2,
@ -267,7 +267,7 @@ HackRFFirmwareView::HackRFFirmwareView(NavigationView& nav) {
&text_description_4, &text_description_4,
&button_yes, &button_yes,
&button_no, &button_no,
} }); });
} }
void HackRFFirmwareView::focus() { void HackRFFirmwareView::focus() {
@ -281,10 +281,10 @@ NotImplementedView::NotImplementedView(NavigationView& nav) {
nav.pop(); nav.pop();
}; };
add_children({ { add_children({
&text_title, &text_title,
&button_done, &button_done,
} }); });
} }
void NotImplementedView::focus() { void NotImplementedView::focus() {
@ -303,10 +303,10 @@ ModalMessageView::ModalMessageView(
nav.pop(); nav.pop();
}; };
add_children({ { add_children({
&text_message, &text_message,
&button_done, &button_done,
} }); });
text_message.set(message); text_message.set(message);

View File

@ -241,12 +241,12 @@ FrequencyOptionsView::FrequencyOptionsView(
this->on_reference_ppm_correction_changed(v); this->on_reference_ppm_correction_changed(v);
}; };
add_children({ { add_children({
&text_step, &text_step,
&field_step, &field_step,
&field_ppm, &field_ppm,
&text_ppm, &text_ppm,
} }); });
} }
void FrequencyOptionsView::set_step(rf::Frequency f) { void FrequencyOptionsView::set_step(rf::Frequency f) {
@ -297,10 +297,10 @@ RadioGainOptionsView::RadioGainOptionsView(
{ {
set_style(style); set_style(style);
add_children({ { add_children({
&label_rf_amp, &label_rf_amp,
&field_rf_amp, &field_rf_amp,
} }); });
} }
/* LNAGainField **********************************************************/ /* LNAGainField **********************************************************/

View File

@ -177,13 +177,13 @@ RecordView::RecordView(
write_size { write_size }, write_size { write_size },
buffer_count { buffer_count } buffer_count { buffer_count }
{ {
add_children({ { add_children({
&rect_background, &rect_background,
&button_record, &button_record,
&text_record_filename, &text_record_filename,
&text_record_dropped, &text_record_dropped,
&text_time_available, &text_time_available,
} }); });
rect_background.set_parent_rect({ { 0, 0 }, size() }); rect_background.set_parent_rect({ { 0, 0 }, size() });

View File

@ -230,7 +230,7 @@ Thread* SDCardTestThread::thread { nullptr };
namespace ui { namespace ui {
SDCardDebugView::SDCardDebugView(NavigationView& nav) { SDCardDebugView::SDCardDebugView(NavigationView& nav) {
add_children({ { add_children({
&text_title, &text_title,
&text_csd_title, &text_csd_title,
&text_csd_value_3, &text_csd_value_3,
@ -257,7 +257,7 @@ SDCardDebugView::SDCardDebugView(NavigationView& nav) {
&text_test_read_rate_value, &text_test_read_rate_value,
&button_test, &button_test,
&button_ok, &button_ok,
} }); });
button_test.on_select = [this](Button&){ this->on_test(); }; button_test.on_select = [this](Button&){ this->on_test(); };
button_ok.on_select = [&nav](Button&){ nav.pop(); }; button_ok.on_select = [&nav](Button&){ nav.pop(); };

View File

@ -51,7 +51,7 @@ SetDateTimeView::SetDateTimeView(
nav.pop(); nav.pop();
}, },
add_children({ { add_children({
&text_title, &text_title,
&field_year, &field_year,
&text_slash1, &text_slash1,
@ -66,7 +66,7 @@ SetDateTimeView::SetDateTimeView(
&text_format, &text_format,
&button_ok, &button_ok,
&button_cancel, &button_cancel,
} }); });
rtc::RTC datetime; rtc::RTC datetime;
rtcGetTime(&RTCD1, &datetime); rtcGetTime(&RTCD1, &datetime);
@ -119,13 +119,13 @@ SetFrequencyCorrectionView::SetFrequencyCorrectionView(
nav.pop(); nav.pop();
}, },
add_children({ { add_children({
&text_title, &text_title,
&field_ppm, &field_ppm,
&text_ppm, &text_ppm,
&button_ok, &button_ok,
&button_cancel, &button_cancel,
} }); });
SetFrequencyCorrectionModel model { SetFrequencyCorrectionModel model {
static_cast<int8_t>(portapack::persistent_memory::correction_ppb() / 1000) static_cast<int8_t>(portapack::persistent_memory::correction_ppb() / 1000)
@ -149,7 +149,7 @@ SetFrequencyCorrectionModel SetFrequencyCorrectionView::form_collect() {
} }
AntennaBiasSetupView::AntennaBiasSetupView(NavigationView& nav) { AntennaBiasSetupView::AntennaBiasSetupView(NavigationView& nav) {
add_children({ { add_children({
&text_title, &text_title,
&text_description_1, &text_description_1,
&text_description_2, &text_description_2,
@ -157,7 +157,7 @@ AntennaBiasSetupView::AntennaBiasSetupView(NavigationView& nav) {
&text_description_4, &text_description_4,
&options_bias, &options_bias,
&button_done, &button_done,
} }); });
options_bias.set_by_value(receiver_model.antenna_bias() ? 1 : 0); options_bias.set_by_value(receiver_model.antenna_bias() ? 1 : 0);
options_bias.on_change = [this](size_t, OptionsField::value_t v) { options_bias.on_change = [this](size_t, OptionsField::value_t v) {
@ -172,13 +172,13 @@ void AntennaBiasSetupView::focus() {
} }
AboutView::AboutView(NavigationView& nav) { AboutView::AboutView(NavigationView& nav) {
add_children({ { add_children({
&text_title, &text_title,
&text_firmware, &text_firmware,
&text_cpld_hackrf, &text_cpld_hackrf,
&text_cpld_hackrf_status, &text_cpld_hackrf_status,
&button_ok, &button_ok,
} }); });
button_ok.on_select = [&nav](Button&){ nav.pop(); }; button_ok.on_select = [&nav](Button&){ nav.pop(); };

View File

@ -33,7 +33,7 @@ TouchCalibrationView::TouchCalibrationView(
) : nav { nav }, ) : nav { nav },
calibration { touch::default_calibration() } calibration { touch::default_calibration() }
{ {
add_children({ { add_children({
&image_calibrate_0, &image_calibrate_0,
&image_calibrate_1, &image_calibrate_1,
&image_calibrate_2, &image_calibrate_2,
@ -46,7 +46,7 @@ TouchCalibrationView::TouchCalibrationView(
&label_failure, &label_failure,
&button_cancel, &button_cancel,
&button_ok, &button_ok,
} }); });
button_cancel.on_select = [this](Button&){ this->on_cancel(); }; button_cancel.on_select = [this](Button&){ this->on_cancel(); };
button_ok.on_select = [this](Button&){ this->on_ok(); }; button_ok.on_select = [this](Button&){ this->on_ok(); };

View File

@ -232,9 +232,11 @@ void View::add_child(Widget* const widget) {
} }
} }
void View::add_children(const std::vector<Widget*>& children) { void View::add_children(const std::initializer_list<Widget*> children) {
children_.insert(std::end(children_), children);
for(auto child : children) { for(auto child : children) {
add_child(child); child->set_parent(this);
child->set_dirty();
} }
} }

View File

@ -154,7 +154,7 @@ public:
void paint(Painter& painter) override; void paint(Painter& painter) override;
void add_child(Widget* const widget); void add_child(Widget* const widget);
void add_children(const std::vector<Widget*>& children); void add_children(const std::initializer_list<Widget*> children);
void remove_child(Widget* const widget); void remove_child(Widget* const widget);
const std::vector<Widget*>& children() const override; const std::vector<Widget*>& children() const override;