Move nav back button outside of ReceiverView.

This commit is contained in:
Jared Boone 2016-01-25 11:13:19 -08:00
parent 029a44e24c
commit 15800eea33
4 changed files with 40 additions and 12 deletions

View File

@ -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<View> 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<ui::Dim>(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?

View File

@ -39,11 +39,20 @@ namespace ui {
class SystemStatusView : public View {
public:
std::function<void(void)> 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<void(void)> on_view_changed;
NavigationView() { }
NavigationView(const NavigationView&) = delete;
NavigationView(NavigationView&&) = delete;
bool is_top() const;
template<class T, class... Args>
T* push(Args&&... args) {
return reinterpret_cast<T*>(push_view(std::unique_ptr<View>(new T(*this, std::forward<Args>(args)...))));

View File

@ -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) {

View File

@ -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 },
};