]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/panel.cpp
Use std::unique_ptr for managing memory
[libs/gltk.git] / source / panel.cpp
index 56aa2dcb5545003fd3feb2975be9fd451bc029ac..d4e737bee7de6e9b48ef459b02f35f111a8e453f 100644 (file)
@@ -1,6 +1,5 @@
 #include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
-#include <msp/core/refptr.h>
 #include "button.h"
 #include "column.h"
 #include "draghandle.h"
@@ -32,17 +31,11 @@ Panel::Panel()
        input_type = INPUT_NAVIGATION;
 }
 
-Panel::~Panel()
-{
-       delete layout;
-       layout = nullptr;
-}
-
 Layout &Panel::get_or_create_layout()
 {
        if(!layout)
        {
-               layout = new Layout;
+               layout = make_unique<Layout>();
                layout->set_container(*this);
        }
 
@@ -59,7 +52,7 @@ void Panel::render_special(const Part &part, GL::Renderer &renderer) const
 {
        if(part.get_name()=="children")
        {
-               for(const Child *c: children)
+               for(const unique_ptr<Child> &c: children)
                        if(c->widget->is_visible())
                                c->widget->render(renderer);
        }
@@ -140,7 +133,7 @@ Widget *Panel::find_next_child(int origin_x, int origin_y, int origin_dim, int n
 {
        Widget *sibling = nullptr;
        int best_score = 0;
-       for(const Child *c: children)
+       for(const unique_ptr<Child> &c: children)
        {
                if(c->widget==input_focus || !c->widget->is_focusable())
                        continue;
@@ -300,7 +293,7 @@ void Panel::Loader::layout()
 template<>
 void Panel::Loader::unnamed_child<Panel>()
 {
-       RefPtr<Panel> pnl = new Panel();
+       unique_ptr<Panel> pnl = make_unique<Panel>();
        load_sub(*pnl, wdg_map);
        obj.add(*pnl.get());
        last_widget = pnl.release();