mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-01-13 14:23:37 +00:00
Clean up navigation stack alloc/delete sequence.
This commit is contained in:
parent
97f29f8336
commit
18c4672ba2
@ -49,43 +49,41 @@ NavigationView::NavigationView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NavigationView::push_view(View* new_view) {
|
void NavigationView::push_view(View* new_view) {
|
||||||
// TODO: Trap nullptr?
|
free_view();
|
||||||
// TODO: Trap push of object already on stack?
|
|
||||||
view_stack.push_back(new_view);
|
view_stack.push_back(new_view);
|
||||||
set_view(new_view);
|
|
||||||
|
update_view();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationView::pop() {
|
void NavigationView::pop() {
|
||||||
// Can't pop last item from stack.
|
// Can't pop last item from stack.
|
||||||
if( view_stack.size() > 1 ) {
|
if( view_stack.size() > 1 ) {
|
||||||
const auto old_view = view_stack.back();
|
free_view();
|
||||||
|
|
||||||
|
delete view_stack.back();
|
||||||
view_stack.pop_back();
|
view_stack.pop_back();
|
||||||
const auto new_view = view_stack.back();
|
|
||||||
set_view(new_view);
|
update_view();
|
||||||
delete old_view;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NavigationView::free_view() {
|
||||||
|
remove_child(view());
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigationView::update_view() {
|
||||||
|
const auto new_view = view_stack.back();
|
||||||
|
add_child(new_view);
|
||||||
|
new_view->set_parent_rect({ {0, 0}, size() });
|
||||||
|
focus();
|
||||||
|
set_dirty();
|
||||||
|
}
|
||||||
|
|
||||||
Widget* NavigationView::view() const {
|
Widget* NavigationView::view() const {
|
||||||
return children_.empty() ? nullptr : children_[0];
|
return children_.empty() ? nullptr : children_[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationView::set_view(Widget* const new_view) {
|
|
||||||
const auto old_view = view();
|
|
||||||
if( old_view ) {
|
|
||||||
remove_child(old_view);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Allow new_view == nullptr?!
|
|
||||||
if( new_view ) {
|
|
||||||
add_child(new_view);
|
|
||||||
new_view->set_parent_rect({ {0, 0}, size() });
|
|
||||||
focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
set_dirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NavigationView::focus() {
|
void NavigationView::focus() {
|
||||||
if( view() ) {
|
if( view() ) {
|
||||||
view()->focus();
|
view()->focus();
|
||||||
|
@ -72,8 +72,9 @@ private:
|
|||||||
std::vector<View*> view_stack;
|
std::vector<View*> view_stack;
|
||||||
|
|
||||||
Widget* view() const;
|
Widget* view() const;
|
||||||
void set_view(Widget* const new_view);
|
|
||||||
|
|
||||||
|
void free_view();
|
||||||
|
void update_view();
|
||||||
void push_view(View* new_view);
|
void push_view(View* new_view);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user