mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-03-20 13:46:28 -04:00
Use std::unique_ptr inside NavigationView.
This commit is contained in:
parent
18c4672ba2
commit
969d9bd070
@ -48,12 +48,15 @@ NavigationView::NavigationView()
|
||||
{
|
||||
}
|
||||
|
||||
void NavigationView::push_view(View* new_view) {
|
||||
View* NavigationView::push_view(std::unique_ptr<View> new_view) {
|
||||
free_view();
|
||||
|
||||
view_stack.push_back(new_view);
|
||||
const auto p = new_view.get();
|
||||
view_stack.emplace_back(std::move(new_view));
|
||||
|
||||
update_view();
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void NavigationView::pop() {
|
||||
@ -61,7 +64,6 @@ void NavigationView::pop() {
|
||||
if( view_stack.size() > 1 ) {
|
||||
free_view();
|
||||
|
||||
delete view_stack.back();
|
||||
view_stack.pop_back();
|
||||
|
||||
update_view();
|
||||
@ -73,7 +75,7 @@ void NavigationView::free_view() {
|
||||
}
|
||||
|
||||
void NavigationView::update_view() {
|
||||
const auto new_view = view_stack.back();
|
||||
const auto new_view = view_stack.back().get();
|
||||
add_child(new_view);
|
||||
new_view->set_parent_rect({ {0, 0}, size() });
|
||||
focus();
|
||||
|
@ -59,9 +59,7 @@ public:
|
||||
|
||||
template<class T, class... Args>
|
||||
T* push(Args&&... args) {
|
||||
const auto new_view = new T(std::forward<Args>(args)...);
|
||||
push_view(new_view);
|
||||
return reinterpret_cast<T*>(new_view);
|
||||
return reinterpret_cast<T*>(push_view(std::unique_ptr<View>(new T(std::forward<Args>(args)...))));
|
||||
}
|
||||
|
||||
void pop();
|
||||
@ -69,13 +67,13 @@ public:
|
||||
void focus() override;
|
||||
|
||||
private:
|
||||
std::vector<View*> view_stack;
|
||||
std::vector<std::unique_ptr<View>> view_stack;
|
||||
|
||||
Widget* view() const;
|
||||
|
||||
void free_view();
|
||||
void update_view();
|
||||
void push_view(View* new_view);
|
||||
View* push_view(std::unique_ptr<View> new_view);
|
||||
};
|
||||
|
||||
class SystemMenuView : public MenuView {
|
||||
|
Loading…
x
Reference in New Issue
Block a user