Skip to content

Commit

Permalink
Fix row column weight.
Browse files Browse the repository at this point in the history
  • Loading branch information
czeidler authored and yourpalal committed May 2, 2012
1 parent 35babcf commit c4340ea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/libs/alm/RowColumnManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
nAreas++;
pref += prefSize.height;
}
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;
Expand All @@ -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) {
nAreas++;
pref += prefSize.width;
}
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;
Expand Down
17 changes: 14 additions & 3 deletions src/libs/alm/RowColumnManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -26,9 +40,6 @@ class RowColumnManager {

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);
Expand Down

0 comments on commit c4340ea

Please sign in to comment.