diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index a92312b5..d9f7a107 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -40,14 +40,29 @@ namespace ui { SystemStatusView::SystemStatusView() { add_children({ { + &button_back, &portapack, &sd_card_status_view, } }); sd_card_status_view.set_parent_rect({ 28 * 8, 0 * 16, 2 * 8, 1 * 16 }); + + button_back.on_select = [this](Button&){ + if( this->on_back ) { + this->on_back(); + } + }; +} + +void SystemStatusView::set_back_visible(bool new_value) { + button_back.hidden(!new_value); } /* Navigation ************************************************************/ +bool NavigationView::is_top() const { + return view_stack.size() == 1; +} + View* NavigationView::push_view(std::unique_ptr new_view) { free_view(); @@ -80,6 +95,10 @@ void NavigationView::update_view() { new_view->set_parent_rect({ {0, 0}, size() }); focus(); set_dirty(); + + if( on_view_changed ) { + on_view_changed(); + } } Widget* NavigationView::view() const { @@ -148,12 +167,18 @@ SystemView::SystemView( { 0, 0 }, { parent_rect.width(), status_view_height } }); + status_view.on_back = [this]() { + this->navigation_view.pop(); + }; add_child(&navigation_view); navigation_view.set_parent_rect({ { 0, status_view_height }, { parent_rect.width(), static_cast(parent_rect.height() - status_view_height) } }); + navigation_view.on_view_changed = [this]() { + this->status_view.set_back_visible(!this->navigation_view.is_top()); + }; // Initial view. // TODO: Restore from non-volatile memory? diff --git a/firmware/application/ui_navigation.hpp b/firmware/application/ui_navigation.hpp index ca15b11d..01ff26b6 100644 --- a/firmware/application/ui_navigation.hpp +++ b/firmware/application/ui_navigation.hpp @@ -39,11 +39,20 @@ namespace ui { class SystemStatusView : public View { public: + std::function on_back; + SystemStatusView(); + void set_back_visible(bool new_value); + private: + Button button_back { + { 0 * 8, 0 * 16, 3 * 8, 16 }, + " < ", + }; + Text portapack { - { 0, 0, 9 * 8, 1 * 16 }, + { 3 * 8, 0, 9 * 8, 1 * 16 }, "PortaPack", }; @@ -52,11 +61,15 @@ private: class NavigationView : public View { public: + std::function on_view_changed; + NavigationView() { } NavigationView(const NavigationView&) = delete; NavigationView(NavigationView&&) = delete; + bool is_top() const; + template T* push(Args&&... args) { return reinterpret_cast(push_view(std::unique_ptr(new T(*this, std::forward(args)...)))); diff --git a/firmware/application/ui_receiver.cpp b/firmware/application/ui_receiver.cpp index a5f59584..d4996dba 100644 --- a/firmware/application/ui_receiver.cpp +++ b/firmware/application/ui_receiver.cpp @@ -369,7 +369,6 @@ ReceiverView::ReceiverView( &rssi, &channel, &audio, - &button_done, &field_frequency, &field_lna, //&options_baseband_bandwidth, @@ -381,10 +380,6 @@ ReceiverView::ReceiverView( &view_rf_gain_options, } }); - button_done.on_select = [&nav](Button&){ - nav.pop(); - }; - field_frequency.set_value(receiver_model.tuning_frequency()); field_frequency.set_step(receiver_model.frequency_step()); field_frequency.on_change = [this](rf::Frequency f) { @@ -480,7 +475,7 @@ void ReceiverView::on_hide() { } void ReceiverView::focus() { - button_done.focus(); + field_frequency.focus(); } void ReceiverView::on_tuning_frequency_changed(rf::Frequency f) { diff --git a/firmware/application/ui_receiver.hpp b/firmware/application/ui_receiver.hpp index 131d26e4..51511828 100644 --- a/firmware/application/ui_receiver.hpp +++ b/firmware/application/ui_receiver.hpp @@ -375,11 +375,6 @@ private: { 19 * 8, 10, 11 * 8, 4 }, }; - Button button_done { - { 0 * 8, 0 * 16, 3 * 8, 16 }, - " < ", - }; - FrequencyField field_frequency { { 0 * 8, 1 * 16 }, };