]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/layout.cpp
Don't let input events that are passed to widgets go to other consumers
[libs/gltk.git] / source / layout.cpp
index d5437f0b0a29ed04c1ce000534174fd0d9b9fa12..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);
@@ -304,6 +316,16 @@ void Layout::solve_constraints(int dir, SolveMode mode)
                        row.back() = geom.*(ptrs.dim)-margin.*(ptrs.high_margin);
                }
 
+               if(((*i)->*(ptrs.packing)).gravity==0)
+               {
+                       /* This forces the widget's distance from the left and right edge of
+                       the container to be equal.  It's a bit of a hack, but more time and
+                       thought is needed for a better solution. */
+                       LinearProgram::Row row = linprog.add_row();
+                       row[(*i)->index*5+2] = 1;
+                       row[(*i)->index*5+3] = -1;
+               }
+
                {
                        /* Only allow the widget's dimension to increase.  The geometry has
                        previously been set to the smallest allowable size. */
@@ -329,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));
                        }
        }
 
@@ -358,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)
 { }