mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-09 16:24:57 +01:00
Canvas: continued work on constraint packer
This commit is contained in:
parent
01137cbbf3
commit
1c3e743d2a
2 changed files with 69 additions and 0 deletions
|
|
@ -16,16 +16,25 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "pbd/i18n.h"
|
||||
|
||||
|
||||
#include "kiwi/kiwi.h"
|
||||
|
||||
#include "canvas/constraint_packer.h"
|
||||
#include "canvas/constrained_item.h"
|
||||
#include "canvas/item.h"
|
||||
#include "canvas/rectangle.h"
|
||||
|
||||
using namespace ArdourCanvas;
|
||||
|
||||
ConstraintPacker::ConstraintPacker (Canvas* canvas)
|
||||
: Item (canvas)
|
||||
, width (X_("width"))
|
||||
, height (X_("height"))
|
||||
{
|
||||
_solver.addEditVariable (width, kiwi::strength::strong);
|
||||
_solver.addEditVariable (height, kiwi::strength::strong);
|
||||
}
|
||||
|
||||
ConstraintPacker::ConstraintPacker (Item* parent)
|
||||
|
|
@ -88,3 +97,45 @@ ConstraintPacker::child_changed ()
|
|||
reposition_children ();
|
||||
}
|
||||
|
||||
void
|
||||
ConstraintPacker::constrain (kiwi::Constraint const &c)
|
||||
{
|
||||
_solver.addConstraint (c);
|
||||
}
|
||||
|
||||
void
|
||||
ConstraintPacker::size_allocate (Rect const & r)
|
||||
{
|
||||
Item::size_allocate (r);
|
||||
|
||||
_solver.suggestValue (width, r.width());
|
||||
_solver.suggestValue (height, r.height());
|
||||
|
||||
solve ();
|
||||
}
|
||||
|
||||
void
|
||||
ConstraintPacker::add (Item* item)
|
||||
{
|
||||
Item::add (item);
|
||||
ConstrainedItem* ci = new ConstrainedItem (*item);
|
||||
constraint_map.insert (std::make_pair (item, ci));
|
||||
}
|
||||
|
||||
void
|
||||
ConstraintPacker::remove (Item* item)
|
||||
{
|
||||
Item::remove (item);
|
||||
constraint_map.erase (item);
|
||||
}
|
||||
|
||||
void
|
||||
ConstraintPacker::solve ()
|
||||
{
|
||||
_solver.updateVariables ();
|
||||
|
||||
for (ConstraintMap::iterator x = constraint_map.begin(); x != constraint_map.end(); ++x) {
|
||||
x->first->constrained (*(x->second));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue