mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-07-31 02:29:38 -04:00
Use std::unique_ptr inside NavigationView.
This commit is contained in:
parent
18c4672ba2
commit
969d9bd070
2 changed files with 9 additions and 9 deletions
|
@ -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();
|
free_view();
|
||||||
|
|
||||||
view_stack.push_back(new_view);
|
const auto p = new_view.get();
|
||||||
|
view_stack.emplace_back(std::move(new_view));
|
||||||
|
|
||||||
update_view();
|
update_view();
|
||||||
|
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationView::pop() {
|
void NavigationView::pop() {
|
||||||
|
@ -61,7 +64,6 @@ void NavigationView::pop() {
|
||||||
if( view_stack.size() > 1 ) {
|
if( view_stack.size() > 1 ) {
|
||||||
free_view();
|
free_view();
|
||||||
|
|
||||||
delete view_stack.back();
|
|
||||||
view_stack.pop_back();
|
view_stack.pop_back();
|
||||||
|
|
||||||
update_view();
|
update_view();
|
||||||
|
@ -73,7 +75,7 @@ void NavigationView::free_view() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationView::update_view() {
|
void NavigationView::update_view() {
|
||||||
const auto new_view = view_stack.back();
|
const auto new_view = view_stack.back().get();
|
||||||
add_child(new_view);
|
add_child(new_view);
|
||||||
new_view->set_parent_rect({ {0, 0}, size() });
|
new_view->set_parent_rect({ {0, 0}, size() });
|
||||||
focus();
|
focus();
|
||||||
|
|
|
@ -59,9 +59,7 @@ public:
|
||||||
|
|
||||||
template<class T, class... Args>
|
template<class T, class... Args>
|
||||||
T* push(Args&&... args) {
|
T* push(Args&&... args) {
|
||||||
const auto new_view = new T(std::forward<Args>(args)...);
|
return reinterpret_cast<T*>(push_view(std::unique_ptr<View>(new T(std::forward<Args>(args)...))));
|
||||||
push_view(new_view);
|
|
||||||
return reinterpret_cast<T*>(new_view);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop();
|
void pop();
|
||||||
|
@ -69,13 +67,13 @@ public:
|
||||||
void focus() override;
|
void focus() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<View*> view_stack;
|
std::vector<std::unique_ptr<View>> view_stack;
|
||||||
|
|
||||||
Widget* view() const;
|
Widget* view() const;
|
||||||
|
|
||||||
void free_view();
|
void free_view();
|
||||||
void update_view();
|
void update_view();
|
||||||
void push_view(View* new_view);
|
View* push_view(std::unique_ptr<View> new_view);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SystemMenuView : public MenuView {
|
class SystemMenuView : public MenuView {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue