Make BALMLayout::BasePreferredSize() useful again.
This commit is contained in:
@@ -851,8 +851,11 @@ BALMLayout::BaseMaxSize()
|
|||||||
BSize
|
BSize
|
||||||
BALMLayout::BasePreferredSize()
|
BALMLayout::BasePreferredSize()
|
||||||
{
|
{
|
||||||
fSolver->ValidateMinSize();
|
ResultType result = fSolver->ValidatePreferredSize();
|
||||||
return fMinSize;
|
if (result != kOptimal)
|
||||||
|
fBadLayoutPolicy->OnBadLayout(this, result, NULL);
|
||||||
|
|
||||||
|
return fPreferredSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -91,11 +91,33 @@ struct SharedSolver::MaxSizeValidator : LayoutOperation {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct SharedSolver::PreferredSizeValidator : LayoutOperation {
|
||||||
|
PreferredSizeValidator(BObjectList<BALMLayout>* layouts)
|
||||||
|
:
|
||||||
|
LayoutOperation(layouts)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CallSolverMethod(LinearSpec* spec, VariableList* vars)
|
||||||
|
{
|
||||||
|
spec->Solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Finalize(BALMLayout* layout, SharedSolver* solver)
|
||||||
|
{
|
||||||
|
float width = layout->Right()->Value() - layout->Left()->Value();
|
||||||
|
float height = layout->Top()->Value() - layout->Bottom()->Value();
|
||||||
|
solver->SetPreferredSize(layout, BSize(width, height));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
SharedSolver::SharedSolver()
|
SharedSolver::SharedSolver()
|
||||||
:
|
:
|
||||||
fConstraintsValid(false),
|
fConstraintsValid(false),
|
||||||
fMinValid(false),
|
fMinValid(false),
|
||||||
fMaxValid(false),
|
fMaxValid(false),
|
||||||
|
fPreferredValid(false),
|
||||||
fLayoutValid(false),
|
fLayoutValid(false),
|
||||||
fLayoutContext(NULL)
|
fLayoutContext(NULL)
|
||||||
{
|
{
|
||||||
@@ -127,6 +149,7 @@ SharedSolver::Invalidate(bool children)
|
|||||||
fConstraintsValid = false;
|
fConstraintsValid = false;
|
||||||
fMinValid = false;
|
fMinValid = false;
|
||||||
fMaxValid = false;
|
fMaxValid = false;
|
||||||
|
fPreferredValid = false;
|
||||||
fLayoutValid = false;
|
fLayoutValid = false;
|
||||||
|
|
||||||
_SetContext(NULL);
|
_SetContext(NULL);
|
||||||
@@ -191,6 +214,26 @@ SharedSolver::ValidateMaxSize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResultType
|
||||||
|
SharedSolver::ValidatePreferredSize()
|
||||||
|
{
|
||||||
|
if (fPreferredValid)
|
||||||
|
return fPreferredResult;
|
||||||
|
|
||||||
|
_ValidateConstraints();
|
||||||
|
|
||||||
|
PreferredSizeValidator validator(&fLayouts);
|
||||||
|
validator.Validate(this);
|
||||||
|
|
||||||
|
fPreferredResult = fLinearSpec.Result();
|
||||||
|
|
||||||
|
fPreferredValid = true;
|
||||||
|
fLayoutValid = false;
|
||||||
|
|
||||||
|
return fPreferredResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ResultType
|
ResultType
|
||||||
SharedSolver::ValidateLayout(BLayoutContext* context)
|
SharedSolver::ValidateLayout(BLayoutContext* context)
|
||||||
{
|
{
|
||||||
@@ -227,6 +270,13 @@ SharedSolver::SetMinSize(BALMLayout* layout, const BSize& min)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SharedSolver::SetPreferredSize(BALMLayout* layout, const BSize& preferred)
|
||||||
|
{
|
||||||
|
layout->fPreferredSize = preferred;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SharedSolver::LayoutContextLeft(BLayoutContext* context)
|
SharedSolver::LayoutContextLeft(BLayoutContext* context)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,18 +37,23 @@ public:
|
|||||||
|
|
||||||
ResultType ValidateMinSize();
|
ResultType ValidateMinSize();
|
||||||
ResultType ValidateMaxSize();
|
ResultType ValidateMaxSize();
|
||||||
|
ResultType ValidatePreferredSize();
|
||||||
ResultType ValidateLayout(BLayoutContext* context);
|
ResultType ValidateLayout(BLayoutContext* context);
|
||||||
private:
|
private:
|
||||||
struct MinSizeValidator;
|
struct MinSizeValidator;
|
||||||
struct MaxSizeValidator;
|
struct MaxSizeValidator;
|
||||||
|
struct PreferredSizeValidator;
|
||||||
|
|
||||||
friend struct MinSizeValidator;
|
friend struct MinSizeValidator;
|
||||||
friend struct MaxSizeValidator;
|
friend struct MaxSizeValidator;
|
||||||
|
friend struct PreferredSizeValidator;
|
||||||
|
|
||||||
void SetMaxSize(BALM::BALMLayout* layout,
|
void SetMaxSize(BALM::BALMLayout* layout,
|
||||||
const BSize& max);
|
const BSize& max);
|
||||||
void SetMinSize(BALM::BALMLayout* layout,
|
void SetMinSize(BALM::BALMLayout* layout,
|
||||||
const BSize& min);
|
const BSize& min);
|
||||||
|
void SetPreferredSize(BALM::BALMLayout* layout,
|
||||||
|
const BSize& preferred);
|
||||||
|
|
||||||
virtual void LayoutContextLeft(BLayoutContext* context);
|
virtual void LayoutContextLeft(BLayoutContext* context);
|
||||||
|
|
||||||
@@ -61,6 +66,7 @@ private:
|
|||||||
bool fConstraintsValid;
|
bool fConstraintsValid;
|
||||||
bool fMinValid;
|
bool fMinValid;
|
||||||
bool fMaxValid;
|
bool fMaxValid;
|
||||||
|
bool fPreferredValid;
|
||||||
bool fLayoutValid;
|
bool fLayoutValid;
|
||||||
|
|
||||||
BLayoutContext* fLayoutContext;
|
BLayoutContext* fLayoutContext;
|
||||||
@@ -69,6 +75,7 @@ private:
|
|||||||
|
|
||||||
ResultType fMinResult;
|
ResultType fMinResult;
|
||||||
ResultType fMaxResult;
|
ResultType fMaxResult;
|
||||||
|
ResultType fPreferredResult;
|
||||||
ResultType fLayoutResult;
|
ResultType fLayoutResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user