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:
parent
3ccba98ce3
commit
96e2013e70
@ -28,7 +28,7 @@ namespace BALM {
|
||||
*/
|
||||
class BALMLayout : public BAbstractLayout {
|
||||
public:
|
||||
BALMLayout();
|
||||
BALMLayout(float spacing = 0.0f);
|
||||
virtual ~BALMLayout();
|
||||
|
||||
XTab* AddXTab();
|
||||
@ -65,6 +65,12 @@ public:
|
||||
|
||||
LinearSpec* Solver();
|
||||
|
||||
void SetInset(float inset);
|
||||
float Inset();
|
||||
|
||||
void SetSpacing(float spacing);
|
||||
float Spacing();
|
||||
|
||||
private:
|
||||
void _SolveLayout();
|
||||
|
||||
@ -86,6 +92,9 @@ private:
|
||||
BSize fMaxSize;
|
||||
BSize fPreferredSize;
|
||||
char* fPerformancePath;
|
||||
|
||||
float fInset;
|
||||
float fSpacing;
|
||||
};
|
||||
|
||||
} // namespace BALM
|
||||
|
@ -93,6 +93,7 @@ private:
|
||||
|
||||
private:
|
||||
BLayoutItem* fLayoutItem;
|
||||
|
||||
LinearSpec* fLS;
|
||||
|
||||
XTab* fLeft;
|
||||
@ -106,10 +107,8 @@ private:
|
||||
BSize fShrinkPenalties;
|
||||
BSize fGrowPenalties;
|
||||
|
||||
int32 fLeftInset;
|
||||
int32 fTopInset;
|
||||
int32 fRightInset;
|
||||
int32 fBottomInset;
|
||||
BSize fTopLeftInset;
|
||||
BSize fRightBottomInset;
|
||||
|
||||
BList fConstraints;
|
||||
Constraint* fMinContentWidth;
|
||||
|
@ -28,9 +28,10 @@ const BSize kMaxSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
|
||||
* 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);
|
||||
@ -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
|
||||
BALMLayout::_SolveLayout()
|
||||
{
|
||||
|
@ -305,7 +305,13 @@ Area::SetContentAspectRatio(double ratio)
|
||||
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 @@ Area::LeftInset() const
|
||||
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 @@ Area::TopInset() const
|
||||
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 @@ Area::RightInset() const
|
||||
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 @@ Area::BottomInset() const
|
||||
void
|
||||
Area::SetLeftInset(int32 left)
|
||||
{
|
||||
fLeftInset = left;
|
||||
fTopLeftInset.width = left;
|
||||
fLayoutItem->Layout()->InvalidateLayout();
|
||||
}
|
||||
|
||||
@ -356,7 +380,7 @@ Area::SetLeftInset(int32 left)
|
||||
void
|
||||
Area::SetTopInset(int32 top)
|
||||
{
|
||||
fTopInset = top;
|
||||
fTopLeftInset.height = top;
|
||||
fLayoutItem->Layout()->InvalidateLayout();
|
||||
}
|
||||
|
||||
@ -367,7 +391,8 @@ Area::SetTopInset(int32 top)
|
||||
void
|
||||
Area::SetRightInset(int32 right)
|
||||
{
|
||||
fRightInset = right;
|
||||
fRightBottomInset.width = right;
|
||||
fLayoutItem->Layout()->InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
@ -377,7 +402,8 @@ Area::SetRightInset(int32 right)
|
||||
void
|
||||
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;
|
||||
|
||||
fLeftInset = 0;
|
||||
fTopInset = 0;
|
||||
fRightInset = 0;
|
||||
fBottomInset = 0;
|
||||
|
||||
fLS = ls;
|
||||
fLeft = left;
|
||||
fRight = right;
|
||||
@ -578,10 +599,10 @@ Area::_DoLayout()
|
||||
|
||||
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 @@ Area::_DoLayout()
|
||||
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 @@ Area::_UpdateMaxSizeConstraint(BSize max)
|
||||
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(),
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
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
|
||||
|
@ -38,9 +38,11 @@ public:
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user