]> git.tdb.fi Git - libs/gltk.git/commitdiff
Allow specifying a custom spacing for a constraint
authorMikko Rasa <tdb@tdb.fi>
Sat, 15 Dec 2012 18:11:56 +0000 (20:11 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 15 Dec 2012 18:11:56 +0000 (20:11 +0200)
source/layout.cpp
source/layout.h

index bfe46c47f8b1dcd683238532bdd0fc7497185879..d3d015f7305c7ddb70a024c4884ee88cbf3711f2 100644 (file)
@@ -203,7 +203,7 @@ Layout::ConstraintType Layout::complement(ConstraintType type)
                return type;
 }
 
-void Layout::add_constraint(Widget &src, ConstraintType type, Widget &tgt)
+void Layout::create_constraint(Widget &src, ConstraintType type, Widget &tgt, int sp)
 {
        if(&src==&tgt)
                throw invalid_argument("&src==&tgt");
@@ -216,11 +216,23 @@ void Layout::add_constraint(Widget &src, ConstraintType type, Widget &tgt)
                        return;
 
        src_slot.constraints.push_back(Constraint(type, tgt_slot));
+       src_slot.constraints.back().spacing = sp;
        tgt_slot.constraints.push_back(Constraint(complement(type), src_slot));
+       tgt_slot.constraints.back().spacing = sp;
 
        update();
 }
 
+void Layout::add_constraint(Widget &src, ConstraintType type, Widget &tgt)
+{
+       create_constraint(src, type, tgt, -1);
+}
+
+void Layout::add_constraint(Widget &src, ConstraintType type, Widget &tgt, unsigned spacing)
+{
+       create_constraint(src, type, tgt, spacing);
+}
+
 void Layout::set_gravity(Widget &wdg, int h, int v)
 {
        Slot &slot = get_slot_for_widget(wdg);
@@ -339,7 +351,7 @@ void Layout::solve_constraints(int dir, SolveMode mode)
                                if(j->type&TARGET_DIM)
                                        row[j->target.index*5+1] = -1;
                                if(j->type&SPACING)
-                                       row.back() = this->*(ptrs.spacing);
+                                       row.back() = (j->spacing>=0 ? j->spacing : this->*(ptrs.spacing));
                        }
        }
 
@@ -368,7 +380,8 @@ void Layout::solve_constraints(int dir, SolveMode mode)
 
 Layout::Constraint::Constraint(ConstraintType t, Slot &s):
        type(t),
-       target(s)
+       target(s),
+       spacing(-1)
 { }
 
 
index cbd763e9e5337dc7a6395d7d0b3a860c6d9ad7e1..230365182e1d84a881bc363a48487234215fd3a7 100644 (file)
@@ -84,6 +84,7 @@ protected:
        {
                ConstraintType type;
                Slot &target;
+               int spacing;
 
                Constraint(ConstraintType, Slot &);
        };
@@ -147,8 +148,16 @@ protected:
        virtual Slot *create_slot(Widget &);
        Slot &get_slot_for_widget(Widget &);
        static ConstraintType complement(ConstraintType);
+       void create_constraint(Widget &, ConstraintType, Widget &, int);
+
 public:
-       void add_constraint(Widget &, ConstraintType, Widget &);
+       /** Adds a constraint between two widgets. */
+       void add_constraint(Widget &src, ConstraintType type, Widget &tgt);
+
+       /** Adds a constraint between two widgets, overriding the default spacing.
+       Not all constraint types use a spacing. */
+       void add_constraint(Widget &src, ConstraintType type, Widget &tgt, unsigned);
+
        void set_gravity(Widget &, int, int);
        void set_expand(Widget &, bool, bool);