In BALMLayout, allow for more flexibility in spacing and insets.
* allow for independent left, top, right and bottom insets * allow for independent vertical and horizontal spacing between tabs * allow for the usage of Haiku's spacing constants such as B_USE_WINDOW_INSETS
This commit is contained in:
+86
-17
@@ -4,8 +4,6 @@
|
||||
* Copyright 2010, Clemens Zeidler <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "ALMLayout.h"
|
||||
|
||||
#include <math.h> // for floor
|
||||
@@ -13,6 +11,8 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <ControlLook.h>
|
||||
|
||||
#include "RowColumnManager.h"
|
||||
#include "ViewLayoutItem.h"
|
||||
|
||||
@@ -29,10 +29,14 @@ const BSize kUnsetSize(B_SIZE_UNSET, B_SIZE_UNSET);
|
||||
*
|
||||
* If friendLayout is not NULL the solver of the friend layout is used.
|
||||
*/
|
||||
BALMLayout::BALMLayout(float spacing, BALMLayout* friendLayout)
|
||||
BALMLayout::BALMLayout(float hSpacing, float vSpacing, BALMLayout* friendLayout)
|
||||
:
|
||||
fInset(0.0f),
|
||||
fSpacing(spacing / 2),
|
||||
fLeftInset(0),
|
||||
fRightInset(0),
|
||||
fTopInset(0),
|
||||
fBottomInset(0),
|
||||
fHSpacing(hSpacing),
|
||||
fVSpacing(vSpacing),
|
||||
fCurrentArea(NULL)
|
||||
{
|
||||
fSolver = friendLayout ? friendLayout->Solver() : &fOwnSolver;
|
||||
@@ -977,30 +981,95 @@ BALMLayout::Solver() const
|
||||
|
||||
|
||||
void
|
||||
BALMLayout::SetInset(float inset)
|
||||
BALMLayout::SetInsets(float left, float top, float right,
|
||||
float bottom)
|
||||
{
|
||||
fInset = inset;
|
||||
}
|
||||
fLeftInset = BControlLook::ComposeSpacing(left);
|
||||
fTopInset = BControlLook::ComposeSpacing(top);
|
||||
fRightInset = BControlLook::ComposeSpacing(right);
|
||||
fBottomInset = BControlLook::ComposeSpacing(bottom);
|
||||
|
||||
|
||||
float
|
||||
BALMLayout::Inset() const
|
||||
{
|
||||
return fInset;
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BALMLayout::SetSpacing(float spacing)
|
||||
BALMLayout::SetInsets(float horizontal, float vertical)
|
||||
{
|
||||
fSpacing = spacing / 2;
|
||||
fLeftInset = BControlLook::ComposeSpacing(horizontal);
|
||||
fRightInset = fLeftInset;
|
||||
|
||||
fTopInset = BControlLook::ComposeSpacing(vertical);
|
||||
fBottomInset = fTopInset;
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BALMLayout::SetInsets(float insets)
|
||||
{
|
||||
fLeftInset = BControlLook::ComposeSpacing(insets);
|
||||
fRightInset = fLeftInset;
|
||||
fTopInset = fLeftInset;
|
||||
fBottomInset = fLeftInset;
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BALMLayout::GetInsets(float* left, float* top, float* right,
|
||||
float* bottom) const
|
||||
{
|
||||
if (left)
|
||||
*left = fLeftInset;
|
||||
if (top)
|
||||
*top = fTopInset;
|
||||
if (right)
|
||||
*right = fRightInset;
|
||||
if (bottom)
|
||||
*bottom = fBottomInset;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BALMLayout::SetSpacing(float hSpacing, float vSpacing)
|
||||
{
|
||||
fHSpacing = BControlLook::ComposeSpacing(hSpacing);
|
||||
fVSpacing = BControlLook::ComposeSpacing(vSpacing);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BALMLayout::GetSpacing(float *_hSpacing, float *_vSpacing) const
|
||||
{
|
||||
if (_hSpacing)
|
||||
*_hSpacing = fHSpacing;
|
||||
if (_vSpacing)
|
||||
*_vSpacing = fVSpacing;
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
BALMLayout::Spacing() const
|
||||
BALMLayout::InsetForTab(XTab* tab)
|
||||
{
|
||||
return fSpacing * 2;
|
||||
if (tab == fLeft.Get())
|
||||
return fLeftInset;
|
||||
if (tab == fRight.Get())
|
||||
return fRightInset;
|
||||
return fHSpacing / 2;
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
BALMLayout::InsetForTab(YTab* tab)
|
||||
{
|
||||
if (tab == fTop.Get())
|
||||
return fTopInset;
|
||||
if (tab == fBottom.Get())
|
||||
return fBottomInset;
|
||||
return fVSpacing / 2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-12
@@ -337,9 +337,7 @@ Area::LeftInset() const
|
||||
return fTopLeftInset.Width();
|
||||
|
||||
BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout());
|
||||
if (fLeft.Get() == layout->Left())
|
||||
return layout->Inset();
|
||||
return layout->Spacing() / 2;
|
||||
return layout->InsetForTab(fLeft.Get());
|
||||
}
|
||||
|
||||
|
||||
@@ -353,9 +351,7 @@ Area::TopInset() const
|
||||
return fTopLeftInset.Height();
|
||||
|
||||
BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout());
|
||||
if (fTop.Get() == layout->Top())
|
||||
return layout->Inset();
|
||||
return layout->Spacing() / 2;
|
||||
return layout->InsetForTab(fTop.Get());
|
||||
}
|
||||
|
||||
|
||||
@@ -369,9 +365,7 @@ Area::RightInset() const
|
||||
return fRightBottomInset.Width();
|
||||
|
||||
BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout());
|
||||
if (fRight.Get() == layout->Right())
|
||||
return layout->Inset();
|
||||
return layout->Spacing() / 2;
|
||||
return layout->InsetForTab(fRight.Get());
|
||||
}
|
||||
|
||||
|
||||
@@ -385,9 +379,7 @@ Area::BottomInset() const
|
||||
return fRightBottomInset.Height();
|
||||
|
||||
BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout());
|
||||
if (fBottom.Get() == layout->Bottom())
|
||||
return layout->Inset();
|
||||
return layout->Spacing() / 2;
|
||||
return layout->InsetForTab(fBottom.Get());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user