Remove unsupported reverse engineering feature. Further clean up.

Also remove LayoutStyle feature because resizing the parent view might not be a good idea. If the parent view should be resized you should better but it into a BLayout too.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38779 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler
2010-09-22 05:29:50 +00:00
parent 33c82c1e9d
commit 0871de7bdf
3 changed files with 58 additions and 155 deletions
+5 -14
View File
@@ -14,7 +14,6 @@
#include "Area.h" #include "Area.h"
#include "Column.h" #include "Column.h"
#include "LayoutStyleType.h"
#include "LinearSpec.h" #include "LinearSpec.h"
#include "Row.h" #include "Row.h"
#include "XTab.h" #include "XTab.h"
@@ -31,8 +30,6 @@ public:
BALMLayout(); BALMLayout();
virtual ~BALMLayout(); virtual ~BALMLayout();
void SolveLayout();
XTab* AddXTab(); XTab* AddXTab();
YTab* AddYTab(); YTab* AddYTab();
Row* AddRow(); Row* AddRow();
@@ -54,11 +51,6 @@ public:
XTab* Right() const; XTab* Right() const;
YTab* Top() const; YTab* Top() const;
YTab* Bottom() const; YTab* Bottom() const;
void RecoverLayout(BView* parent);
LayoutStyleType LayoutStyle() const;
void SetLayoutStyle(LayoutStyleType style);
virtual BSize BaseMinSize(); virtual BSize BaseMinSize();
virtual BSize BaseMaxSize(); virtual BSize BaseMaxSize();
@@ -77,16 +69,15 @@ public:
LinearSpec* Solver(); LinearSpec* Solver();
private: private:
void _SolveLayout();
Area* _AreaForItem(BLayoutItem* item) const; Area* _AreaForItem(BLayoutItem* item) const;
void _UpdateAreaConstraints(); void _UpdateAreaConstraints();
BSize CalculateMinSize(); BSize _CalculateMinSize();
BSize CalculateMaxSize(); BSize _CalculateMaxSize();
BSize CalculatePreferredSize(); BSize _CalculatePreferredSize();
private:
LayoutStyleType fLayoutStyle;
bool fActivated;
LinearSpec fSolver; LinearSpec fSolver;
-26
View File
@@ -1,26 +0,0 @@
/*
* Copyright 2007-2008, Christof Lutteroth, [email protected]
* Copyright 2007-2008, James Kim, [email protected]
* Distributed under the terms of the MIT License.
*/
#ifndef LAYOUT_STYLE_TYPE_H
#define LAYOUT_STYLE_TYPE_H
namespace BALM {
/**
* The possibilities for adjusting a GUI's layout.
* Either change the child controls so that they fit into their parent control, or adjust
* the size of the parent control so that the children have as much space as they want.
*/
enum LayoutStyleType {
FIT_TO_SIZE, ADJUST_SIZE
};
} // namespace BALM
using BALM::LayoutStyleType;
#endif
+53 -115
View File
@@ -31,9 +31,6 @@ BALMLayout::BALMLayout()
: :
BAbstractLayout() BAbstractLayout()
{ {
fLayoutStyle = FIT_TO_SIZE;
fActivated = true;
fLeft = new XTab(&fSolver); fLeft = new XTab(&fSolver);
fRight = new XTab(&fSolver); fRight = new XTab(&fSolver);
fTop = new YTab(&fSolver); fTop = new YTab(&fSolver);
@@ -59,47 +56,6 @@ BALMLayout::~BALMLayout()
} }
/**
* Solves the layout.
*/
void
BALMLayout::SolveLayout()
{
// if autoPreferredContentSize is set on an area,
// readjust its preferredContentSize and penalties settings
for (int32 i = 0; i < CountItems(); i++) {
Area* currentArea = _AreaForItem(ItemAt(i));
if (currentArea && currentArea->AutoPreferredContentSize())
currentArea->SetDefaultBehavior();
}
// Try to solve the layout until the result is OPTIMAL or INFEASIBLE,
// maximally 15 tries sometimes the solving algorithm encounters numerical
// problems (NUMFAILURE), and repeating the solving often helps to overcome
// them.
BFile* file = NULL;
if (fPerformancePath != NULL) {
file = new BFile(fPerformancePath,
B_READ_WRITE | B_CREATE_FILE | B_OPEN_AT_END);
}
ResultType result;
for (int32 tries = 0; tries < 15; tries++) {
result = fSolver.Solve();
if (fPerformancePath != NULL) {
/*char buffer [100];
file->Write(buffer, sprintf(buffer, "%d\t%fms\t#vars=%ld\t"
"#constraints=%ld\n", result, fSolver.SolvingTime(),
fSolver.Variables()->CountItems(),
fSolver.Constraints()->CountItems()));*/
}
if (result == OPTIMAL || result == INFEASIBLE)
break;
}
delete file;
}
/** /**
* Adds a new x-tab to the specification. * Adds a new x-tab to the specification.
* *
@@ -338,41 +294,13 @@ BALMLayout::Bottom() const
} }
/**
* Reverse engineers a GUI and recovers an ALM specification.
* @param parent the parent container of the GUI
*/
void
BALMLayout::RecoverLayout(BView* parent) {} // Still working on it.
/**
* Gets the current layout style.
*/
LayoutStyleType
BALMLayout::LayoutStyle() const
{
return fLayoutStyle;
}
/**
* Sets the current layout style.
*/
void
BALMLayout::SetLayoutStyle(LayoutStyleType style)
{
fLayoutStyle = style;
}
/** /**
* Gets minimum size. * Gets minimum size.
*/ */
BSize BSize
BALMLayout::BaseMinSize() { BALMLayout::BaseMinSize() {
if (fMinSize == kUnsetSize) if (fMinSize == kUnsetSize)
fMinSize = CalculateMinSize(); fMinSize = _CalculateMinSize();
return fMinSize; return fMinSize;
} }
@@ -384,7 +312,7 @@ BSize
BALMLayout::BaseMaxSize() BALMLayout::BaseMaxSize()
{ {
if (fMaxSize == kUnsetSize) if (fMaxSize == kUnsetSize)
fMaxSize = CalculateMaxSize(); fMaxSize = _CalculateMaxSize();
return fMaxSize; return fMaxSize;
} }
@@ -396,7 +324,7 @@ BSize
BALMLayout::BasePreferredSize() BALMLayout::BasePreferredSize()
{ {
if (fPreferredSize == kUnsetSize) if (fPreferredSize == kUnsetSize)
fPreferredSize = CalculatePreferredSize(); fPreferredSize = _CalculatePreferredSize();
return fPreferredSize; return fPreferredSize;
} }
@@ -453,37 +381,18 @@ BALMLayout::ItemRemoved(BLayoutItem* item, int32 fromIndex)
void void
BALMLayout::DerivedLayoutItems() BALMLayout::DerivedLayoutItems()
{ {
// TODO: modify to allow for viewlessness
// make sure that layout events occuring during layout are ignored
// i.e. activated is set to false during layout calculation
if (!fActivated)
return;
fActivated = false;
if (Owner() == NULL)
return;
_UpdateAreaConstraints(); _UpdateAreaConstraints();
// reverse engineer a layout specification if none was given // Enforced absolute positions of Right and Bottom
//~ if (this == NULL) RecoverLayout(View()); BRect area(LayoutArea());
Right()->SetRange(area.right, area.right);
Bottom()->SetRange(area.bottom, area.bottom);
// if the layout engine is set to fit the GUI to the given size, _SolveLayout();
// then the given size is enforced by setting absolute positions
// for Right and Bottom
if (fLayoutStyle == FIT_TO_SIZE) {
BRect area(LayoutArea());
Right()->SetRange(area.right, area.right);
Bottom()->SetRange(area.bottom, area.bottom);
}
SolveLayout();
// if new layout is infasible, use previous layout // if new layout is infasible, use previous layout
if (fSolver.Result() == INFEASIBLE) { if (fSolver.Result() == INFEASIBLE)
fActivated = true; // now layout calculation is allowed to run again
return; return;
}
if (fSolver.Result() != OPTIMAL) { if (fSolver.Result() != OPTIMAL) {
fSolver.Save("failed-layout.txt"); fSolver.Save("failed-layout.txt");
@@ -492,18 +401,9 @@ BALMLayout::DerivedLayoutItems()
printf("Saved specification in file failed-layout.txt\n"); printf("Saved specification in file failed-layout.txt\n");
} }
// change the size of the GUI according to the calculated size
// if the layout engine was configured to do so
if (fLayoutStyle == ADJUST_SIZE) {
Owner()->ResizeTo(floor(Right()->Value() - Left()->Value() + 0.5),
floor(Bottom()->Value() - Top()->Value() + 0.5));
}
// set the calculated positions and sizes for every area // set the calculated positions and sizes for every area
for (int32 i = 0; i < CountItems(); i++) for (int32 i = 0; i < CountItems(); i++)
_AreaForItem(ItemAt(i))->DoLayout(); _AreaForItem(ItemAt(i))->DoLayout();
fActivated = true;
} }
@@ -538,11 +438,49 @@ BALMLayout::Solver()
} }
void
BALMLayout::_SolveLayout()
{
// if autoPreferredContentSize is set on an area,
// readjust its preferredContentSize and penalties settings
for (int32 i = 0; i < CountItems(); i++) {
Area* currentArea = _AreaForItem(ItemAt(i));
if (currentArea && currentArea->AutoPreferredContentSize())
currentArea->SetDefaultBehavior();
}
// Try to solve the layout until the result is OPTIMAL or INFEASIBLE,
// maximally 15 tries sometimes the solving algorithm encounters numerical
// problems (NUMFAILURE), and repeating the solving often helps to overcome
// them.
BFile* file = NULL;
if (fPerformancePath != NULL) {
file = new BFile(fPerformancePath,
B_READ_WRITE | B_CREATE_FILE | B_OPEN_AT_END);
}
ResultType result;
for (int32 tries = 0; tries < 15; tries++) {
result = fSolver.Solve();
if (fPerformancePath != NULL) {
/*char buffer [100];
file->Write(buffer, sprintf(buffer, "%d\t%fms\t#vars=%ld\t"
"#constraints=%ld\n", result, fSolver.SolvingTime(),
fSolver.Variables()->CountItems(),
fSolver.Constraints()->CountItems()));*/
}
if (result == OPTIMAL || result == INFEASIBLE)
break;
}
delete file;
}
/** /**
* Caculates the miminum size. * Caculates the miminum size.
*/ */
BSize BSize
BALMLayout::CalculateMinSize() BALMLayout::_CalculateMinSize()
{ {
_UpdateAreaConstraints(); _UpdateAreaConstraints();
@@ -551,7 +489,7 @@ BALMLayout::CalculateMinSize()
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));
fSolver.SetObjFunction(newObjFunction); fSolver.SetObjFunction(newObjFunction);
SolveLayout(); _SolveLayout();
fSolver.SetObjFunction(oldObjFunction); fSolver.SetObjFunction(oldObjFunction);
fSolver.UpdateObjFunction(); fSolver.UpdateObjFunction();
delete newObjFunction->ItemAt(0); delete newObjFunction->ItemAt(0);
@@ -575,7 +513,7 @@ BALMLayout::CalculateMinSize()
* Caculates the maximum size. * Caculates the maximum size.
*/ */
BSize BSize
BALMLayout::CalculateMaxSize() BALMLayout::_CalculateMaxSize()
{ {
_UpdateAreaConstraints(); _UpdateAreaConstraints();
@@ -584,7 +522,7 @@ BALMLayout::CalculateMaxSize()
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));
fSolver.SetObjFunction(newObjFunction); fSolver.SetObjFunction(newObjFunction);
SolveLayout(); _SolveLayout();
fSolver.SetObjFunction(oldObjFunction); fSolver.SetObjFunction(oldObjFunction);
fSolver.UpdateObjFunction(); fSolver.UpdateObjFunction();
delete newObjFunction->ItemAt(0); delete newObjFunction->ItemAt(0);
@@ -608,11 +546,11 @@ BALMLayout::CalculateMaxSize()
* Caculates the preferred size. * Caculates the preferred size.
*/ */
BSize BSize
BALMLayout::CalculatePreferredSize() BALMLayout::_CalculatePreferredSize()
{ {
_UpdateAreaConstraints(); _UpdateAreaConstraints();
SolveLayout(); _SolveLayout();
if (fSolver.Result() != OPTIMAL) { if (fSolver.Result() != OPTIMAL) {
fSolver.Save("failed-layout.txt"); fSolver.Save("failed-layout.txt");
printf("Could not solve the layout specification (%d). " printf("Could not solve the layout specification (%d). "