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:
parent
1be46cf584
commit
75e2dcf8fe
@ -31,7 +31,8 @@ class RowColumnManager;
|
||||
*/
|
||||
class BALMLayout : public BAbstractLayout {
|
||||
public:
|
||||
BALMLayout(float spacing = 0.0f,
|
||||
BALMLayout(float hSpacing = 0.0f,
|
||||
float vSpacing = 0.0f,
|
||||
BALMLayout* friendLayout = NULL);
|
||||
virtual ~BALMLayout();
|
||||
|
||||
@ -56,11 +57,16 @@ public:
|
||||
|
||||
LinearSpec* Solver() const;
|
||||
|
||||
void SetInset(float inset);
|
||||
float Inset() const;
|
||||
void SetInsets(float insets);
|
||||
void SetInsets(float x, float y);
|
||||
void SetInsets(float left, float top, float right,
|
||||
float bottom);
|
||||
void GetInsets(float* left, float* top, float* right,
|
||||
float* bottom) const;
|
||||
|
||||
void SetSpacing(float spacing);
|
||||
float Spacing() const;
|
||||
void SetSpacing(float hSpacing, float vSpacing);
|
||||
void GetSpacing(float* _hSpacing,
|
||||
float* _vSpacing) const;
|
||||
|
||||
Area* AreaFor(int32 id) const;
|
||||
Area* AreaFor(const BView* view) const;
|
||||
@ -139,6 +145,10 @@ protected:
|
||||
private:
|
||||
friend class XTab;
|
||||
friend class YTab;
|
||||
friend class Area;
|
||||
|
||||
float InsetForTab(XTab* tab);
|
||||
float InsetForTab(YTab* tab);
|
||||
|
||||
/*! Add a view without initialize the Area. */
|
||||
BLayoutItem* _CreateLayoutItem(BView* view);
|
||||
@ -165,8 +175,13 @@ private:
|
||||
BSize fMaxSize;
|
||||
BSize fPreferredSize;
|
||||
|
||||
float fInset;
|
||||
float fSpacing;
|
||||
float fLeftInset;
|
||||
float fRightInset;
|
||||
float fTopInset;
|
||||
float fBottomInset;
|
||||
|
||||
float fHSpacing;
|
||||
float fVSpacing;
|
||||
|
||||
Area* fCurrentArea;
|
||||
|
||||
|
@ -4,8 +4,6 @@
|
||||
* Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de>
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user