]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/layout.cpp
Smarter way of complementing constraint types
[libs/gltk.git] / source / layout.cpp
index e9f9b40d0e9e0cced67238e62f2b0d8b480754d2..66eb66b8b98c3a1e817a5dcbca9a11116aea3829 100644 (file)
@@ -204,16 +204,7 @@ Layout::Slot &Layout::get_slot_for_widget(Widget &wdg)
 
 Layout::ConstraintType Layout::complement(ConstraintType type)
 {
-       if(type==RIGHT_OF)
-               return LEFT_OF;
-       else if(type==LEFT_OF)
-               return RIGHT_OF;
-       else if(type==ABOVE)
-               return BELOW;
-       else if(type==BELOW)
-               return ABOVE;
-       else
-               return type;
+       return static_cast<ConstraintType>((type&~(SELF_MASK|TARGET_MASK)) | ((type&SELF_MASK)<<2) | ((type&TARGET_MASK)>>2));
 }
 
 void Layout::create_constraint(Widget &src, ConstraintType type, Widget &tgt, int sp)
@@ -343,29 +334,29 @@ void Layout::solve_constraints(int dir, SolveMode mode)
                }
 
                {
-                       /* Only allow the widget's dimension to increase.  The geometry has
-                       previously been set to the smallest allowable size. */
+                       /* Don't allow the widget's dimension to get below that determined
+                       by autosizing. */
                        LinearProgram::Row row = linprog.add_row();
                        row[(*i)->index*5+1] = 1;
                        row[(*i)->index*5+4] = -1;
                        row.back() = (*i)->autosize_geom.*(ptrs.dim);
                }
 
-               /* Add rows for user-defined constraints.  Below/above and left/right of
-               constraints are always added in pairs, so it's only necessary to create a
-               row for one half. */
+               /* Add rows for user-defined constraints.  Constraints are always added
+               in pairs, so it's only necessary to create a row for one half. */
                for(list<Constraint>::iterator j=(*i)->constraints.begin(); j!=(*i)->constraints.end(); ++j)
-                       if(j->target.index>=0 && (j->type&1)==dir && j->type!=BELOW && j->type!=LEFT_OF)
+                       if(j->target.index>(*i)->index && (j->type&1)==dir)
                        {
                                LinearProgram::Row row = linprog.add_row();
+                               float polarity = ((j->type&SELF_DIM) ? -1 : 1);
                                if(j->type&SELF_POS)
-                                       row[(*i)->index*5] = 1;
+                                       row[(*i)->index*5] = polarity;
                                if(j->type&SELF_DIM)
-                                       row[(*i)->index*5+1] = 1;
+                                       row[(*i)->index*5+1] = polarity;
                                if(j->type&TARGET_POS)
-                                       row[j->target.index*5] = -1;
+                                       row[j->target.index*5] = -polarity;
                                if(j->type&TARGET_DIM)
-                                       row[j->target.index*5+1] = -1;
+                                       row[j->target.index*5+1] = -polarity;
                                if(j->type&SPACING)
                                        row.back() = (j->spacing>=0 ? j->spacing : this->*(ptrs.spacing));
                        }