diff --git a/libs/canvas/canvas/constraint_packer.h b/libs/canvas/canvas/constraint_packer.h index c7507c5942..e96af367a7 100644 --- a/libs/canvas/canvas/constraint_packer.h +++ b/libs/canvas/canvas/constraint_packer.h @@ -43,6 +43,9 @@ public: void remove (Item *); void constrain (kiwi::Constraint const &); + BoxConstrainedItem* pack_start (Item*, PackOptions primary_axis_packing = PackOptions (0), PackOptions secondary_axis_packing = PackOptions (PackExpand|PackFill)); + BoxConstrainedItem* pack_end (Item*, PackOptions primary_axis_packing = PackOptions (0), PackOptions secondary_axis_packing = PackOptions (PackExpand|PackFill)); + virtual ConstrainedItem* add_constrained (Item* item); void solve (); @@ -79,6 +82,8 @@ public: typedef std::list BoxPackedItems; BoxPackedItems vpacked; BoxPackedItems hpacked; + + BoxConstrainedItem* pack (Item*, PackOptions primary_axis_packing, PackOptions secondary_axis_packing); }; } diff --git a/libs/canvas/constraint_packer.cc b/libs/canvas/constraint_packer.cc index 3a56b7dfc2..4daf930eb9 100644 --- a/libs/canvas/constraint_packer.cc +++ b/libs/canvas/constraint_packer.cc @@ -294,6 +294,26 @@ ConstraintPacker::remove (Item* item) } + bool found_packed = false; + + for (BoxPackedItems::iterator t = hpacked.begin(); t != hpacked.end(); ++t) { + if (&(*t)->item() == item) { + hpacked.erase (t); + found_packed = true; + break; + } + } + + if (!found_packed) { + for (BoxPackedItems::iterator t = vpacked.begin(); t != vpacked.end(); ++t) { + if (&(*t)->item() == item) { + vpacked.erase (t); + found_packed = true; + break; + } + } + } + _need_constraint_update = true; } @@ -331,3 +351,32 @@ ConstraintPacker::update_constraints () _solver.addConstraint (*c); } } + +BoxConstrainedItem* +ConstraintPacker::pack_start (Item* item, PackOptions primary_axis_opts, PackOptions secondary_axis_opts) +{ + return pack (item, PackOptions (primary_axis_opts|PackFromStart), secondary_axis_opts); +} + +BoxConstrainedItem* +ConstraintPacker::pack_end (Item* item, PackOptions primary_axis_opts, PackOptions secondary_axis_opts) +{ + return pack (item, PackOptions (primary_axis_opts|PackFromEnd), secondary_axis_opts); +} + +BoxConstrainedItem* +ConstraintPacker::pack (Item* item, PackOptions primary_axis_opts, PackOptions secondary_axis_opts) +{ + BoxConstrainedItem* ci = new BoxConstrainedItem (*item, primary_axis_opts, secondary_axis_opts); + + add_constrained_internal (item, ci); + + if (_orientation == Horizontal) { + hpacked.push_back (ci); + } else { + vpacked.push_back (ci); + } + + return ci; +} +