]> git.tdb.fi Git - libs/gltk.git/commitdiff
Allow overriding the spacing between two widgets in LinearArrangement
authorMikko Rasa <tdb@tdb.fi>
Sat, 26 Nov 2016 11:39:26 +0000 (13:39 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 26 Nov 2016 11:39:26 +0000 (13:39 +0200)
source/arrangement.cpp
source/arrangement.h
source/lineararrangement.cpp
source/lineararrangement.h

index 9982691e4cb0a81a3fdedb6c891739ce1a198701..5eeebbb99abe8df310fca5720df8f1ff7d3233d3 100644 (file)
@@ -37,16 +37,21 @@ void Arrangement::arrange(Arrangement &arr)
        finish_slot();
 }
 
-void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, Side side)
+void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, Side side, int spacing)
 {
-       add_constraint(wdg, type, edges[side]);
+       add_constraint(wdg, type, edges[side], spacing);
 }
 
-void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, const Edge &edge)
+void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, const Edge &edge, int spacing)
 {
        for(list<Widget *>::const_iterator i=edge.widgets.begin(); i!=edge.widgets.end(); ++i)
                if(*i!=&wdg)
-                       layout.add_constraint(wdg, type, **i);
+               {
+                       if(spacing<0)
+                               layout.add_constraint(wdg, type, **i);
+                       else
+                               layout.add_constraint(wdg, type, **i, spacing);
+               }
 }
 
 Layout::ConstraintType Arrangement::get_order_constraint(Side s, bool slack)
index f323a9b232da37389f4285de968380fe427f8e54..7028aed4ecfd868b0ccfedb56e58194094179e02 100644 (file)
@@ -57,8 +57,8 @@ protected:
        virtual void finish_widget(Widget &) = 0;
        virtual void finish_slot() = 0;
        const Edge &get_edge(Side s) const { return edges[s]; }
-       void add_constraint(Widget &, Layout::ConstraintType, Side);
-       void add_constraint(Widget &, Layout::ConstraintType, const Edge &);
+       void add_constraint(Widget &, Layout::ConstraintType, Side, int = -1);
+       void add_constraint(Widget &, Layout::ConstraintType, const Edge &, int = -1);
 
        static Layout::ConstraintType get_order_constraint(Side, bool);
        static Layout::ConstraintType get_align_constraint(Side);
index 6148be3b38ce4313bb4cb19073dbf958b3a413a6..fb2e71c180dac87aa81c41ec3fce0d6c80b06a4b 100644 (file)
@@ -10,7 +10,8 @@ LinearArrangement::LinearArrangement(Layout &l, Side p):
        first(true),
        split_here(false),
        gravity(opposite),
-       internal_aligned(false)
+       internal_aligned(false),
+       next_spacing(-1)
 { }
 
 void LinearArrangement::split()
@@ -35,12 +36,17 @@ void LinearArrangement::expand()
        gravity = primary;
 }
 
+void LinearArrangement::spacing(unsigned s)
+{
+       next_spacing = s;
+}
+
 void LinearArrangement::process_widget(Widget &wdg, Side side, bool aligned)
 {
        if(side==opposite)
        {
                bool snug = (internal_aligned && aligned && !split_here);
-               add_constraint(wdg, get_order_constraint(primary, !snug), primary);
+               add_constraint(wdg, get_order_constraint(primary, !snug), primary, next_spacing);
                if(first)
                        edges[side].add(wdg, (aligned && gravity==opposite));
        }
@@ -63,6 +69,7 @@ void LinearArrangement::finish_slot()
        next.clear();
        split_here = false;
        first = false;
+       next_spacing = -1;
 }
 
 
@@ -70,6 +77,7 @@ LinearArrangement::Loader::Loader(LinearArrangement &c):
        DataFile::ObjectLoader<LinearArrangement>(c)
 {
        add("expand", &Loader::expand);
+       add("spacing", &Loader::spacing);
        add("split", &Loader::split);
 }
 
@@ -78,6 +86,11 @@ void LinearArrangement::Loader::expand()
        obj.expand();
 }
 
+void LinearArrangement::Loader::spacing(unsigned s)
+{
+       obj.spacing(s);
+}
+
 void LinearArrangement::Loader::split()
 {
        obj.split();
index a18c849fcafacf210a5381e2e0ce90f98ca89e42..4b149a4ad2d7284901dea33d995f361ae78cf985 100644 (file)
@@ -16,6 +16,7 @@ public:
                Loader(LinearArrangement &);
        private:
                void expand();
+               void spacing(unsigned);
                void split();
        };
 
@@ -27,12 +28,14 @@ protected:
        bool split_here;
        Side gravity;
        bool internal_aligned;
+       int next_spacing;
 
        LinearArrangement(Layout &, Side);
 
 public:
        void split();
        void expand();
+       void spacing(unsigned);
 
 protected:
        virtual void process_widget(Widget &, Side, bool);