From c4340eab04bfd4baa7bda6782c7e55dea1f5c467 Mon Sep 17 00:00:00 2001 From: czeidler Date: Fri, 20 Jan 2012 16:47:01 +1300 Subject: [PATCH] Fix row column weight. --- src/libs/alm/RowColumnManager.cpp | 21 +++++++++++---------- src/libs/alm/RowColumnManager.h | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/libs/alm/RowColumnManager.cpp b/src/libs/alm/RowColumnManager.cpp index 269909691e..ebd4e223bf 100644 --- a/src/libs/alm/RowColumnManager.cpp +++ b/src/libs/alm/RowColumnManager.cpp @@ -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; @@ -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; diff --git a/src/libs/alm/RowColumnManager.h b/src/libs/alm/RowColumnManager.h index b18006e021..55a844397a 100644 --- a/src/libs/alm/RowColumnManager.h +++ b/src/libs/alm/RowColumnManager.h @@ -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);