Make BALMLayout::BasePreferredSize() useful again.
This commit is contained in:
parent
ac84362568
commit
3ade12dd15
@ -851,8 +851,11 @@ BALMLayout::BaseMaxSize()
|
||||
BSize
|
||||
BALMLayout::BasePreferredSize()
|
||||
{
|
||||
fSolver->ValidateMinSize();
|
||||
return fMinSize;
|
||||
ResultType result = fSolver->ValidatePreferredSize();
|
||||
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()
|
||||
:
|
||||
fConstraintsValid(false),
|
||||
fMinValid(false),
|
||||
fMaxValid(false),
|
||||
fPreferredValid(false),
|
||||
fLayoutValid(false),
|
||||
fLayoutContext(NULL)
|
||||
{
|
||||
@ -127,6 +149,7 @@ SharedSolver::Invalidate(bool children)
|
||||
fConstraintsValid = false;
|
||||
fMinValid = false;
|
||||
fMaxValid = false;
|
||||
fPreferredValid = false;
|
||||
fLayoutValid = false;
|
||||
|
||||
_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
|
||||
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
|
||||
SharedSolver::LayoutContextLeft(BLayoutContext* context)
|
||||
{
|
||||
|
@ -37,18 +37,23 @@ public:
|
||||
|
||||
ResultType ValidateMinSize();
|
||||
ResultType ValidateMaxSize();
|
||||
ResultType ValidatePreferredSize();
|
||||
ResultType ValidateLayout(BLayoutContext* context);
|
||||
private:
|
||||
struct MinSizeValidator;
|
||||
struct MaxSizeValidator;
|
||||
struct PreferredSizeValidator;
|
||||
|
||||
friend struct MinSizeValidator;
|
||||
friend struct MaxSizeValidator;
|
||||
friend struct PreferredSizeValidator;
|
||||
|
||||
void SetMaxSize(BALM::BALMLayout* layout,
|
||||
const BSize& max);
|
||||
void SetMinSize(BALM::BALMLayout* layout,
|
||||
const BSize& min);
|
||||
void SetPreferredSize(BALM::BALMLayout* layout,
|
||||
const BSize& preferred);
|
||||
|
||||
virtual void LayoutContextLeft(BLayoutContext* context);
|
||||
|
||||
@ -61,6 +66,7 @@ private:
|
||||
bool fConstraintsValid;
|
||||
bool fMinValid;
|
||||
bool fMaxValid;
|
||||
bool fPreferredValid;
|
||||
bool fLayoutValid;
|
||||
|
||||
BLayoutContext* fLayoutContext;
|
||||
@ -69,6 +75,7 @@ private:
|
||||
|
||||
ResultType fMinResult;
|
||||
ResultType fMaxResult;
|
||||
ResultType fPreferredResult;
|
||||
ResultType fLayoutResult;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user