X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpanel.cpp;h=ba66c682e85decb9608c084caeaaa6b5763c0318;hb=HEAD;hp=97e13a2591b34dd9107f2dd65c22baa86750f676;hpb=cfb830ca263defc307f9cfac74fb6771f6b7bfc6;p=libs%2Fgltk.git diff --git a/source/panel.cpp b/source/panel.cpp index 97e13a2..ba66c68 100644 --- a/source/panel.cpp +++ b/source/panel.cpp @@ -1,46 +1,45 @@ #include #include -#include #include "button.h" #include "column.h" #include "draghandle.h" #include "dropdown.h" #include "entry.h" #include "grid.h" -#include "hslider.h" #include "image.h" #include "indicator.h" #include "label.h" #include "list.h" #include "panel.h" #include "part.h" +#include "progressbar.h" #include "row.h" +#include "slider.h" #include "stack.h" #include "toggle.h" -#include "vslider.h" using namespace std; namespace Msp { namespace GLtk { -Panel::Panel(): - layout(0) +TypeRegistry Panel::widget_registry; +bool Panel::widget_registry_init_done = false; + +Panel::Panel() { input_type = INPUT_NAVIGATION; } -Panel::~Panel() +Layout &Panel::get_or_create_layout() { - delete layout; - layout = 0; -} + if(!layout) + { + layout = make_unique(); + layout->set_container(*this); + } -void Panel::set_layout(Layout *l) -{ - l->set_container(*this); - delete layout; - layout = l; + return *layout; } void Panel::autosize_special(const Part &part, Geometry &ageom) const @@ -53,9 +52,9 @@ void Panel::render_special(const Part &part, GL::Renderer &renderer) const { if(part.get_name()=="children") { - for(list::const_iterator i=children.begin(); i!=children.end(); ++i) - if((*i)->widget->is_visible()) - (*i)->widget->render(renderer); + for(const unique_ptr &c: children) + if(c->widget->is_visible()) + c->widget->render(renderer); } } @@ -106,7 +105,7 @@ bool Panel::navigate(Navigation nav) } else if(nav==NAV_NEXT || nav==NAV_PREVIOUS) { - vector::iterator i = find(nav_order, input_focus); + auto i = find(nav_order, input_focus); if(nav==NAV_NEXT) { @@ -132,14 +131,14 @@ bool Panel::navigate(Navigation nav) Widget *Panel::find_next_child(int origin_x, int origin_y, int origin_dim, int nav_x, int nav_y) const { - Widget *sibling = 0; + Widget *sibling = nullptr; int best_score = 0; - for(list::const_iterator i=children.begin(); i!=children.end(); ++i) + for(const unique_ptr &c: children) { - if((*i)->widget==input_focus || !(*i)->widget->is_focusable()) + if(c->widget==input_focus || !c->widget->is_focusable()) continue; - const Geometry &cgeom = (*i)->widget->get_geometry(); + const Geometry &cgeom = c->widget->get_geometry(); int dx = compute_delta(cgeom.x, cgeom.w, origin_x, origin_dim, nav_x); int dy = compute_delta(cgeom.y, cgeom.h, origin_y, origin_dim, nav_y); @@ -151,7 +150,7 @@ Widget *Panel::find_next_child(int origin_x, int origin_y, int origin_dim, int n if(score>=0 && (!sibling || scorewidget; + sibling = c->widget; best_score = score; } } @@ -173,7 +172,7 @@ int Panel::compute_delta(int pos, int dim, int origin_pos, int origin_dim, int n return 0; } -void Panel::on_geometry_change() +void Panel::on_size_change() { if(layout) layout->update(); @@ -193,7 +192,7 @@ void Panel::on_child_added(Widget &wdg) void Panel::on_child_removed(Widget &wdg) { - vector::iterator i = std::remove(nav_order.begin(), nav_order.end(), &wdg); + auto i = std::remove(nav_order.begin(), nav_order.end(), &wdg); if(i!=nav_order.end()) nav_order.erase(i, nav_order.end()); @@ -208,44 +207,36 @@ void Panel::on_child_removed(Widget &wdg) Panel::Loader::Loader(Panel &p, map &m): DataFile::DerivedObjectLoader(p), wdg_map(m), - last_widget(0) + last_widget(nullptr) { - add_child_type