]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/entry.cpp
Refactor child positioning logic
[libs/gltk.git] / source / entry.cpp
index 44a169aad7f60283188bc84a3c82c92d2ad56bb8..cee23b02372904317419fc294a17f783fa457589 100644 (file)
@@ -47,22 +47,7 @@ void Entry::autosize_special(const Part &part, Geometry &ageom) const
                        ageom.h = max(ageom.h, line_height+margin.top+margin.bottom);
        }
        else if(part.get_name()=="slider" && multiline)
-       {
-               Geometry sgeom = part.get_geometry();
-               if(!sgeom.w || !sgeom.h)
-               {
-                       Geometry wgeom;
-                       slider->autosize(wgeom);
-                       if(!sgeom.w)
-                               sgeom.w = wgeom.w;
-                       if(!sgeom.h)
-                               sgeom.h = wgeom.h;
-               }
-
-               const Sides &margin = part.get_margin();
-               ageom.w = max(ageom.w, sgeom.w+margin.left+margin.right);
-               ageom.h = max(ageom.h, sgeom.h+margin.top+margin.bottom);
-       }
+               autosize_child(*slider, part, ageom);
 }
 
 void Entry::set_text(const string &t)
@@ -94,7 +79,7 @@ void Entry::set_multiline(bool m)
                        add(*slider);
                        slider->set_step(1);
                        slider->signal_value_changed.connect(sigc::mem_fun(this, &Entry::slider_value_changed));
-                       reposition_slider();
+                       rebuild();
                }
                check_view_range();
        }
@@ -122,6 +107,14 @@ void Entry::rebuild_special(const Part &part)
                bld.matrix() *= GL::Matrix::translation(rgeom.x, rgeom.y, 0);
                graphic->build(part.get_geometry().w, part.get_geometry().h, bld);
        }
+       else if(part.get_name()=="slider")
+       {
+               if(multiline)
+               {
+                       reposition_child(*slider, part);
+                       Widget::rebuild_special(part);
+               }
+       }
        else
                Widget::rebuild_special(part);
 }
@@ -197,8 +190,6 @@ void Entry::focus_out()
 
 void Entry::on_geometry_change()
 {
-       reposition_slider();
-
        if(multiline)
                check_view_range();
 }
@@ -215,8 +206,6 @@ void Entry::on_style_change()
 
        text_part = style->get_part("text");
 
-       reposition_slider();
-
        if(multiline)
                check_view_range();
 }
@@ -228,29 +217,6 @@ void Entry::set_edit_position(unsigned ep)
        rebuild();
 }
 
-void Entry::reposition_slider()
-{
-       if(!style || !slider)
-               return;
-
-       if(const Part *slider_part = style->get_part("slider"))
-       {
-               Geometry sgeom = slider_part->get_geometry();
-               if(!sgeom.w || !sgeom.h)
-               {
-                       Geometry wgeom;
-                       slider->autosize(wgeom);
-                       if(!sgeom.w)
-                               sgeom.w = wgeom.w;
-                       if(!sgeom.h)
-                               sgeom.h = wgeom.h;
-               }
-
-               slider_part->get_alignment().apply(sgeom, geom, slider_part->get_margin());
-               slider->set_geometry(sgeom);
-       }
-}
-
 void Entry::check_view_range()
 {
        if(!multiline || !text_part)