diff --git a/libs/canvas/canvas/constraint_packer.h b/libs/canvas/canvas/constraint_packer.h new file mode 100644 index 0000000000..70ef55c91a --- /dev/null +++ b/libs/canvas/canvas/constraint_packer.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2020 Paul Davis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __CANVAS_CONSTRAINT_PACKER_H__ +#define __CANVAS_CONSTRAINT_PACKER_H__ + +#include "canvas/item.h" + +namespace ArdourCanvas +{ + +class Rectangle; + +class LIBCANVAS_API ConstraintPacker : public Item +{ +public: + ConstraintPacker (Canvas *); + ConstraintPacker (Item *); + + void compute_bounding_box () const; + void render (Rect const & area, Cairo::RefPtr context) const; + + protected: + void child_changed (); + + private: + Rectangle *self; + bool collapse_on_hide; + + void reset_self (); + void reposition_children (); +}; + +} + +#endif diff --git a/libs/canvas/constraint_packer.cc b/libs/canvas/constraint_packer.cc new file mode 100644 index 0000000000..dc8b24ea88 --- /dev/null +++ b/libs/canvas/constraint_packer.cc @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2020 Paul Davis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "kiwi/kiwi.h" + +#include "canvas/constraint_packer.h" +#include "canvas/rectangle.h" + +using namespace ArdourCanvas; + +ConstraintPacker::ConstraintPacker (Canvas* canvas) + : Item (canvas) +{ +} + +ConstraintPacker::ConstraintPacker (Item* parent) + : Item (parent) +{ +} + +void +ConstraintPacker::render (Rect const & area, Cairo::RefPtr context) const +{ + Item::render_children (area, context); +} + +void +ConstraintPacker::compute_bounding_box () const +{ + _bounding_box = Rect(); + + if (_items.empty()) { + _bounding_box_dirty = false; + return; + } + + add_child_bounding_boxes (!collapse_on_hide); + + _bounding_box_dirty = false; +} + +void +ConstraintPacker::reset_self () +{ + if (_bounding_box_dirty) { + compute_bounding_box (); + } + + if (!_bounding_box) { + self->hide (); + return; + } + + Rect r (_bounding_box); + + /* XXX need to shrink by margin */ + + self->set (r); +} + +void +ConstraintPacker::reposition_children () +{ + _bounding_box_dirty = true; + reset_self (); +} +void +ConstraintPacker::child_changed () +{ + /* catch visibility and size changes */ + + Item::child_changed (); + reposition_children (); +} + diff --git a/libs/kiwi/AssocVector.h b/libs/canvas/kiwi/AssocVector.h similarity index 100% rename from libs/kiwi/AssocVector.h rename to libs/canvas/kiwi/AssocVector.h diff --git a/libs/kiwi/constraint.h b/libs/canvas/kiwi/constraint.h similarity index 100% rename from libs/kiwi/constraint.h rename to libs/canvas/kiwi/constraint.h diff --git a/libs/kiwi/debug.h b/libs/canvas/kiwi/debug.h similarity index 100% rename from libs/kiwi/debug.h rename to libs/canvas/kiwi/debug.h diff --git a/libs/kiwi/errors.h b/libs/canvas/kiwi/errors.h similarity index 100% rename from libs/kiwi/errors.h rename to libs/canvas/kiwi/errors.h diff --git a/libs/kiwi/expression.h b/libs/canvas/kiwi/expression.h similarity index 100% rename from libs/kiwi/expression.h rename to libs/canvas/kiwi/expression.h diff --git a/libs/kiwi/kiwi.h b/libs/canvas/kiwi/kiwi.h similarity index 100% rename from libs/kiwi/kiwi.h rename to libs/canvas/kiwi/kiwi.h diff --git a/libs/kiwi/maptype.h b/libs/canvas/kiwi/maptype.h similarity index 100% rename from libs/kiwi/maptype.h rename to libs/canvas/kiwi/maptype.h diff --git a/libs/kiwi/row.h b/libs/canvas/kiwi/row.h similarity index 100% rename from libs/kiwi/row.h rename to libs/canvas/kiwi/row.h diff --git a/libs/kiwi/shareddata.h b/libs/canvas/kiwi/shareddata.h similarity index 100% rename from libs/kiwi/shareddata.h rename to libs/canvas/kiwi/shareddata.h diff --git a/libs/kiwi/solver.h b/libs/canvas/kiwi/solver.h similarity index 100% rename from libs/kiwi/solver.h rename to libs/canvas/kiwi/solver.h diff --git a/libs/kiwi/solverimpl.h b/libs/canvas/kiwi/solverimpl.h similarity index 100% rename from libs/kiwi/solverimpl.h rename to libs/canvas/kiwi/solverimpl.h diff --git a/libs/kiwi/strength.h b/libs/canvas/kiwi/strength.h similarity index 100% rename from libs/kiwi/strength.h rename to libs/canvas/kiwi/strength.h diff --git a/libs/kiwi/symbol.h b/libs/canvas/kiwi/symbol.h similarity index 100% rename from libs/kiwi/symbol.h rename to libs/canvas/kiwi/symbol.h diff --git a/libs/kiwi/symbolics.h b/libs/canvas/kiwi/symbolics.h similarity index 100% rename from libs/kiwi/symbolics.h rename to libs/canvas/kiwi/symbolics.h diff --git a/libs/kiwi/term.h b/libs/canvas/kiwi/term.h similarity index 100% rename from libs/kiwi/term.h rename to libs/canvas/kiwi/term.h diff --git a/libs/kiwi/util.h b/libs/canvas/kiwi/util.h similarity index 100% rename from libs/kiwi/util.h rename to libs/canvas/kiwi/util.h diff --git a/libs/kiwi/variable.h b/libs/canvas/kiwi/variable.h similarity index 100% rename from libs/kiwi/variable.h rename to libs/canvas/kiwi/variable.h diff --git a/libs/kiwi/version.h b/libs/canvas/kiwi/version.h similarity index 100% rename from libs/kiwi/version.h rename to libs/canvas/kiwi/version.h