diff --git a/headers/libs/alm/ALMLayout.h b/headers/libs/alm/ALMLayout.h index 118ecb4db5..ebdad7b734 100644 --- a/headers/libs/alm/ALMLayout.h +++ b/headers/libs/alm/ALMLayout.h @@ -22,7 +22,7 @@ namespace BALM { - + /*! * A GUI layout engine using the Auckland Layout Model (ALM). */ diff --git a/headers/libs/alm/Area.h b/headers/libs/alm/Area.h index 0d305d0c3b..f3ba46adca 100644 --- a/headers/libs/alm/Area.h +++ b/headers/libs/alm/Area.h @@ -72,9 +72,8 @@ public: operator BString() const; void GetString(BString& string) const; - Constraint* HasSameWidthAs(Area* area); - Constraint* HasSameHeightAs(Area* area); - BList* HasSameSizeAs(Area* area); + Constraint* SetWidthAs(Area* area, float factor = 1.0f); + Constraint* SetHeightAs(Area* area, float factor = 1.0f); void InvalidateSizeConstraints(); diff --git a/src/libs/alm/Area.cpp b/src/libs/alm/Area.cpp index bc0de761f4..e4ae11a3f5 100644 --- a/src/libs/alm/Area.cpp +++ b/src/libs/alm/Area.cpp @@ -432,55 +432,43 @@ Area::GetString(BString& string) const } -/** - * Sets the width of the area to be the same as the width of the given area. +/*! + * Sets the width of the area times factor to be the same as the width of the + * given area. * * @param area the area that should have the same width * @return the same-width constraint */ Constraint* -Area::HasSameWidthAs(Area* area) +Area::SetWidthAs(Area* area, float factor) { - return fLS->AddConstraint( - -1.0, fLeft, 1.0, fRight, 1.0, area->fLeft, -1.0, area->fRight, - OperatorType(EQ), 0.0); + return fLS->AddConstraint(-factor, fLeft, factor, fRight, 1.0, area->Left(), + -1.0, area->Right(), OperatorType(EQ), 0.0); } -/** - * Sets the height of the area to be the same as the height of the given area. +/*! + * Sets the height of the area times factor to be the same as the height of the + * given area. * * @param area the area that should have the same height * @return the same-height constraint */ Constraint* -Area::HasSameHeightAs(Area* area) +Area::SetHeightAs(Area* area, float factor) { - return fLS->AddConstraint( - -1.0, fTop, 1.0, fBottom, 1.0, area->fTop, -1.0, area->fBottom, - OperatorType(EQ), 0.0); -} - - -/** - * Sets the size of the area to be the same as the size of the given area. - * - * @param area the area that should have the same size - * @return a list containing a same-width and same-height constraint - */ -BList* -Area::HasSameSizeAs(Area* area) -{ - BList* constraints = new BList(2); - constraints->AddItem(this->HasSameWidthAs(area)); - constraints->AddItem(this->HasSameHeightAs(area)); - return constraints; + return fLS->AddConstraint(-factor, fTop, factor, fBottom, 1.0, area->Top(), + -1.0, area->Bottom(), OperatorType(EQ), 0.0); } void Area::InvalidateSizeConstraints() { + // check if if we are initialized + if (!fLeft) + return; + BSize minSize = fLayoutItem->MinSize(); BSize maxSize = fLayoutItem->MaxSize(); BSize prefSize = fLayoutItem->PreferredSize(); @@ -508,7 +496,24 @@ Area::~Area() */ Area::Area(BLayoutItem* item) : - fLayoutItem(item) + fLayoutItem(item), + + fLS(NULL), + fLeft(NULL), + fRight(NULL), + fTop(NULL), + fBottom(NULL), + + fRow(NULL), + fColumn(NULL), + + fMinContentWidth(NULL), + fMaxContentWidth(NULL), + fMinContentHeight(NULL), + fMaxContentHeight(NULL), + fPreferredContentWidth(NULL), + fPreferredContentHeight(NULL), + fContentAspectRatioC(NULL) { } @@ -521,19 +526,12 @@ void Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom, BView* content) { - fMaxContentWidth = NULL; - fMaxContentHeight = NULL; - fShrinkPenalties = BSize(2, 2); fGrowPenalties = BSize(1, 1); fContentAspectRatio = 0; - fContentAspectRatioC = NULL; fAutoPreferredContentSize = false; - fPreferredContentWidth = NULL; - fPreferredContentHeight = NULL; - fLeftInset = 0; fTopInset = 0; fRightInset = 0; @@ -571,10 +569,15 @@ Area::_Init(LinearSpec* ls, Row* row, Column* column, BView* content) /** * Perform layout on the area. */ -void Area::_DoLayout() +void +Area::_DoLayout() { - BRect areaFrame(round(Left()->Value()), round(Top()->Value()), - round(Right()->Value()), round(Bottom()->Value())); + // check if if we are initialized + if (!fLeft) + return; + + BRect areaFrame(round(fLeft->Value()), round(fTop->Value()), + round(fRight->Value()), round(fBottom->Value())); areaFrame.left += fLeftInset; areaFrame.right -= fRightInset; areaFrame.top += fTopInset;