mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04: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) {
|
||||
// TODO: Trap nullptr?
|
||||
// TODO: Trap push of object already on stack?
|
||||
free_view();
|
||||
|
||||
view_stack.push_back(new_view);
|
||||
set_view(new_view);
|
||||
|
||||
update_view();
|
||||
}
|
||||
|
||||
void NavigationView::pop() {
|
||||
// Can't pop last item from stack.
|
||||
if( view_stack.size() > 1 ) {
|
||||
const auto old_view = view_stack.back();
|
||||
free_view();
|
||||
|
||||
delete view_stack.back();
|
||||
view_stack.pop_back();
|
||||
const auto new_view = view_stack.back();
|
||||
set_view(new_view);
|
||||
delete old_view;
|
||||
|
||||
update_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 {
|
||||
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() {
|
||||
if( view() ) {
|
||||
view()->focus();
|
||||
|
@ -72,8 +72,9 @@ private:
|
||||
std::vector<View*> view_stack;
|
||||
|
||||
Widget* view() const;
|
||||
void set_view(Widget* const new_view);
|
||||
|
||||
void free_view();
|
||||
void update_view();
|
||||
void push_view(View* new_view);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user