mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-06 14:54:56 +01:00
Canvas: improve implementation/design of ConstraintPacker::preferred_size()
This commit is contained in:
parent
0af555e146
commit
4ce38fb59d
3 changed files with 34 additions and 15 deletions
|
|
@ -70,6 +70,7 @@ public:
|
||||||
|
|
||||||
void add_constraints (kiwi::Solver&, ConstrainedItem*) const;
|
void add_constraints (kiwi::Solver&, ConstrainedItem*) const;
|
||||||
|
|
||||||
|
void non_const_preferred_size (Duple& mininum, Duple& natural);
|
||||||
virtual void update_constraints ();
|
virtual void update_constraints ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,12 @@ ConstraintPacker::constrain (kiwi::Constraint const &c)
|
||||||
void
|
void
|
||||||
ConstraintPacker::preferred_size (Duple& minimum, Duple& natural) const
|
ConstraintPacker::preferred_size (Duple& minimum, Duple& natural) const
|
||||||
{
|
{
|
||||||
#if 0
|
const_cast<ConstraintPacker*>(this)->non_const_preferred_size (minimum, natural);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ConstraintPacker::non_const_preferred_size (Duple& minimum, Duple& natural)
|
||||||
|
{
|
||||||
/* our parent wants to know how big we are.
|
/* our parent wants to know how big we are.
|
||||||
|
|
||||||
We may have some intrinsic size (i.e. "everything in this constraint
|
We may have some intrinsic size (i.e. "everything in this constraint
|
||||||
|
|
@ -152,6 +157,12 @@ ConstraintPacker::preferred_size (Duple& minimum, Duple& natural) const
|
||||||
We may have no intrinsic dimensions at all. This is the tricky one.
|
We may have no intrinsic dimensions at all. This is the tricky one.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (_intrinsic_width == 0 && _intrinsic_height == 0) {
|
||||||
|
natural = Duple (100,100);
|
||||||
|
minimum = natural;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_need_constraint_update) {
|
if (_need_constraint_update) {
|
||||||
const_cast<ConstraintPacker*>(this)->update_constraints ();
|
const_cast<ConstraintPacker*>(this)->update_constraints ();
|
||||||
}
|
}
|
||||||
|
|
@ -163,19 +174,24 @@ ConstraintPacker::preferred_size (Duple& minimum, Duple& natural) const
|
||||||
}
|
}
|
||||||
|
|
||||||
_solver.updateVariables ();
|
_solver.updateVariables ();
|
||||||
|
apply (0);
|
||||||
|
|
||||||
|
Rect bb (bounding_box());
|
||||||
|
|
||||||
Duple ret;
|
Duple ret;
|
||||||
|
|
||||||
natural.x = width.value ();
|
natural.x = std::max (bb.width(), _intrinsic_width);
|
||||||
natural.y = height.value ();
|
natural.y = std::max (bb.height(), _intrinsic_width);
|
||||||
|
|
||||||
minimum = natural;
|
minimum.x = std::min (bb.width(), _intrinsic_width);
|
||||||
#endif
|
minimum.y = std::min (bb.height(), _intrinsic_width);
|
||||||
natural.x = 100;
|
|
||||||
natural.y = 100;
|
|
||||||
minimum = natural;
|
|
||||||
|
|
||||||
cerr << "CP::sr returns " << natural<< endl;
|
/* put solver back to default state */
|
||||||
|
|
||||||
|
_solver.reset ();
|
||||||
|
_need_constraint_update = true;
|
||||||
|
|
||||||
|
cerr << "CP min " << minimum << " pref " << natural << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -301,10 +317,10 @@ ConstraintPacker::update_constraints ()
|
||||||
|
|
||||||
x->first->preferred_size (min, natural);
|
x->first->preferred_size (min, natural);
|
||||||
|
|
||||||
_solver.addConstraint (ci->width() >= min.width() | kiwi::strength::required);
|
_solver.addConstraint ((ci->width() >= min.width()) | kiwi::strength::required);
|
||||||
_solver.addConstraint (ci->height() >= min.height() | kiwi::strength::required);
|
_solver.addConstraint ((ci->height() >= min.height()) | kiwi::strength::required);
|
||||||
_solver.addConstraint (ci->width() == natural.width() | kiwi::strength::medium);
|
_solver.addConstraint ((ci->width() == natural.width()) | kiwi::strength::medium);
|
||||||
_solver.addConstraint (ci->height() == natural.width() | kiwi::strength::medium);
|
_solver.addConstraint ((ci->height() == natural.width()) | kiwi::strength::medium);
|
||||||
|
|
||||||
add_constraints (_solver, ci);
|
add_constraints (_solver, ci);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,6 @@ main (int argc, char* argv[])
|
||||||
|
|
||||||
srandom (time ((time_t) 0));
|
srandom (time ((time_t) 0));
|
||||||
|
|
||||||
cview.set_size_request (100, 100);
|
|
||||||
|
|
||||||
win.add (cview);
|
win.add (cview);
|
||||||
|
|
||||||
/* Make some items */
|
/* Make some items */
|
||||||
|
|
@ -75,6 +73,10 @@ main (int argc, char* argv[])
|
||||||
|
|
||||||
ConstraintPacker* packer = new ConstraintPacker (c->root());
|
ConstraintPacker* packer = new ConstraintPacker (c->root());
|
||||||
|
|
||||||
|
/* give it a minimum size */
|
||||||
|
|
||||||
|
packer->set_intrinsic_size (100, 100);
|
||||||
|
|
||||||
/* add stuff */
|
/* add stuff */
|
||||||
|
|
||||||
ConstrainedItem* left = packer->add_constrained (r1);
|
ConstrainedItem* left = packer->add_constrained (r1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue