Author: czeidler Date: 2010-09-23 02:53:33 +0200 (Thu, 23 Sep 2010) New Revision: 38792 Changeset: http://dev.haiku-os.org/changeset/38792 Modified: haiku/trunk/headers/libs/alm/ALMLayout.h haiku/trunk/headers/libs/alm/Area.h haiku/trunk/src/libs/alm/ALMLayout.cpp haiku/trunk/src/libs/alm/Area.cpp haiku/trunk/src/tests/libs/alm/Areas.cpp haiku/trunk/src/tests/libs/alm/Pinwheel.cpp Log: Add inset and spacing to BALMLayout. Each Area is able to overwrite this global values and use his own inset. Add spacing and inset to the tests. Modified: haiku/trunk/headers/libs/alm/ALMLayout.h =================================================================== --- haiku/trunk/headers/libs/alm/ALMLayout.h 2010-09-23 00:04:50 UTC (rev 38791) +++ haiku/trunk/headers/libs/alm/ALMLayout.h 2010-09-23 00:53:33 UTC (rev 38792) @@ -28,7 +28,7 @@ */ class BALMLayout : public BAbstractLayout { public: - BALMLayout(); + BALMLayout(float spacing = 0.0f); virtual ~BALMLayout(); XTab* AddXTab(); @@ -65,6 +65,12 @@ LinearSpec* Solver(); + void SetInset(float inset); + float Inset(); + + void SetSpacing(float spacing); + float Spacing(); + private: void _SolveLayout(); @@ -86,6 +92,9 @@ BSize fMaxSize; BSize fPreferredSize; char* fPerformancePath; + + float fInset; + float fSpacing; }; } // namespace BALM Modified: haiku/trunk/headers/libs/alm/Area.h =================================================================== --- haiku/trunk/headers/libs/alm/Area.h 2010-09-23 00:04:50 UTC (rev 38791) +++ haiku/trunk/headers/libs/alm/Area.h 2010-09-23 00:53:33 UTC (rev 38792) @@ -93,6 +93,7 @@ private: BLayoutItem* fLayoutItem; + LinearSpec* fLS; XTab* fLeft; @@ -106,10 +107,8 @@ BSize fShrinkPenalties; BSize fGrowPenalties; - int32 fLeftInset; - int32 fTopInset; - int32 fRightInset; - int32 fBottomInset; + BSize fTopLeftInset; + BSize fRightBottomInset; BList fConstraints; Constraint* fMinContentWidth; Modified: haiku/trunk/src/libs/alm/ALMLayout.cpp =================================================================== --- haiku/trunk/src/libs/alm/ALMLayout.cpp 2010-09-23 00:04:50 UTC (rev 38791) +++ haiku/trunk/src/libs/alm/ALMLayout.cpp 2010-09-23 00:53:33 UTC (rev 38792) @@ -28,9 +28,10 @@ * Constructor. * Creates new layout engine. */ -BALMLayout::BALMLayout() +BALMLayout::BALMLayout(float spacing) : - BAbstractLayout() + fInset(0.0f), + fSpacing(spacing) { fLeft = new XTab(&fSolver); fRight = new XTab(&fSolver); @@ -390,6 +391,34 @@ void +BALMLayout::SetInset(float inset) +{ + fInset = inset; +} + + +float +BALMLayout::Inset() +{ + return fInset; +} + + +void +BALMLayout::SetSpacing(float spacing) +{ + fSpacing = spacing; +} + + +float +BALMLayout::Spacing() +{ + return fSpacing; +} + + +void BALMLayout::_SolveLayout() { // if autoPreferredContentSize is set on an area, Modified: haiku/trunk/src/libs/alm/Area.cpp =================================================================== --- haiku/trunk/src/libs/alm/Area.cpp 2010-09-23 00:04:50 UTC (rev 38791) +++ haiku/trunk/src/libs/alm/Area.cpp 2010-09-23 00:53:33 UTC (rev 38792) @@ -305,7 +305,13 @@ int32 Area::LeftInset() const { - return fLeftInset; + if (fTopLeftInset.IsWidthSet()) + return fTopLeftInset.Width(); + + BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout()); + if (fLeft == layout->Left()) + return layout->Inset(); + return layout->Spacing() / 2; } @@ -315,7 +321,13 @@ int32 Area::TopInset() const { - return fTopInset; + if (fTopLeftInset.IsHeightSet()) + return fTopLeftInset.Height(); + + BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout()); + if (fTop == layout->Top()) + return layout->Inset(); + return layout->Spacing() / 2; } @@ -325,7 +337,13 @@ int32 Area::RightInset() const { - return fRightInset; + if (fRightBottomInset.IsWidthSet()) + return fRightBottomInset.Width(); + + BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout()); + if (fRight == layout->Right()) + return layout->Inset(); + return layout->Spacing() / 2; } @@ -335,7 +353,13 @@ int32 Area::BottomInset() const { - return fBottomInset; + if (fRightBottomInset.IsHeightSet()) + return fRightBottomInset.Height(); + + BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout()); + if (fBottom == layout->Bottom()) + return layout->Inset(); + return layout->Spacing() / 2; } @@ -345,7 +369,7 @@ void Area::SetLeftInset(int32 left) { - fLeftInset = left; + fTopLeftInset.width = left; fLayoutItem->Layout()->InvalidateLayout(); } @@ -356,7 +380,7 @@ void Area::SetTopInset(int32 top) { - fTopInset = top; + fTopLeftInset.height = top; fLayoutItem->Layout()->InvalidateLayout(); } @@ -367,7 +391,8 @@ void Area::SetRightInset(int32 right) { - fRightInset = right; + fRightBottomInset.width = right; + fLayoutItem->Layout()->InvalidateLayout(); } @@ -377,7 +402,8 @@ void Area::SetBottomInset(int32 bottom) { - fBottomInset = bottom; + fRightBottomInset.height = bottom; + fLayoutItem->Layout()->InvalidateLayout(); } @@ -532,11 +558,6 @@ fAutoPreferredContentSize = false; - fLeftInset = 0; - fTopInset = 0; - fRightInset = 0; - fBottomInset = 0; - fLS = ls; fLeft = left; fRight = right; @@ -578,10 +599,10 @@ BRect areaFrame(round(fLeft->Value()), round(fTop->Value()), round(fRight->Value()), round(fBottom->Value())); - areaFrame.left += fLeftInset; - areaFrame.right -= fRightInset; - areaFrame.top += fTopInset; - areaFrame.bottom -= fBottomInset; + areaFrame.left += LeftInset(); + areaFrame.right -= RightInset(); + areaFrame.top += TopInset(); + areaFrame.bottom -= BottomInset(); fLayoutItem->AlignInFrame(areaFrame); } @@ -590,16 +611,16 @@ void Area::_UpdateMinSizeConstraint(BSize min) { - fMinContentWidth->SetRightSide(min.Width() + fLeftInset + fRightInset); - fMinContentHeight->SetRightSide(min.Height() + fTopInset + fBottomInset); + fMinContentWidth->SetRightSide(min.Width() + LeftInset() + RightInset()); + fMinContentHeight->SetRightSide(min.Height() + TopInset() + BottomInset()); } void Area::_UpdateMaxSizeConstraint(BSize max) { - max.width += fLeftInset + fRightInset; - max.height += fTopInset + fBottomInset; + max.width += LeftInset() + RightInset(); + max.height += TopInset() + BottomInset(); // we only need max constraints if the alignment is full height/width // otherwise we can just align the item in the free space @@ -643,8 +664,8 @@ void Area::_UpdatePreferredConstraint(BSize preferred) { - preferred.width += fLeftInset + fRightInset; - preferred.height += fTopInset + fBottomInset; + preferred.width += LeftInset() + RightInset(); + preferred.height += TopInset() + BottomInset(); if (fPreferredContentWidth == NULL) { fPreferredContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, OperatorType(EQ), preferred.Width(), Modified: haiku/trunk/src/tests/libs/alm/Areas.cpp =================================================================== --- haiku/trunk/src/tests/libs/alm/Areas.cpp 2010-09-23 00:04:50 UTC (rev 38791) +++ haiku/trunk/src/tests/libs/alm/Areas.cpp 2010-09-23 00:53:33 UTC (rev 38792) @@ -21,7 +21,7 @@ button1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); // create a new BALMLayout and use it for this window - BALMLayout* layout = new BALMLayout(); + BALMLayout* layout = new BALMLayout(6); SetLayout(layout); // create extra tabs Modified: haiku/trunk/src/tests/libs/alm/Pinwheel.cpp =================================================================== --- haiku/trunk/src/tests/libs/alm/Pinwheel.cpp 2010-09-23 00:04:50 UTC (rev 38791) +++ haiku/trunk/src/tests/libs/alm/Pinwheel.cpp 2010-09-23 00:53:33 UTC (rev 38792) @@ -38,9 +38,11 @@ button4->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); // create a new BALMLayout and use it for this window - BALMLayout* layout = new BALMLayout(); + BALMLayout* layout = new BALMLayout(10.); SetLayout(layout); + layout->SetInset(5.); + // create extra tabs XTab* x1 = layout->AddXTab(); XTab* x2 = layout->AddXTab();