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