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.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38792 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -28,7 +28,7 @@ namespace BALM {
|
|||||||
*/
|
*/
|
||||||
class BALMLayout : public BAbstractLayout {
|
class BALMLayout : public BAbstractLayout {
|
||||||
public:
|
public:
|
||||||
BALMLayout();
|
BALMLayout(float spacing = 0.0f);
|
||||||
virtual ~BALMLayout();
|
virtual ~BALMLayout();
|
||||||
|
|
||||||
XTab* AddXTab();
|
XTab* AddXTab();
|
||||||
@@ -65,6 +65,12 @@ public:
|
|||||||
|
|
||||||
LinearSpec* Solver();
|
LinearSpec* Solver();
|
||||||
|
|
||||||
|
void SetInset(float inset);
|
||||||
|
float Inset();
|
||||||
|
|
||||||
|
void SetSpacing(float spacing);
|
||||||
|
float Spacing();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _SolveLayout();
|
void _SolveLayout();
|
||||||
|
|
||||||
@@ -86,6 +92,9 @@ private:
|
|||||||
BSize fMaxSize;
|
BSize fMaxSize;
|
||||||
BSize fPreferredSize;
|
BSize fPreferredSize;
|
||||||
char* fPerformancePath;
|
char* fPerformancePath;
|
||||||
|
|
||||||
|
float fInset;
|
||||||
|
float fSpacing;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BALM
|
} // namespace BALM
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BLayoutItem* fLayoutItem;
|
BLayoutItem* fLayoutItem;
|
||||||
|
|
||||||
LinearSpec* fLS;
|
LinearSpec* fLS;
|
||||||
|
|
||||||
XTab* fLeft;
|
XTab* fLeft;
|
||||||
@@ -106,10 +107,8 @@ private:
|
|||||||
BSize fShrinkPenalties;
|
BSize fShrinkPenalties;
|
||||||
BSize fGrowPenalties;
|
BSize fGrowPenalties;
|
||||||
|
|
||||||
int32 fLeftInset;
|
BSize fTopLeftInset;
|
||||||
int32 fTopInset;
|
BSize fRightBottomInset;
|
||||||
int32 fRightInset;
|
|
||||||
int32 fBottomInset;
|
|
||||||
|
|
||||||
BList fConstraints;
|
BList fConstraints;
|
||||||
Constraint* fMinContentWidth;
|
Constraint* fMinContentWidth;
|
||||||
|
|||||||
@@ -28,9 +28,10 @@ const BSize kMaxSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
* Creates new layout engine.
|
* Creates new layout engine.
|
||||||
*/
|
*/
|
||||||
BALMLayout::BALMLayout()
|
BALMLayout::BALMLayout(float spacing)
|
||||||
:
|
:
|
||||||
BAbstractLayout()
|
fInset(0.0f),
|
||||||
|
fSpacing(spacing)
|
||||||
{
|
{
|
||||||
fLeft = new XTab(&fSolver);
|
fLeft = new XTab(&fSolver);
|
||||||
fRight = new XTab(&fSolver);
|
fRight = new XTab(&fSolver);
|
||||||
@@ -389,6 +390,34 @@ BALMLayout::Solver()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
void
|
||||||
BALMLayout::_SolveLayout()
|
BALMLayout::_SolveLayout()
|
||||||
{
|
{
|
||||||
|
|||||||
+44
-23
@@ -305,7 +305,13 @@ Area::SetContentAspectRatio(double ratio)
|
|||||||
int32
|
int32
|
||||||
Area::LeftInset() const
|
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 @@ Area::LeftInset() const
|
|||||||
int32
|
int32
|
||||||
Area::TopInset() const
|
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 @@ Area::TopInset() const
|
|||||||
int32
|
int32
|
||||||
Area::RightInset() const
|
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 @@ Area::RightInset() const
|
|||||||
int32
|
int32
|
||||||
Area::BottomInset() const
|
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 @@ Area::BottomInset() const
|
|||||||
void
|
void
|
||||||
Area::SetLeftInset(int32 left)
|
Area::SetLeftInset(int32 left)
|
||||||
{
|
{
|
||||||
fLeftInset = left;
|
fTopLeftInset.width = left;
|
||||||
fLayoutItem->Layout()->InvalidateLayout();
|
fLayoutItem->Layout()->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +380,7 @@ Area::SetLeftInset(int32 left)
|
|||||||
void
|
void
|
||||||
Area::SetTopInset(int32 top)
|
Area::SetTopInset(int32 top)
|
||||||
{
|
{
|
||||||
fTopInset = top;
|
fTopLeftInset.height = top;
|
||||||
fLayoutItem->Layout()->InvalidateLayout();
|
fLayoutItem->Layout()->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +391,8 @@ Area::SetTopInset(int32 top)
|
|||||||
void
|
void
|
||||||
Area::SetRightInset(int32 right)
|
Area::SetRightInset(int32 right)
|
||||||
{
|
{
|
||||||
fRightInset = right;
|
fRightBottomInset.width = right;
|
||||||
|
fLayoutItem->Layout()->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -377,7 +402,8 @@ Area::SetRightInset(int32 right)
|
|||||||
void
|
void
|
||||||
Area::SetBottomInset(int32 bottom)
|
Area::SetBottomInset(int32 bottom)
|
||||||
{
|
{
|
||||||
fBottomInset = bottom;
|
fRightBottomInset.height = bottom;
|
||||||
|
fLayoutItem->Layout()->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -532,11 +558,6 @@ Area::_Init(LinearSpec* ls, XTab* left, YTab* top, XTab* right, YTab* bottom,
|
|||||||
|
|
||||||
fAutoPreferredContentSize = false;
|
fAutoPreferredContentSize = false;
|
||||||
|
|
||||||
fLeftInset = 0;
|
|
||||||
fTopInset = 0;
|
|
||||||
fRightInset = 0;
|
|
||||||
fBottomInset = 0;
|
|
||||||
|
|
||||||
fLS = ls;
|
fLS = ls;
|
||||||
fLeft = left;
|
fLeft = left;
|
||||||
fRight = right;
|
fRight = right;
|
||||||
@@ -578,10 +599,10 @@ Area::_DoLayout()
|
|||||||
|
|
||||||
BRect areaFrame(round(fLeft->Value()), round(fTop->Value()),
|
BRect areaFrame(round(fLeft->Value()), round(fTop->Value()),
|
||||||
round(fRight->Value()), round(fBottom->Value()));
|
round(fRight->Value()), round(fBottom->Value()));
|
||||||
areaFrame.left += fLeftInset;
|
areaFrame.left += LeftInset();
|
||||||
areaFrame.right -= fRightInset;
|
areaFrame.right -= RightInset();
|
||||||
areaFrame.top += fTopInset;
|
areaFrame.top += TopInset();
|
||||||
areaFrame.bottom -= fBottomInset;
|
areaFrame.bottom -= BottomInset();
|
||||||
|
|
||||||
fLayoutItem->AlignInFrame(areaFrame);
|
fLayoutItem->AlignInFrame(areaFrame);
|
||||||
}
|
}
|
||||||
@@ -590,16 +611,16 @@ Area::_DoLayout()
|
|||||||
void
|
void
|
||||||
Area::_UpdateMinSizeConstraint(BSize min)
|
Area::_UpdateMinSizeConstraint(BSize min)
|
||||||
{
|
{
|
||||||
fMinContentWidth->SetRightSide(min.Width() + fLeftInset + fRightInset);
|
fMinContentWidth->SetRightSide(min.Width() + LeftInset() + RightInset());
|
||||||
fMinContentHeight->SetRightSide(min.Height() + fTopInset + fBottomInset);
|
fMinContentHeight->SetRightSide(min.Height() + TopInset() + BottomInset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Area::_UpdateMaxSizeConstraint(BSize max)
|
Area::_UpdateMaxSizeConstraint(BSize max)
|
||||||
{
|
{
|
||||||
max.width += fLeftInset + fRightInset;
|
max.width += LeftInset() + RightInset();
|
||||||
max.height += fTopInset + fBottomInset;
|
max.height += TopInset() + BottomInset();
|
||||||
|
|
||||||
// we only need max constraints if the alignment is full height/width
|
// we only need max constraints if the alignment is full height/width
|
||||||
// otherwise we can just align the item in the free space
|
// otherwise we can just align the item in the free space
|
||||||
@@ -643,8 +664,8 @@ Area::_UpdateMaxSizeConstraint(BSize max)
|
|||||||
void
|
void
|
||||||
Area::_UpdatePreferredConstraint(BSize preferred)
|
Area::_UpdatePreferredConstraint(BSize preferred)
|
||||||
{
|
{
|
||||||
preferred.width += fLeftInset + fRightInset;
|
preferred.width += LeftInset() + RightInset();
|
||||||
preferred.height += fTopInset + fBottomInset;
|
preferred.height += TopInset() + BottomInset();
|
||||||
if (fPreferredContentWidth == NULL) {
|
if (fPreferredContentWidth == NULL) {
|
||||||
fPreferredContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0,
|
fPreferredContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0,
|
||||||
fRight, OperatorType(EQ), preferred.Width(),
|
fRight, OperatorType(EQ), preferred.Width(),
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public:
|
|||||||
button1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
|
button1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
|
||||||
|
|
||||||
// create a new BALMLayout and use it for this window
|
// create a new BALMLayout and use it for this window
|
||||||
BALMLayout* layout = new BALMLayout();
|
BALMLayout* layout = new BALMLayout(6);
|
||||||
SetLayout(layout);
|
SetLayout(layout);
|
||||||
|
|
||||||
// create extra tabs
|
// create extra tabs
|
||||||
|
|||||||
@@ -38,9 +38,11 @@ public:
|
|||||||
button4->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
|
button4->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
|
||||||
|
|
||||||
// create a new BALMLayout and use it for this window
|
// create a new BALMLayout and use it for this window
|
||||||
BALMLayout* layout = new BALMLayout();
|
BALMLayout* layout = new BALMLayout(10.);
|
||||||
SetLayout(layout);
|
SetLayout(layout);
|
||||||
|
|
||||||
|
layout->SetInset(5.);
|
||||||
|
|
||||||
// create extra tabs
|
// create extra tabs
|
||||||
XTab* x1 = layout->AddXTab();
|
XTab* x1 = layout->AddXTab();
|
||||||
XTab* x2 = layout->AddXTab();
|
XTab* x2 = layout->AddXTab();
|
||||||
|
|||||||
Reference in New Issue
Block a user