]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/layout.cpp
Add some classes for automatically creating basic layouts
[libs/gltk.git] / source / layout.cpp
index 35019482bcfbc1efe288be7cf6136723ce3f39a3..468d45ff213267a88c55dba98a2777e20dadb3b8 100644 (file)
@@ -1,3 +1,10 @@
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2011  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
 #include <limits>
 #include "container.h"
 #include "layout.h"
@@ -179,6 +186,9 @@ Layout::ConstraintType Layout::complement(ConstraintType type)
 
 void Layout::add_constraint(Widget &src, ConstraintType type, Widget &tgt)
 {
+       if(&src==&tgt)
+               throw InvalidParameterValue("Can't add a self-referencing constraint");
+
        Slot &src_slot = get_slot_for_widget(src);
        Slot &tgt_slot = get_slot_for_widget(tgt);
 
@@ -233,10 +243,11 @@ void Layout::solve_constraints(int dir)
        Pointers &ptrs = pointers[dir&VERTICAL];
 
        LinearProgram linprog(slots.size()*5+1);
+       float weight = slots.size();
        for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
        {
-               linprog.get_object_row()[(*i)->index*5] = 0.1*((*i)->*(ptrs.packing)).gravity;
-               linprog.get_object_row()[(*i)->index*5+1] = (((*i)->*(ptrs.packing)).expand ? 5 : -1);
+               linprog.get_object_row()[(*i)->index*5] = ((*i)->*(ptrs.packing)).gravity/weight;
+               linprog.get_object_row()[(*i)->index*5+1] = (((*i)->*(ptrs.packing)).expand ? weight : -1);
 
                {
                        LinearProgram::Row row = linprog.add_row();