mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2024-12-13 11:44:31 +00:00
Centralize handling of modal error display.
This commit is contained in:
parent
682a1706a3
commit
6a3cd4c144
@ -140,7 +140,7 @@ AnalogAudioView::AnalogAudioView(
|
||||
};
|
||||
|
||||
record_view.on_error = [&nav](std::string message) {
|
||||
nav.push<ModalMessageView>(message);
|
||||
nav.display_error(message);
|
||||
};
|
||||
|
||||
audio::output::start();
|
||||
|
@ -71,7 +71,7 @@ CaptureAppView::CaptureAppView(NavigationView& nav) {
|
||||
|
||||
record_view.set_sampling_rate(sampling_rate / 8);
|
||||
record_view.on_error = [&nav](std::string message) {
|
||||
nav.push<ModalMessageView>(message);
|
||||
nav.display_error(message);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -117,6 +117,10 @@ View* NavigationView::push_view(std::unique_ptr<View> new_view) {
|
||||
}
|
||||
|
||||
void NavigationView::pop() {
|
||||
if( view() == modal_view ) {
|
||||
modal_view = nullptr;
|
||||
}
|
||||
|
||||
// Can't pop last item from stack.
|
||||
if( view_stack.size() > 1 ) {
|
||||
free_view();
|
||||
@ -127,6 +131,13 @@ void NavigationView::pop() {
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationView::display_error(const std::string& message) {
|
||||
/* If a modal view is already visible, don't display another */
|
||||
if( !modal_view ) {
|
||||
modal_view = push<ModalMessageView>(message);
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationView::free_view() {
|
||||
remove_child(view());
|
||||
}
|
||||
|
@ -102,10 +102,13 @@ public:
|
||||
|
||||
void pop();
|
||||
|
||||
void display_error(const std::string& message);
|
||||
|
||||
void focus() override;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<View>> view_stack;
|
||||
Widget* modal_view { nullptr };
|
||||
|
||||
Widget* view() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user