From 8fa4fd37b76486e5baa22f594c883a7f94ce3c61 Mon Sep 17 00:00:00 2001 From: Clemens Zeidler Date: Fri, 26 Nov 2010 04:20:38 +0000 Subject: [PATCH] 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 --- headers/libs/alm/ALMLayout.h | 3 +++ headers/libs/alm/Area.h | 11 +++++++++-- src/libs/alm/ALMLayout.cpp | 10 +++++++--- src/libs/alm/Area.cpp | 28 +++++++++++++++++++--------- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/headers/libs/alm/ALMLayout.h b/headers/libs/alm/ALMLayout.h index 647a30ef11..c477400e61 100644 --- a/headers/libs/alm/ALMLayout.h +++ b/headers/libs/alm/ALMLayout.h @@ -151,6 +151,9 @@ private: float fSpacing; Area* fCurrentArea; + + Variable* fScaleWidth; + Variable* fScaleHeight; }; } // namespace BALM diff --git a/headers/libs/alm/Area.h b/headers/libs/alm/Area.h index d8df750c6d..9bb33a18a6 100644 --- a/headers/libs/alm/Area.h +++ b/headers/libs/alm/Area.h @@ -107,8 +107,12 @@ private: Area(BLayoutItem* item); void _Init(LinearSpec* ls, XTab* left, YTab* top, - XTab* right, YTab* bottom); - void _Init(LinearSpec* ls, Row* row, Column* column); + XTab* right, YTab* bottom, + Variable* scaleWidth, + Variable* scaleHeight); + void _Init(LinearSpec* ls, Row* row, Column* column, + Variable* scaleWidth, + Variable* scaleHeight); void _DoLayout(); @@ -145,6 +149,9 @@ private: double fContentAspectRatio; Constraint* fContentAspectRatioC; + Variable* fScaleWidth; + Variable* fScaleHeight; + public: friend class BALMLayout; diff --git a/src/libs/alm/ALMLayout.cpp b/src/libs/alm/ALMLayout.cpp index d6208b01c9..dd8b20d1cd 100644 --- a/src/libs/alm/ALMLayout.cpp +++ b/src/libs/alm/ALMLayout.cpp @@ -52,12 +52,16 @@ BALMLayout::BALMLayout(float spacing, BALMLayout* friendLayout) fPreferredSize = kUnsetSize; fPerformancePath = NULL; + + fScaleWidth = fSolver->AddVariable(); + fScaleHeight = fSolver->AddVariable(); } BALMLayout::~BALMLayout() { - + delete fScaleWidth; + delete fScaleHeight; } @@ -479,7 +483,7 @@ BALMLayout::AddItem(BLayoutItem* item, XTab* left, YTab* top, XTab* right, return NULL; fCurrentArea = area; - area->_Init(fSolver, left, top, right, bottom); + area->_Init(fSolver, left, top, right, bottom, fScaleWidth, fScaleHeight); return area; } @@ -494,7 +498,7 @@ BALMLayout::AddItem(BLayoutItem* item, Row* row, Column* column) return NULL; fCurrentArea = area; - area->_Init(fSolver, row, column); + area->_Init(fSolver, row, column, fScaleWidth, fScaleHeight); return area; } diff --git a/src/libs/alm/Area.cpp b/src/libs/alm/Area.cpp index ab5a35684e..18e012d801 100644 --- a/src/libs/alm/Area.cpp +++ b/src/libs/alm/Area.cpp @@ -593,7 +593,8 @@ Area::Area(BLayoutItem* item) * Initialize variables. */ 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; fLeft = left; @@ -601,6 +602,9 @@ Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom) fTop = top; fBottom = bottom; + fScaleWidth = scaleWidth; + fScaleHeight = scaleHeight; + // 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 // 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(fMinContentHeight); - fPreferredContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, - OperatorType(EQ), 0, fShrinkPenalties.Height(), fGrowPenalties.Width()); + fPreferredContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, -1.0, + fScaleWidth, OperatorType(EQ), 0, fShrinkPenalties.Height(), + fGrowPenalties.Width()); - fPreferredContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, - OperatorType(EQ), 0, fShrinkPenalties.Height(), + fPreferredContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, -1.0, + fScaleHeight, OperatorType(EQ), 0, fShrinkPenalties.Height(), fGrowPenalties.Height()); fConstraints.AddItem(fPreferredContentWidth); @@ -625,9 +630,11 @@ Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom) 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; fColumn = column; } @@ -718,6 +725,9 @@ Area::_UpdatePreferredConstraint(BSize preferred) if (preferred.height > 0) height = preferred.Height() + TopInset() + BottomInset(); - fPreferredContentWidth->SetRightSide(width); - fPreferredContentHeight->SetRightSide(height); + fPreferredContentWidth->SetLeftSide(-1.0, fLeft, 1.0, fRight, -width, + fScaleWidth); + + fPreferredContentHeight->SetLeftSide(-1.0, fTop, 1.0, fBottom, -height, + fScaleHeight); }