- Add some checks if the Area is initialized.

- Init some more variables in the constructor.
- Rename HasSame*As to Set*As. The old one is more a question. Also add an optional factor and remove the HasSameSizeAs function which tempt the user to leak a BList.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38790 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler
2010-09-23 00:04:08 +00:00
parent a2336b86cc
commit 40d939a43f
3 changed files with 45 additions and 43 deletions
+2 -3
View File
@@ -72,9 +72,8 @@ public:
operator BString() const; operator BString() const;
void GetString(BString& string) const; void GetString(BString& string) const;
Constraint* HasSameWidthAs(Area* area); Constraint* SetWidthAs(Area* area, float factor = 1.0f);
Constraint* HasSameHeightAs(Area* area); Constraint* SetHeightAs(Area* area, float factor = 1.0f);
BList* HasSameSizeAs(Area* area);
void InvalidateSizeConstraints(); void InvalidateSizeConstraints();
+42 -39
View File
@@ -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 * @param area the area that should have the same width
* @return the same-width constraint * @return the same-width constraint
*/ */
Constraint* Constraint*
Area::HasSameWidthAs(Area* area) Area::SetWidthAs(Area* area, float factor)
{ {
return fLS->AddConstraint( return fLS->AddConstraint(-factor, fLeft, factor, fRight, 1.0, area->Left(),
-1.0, fLeft, 1.0, fRight, 1.0, area->fLeft, -1.0, area->fRight, -1.0, area->Right(), OperatorType(EQ), 0.0);
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 * @param area the area that should have the same height
* @return the same-height constraint * @return the same-height constraint
*/ */
Constraint* Constraint*
Area::HasSameHeightAs(Area* area) Area::SetHeightAs(Area* area, float factor)
{ {
return fLS->AddConstraint( return fLS->AddConstraint(-factor, fTop, factor, fBottom, 1.0, area->Top(),
-1.0, fTop, 1.0, fBottom, 1.0, area->fTop, -1.0, area->fBottom, -1.0, area->Bottom(), OperatorType(EQ), 0.0);
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;
} }
void void
Area::InvalidateSizeConstraints() Area::InvalidateSizeConstraints()
{ {
// check if if we are initialized
if (!fLeft)
return;
BSize minSize = fLayoutItem->MinSize(); BSize minSize = fLayoutItem->MinSize();
BSize maxSize = fLayoutItem->MaxSize(); BSize maxSize = fLayoutItem->MaxSize();
BSize prefSize = fLayoutItem->PreferredSize(); BSize prefSize = fLayoutItem->PreferredSize();
@@ -508,7 +496,24 @@ Area::~Area()
*/ */
Area::Area(BLayoutItem* item) 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, Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom,
BView* content) BView* content)
{ {
fMaxContentWidth = NULL;
fMaxContentHeight = NULL;
fShrinkPenalties = BSize(2, 2); fShrinkPenalties = BSize(2, 2);
fGrowPenalties = BSize(1, 1); fGrowPenalties = BSize(1, 1);
fContentAspectRatio = 0; fContentAspectRatio = 0;
fContentAspectRatioC = NULL;
fAutoPreferredContentSize = false; fAutoPreferredContentSize = false;
fPreferredContentWidth = NULL;
fPreferredContentHeight = NULL;
fLeftInset = 0; fLeftInset = 0;
fTopInset = 0; fTopInset = 0;
fRightInset = 0; fRightInset = 0;
@@ -571,10 +569,15 @@ Area::_Init(LinearSpec* ls, Row* row, Column* column, BView* content)
/** /**
* Perform layout on the area. * Perform layout on the area.
*/ */
void Area::_DoLayout() void
Area::_DoLayout()
{ {
BRect areaFrame(round(Left()->Value()), round(Top()->Value()), // check if if we are initialized
round(Right()->Value()), round(Bottom()->Value())); if (!fLeft)
return;
BRect areaFrame(round(fLeft->Value()), round(fTop->Value()),
round(fRight->Value()), round(fBottom->Value()));
areaFrame.left += fLeftInset; areaFrame.left += fLeftInset;
areaFrame.right -= fRightInset; areaFrame.right -= fRightInset;
areaFrame.top += fTopInset; areaFrame.top += fTopInset;