]> git.tdb.fi Git - libs/gltk.git/commitdiff
Support widget expansion in linear layouts
authorMikko Rasa <tdb@tdb.fi>
Sun, 16 Jun 2013 12:03:48 +0000 (15:03 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 16 Jun 2013 12:03:48 +0000 (15:03 +0300)
source/arrangement.cpp
source/arrangement.h
source/lineararrangement.cpp
source/lineararrangement.h

index 581e6b405ccf9da2bbeea1f94401ab04bb185c01..9982691e4cb0a81a3fdedb6c891739ce1a198701 100644 (file)
@@ -45,7 +45,8 @@ void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, Side
 void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, const Edge &edge)
 {
        for(list<Widget *>::const_iterator i=edge.widgets.begin(); i!=edge.widgets.end(); ++i)
-               layout.add_constraint(wdg, type, **i);
+               if(*i!=&wdg)
+                       layout.add_constraint(wdg, type, **i);
 }
 
 Layout::ConstraintType Arrangement::get_order_constraint(Side s, bool slack)
@@ -95,5 +96,17 @@ void Arrangement::Edge::add(Widget &wdg, bool algn)
        aligned = algn;
 }
 
+void Arrangement::Edge::align()
+{
+       if(aligned || widgets.empty())
+               return;
+
+       list<Widget *>::iterator second = widgets.begin();
+       ++second;
+
+       widgets.erase(second, widgets.end());
+       aligned = true;
+}
+
 } // namespace GLtk
 } // namespace Msp
index fc3ec8226cfed99c59b6676ee3834797fb273409..f323a9b232da37389f4285de968380fe427f8e54 100644 (file)
@@ -38,6 +38,7 @@ protected:
                bool empty() { return widgets.empty(); }
                void clear();
                void add(Widget &, bool);
+               void align();
        };
 
        Layout &layout;
index 891b858115f016b73900423d69b85a75df382e06..9e6441afaa8c72a3cdad8720f56ca0103186b20d 100644 (file)
@@ -21,6 +21,19 @@ void LinearArrangement::split()
        gravity = primary;
 }
 
+void LinearArrangement::expand()
+{
+       if(gravity==primary)
+               throw arrangement_error("already split");
+       if(edges[primary].empty())
+               throw arrangement_error("no widgets");
+
+       add_constraint(*edges[primary].widgets.front(), get_align_constraint(primary), primary);
+       layout.set_expand(*edges[primary].widgets.front(), false, true);
+       edges[primary].align();
+       gravity = primary;
+}
+
 void LinearArrangement::process_widget(Widget &wdg, Side side, bool aligned)
 {
        if(side==opposite)
@@ -52,9 +65,15 @@ void LinearArrangement::finish_slot()
 LinearArrangement::Loader::Loader(LinearArrangement &c):
        DataFile::ObjectLoader<LinearArrangement>(c)
 {
+       add("expand", &Loader::expand);
        add("split", &Loader::split);
 }
 
+void LinearArrangement::Loader::expand()
+{
+       obj.expand();
+}
+
 void LinearArrangement::Loader::split()
 {
        obj.split();
index 571e279af3cccc4093736dab6e994d48cae585da..3fd5ef770623c2db2d5004ab9e5ffe6f245ba665 100644 (file)
@@ -15,6 +15,7 @@ public:
        public:
                Loader(LinearArrangement &);
        private:
+               void expand();
                void split();
        };