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:
Alex Wilson
2012-05-03 08:44:17 +12:00
parent 1be46cf584
commit 75e2dcf8fe
3 changed files with 112 additions and 36 deletions
+22 -7
View File
@@ -31,7 +31,8 @@ class RowColumnManager;
*/ */
class BALMLayout : public BAbstractLayout { class BALMLayout : public BAbstractLayout {
public: public:
BALMLayout(float spacing = 0.0f, BALMLayout(float hSpacing = 0.0f,
float vSpacing = 0.0f,
BALMLayout* friendLayout = NULL); BALMLayout* friendLayout = NULL);
virtual ~BALMLayout(); virtual ~BALMLayout();
@@ -56,11 +57,16 @@ public:
LinearSpec* Solver() const; LinearSpec* Solver() const;
void SetInset(float inset); void SetInsets(float insets);
float Inset() const; 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); void SetSpacing(float hSpacing, float vSpacing);
float Spacing() const; void GetSpacing(float* _hSpacing,
float* _vSpacing) const;
Area* AreaFor(int32 id) const; Area* AreaFor(int32 id) const;
Area* AreaFor(const BView* view) const; Area* AreaFor(const BView* view) const;
@@ -139,6 +145,10 @@ protected:
private: private:
friend class XTab; friend class XTab;
friend class YTab; friend class YTab;
friend class Area;
float InsetForTab(XTab* tab);
float InsetForTab(YTab* tab);
/*! Add a view without initialize the Area. */ /*! Add a view without initialize the Area. */
BLayoutItem* _CreateLayoutItem(BView* view); BLayoutItem* _CreateLayoutItem(BView* view);
@@ -165,8 +175,13 @@ private:
BSize fMaxSize; BSize fMaxSize;
BSize fPreferredSize; BSize fPreferredSize;
float fInset; float fLeftInset;
float fSpacing; float fRightInset;
float fTopInset;
float fBottomInset;
float fHSpacing;
float fVSpacing;
Area* fCurrentArea; Area* fCurrentArea;
+86 -17
View File
@@ -4,8 +4,6 @@
* Copyright 2010, Clemens Zeidler <[email protected]> * Copyright 2010, Clemens Zeidler <[email protected]>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "ALMLayout.h" #include "ALMLayout.h"
#include <math.h> // for floor #include <math.h> // for floor
@@ -13,6 +11,8 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <ControlLook.h>
#include "RowColumnManager.h" #include "RowColumnManager.h"
#include "ViewLayoutItem.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. * 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), fLeftInset(0),
fSpacing(spacing / 2), fRightInset(0),
fTopInset(0),
fBottomInset(0),
fHSpacing(hSpacing),
fVSpacing(vSpacing),
fCurrentArea(NULL) fCurrentArea(NULL)
{ {
fSolver = friendLayout ? friendLayout->Solver() : &fOwnSolver; fSolver = friendLayout ? friendLayout->Solver() : &fOwnSolver;
@@ -977,30 +981,95 @@ BALMLayout::Solver() const
void 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);
InvalidateLayout();
float
BALMLayout::Inset() const
{
return fInset;
} }
void 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 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
View File
@@ -337,9 +337,7 @@ Area::LeftInset() const
return fTopLeftInset.Width(); return fTopLeftInset.Width();
BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout()); BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout());
if (fLeft.Get() == layout->Left()) return layout->InsetForTab(fLeft.Get());
return layout->Inset();
return layout->Spacing() / 2;
} }
@@ -353,9 +351,7 @@ Area::TopInset() const
return fTopLeftInset.Height(); return fTopLeftInset.Height();
BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout()); BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout());
if (fTop.Get() == layout->Top()) return layout->InsetForTab(fTop.Get());
return layout->Inset();
return layout->Spacing() / 2;
} }
@@ -369,9 +365,7 @@ Area::RightInset() const
return fRightBottomInset.Width(); return fRightBottomInset.Width();
BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout()); BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout());
if (fRight.Get() == layout->Right()) return layout->InsetForTab(fRight.Get());
return layout->Inset();
return layout->Spacing() / 2;
} }
@@ -385,9 +379,7 @@ Area::BottomInset() const
return fRightBottomInset.Height(); return fRightBottomInset.Height();
BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout()); BALMLayout* layout = static_cast<BALMLayout*>(fLayoutItem->Layout());
if (fBottom.Get() == layout->Bottom()) return layout->InsetForTab(fBottom.Get());
return layout->Inset();
return layout->Spacing() / 2;
} }