X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpanel.cpp;h=56aa2dcb5545003fd3feb2975be9fd451bc029ac;hb=90d5f5f2ebaeb8aaa4aa47a0c2207f96758cba8c;hp=97e13a2591b34dd9107f2dd65c22baa86750f676;hpb=cfb830ca263defc307f9cfac74fb6771f6b7bfc6;p=libs%2Fgltk.git diff --git a/source/panel.cpp b/source/panel.cpp index 97e13a2..56aa2dc 100644 --- a/source/panel.cpp +++ b/source/panel.cpp @@ -7,25 +7,27 @@ #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; } @@ -33,14 +35,18 @@ Panel::Panel(): Panel::~Panel() { delete layout; - layout = 0; + layout = nullptr; } -void Panel::set_layout(Layout *l) +Layout &Panel::get_or_create_layout() { - l->set_container(*this); - delete layout; - layout = l; + if(!layout) + { + layout = new Layout; + layout->set_container(*this); + } + + return *layout; } void Panel::autosize_special(const Part &part, Geometry &ageom) const @@ -53,9 +59,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 Child *c: children) + if(c->widget->is_visible()) + c->widget->render(renderer); } } @@ -106,7 +112,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 +138,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 Child *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 +157,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 +179,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 +199,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 +214,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