Encapsulate the solver in the ALM layout class.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38750 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+17
-16
@@ -13,11 +13,11 @@
|
|||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
#include "Column.h"
|
||||||
|
#include "LinearSpec.h"
|
||||||
|
#include "Row.h"
|
||||||
#include "XTab.h"
|
#include "XTab.h"
|
||||||
#include "YTab.h"
|
#include "YTab.h"
|
||||||
#include "Area.h"
|
|
||||||
#include "Row.h"
|
|
||||||
#include "Column.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Constraint;
|
class Constraint;
|
||||||
@@ -26,8 +26,6 @@ class Constraint;
|
|||||||
namespace BALM {
|
namespace BALM {
|
||||||
|
|
||||||
|
|
||||||
class BALMLayout;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rectangular area in the GUI, defined by a tab on each side.
|
* Rectangular area in the GUI, defined by a tab on each side.
|
||||||
*/
|
*/
|
||||||
@@ -96,22 +94,22 @@ public:
|
|||||||
BList* HasSameSizeAs(Area* area);
|
BList* HasSameSizeAs(Area* area);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Area(BALMLayout* ls, XTab* left, YTab* top,
|
Area(BALMLayout* layout,
|
||||||
XTab* right, YTab* bottom,
|
LinearSpec* ls, XTab* left, YTab* top,
|
||||||
BView* content,
|
XTab* right, YTab* bottom, BView* content,
|
||||||
BSize minContentSize);
|
BSize minContentSize);
|
||||||
Area(BALMLayout* ls, Row* row, Column* column,
|
Area(BALMLayout* layout,
|
||||||
BView* content,
|
LinearSpec* ls, Row* row, Column* column,
|
||||||
BSize minContentSize);
|
BView* content, BSize minContentSize);
|
||||||
void DoLayout();
|
void DoLayout();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitChildArea();
|
void InitChildArea();
|
||||||
void UpdateHorizontal();
|
void UpdateHorizontal();
|
||||||
void UpdateVertical();
|
void UpdateVertical();
|
||||||
void Init(BALMLayout* ls, XTab* left, YTab* top,
|
void Init(BALMLayout* layout,
|
||||||
XTab* right, YTab* bottom,
|
LinearSpec* ls, XTab* left, YTab* top,
|
||||||
BView* content,
|
XTab* right, YTab* bottom, BView* content,
|
||||||
BSize minContentSize);
|
BSize minContentSize);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -124,7 +122,10 @@ protected:
|
|||||||
BList* fConstraints;
|
BList* fConstraints;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BALMLayout* fLS;
|
// TODO remove the layout pointer when making Area a LayoutItem
|
||||||
|
BALMLayout* fALMLayout;
|
||||||
|
|
||||||
|
LinearSpec* fLS;
|
||||||
XTab* fLeft;
|
XTab* fLeft;
|
||||||
XTab* fRight;
|
XTab* fRight;
|
||||||
YTab* fTop;
|
YTab* fTop;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace BALM {
|
|||||||
/**
|
/**
|
||||||
* A GUI layout engine using the ALM.
|
* A GUI layout engine using the ALM.
|
||||||
*/
|
*/
|
||||||
class BALMLayout : public BAbstractLayout, public LinearSpec {
|
class BALMLayout : public BAbstractLayout {
|
||||||
public:
|
public:
|
||||||
BALMLayout();
|
BALMLayout();
|
||||||
void SolveLayout();
|
void SolveLayout();
|
||||||
@@ -80,6 +80,8 @@ public:
|
|||||||
char* PerformancePath() const;
|
char* PerformancePath() const;
|
||||||
void SetPerformancePath(char* path);
|
void SetPerformancePath(char* path);
|
||||||
|
|
||||||
|
LinearSpec* Solver();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BSize CalculateMinSize();
|
BSize CalculateMinSize();
|
||||||
BSize CalculateMaxSize();
|
BSize CalculateMaxSize();
|
||||||
@@ -89,6 +91,8 @@ private:
|
|||||||
LayoutStyleType fLayoutStyle;
|
LayoutStyleType fLayoutStyle;
|
||||||
bool fActivated;
|
bool fActivated;
|
||||||
|
|
||||||
|
LinearSpec fSolver;
|
||||||
|
|
||||||
BList* fAreas;
|
BList* fAreas;
|
||||||
XTab* fLeft;
|
XTab* fLeft;
|
||||||
XTab* fRight;
|
XTab* fRight;
|
||||||
|
|||||||
+25
-26
@@ -3,14 +3,14 @@
|
|||||||
* Copyright 2007-2008, James Kim, [email protected]
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef COLUMN_H
|
#ifndef COLUMN_H
|
||||||
#define COLUMN_H
|
#define COLUMN_H
|
||||||
|
|
||||||
#include "Constraint.h"
|
|
||||||
|
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
|
||||||
|
#include "Constraint.h"
|
||||||
|
#include "LinearSpec.h"
|
||||||
|
|
||||||
|
|
||||||
namespace BALM {
|
namespace BALM {
|
||||||
|
|
||||||
@@ -21,36 +21,35 @@ class XTab;
|
|||||||
* Represents a column defined by two x-tabs.
|
* Represents a column defined by two x-tabs.
|
||||||
*/
|
*/
|
||||||
class Column {
|
class Column {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XTab* Left() const;
|
XTab* Left() const;
|
||||||
XTab* Right() const;
|
XTab* Right() const;
|
||||||
Column* Previous() const;
|
Column* Previous() const;
|
||||||
void SetPrevious(Column* value);
|
void SetPrevious(Column* value);
|
||||||
Column* Next() const;
|
Column* Next() const;
|
||||||
void SetNext(Column* value);
|
void SetNext(Column* value);
|
||||||
//~ string ToString();
|
//~ string ToString();
|
||||||
void InsertBefore(Column* column);
|
void InsertBefore(Column* column);
|
||||||
void InsertAfter(Column* column);
|
void InsertAfter(Column* column);
|
||||||
Constraint* HasSameWidthAs(Column* column);
|
Constraint* HasSameWidthAs(Column* column);
|
||||||
BList* Constraints() const;
|
BList* Constraints() const;
|
||||||
void SetConstraints(BList* constraints);
|
void SetConstraints(BList* constraints);
|
||||||
~Column();
|
~Column();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Column(BALMLayout* ls);
|
Column(LinearSpec* ls);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BALMLayout* fLS;
|
LinearSpec* fLS;
|
||||||
XTab* fLeft;
|
XTab* fLeft;
|
||||||
XTab* fRight;
|
XTab* fRight;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Column* fPrevious;
|
Column* fPrevious;
|
||||||
Column* fNext;
|
Column* fNext;
|
||||||
Constraint* fPreviousGlue;
|
Constraint* fPreviousGlue;
|
||||||
Constraint* fNextGlue;
|
Constraint* fNextGlue;
|
||||||
BList* fConstraints;
|
BList* fConstraints;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend class BALMLayout;
|
friend class BALMLayout;
|
||||||
|
|||||||
+25
-25
@@ -7,10 +7,11 @@
|
|||||||
#ifndef ROW_H
|
#ifndef ROW_H
|
||||||
#define ROW_H
|
#define ROW_H
|
||||||
|
|
||||||
#include "Constraint.h"
|
|
||||||
|
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
|
||||||
|
#include "Constraint.h"
|
||||||
|
#include "LinearSpec.h"
|
||||||
|
|
||||||
|
|
||||||
namespace BALM {
|
namespace BALM {
|
||||||
|
|
||||||
@@ -21,36 +22,35 @@ class YTab;
|
|||||||
* Represents a row defined by two y-tabs.
|
* Represents a row defined by two y-tabs.
|
||||||
*/
|
*/
|
||||||
class Row {
|
class Row {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
YTab* Top() const;
|
YTab* Top() const;
|
||||||
YTab* Bottom() const;
|
YTab* Bottom() const;
|
||||||
Row* Previous() const;
|
Row* Previous() const;
|
||||||
void SetPrevious(Row* value);
|
void SetPrevious(Row* value);
|
||||||
Row* Next() const;
|
Row* Next() const;
|
||||||
void SetNext(Row* value);
|
void SetNext(Row* value);
|
||||||
//~ string ToString();
|
//~ string ToString();
|
||||||
void InsertBefore(Row* row);
|
void InsertBefore(Row* row);
|
||||||
void InsertAfter(Row* row);
|
void InsertAfter(Row* row);
|
||||||
Constraint* HasSameHeightAs(Row* row);
|
Constraint* HasSameHeightAs(Row* row);
|
||||||
BList* Constraints() const;
|
BList* Constraints() const;
|
||||||
void SetConstraints(BList* constraints);
|
void SetConstraints(BList* constraints);
|
||||||
~Row();
|
~Row();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Row(BALMLayout* ls);
|
Row(LinearSpec* ls);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BALMLayout* fLS;
|
LinearSpec* fLS;
|
||||||
YTab* fTop;
|
YTab* fTop;
|
||||||
YTab* fBottom;
|
YTab* fBottom;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Row* fPrevious;
|
Row* fPrevious;
|
||||||
Row* fNext;
|
Row* fNext;
|
||||||
Constraint* fPreviousGlue;
|
Constraint* fPreviousGlue;
|
||||||
Constraint* fNextGlue;
|
Constraint* fNextGlue;
|
||||||
BList* fConstraints;
|
BList* fConstraints;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend class BALMLayout;
|
friend class BALMLayout;
|
||||||
|
|||||||
+9
-11
@@ -3,32 +3,30 @@
|
|||||||
* Copyright 2007-2008, James Kim, [email protected]
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef X_TAB_H
|
#ifndef X_TAB_H
|
||||||
#define X_TAB_H
|
#define X_TAB_H
|
||||||
|
|
||||||
|
#include "LinearSpec.h"
|
||||||
#include "Variable.h"
|
#include "Variable.h"
|
||||||
|
|
||||||
|
|
||||||
namespace BALM {
|
namespace BALM {
|
||||||
|
|
||||||
class BALMLayout;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vertical grid line (x-tab).
|
* Vertical grid line (x-tab).
|
||||||
*/
|
*/
|
||||||
class XTab : public Variable {
|
class XTab : public Variable {
|
||||||
|
protected:
|
||||||
|
XTab(LinearSpec* ls);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
XTab(BALMLayout* ls);
|
/**
|
||||||
|
* Property signifying if there is a constraint which relates
|
||||||
protected:
|
* this tab to a different tab that is further to the left.
|
||||||
/**
|
* Only used for reverse engineering.
|
||||||
* Property signifying if there is a constraint which relates
|
*/
|
||||||
* this tab to a different tab that is further to the left.
|
bool fLeftLink;
|
||||||
* Only used for reverse engineering.
|
|
||||||
*/
|
|
||||||
bool fLeftLink;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend class Area;
|
friend class Area;
|
||||||
|
|||||||
+10
-11
@@ -3,31 +3,30 @@
|
|||||||
* Copyright 2007-2008, James Kim, [email protected]
|
* Copyright 2007-2008, James Kim, [email protected]
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef Y_TAB_H
|
#ifndef Y_TAB_H
|
||||||
#define Y_TAB_H
|
#define Y_TAB_H
|
||||||
|
|
||||||
|
#include "LinearSpec.h"
|
||||||
#include "Variable.h"
|
#include "Variable.h"
|
||||||
|
|
||||||
|
|
||||||
namespace BALM {
|
namespace BALM {
|
||||||
|
|
||||||
class BALMLayout;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Horizontal grid line (y-tab).
|
* Horizontal grid line (y-tab).
|
||||||
*/
|
*/
|
||||||
class YTab : public Variable {
|
class YTab : public Variable {
|
||||||
|
protected:
|
||||||
|
YTab(LinearSpec* ls);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
YTab(BALMLayout* ls);
|
/**
|
||||||
|
* Property signifying if there is a constraint which relates
|
||||||
protected:
|
* this tab to a different tab that is further to the top.
|
||||||
/**
|
* Only used for reverse engineering.
|
||||||
* Property signifying if there is a constraint which relates
|
*/
|
||||||
* this tab to a different tab that is further to the top.
|
bool fTopLink;
|
||||||
* Only used for reverse engineering.
|
|
||||||
*/
|
|
||||||
bool fTopLink;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend class Area;
|
friend class Area;
|
||||||
|
|||||||
+33
-31
@@ -85,7 +85,7 @@ Area::SetLeft(XTab* left)
|
|||||||
fMaxContentWidth->SetLeftSide(-1.0, fLeft, 1.0, fRight);
|
fMaxContentWidth->SetLeftSide(-1.0, fLeft, 1.0, fRight);
|
||||||
} else
|
} else
|
||||||
UpdateHorizontal();
|
UpdateHorizontal();
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ Area::SetRight(XTab* right)
|
|||||||
fMaxContentWidth->SetLeftSide(-1.0, fLeft, 1.0, fRight);
|
fMaxContentWidth->SetLeftSide(-1.0, fLeft, 1.0, fRight);
|
||||||
} else
|
} else
|
||||||
UpdateHorizontal();
|
UpdateHorizontal();
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ Area::SetTop(YTab* top)
|
|||||||
fMaxContentHeight->SetLeftSide(-1.0, fTop, 1.0, fBottom);
|
fMaxContentHeight->SetLeftSide(-1.0, fTop, 1.0, fBottom);
|
||||||
} else
|
} else
|
||||||
UpdateVertical();
|
UpdateVertical();
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ Area::SetBottom(YTab* bottom)
|
|||||||
fMaxContentHeight->SetLeftSide(-1.0, fTop, 1.0, fBottom);
|
fMaxContentHeight->SetLeftSide(-1.0, fTop, 1.0, fBottom);
|
||||||
} else
|
} else
|
||||||
UpdateVertical();
|
UpdateVertical();
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ Area::SetRow(Row* row)
|
|||||||
SetTop(row->Top());
|
SetTop(row->Top());
|
||||||
SetBottom(row->Bottom());
|
SetBottom(row->Bottom());
|
||||||
fRow = row;
|
fRow = row;
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ Area::SetColumn(Column* column)
|
|||||||
SetLeft(column->Left());
|
SetLeft(column->Left());
|
||||||
SetRight(column->Right());
|
SetRight(column->Right());
|
||||||
fColumn = column;
|
fColumn = column;
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -252,7 +252,7 @@ Area::SetContent(BView* content)
|
|||||||
{
|
{
|
||||||
if (fChildArea == NULL) fContent = content;
|
if (fChildArea == NULL) fContent = content;
|
||||||
else fChildArea->fContent = content;
|
else fChildArea->fContent = content;
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -319,7 +319,7 @@ Area::SetMinContentSize(BSize min)
|
|||||||
fMinContentHeight->SetRightSide(fMinContentSize.Height());
|
fMinContentHeight->SetRightSide(fMinContentSize.Height());
|
||||||
} else
|
} else
|
||||||
fChildArea->SetMinContentSize(min);
|
fChildArea->SetMinContentSize(min);
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -354,7 +354,7 @@ Area::SetMaxContentSize(BSize max)
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
fChildArea->SetMaxContentSize(max);
|
fChildArea->SetMaxContentSize(max);
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ Area::SetPreferredContentSize(BSize preferred)
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
fChildArea->SetPreferredContentSize(preferred);
|
fChildArea->SetPreferredContentSize(preferred);
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -422,7 +422,7 @@ void Area::SetShrinkPenalties(BSize shrink) {
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
fChildArea->SetShrinkPenalties(shrink);
|
fChildArea->SetShrinkPenalties(shrink);
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -448,7 +448,7 @@ Area::SetGrowPenalties(BSize grow)
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
fChildArea->SetGrowPenalties(grow);
|
fChildArea->SetGrowPenalties(grow);
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -458,7 +458,8 @@ Area::SetGrowPenalties(BSize grow)
|
|||||||
double
|
double
|
||||||
Area::ContentAspectRatio() const
|
Area::ContentAspectRatio() const
|
||||||
{
|
{
|
||||||
return (fChildArea == NULL) ? fContentAspectRatio : fChildArea->fContentAspectRatio;
|
return (fChildArea == NULL) ? fContentAspectRatio
|
||||||
|
: fChildArea->fContentAspectRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -482,7 +483,7 @@ Area::SetContentAspectRatio(double ratio)
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
fChildArea->SetContentAspectRatio(ratio);
|
fChildArea->SetContentAspectRatio(ratio);
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -505,7 +506,7 @@ Area::SetAlignment(BAlignment alignment)
|
|||||||
fAlignment = alignment;
|
fAlignment = alignment;
|
||||||
UpdateHorizontal();
|
UpdateHorizontal();
|
||||||
UpdateVertical();
|
UpdateVertical();
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -515,7 +516,7 @@ Area::SetAlignment(BAlignment alignment)
|
|||||||
void Area::SetHorizontalAlignment(alignment horizontal) {
|
void Area::SetHorizontalAlignment(alignment horizontal) {
|
||||||
fAlignment.SetHorizontal(horizontal);
|
fAlignment.SetHorizontal(horizontal);
|
||||||
UpdateHorizontal();
|
UpdateHorizontal();
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -527,7 +528,7 @@ Area::SetVerticalAlignment(vertical_alignment vertical)
|
|||||||
{
|
{
|
||||||
fAlignment.SetVertical(vertical);
|
fAlignment.SetVertical(vertical);
|
||||||
UpdateVertical();
|
UpdateVertical();
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -549,7 +550,7 @@ Area::SetLeftInset(int32 left)
|
|||||||
{
|
{
|
||||||
fLeftInset = left;
|
fLeftInset = left;
|
||||||
UpdateHorizontal();
|
UpdateHorizontal();
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -571,7 +572,7 @@ Area::SetTopInset(int32 top)
|
|||||||
{
|
{
|
||||||
fTopInset = top;
|
fTopInset = top;
|
||||||
UpdateVertical();
|
UpdateVertical();
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -633,7 +634,7 @@ Area::SetDefaultBehavior()
|
|||||||
|
|
||||||
if (PreferredContentSize() != Content()->PreferredSize()){
|
if (PreferredContentSize() != Content()->PreferredSize()){
|
||||||
SetPreferredContentSize(Content()->PreferredSize());
|
SetPreferredContentSize(Content()->PreferredSize());
|
||||||
fLS->InvalidateLayout();
|
fALMLayout->InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dynamic_cast<BButton*>(Content()) != NULL
|
if (dynamic_cast<BButton*>(Content()) != NULL
|
||||||
@@ -729,7 +730,7 @@ Area::~Area()
|
|||||||
if (fChildArea != NULL) delete fChildArea;
|
if (fChildArea != NULL) delete fChildArea;
|
||||||
for (int32 i = 0; i < fConstraints->CountItems(); i++)
|
for (int32 i = 0; i < fConstraints->CountItems(); i++)
|
||||||
delete (Constraint*)fConstraints->ItemAt(i);
|
delete (Constraint*)fConstraints->ItemAt(i);
|
||||||
fLS->Areas()->RemoveItem(this);
|
fALMLayout->Areas()->RemoveItem(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -737,10 +738,10 @@ Area::~Area()
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
* Uses XTabs and YTabs.
|
* Uses XTabs and YTabs.
|
||||||
*/
|
*/
|
||||||
Area::Area(BALMLayout* ls, XTab* left, YTab* top, XTab* right, YTab* bottom,
|
Area::Area(BALMLayout* layout, LinearSpec* ls, XTab* left, YTab* top,
|
||||||
BView* content, BSize minContentSize)
|
XTab* right, YTab* bottom, BView* content, BSize minContentSize)
|
||||||
{
|
{
|
||||||
Init(ls, left, top, right, bottom, content, minContentSize);
|
Init(layout, ls, left, top, right, bottom, content, minContentSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -748,11 +749,11 @@ Area::Area(BALMLayout* ls, XTab* left, YTab* top, XTab* right, YTab* bottom,
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
* Uses Rows and Columns.
|
* Uses Rows and Columns.
|
||||||
*/
|
*/
|
||||||
Area::Area(BALMLayout* ls, Row* row, Column* column, BView* content,
|
Area::Area(BALMLayout* layout, LinearSpec* ls, Row* row, Column* column,
|
||||||
BSize minContentSize)
|
BView* content, BSize minContentSize)
|
||||||
{
|
{
|
||||||
|
|
||||||
Init(ls, column->Left(), row->Top(), column->Right(), row->Bottom(),
|
Init(layout, ls, column->Left(), row->Top(), column->Right(), row->Bottom(),
|
||||||
content, minContentSize);
|
content, minContentSize);
|
||||||
fRow = row;
|
fRow = row;
|
||||||
fColumn = column;
|
fColumn = column;
|
||||||
@@ -763,9 +764,10 @@ Area::Area(BALMLayout* ls, Row* row, Column* column, BView* content,
|
|||||||
* Initialize variables.
|
* Initialize variables.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Area::Init(BALMLayout* ls, XTab* left, YTab* top, XTab* right, YTab* bottom,
|
Area::Init(BALMLayout* layout, LinearSpec* ls, XTab* left, YTab* top,
|
||||||
BView* content, BSize minContentSize)
|
XTab* right, YTab* bottom, BView* content, BSize minContentSize)
|
||||||
{
|
{
|
||||||
|
fALMLayout = layout;
|
||||||
|
|
||||||
fConstraints = new BList(2);
|
fConstraints = new BList(2);
|
||||||
fMaxContentSize = kMaxSize;
|
fMaxContentSize = kMaxSize;
|
||||||
@@ -848,8 +850,8 @@ Area::InitChildArea()
|
|||||||
// add a child area with new tabs,
|
// add a child area with new tabs,
|
||||||
// and add constraints that set its tabs to be equal to the
|
// and add constraints that set its tabs to be equal to the
|
||||||
// coresponding tabs of this area (for a start)
|
// coresponding tabs of this area (for a start)
|
||||||
fChildArea = new Area(fLS, new XTab(fLS), new YTab(fLS), new XTab(fLS),
|
fChildArea = new Area(fALMLayout, fLS, new XTab(fLS), new YTab(fLS),
|
||||||
new YTab(fLS), fContent, BSize(0, 0));
|
new XTab(fLS), new YTab(fLS), fContent, BSize(0, 0));
|
||||||
fLeftConstraint = fLeft->IsEqual(fChildArea->Left());
|
fLeftConstraint = fLeft->IsEqual(fChildArea->Left());
|
||||||
fConstraints->AddItem(fLeftConstraint);
|
fConstraints->AddItem(fLeftConstraint);
|
||||||
fTopConstraint = fTop->IsEqual(fChildArea->Top());
|
fTopConstraint = fTop->IsEqual(fChildArea->Top());
|
||||||
|
|||||||
+62
-46
@@ -21,17 +21,16 @@
|
|||||||
*/
|
*/
|
||||||
BALMLayout::BALMLayout()
|
BALMLayout::BALMLayout()
|
||||||
:
|
:
|
||||||
BAbstractLayout(),
|
BAbstractLayout()
|
||||||
LinearSpec()
|
|
||||||
{
|
{
|
||||||
fLayoutStyle = FIT_TO_SIZE;
|
fLayoutStyle = FIT_TO_SIZE;
|
||||||
fActivated = true;
|
fActivated = true;
|
||||||
|
|
||||||
fAreas = new BList(1);
|
fAreas = new BList(1);
|
||||||
fLeft = new XTab(this);
|
fLeft = new XTab(&fSolver);
|
||||||
fRight = new XTab(this);
|
fRight = new XTab(&fSolver);
|
||||||
fTop = new YTab(this);
|
fTop = new YTab(&fSolver);
|
||||||
fBottom = new YTab(this);
|
fBottom = new YTab(&fSolver);
|
||||||
|
|
||||||
// the Left tab is always at x-position 0, and the Top tab is always at y-position 0
|
// the Left tab is always at x-position 0, and the Top tab is always at y-position 0
|
||||||
fLeft->SetRange(0, 0);
|
fLeft->SetRange(0, 0);
|
||||||
@@ -75,12 +74,13 @@ BALMLayout::SolveLayout()
|
|||||||
|
|
||||||
ResultType result;
|
ResultType result;
|
||||||
for (int32 tries = 0; tries < 15; tries++) {
|
for (int32 tries = 0; tries < 15; tries++) {
|
||||||
result = Solve();
|
result = fSolver.Solve();
|
||||||
if (fPerformancePath != NULL) {
|
if (fPerformancePath != NULL) {
|
||||||
char buffer [100];
|
/*char buffer [100];
|
||||||
file->Write(buffer, sprintf(buffer, "%d\t%fms\t#vars=%ld\t"
|
file->Write(buffer, sprintf(buffer, "%d\t%fms\t#vars=%ld\t"
|
||||||
"#constraints=%ld\n", result, SolvingTime(),
|
"#constraints=%ld\n", result, fSolver.SolvingTime(),
|
||||||
Variables()->CountItems(), Constraints()->CountItems()));
|
fSolver.Variables()->CountItems(),
|
||||||
|
fSolver.Constraints()->CountItems()));*/
|
||||||
}
|
}
|
||||||
if (result == OPTIMAL || result == INFEASIBLE)
|
if (result == OPTIMAL || result == INFEASIBLE)
|
||||||
break;
|
break;
|
||||||
@@ -97,7 +97,7 @@ BALMLayout::SolveLayout()
|
|||||||
XTab*
|
XTab*
|
||||||
BALMLayout::AddXTab()
|
BALMLayout::AddXTab()
|
||||||
{
|
{
|
||||||
return new XTab(this);
|
return new XTab(&fSolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ BALMLayout::AddXTab()
|
|||||||
YTab*
|
YTab*
|
||||||
BALMLayout::AddYTab()
|
BALMLayout::AddYTab()
|
||||||
{
|
{
|
||||||
return new YTab(this);
|
return new YTab(&fSolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ BALMLayout::AddYTab()
|
|||||||
Row*
|
Row*
|
||||||
BALMLayout::AddRow()
|
BALMLayout::AddRow()
|
||||||
{
|
{
|
||||||
return new Row(this);
|
return new Row(&fSolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ BALMLayout::AddRow()
|
|||||||
Row*
|
Row*
|
||||||
BALMLayout::AddRow(YTab* top, YTab* bottom)
|
BALMLayout::AddRow(YTab* top, YTab* bottom)
|
||||||
{
|
{
|
||||||
Row* row = new Row(this);
|
Row* row = new Row(&fSolver);
|
||||||
if (top != NULL)
|
if (top != NULL)
|
||||||
row->Constraints()->AddItem(row->Top()->IsEqual(top));
|
row->Constraints()->AddItem(row->Top()->IsEqual(top));
|
||||||
if (bottom != NULL)
|
if (bottom != NULL)
|
||||||
@@ -152,7 +152,7 @@ BALMLayout::AddRow(YTab* top, YTab* bottom)
|
|||||||
Column*
|
Column*
|
||||||
BALMLayout::AddColumn()
|
BALMLayout::AddColumn()
|
||||||
{
|
{
|
||||||
return new Column(this);
|
return new Column(&fSolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ BALMLayout::AddColumn()
|
|||||||
Column*
|
Column*
|
||||||
BALMLayout::AddColumn(XTab* left, XTab* right)
|
BALMLayout::AddColumn(XTab* left, XTab* right)
|
||||||
{
|
{
|
||||||
Column* column = new Column(this);
|
Column* column = new Column(&fSolver);
|
||||||
if (left != NULL) column->Constraints()->AddItem(column->Left()->IsEqual(left));
|
if (left != NULL) column->Constraints()->AddItem(column->Left()->IsEqual(left));
|
||||||
if (right != NULL) column->Constraints()->AddItem(column->Right()->IsEqual(right));
|
if (right != NULL) column->Constraints()->AddItem(column->Right()->IsEqual(right));
|
||||||
return column;
|
return column;
|
||||||
@@ -191,7 +191,8 @@ BALMLayout::AddArea(XTab* left, YTab* top, XTab* right, YTab* bottom,
|
|||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
if (content != NULL)
|
if (content != NULL)
|
||||||
TargetView()->AddChild(content);
|
TargetView()->AddChild(content);
|
||||||
Area* area = new Area(this, left, top, right, bottom, content, minContentSize);
|
Area* area = new Area(this, &fSolver, left, top, right, bottom, content,
|
||||||
|
minContentSize);
|
||||||
fAreas->AddItem(area);
|
fAreas->AddItem(area);
|
||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
@@ -213,7 +214,7 @@ BALMLayout::AddArea(Row* row, Column* column, BView* content,
|
|||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
if (content != NULL)
|
if (content != NULL)
|
||||||
TargetView()->AddChild(content);
|
TargetView()->AddChild(content);
|
||||||
Area* area = new Area(this, row, column, content, minContentSize);
|
Area* area = new Area(this, &fSolver, row, column, content, minContentSize);
|
||||||
fAreas->AddItem(area);
|
fAreas->AddItem(area);
|
||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
@@ -236,7 +237,8 @@ BALMLayout::AddArea(XTab* left, YTab* top, XTab* right, YTab* bottom,
|
|||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
if (content != NULL)
|
if (content != NULL)
|
||||||
TargetView()->AddChild(content);
|
TargetView()->AddChild(content);
|
||||||
Area* area = new Area(this, left, top, right, bottom, content, BSize(0, 0));
|
Area* area = new Area(this, &fSolver, left, top, right, bottom, content,
|
||||||
|
BSize(0, 0));
|
||||||
area->SetDefaultBehavior();
|
area->SetDefaultBehavior();
|
||||||
area->SetAutoPreferredContentSize(false);
|
area->SetAutoPreferredContentSize(false);
|
||||||
fAreas->AddItem(area);
|
fAreas->AddItem(area);
|
||||||
@@ -258,7 +260,7 @@ BALMLayout::AddArea(Row* row, Column* column, BView* content)
|
|||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
if (content != NULL)
|
if (content != NULL)
|
||||||
TargetView()->AddChild(content);
|
TargetView()->AddChild(content);
|
||||||
Area* area = new Area(this, row, column, content, BSize(0, 0));
|
Area* area = new Area(this, &fSolver, row, column, content, BSize(0, 0));
|
||||||
area->SetDefaultBehavior();
|
area->SetDefaultBehavior();
|
||||||
area->SetAutoPreferredContentSize(false);
|
area->SetAutoPreferredContentSize(false);
|
||||||
fAreas->AddItem(area);
|
fAreas->AddItem(area);
|
||||||
@@ -546,14 +548,15 @@ BALMLayout::DerivedLayoutItems()
|
|||||||
SolveLayout();
|
SolveLayout();
|
||||||
|
|
||||||
// if new layout is infasible, use previous layout
|
// if new layout is infasible, use previous layout
|
||||||
if (Result() == INFEASIBLE) {
|
if (fSolver.Result() == INFEASIBLE) {
|
||||||
fActivated = true; // now layout calculation is allowed to run again
|
fActivated = true; // now layout calculation is allowed to run again
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Result() != OPTIMAL) {
|
if (fSolver.Result() != OPTIMAL) {
|
||||||
Save("failed-layout.txt");
|
fSolver.Save("failed-layout.txt");
|
||||||
printf("Could not solve the layout specification (%d). ", Result());
|
printf("Could not solve the layout specification (%d). ",
|
||||||
|
fSolver.Result());
|
||||||
printf("Saved specification in file failed-layout.txt\n");
|
printf("Saved specification in file failed-layout.txt\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,32 +599,41 @@ BALMLayout::SetPerformancePath(char* path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LinearSpec*
|
||||||
|
BALMLayout::Solver()
|
||||||
|
{
|
||||||
|
return &fSolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caculates the miminum size.
|
* Caculates the miminum size.
|
||||||
*/
|
*/
|
||||||
BSize
|
BSize
|
||||||
BALMLayout::CalculateMinSize()
|
BALMLayout::CalculateMinSize()
|
||||||
{
|
{
|
||||||
SummandList* oldObjFunction = ObjFunction();
|
SummandList* oldObjFunction = fSolver.ObjFunction();
|
||||||
SummandList* newObjFunction = new SummandList(2);
|
SummandList* newObjFunction = new SummandList(2);
|
||||||
newObjFunction->AddItem(new Summand(1.0, fRight));
|
newObjFunction->AddItem(new Summand(1.0, fRight));
|
||||||
newObjFunction->AddItem(new Summand(1.0, fBottom));
|
newObjFunction->AddItem(new Summand(1.0, fBottom));
|
||||||
SetObjFunction(newObjFunction);
|
fSolver.SetObjFunction(newObjFunction);
|
||||||
SolveLayout();
|
SolveLayout();
|
||||||
SetObjFunction(oldObjFunction);
|
fSolver.SetObjFunction(oldObjFunction);
|
||||||
UpdateObjFunction();
|
fSolver.UpdateObjFunction();
|
||||||
delete newObjFunction->ItemAt(0);
|
delete newObjFunction->ItemAt(0);
|
||||||
delete newObjFunction->ItemAt(1);
|
delete newObjFunction->ItemAt(1);
|
||||||
delete newObjFunction;
|
delete newObjFunction;
|
||||||
|
|
||||||
if (Result() == UNBOUNDED)
|
if (fSolver.Result() == UNBOUNDED)
|
||||||
return Area::kMinSize;
|
return Area::kMinSize;
|
||||||
if (Result() != OPTIMAL) {
|
if (fSolver.Result() != OPTIMAL) {
|
||||||
Save("failed-layout.txt");
|
fSolver.Save("failed-layout.txt");
|
||||||
printf("Could not solve the layout specification (%d). Saved specification in file failed-layout.txt", Result());
|
printf("Could not solve the layout specification (%d). "
|
||||||
|
"Saved specification in file failed-layout.txt", fSolver.Result());
|
||||||
}
|
}
|
||||||
|
|
||||||
return BSize(Right()->Value() - Left()->Value(), Bottom()->Value() - Top()->Value());
|
return BSize(Right()->Value() - Left()->Value(),
|
||||||
|
Bottom()->Value() - Top()->Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -631,26 +643,28 @@ BALMLayout::CalculateMinSize()
|
|||||||
BSize
|
BSize
|
||||||
BALMLayout::CalculateMaxSize()
|
BALMLayout::CalculateMaxSize()
|
||||||
{
|
{
|
||||||
SummandList* oldObjFunction = ObjFunction();
|
SummandList* oldObjFunction = fSolver.ObjFunction();
|
||||||
SummandList* newObjFunction = new SummandList(2);
|
SummandList* newObjFunction = new SummandList(2);
|
||||||
newObjFunction->AddItem(new Summand(-1.0, fRight));
|
newObjFunction->AddItem(new Summand(-1.0, fRight));
|
||||||
newObjFunction->AddItem(new Summand(-1.0, fBottom));
|
newObjFunction->AddItem(new Summand(-1.0, fBottom));
|
||||||
SetObjFunction(newObjFunction);
|
fSolver.SetObjFunction(newObjFunction);
|
||||||
SolveLayout();
|
SolveLayout();
|
||||||
SetObjFunction(oldObjFunction);
|
fSolver.SetObjFunction(oldObjFunction);
|
||||||
UpdateObjFunction();
|
fSolver.UpdateObjFunction();
|
||||||
delete newObjFunction->ItemAt(0);
|
delete newObjFunction->ItemAt(0);
|
||||||
delete newObjFunction->ItemAt(1);
|
delete newObjFunction->ItemAt(1);
|
||||||
delete newObjFunction;
|
delete newObjFunction;
|
||||||
|
|
||||||
if (Result() == UNBOUNDED)
|
if (fSolver.Result() == UNBOUNDED)
|
||||||
return Area::kMaxSize;
|
return Area::kMaxSize;
|
||||||
if (Result() != OPTIMAL) {
|
if (fSolver.Result() != OPTIMAL) {
|
||||||
Save("failed-layout.txt");
|
fSolver.Save("failed-layout.txt");
|
||||||
printf("Could not solve the layout specification (%d). Saved specification in file failed-layout.txt", Result());
|
printf("Could not solve the layout specification (%d). "
|
||||||
|
"Saved specification in file failed-layout.txt", fSolver.Result());
|
||||||
}
|
}
|
||||||
|
|
||||||
return BSize(Right()->Value() - Left()->Value(), Bottom()->Value() - Top()->Value());
|
return BSize(Right()->Value() - Left()->Value(),
|
||||||
|
Bottom()->Value() - Top()->Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -661,11 +675,13 @@ BSize
|
|||||||
BALMLayout::CalculatePreferredSize()
|
BALMLayout::CalculatePreferredSize()
|
||||||
{
|
{
|
||||||
SolveLayout();
|
SolveLayout();
|
||||||
if (Result() != OPTIMAL) {
|
if (fSolver.Result() != OPTIMAL) {
|
||||||
Save("failed-layout.txt");
|
fSolver.Save("failed-layout.txt");
|
||||||
printf("Could not solve the layout specification (%d). Saved specification in file failed-layout.txt", Result());
|
printf("Could not solve the layout specification (%d). "
|
||||||
|
"Saved specification in file failed-layout.txt", fSolver.Result());
|
||||||
}
|
}
|
||||||
|
|
||||||
return BSize(Right()->Value() - Left()->Value(), Bottom()->Value() - Top()->Value());
|
return BSize(Right()->Value() - Left()->Value(),
|
||||||
|
Bottom()->Value() - Top()->Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ Column::~Column()
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
Column::Column(BALMLayout* ls)
|
Column::Column(LinearSpec* ls)
|
||||||
{
|
{
|
||||||
fLS = ls;
|
fLS = ls;
|
||||||
fLeft = new XTab(ls);
|
fLeft = new XTab(ls);
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ Row::~Row()
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
Row::Row(BALMLayout* ls)
|
Row::Row(LinearSpec* ls)
|
||||||
{
|
{
|
||||||
fLS = ls;
|
fLS = ls;
|
||||||
fTop = new YTab(ls);
|
fTop = new YTab(ls);
|
||||||
|
|||||||
@@ -5,13 +5,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "XTab.h"
|
#include "XTab.h"
|
||||||
#include "BALMLayout.h"
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
XTab::XTab(BALMLayout* ls)
|
XTab::XTab(LinearSpec* ls)
|
||||||
: Variable(ls)
|
: Variable(ls)
|
||||||
{
|
{
|
||||||
fLeftLink = false;
|
fLeftLink = false;
|
||||||
|
|||||||
@@ -5,13 +5,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "YTab.h"
|
#include "YTab.h"
|
||||||
#include "BALMLayout.h"
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
YTab::YTab(BALMLayout* ls)
|
YTab::YTab(LinearSpec* ls)
|
||||||
: Variable(ls)
|
: Variable(ls)
|
||||||
{
|
{
|
||||||
fTopLink = false;
|
fTopLink = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user