Fix row column weight.

This commit is contained in:
czeidler 2012-01-20 16:47:01 +13:00 committed by Alex Wilson
parent 35babcf06d
commit c4340eab04
2 changed files with 25 additions and 13 deletions

View File

@ -138,16 +138,16 @@ RowColumnManager::_PreferredHeight(Row* row, double& weight)
double pref = 0;
for (int32 i = 0; i < row->fAreas.CountItems(); i++) {
BSize prefSize = row->fAreas.ItemAt(i)->Item()->PreferredSize();
if (prefSize.height > 0) {
if (prefSize.height <= 0)
continue;
nAreas++;
pref += prefSize.height;
}
double negPen = row->fAreas.ItemAt(i)->ShrinkPenalties().height;
if (negPen > 0)
weight += negPen;
}
if (nAreas == 0) {
pref = 0;
pref = -1;
weight = 1;
} else {
pref /= nAreas;
@ -165,16 +165,17 @@ RowColumnManager::_PreferredWidth(Column* column, double& weight)
double pref = 0;
for (int32 i = 0; i < column->fAreas.CountItems(); i++) {
BSize prefSize = column->fAreas.ItemAt(i)->Item()->PreferredSize();
if (prefSize.width > 0) {
if (prefSize.width <= 0)
continue;
nAreas++;
pref += prefSize.width;
}
double negPen = column->fAreas.ItemAt(i)->ShrinkPenalties().height;
if (negPen > 0)
weight += negPen;
}
if (nAreas == 0) {
pref = 0;
pref = -1;
weight = 1;
} else {
pref /= nAreas;

View File

@ -16,6 +16,20 @@
namespace BALM {
/*! The RowColumnManager groups areas with same vertical or horizontal tabs
into column and rows. For each row and column, a preferred size is
calculated from the areas in the row or column. This preferred size is used
to create a preferred size soft-constraint.
Having only one constraint for each row and column avoids the so called
spring effect. That is each area with a preferred size constraint is pulling
or pressing torwards its preferred size. For example, a row with three areas
pushes stronger than a row with two areas. Assuming that all areas have the
same preferred size, the three-area row gets a different size than the
two-area row. However, one would expect that both rows have the same height.
The row and column approach of the RowColumnManager solves this problem.
*/
class RowColumnManager {
public:
RowColumnManager(LinearSpec* spec);
@ -26,9 +40,6 @@ public:
void UpdateConstraints();
void TabsChanged(Area* area);
Row* CreateRow(YTab* top, YTab* bottom);
Column* CreateColumn(XTab* left, XTab* right);
private:
Row* _FindRowFor(Area* area);
Column* _FindColumnFor(Area* area);