mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 23:35:03 +01:00
stub constraint-based packer for canvas
This commit is contained in:
parent
c8f85d6b6c
commit
91af7cd9a2
20 changed files with 141 additions and 0 deletions
51
libs/canvas/canvas/constraint_packer.h
Normal file
51
libs/canvas/canvas/constraint_packer.h
Normal 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
|
||||
90
libs/canvas/constraint_packer.cc
Normal file
90
libs/canvas/constraint_packer.cc
Normal 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 ();
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue