1 /* 2 * Copyright 2011, Haiku, Inc. All rights reserved. 3 * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de> 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef ROW_COLUMN_MANAGER_H 7 #define ROW_COLUMN_MANAGER_H 8 9 10 #include "Area.h" 11 #include "Column.h" 12 #include "LinearSpec.h" 13 #include "Row.h" 14 #include "Tab.h" 15 16 17 namespace BPrivate { 18 class SharedSolver; 19 }; 20 21 22 namespace BALM { 23 24 25 /*! The RowColumnManager groups areas with same vertical or horizontal tabs 26 into column and rows. For each row and column, a preferred size is 27 calculated from the areas in the row or column. This preferred size is used 28 to create a preferred size soft-constraint. 29 Having only one constraint for each row and column avoids the so called 30 spring effect. That is each area with a preferred size constraint is pulling 31 or pressing torwards its preferred size. For example, a row with three areas 32 pushes stronger than a row with two areas. Assuming that all areas have the 33 same preferred size, the three-area row gets a different size than the 34 two-area row. However, one would expect that both rows have the same height. 35 The row and column approach of the RowColumnManager solves this problem. 36 37 */ 38 class RowColumnManager { 39 public: 40 RowColumnManager(LinearSpec* spec); 41 ~RowColumnManager(); 42 43 void AddArea(Area* area); 44 void RemoveArea(Area* area); 45 46 void UpdateConstraints(); 47 void TabsChanged(Area* area); 48 private: 49 friend class BPrivate::SharedSolver; 50 Row* _FindRowFor(Area* area); 51 Column* _FindColumnFor(Area* area); 52 53 double _PreferredHeight(Row* row, 54 double& weight); 55 double _PreferredWidth(Column* column, 56 double& weight); 57 58 void _UpdateConstraints(Row* row); 59 void _UpdateConstraints(Column* column); 60 61 BObjectList<Row> fRows; 62 BObjectList<Column> fColumns; 63 64 LinearSpec* fLinearSpec; 65 }; 66 67 68 } // namespace BALM 69 70 71 #endif // ROW_COLUMN_MANAGER_H 72 73