Keep the preferred size ratio into account. This make layout behaviour much more intuitive when resizing a window. Thanks Christof.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39641 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler
2010-11-26 04:20:38 +00:00
parent 2b602c7364
commit 8fa4fd37b7
4 changed files with 38 additions and 14 deletions
+3
View File
@@ -151,6 +151,9 @@ private:
float fSpacing; float fSpacing;
Area* fCurrentArea; Area* fCurrentArea;
Variable* fScaleWidth;
Variable* fScaleHeight;
}; };
} // namespace BALM } // namespace BALM
+9 -2
View File
@@ -107,8 +107,12 @@ private:
Area(BLayoutItem* item); Area(BLayoutItem* item);
void _Init(LinearSpec* ls, XTab* left, YTab* top, void _Init(LinearSpec* ls, XTab* left, YTab* top,
XTab* right, YTab* bottom); XTab* right, YTab* bottom,
void _Init(LinearSpec* ls, Row* row, Column* column); Variable* scaleWidth,
Variable* scaleHeight);
void _Init(LinearSpec* ls, Row* row, Column* column,
Variable* scaleWidth,
Variable* scaleHeight);
void _DoLayout(); void _DoLayout();
@@ -145,6 +149,9 @@ private:
double fContentAspectRatio; double fContentAspectRatio;
Constraint* fContentAspectRatioC; Constraint* fContentAspectRatioC;
Variable* fScaleWidth;
Variable* fScaleHeight;
public: public:
friend class BALMLayout; friend class BALMLayout;
+7 -3
View File
@@ -52,12 +52,16 @@ BALMLayout::BALMLayout(float spacing, BALMLayout* friendLayout)
fPreferredSize = kUnsetSize; fPreferredSize = kUnsetSize;
fPerformancePath = NULL; fPerformancePath = NULL;
fScaleWidth = fSolver->AddVariable();
fScaleHeight = fSolver->AddVariable();
} }
BALMLayout::~BALMLayout() BALMLayout::~BALMLayout()
{ {
delete fScaleWidth;
delete fScaleHeight;
} }
@@ -479,7 +483,7 @@ BALMLayout::AddItem(BLayoutItem* item, XTab* left, YTab* top, XTab* right,
return NULL; return NULL;
fCurrentArea = area; fCurrentArea = area;
area->_Init(fSolver, left, top, right, bottom); area->_Init(fSolver, left, top, right, bottom, fScaleWidth, fScaleHeight);
return area; return area;
} }
@@ -494,7 +498,7 @@ BALMLayout::AddItem(BLayoutItem* item, Row* row, Column* column)
return NULL; return NULL;
fCurrentArea = area; fCurrentArea = area;
area->_Init(fSolver, row, column); area->_Init(fSolver, row, column, fScaleWidth, fScaleHeight);
return area; return area;
} }
+19 -9
View File
@@ -593,7 +593,8 @@ Area::Area(BLayoutItem* item)
* Initialize variables. * Initialize variables.
*/ */
void void
Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom) Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom,
Variable* scaleWidth, Variable* scaleHeight)
{ {
fLS = ls; fLS = ls;
fLeft = left; fLeft = left;
@@ -601,6 +602,9 @@ Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom)
fTop = top; fTop = top;
fBottom = bottom; fBottom = bottom;
fScaleWidth = scaleWidth;
fScaleHeight = scaleHeight;
// adds the two essential constraints of the area that make sure that the // adds the two essential constraints of the area that make sure that the
// left x-tab is really to the left of the right x-tab, and the top y-tab // left x-tab is really to the left of the right x-tab, and the top y-tab
// really above the bottom y-tab // really above the bottom y-tab
@@ -612,11 +616,12 @@ Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom)
fConstraints.AddItem(fMinContentWidth); fConstraints.AddItem(fMinContentWidth);
fConstraints.AddItem(fMinContentHeight); fConstraints.AddItem(fMinContentHeight);
fPreferredContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, fPreferredContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, -1.0,
OperatorType(EQ), 0, fShrinkPenalties.Height(), fGrowPenalties.Width()); fScaleWidth, OperatorType(EQ), 0, fShrinkPenalties.Height(),
fGrowPenalties.Width());
fPreferredContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, fPreferredContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, -1.0,
OperatorType(EQ), 0, fShrinkPenalties.Height(), fScaleHeight, OperatorType(EQ), 0, fShrinkPenalties.Height(),
fGrowPenalties.Height()); fGrowPenalties.Height());
fConstraints.AddItem(fPreferredContentWidth); fConstraints.AddItem(fPreferredContentWidth);
@@ -625,9 +630,11 @@ Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom)
void void
Area::_Init(LinearSpec* ls, Row* row, Column* column) Area::_Init(LinearSpec* ls, Row* row, Column* column, Variable* scaleWidth,
Variable* scaleHeight)
{ {
_Init(ls, column->Left(), row->Top(), column->Right(), row->Bottom()); _Init(ls, column->Left(), row->Top(), column->Right(), row->Bottom(),
scaleWidth, scaleHeight);
fRow = row; fRow = row;
fColumn = column; fColumn = column;
} }
@@ -718,6 +725,9 @@ Area::_UpdatePreferredConstraint(BSize preferred)
if (preferred.height > 0) if (preferred.height > 0)
height = preferred.Height() + TopInset() + BottomInset(); height = preferred.Height() + TopInset() + BottomInset();
fPreferredContentWidth->SetRightSide(width); fPreferredContentWidth->SetLeftSide(-1.0, fLeft, 1.0, fRight, -width,
fPreferredContentHeight->SetRightSide(height); fScaleWidth);
fPreferredContentHeight->SetLeftSide(-1.0, fTop, 1.0, fBottom, -height,
fScaleHeight);
} }