Canvas: propagate ::size_allocate() down the item tree

This previously wasn't done because of fear that it would affect the traditional fixed-sized canvas,
but only items that _layout_sensitive (i.e. are packed into a constraint packer directly) will
actually do anything in ::size_allocate().

Possibly might want to relax this to cover items that have a constraint packer between them
and a root group.
This commit is contained in:
Paul Davis 2020-07-09 16:38:52 -06:00
parent d51893dec6
commit 860d43697c
6 changed files with 27 additions and 24 deletions

View file

@ -347,6 +347,7 @@ public:
void add_child_bounding_boxes (bool include_hidden = false) const; void add_child_bounding_boxes (bool include_hidden = false) const;
void render_children (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const; void render_children (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const;
void prepare_for_render_children (Rect const & area) const; void prepare_for_render_children (Rect const & area) const;
void size_allocate_children (Rect const & r);
Duple scroll_offset() const; Duple scroll_offset() const;
public: public:

View file

@ -29,7 +29,6 @@ class LIBCANVAS_API Root : public Container
{ {
public: public:
void preferred_size (Duple&, Duple&) const; void preferred_size (Duple&, Duple&) const;
void size_allocate (Rect const &);
private: private:
friend class Canvas; friend class Canvas;

View file

@ -509,8 +509,6 @@ cBox::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
if (fill()) { if (fill()) {
cerr << whoami() << " setting fill context with 0x" << std::hex << _fill_color << std::dec << " draw " << draw << endl;
setup_fill_context (context); setup_fill_context (context);
context->rectangle (draw.x0, draw.y0, draw.width(), draw.height()); context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
context->fill_preserve (); context->fill_preserve ();

View file

@ -24,6 +24,7 @@
#include "pbd/convert.h" #include "pbd/convert.h"
#include "canvas/canvas.h" #include "canvas/canvas.h"
#include "canvas/constraint_packer.h"
#include "canvas/debug.h" #include "canvas/debug.h"
#include "canvas/item.h" #include "canvas/item.h"
#include "canvas/scroll_group.h" #include "canvas/scroll_group.h"
@ -607,6 +608,27 @@ Item::size_allocate (Rect const & r)
_position = Duple (r.x0, r.y0); _position = Duple (r.x0, r.y0);
_allocation = r; _allocation = r;
} }
size_allocate_children (r);
}
void
Item::size_allocate_children (Rect const & r)
{
bool have_constraint_container = false;
for (list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) {
(*i)->size_allocate (r);
if (dynamic_cast<ConstraintPacker*> (*i)) {
have_constraint_container = true;
}
}
if (have_constraint_container) {
_bounding_box_dirty = true;
}
} }
void void

View file

@ -288,13 +288,13 @@ Rectangle::vertical_fraction (double y) const
void void
Rectangle::size_allocate (Rect const & r) Rectangle::size_allocate (Rect const & r)
{ {
_allocation = r; Item::size_allocate (r);
if (_layout_sensitive) { if (_layout_sensitive) {
/* set position, and then set the _rect member with values that /* Item::size_allocate() will have set _position, and then set
use _position as the origin. the _rect member with values that use _position as the
origin.
*/ */
_position = Duple (r.x0, r.y0);
Rect r2 (0, 0, r.x1 - r.x0, r.y1 - r.y0); Rect r2 (0, 0, r.x1 - r.x0, r.y1 - r.y0);
set (r2); set (r2);
} }

View file

@ -21,7 +21,6 @@
#include "canvas/root_group.h" #include "canvas/root_group.h"
#include "canvas/canvas.h" #include "canvas/canvas.h"
#include "canvas/constraint_packer.h"
using namespace std; using namespace std;
using namespace ArdourCanvas; using namespace ArdourCanvas;
@ -48,19 +47,3 @@ Root::preferred_size (Duple& min, Duple& natural) const
Item::preferred_size (min, natural); Item::preferred_size (min, natural);
} }
void
Root::size_allocate (Rect const & r)
{
bool have_constraint_container = false;
for (list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) {
if (dynamic_cast<ConstraintPacker*> (*i)) {
(*i)->size_allocate (r);
have_constraint_container = true;
}
}
if (have_constraint_container) {
_bounding_box_dirty = true;
}
}