stub constraint-based packer for canvas

This commit is contained in:
Paul Davis 2020-05-20 22:29:07 -06:00
parent c8f85d6b6c
commit 91af7cd9a2
20 changed files with 141 additions and 0 deletions

View file

@ -0,0 +1,51 @@
/*
* Copyright (C) 2020 Paul Davis <paul@linuxaudiosystems.com>
*
* 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<Cairo::Context> context) const;
protected:
void child_changed ();
private:
Rectangle *self;
bool collapse_on_hide;
void reset_self ();
void reposition_children ();
};
}
#endif

View file

@ -0,0 +1,90 @@
/*
* Copyright (C) 2020 Paul Davis <paul@linuxaudiosystems.com>
*
* 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<Cairo::Context> 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 ();
}