cnavas: add lots more debug traces to box, and an explanatory comment

This commit is contained in:
Paul Davis 2021-09-10 13:02:01 -06:00
parent 107ff8466a
commit d50693b97d
1 changed files with 28 additions and 0 deletions

View File

@ -19,13 +19,16 @@
#include <algorithm>
#include "pbd/compose.h"
#include "pbd/unwind.h"
#include "pbd/stacktrace.h"
#include "canvas/box.h"
#include "canvas/debug.h"
#include "canvas/rectangle.h"
using namespace ArdourCanvas;
using namespace PBD;
using std::cerr;
using std::endl;
@ -171,6 +174,7 @@ Box::size_request (Distance& w, Distance& h) const
Distance largest_height = 0;
Rect uniform_size;
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("size request for %1\n", this));
if (homogenous) {
for (std::list<Item*>::const_iterator i = _items.begin(); i != _items.end(); ++i) {
@ -182,6 +186,7 @@ Box::size_request (Distance& w, Distance& h) const
}
uniform_size = Rect (0, 0, largest_width, largest_height);
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("homogenous box, uniform size computed as %1\n", uniform_size));
}
Rect r;
@ -196,28 +201,38 @@ Box::size_request (Distance& w, Distance& h) const
Rect isize;
(*i)->size_request (width, height);
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\t%1, desires %2 x %3\n", (*i)->whoami(), width, height));
if (homogenous) {
if (((*i)->pack_options() & PackOptions (PackExpand|PackFill)) == PackOptions (PackExpand|PackFill)) {
if (orientation == Vertical) {
/* use the item's own height and our computed width */
isize = Rect (previous_edge.x, previous_edge.y, previous_edge.x + uniform_size.width(), previous_edge.y + height);
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\t%1, use computed width to give %2\n", (*i)->whoami(), isize));
} else {
/* use the item's own width and our computed height */
isize = Rect (previous_edge.x, previous_edge.y, previous_edge.x + width, previous_edge.y + uniform_size.height());
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\t%1, use computed height to give %2\n", (*i)->whoami(), isize));
}
} else {
isize = Rect (previous_edge.x, previous_edge.y, previous_edge.x + width, previous_edge.y + height);
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\t%1, use item size to give %2\n", (*i)->whoami(), isize));
}
} else {
isize = Rect (previous_edge.x, previous_edge.y, previous_edge.x + width, previous_edge.y + height);
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\t%1, use item size (non-homogenous) to give %2\n", (*i)->whoami(), isize));
}
width = isize.width();
height = isize.height();
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\t%1, initial size %2 x %3\n", (*i)->whoami(), width, height));
r = r.extend (Rect (previous_edge.x, previous_edge.y, previous_edge.x + width, previous_edge.y + height));
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\tcumulative rect is now %1\n", r));
if (orientation == Vertical) {
Distance shift = 0;
@ -255,6 +270,8 @@ Box::size_request (Distance& w, Distance& h) const
r = r.expand (0, right_margin + right_padding, bottom_margin + bottom_padding, 0);
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("add margin and padding, get %1\n", r));
w = r.width();
h = r.height();
}
@ -287,6 +304,11 @@ Box::reposition_children (Distance width, Distance height, bool shrink_width, bo
}
}
/* these two represent the width and height available for
* contents (i.e. after we've taken "borders" "owned" by this
* box into account)
*/
const Distance contents_width = width - (left_margin + left_padding + right_margin + right_padding);
const Distance contents_height = height - (top_margin + top_padding + bottom_margin + bottom_padding);
@ -310,6 +332,7 @@ Box::reposition_children (Distance width, Distance height, bool shrink_width, bo
}
uniform_size = Rect (0, 0, largest_width, largest_height);
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("allocating for homogenous box, uniform size computed as %1\n", uniform_size));
}
{
@ -328,17 +351,22 @@ Box::reposition_children (Distance width, Distance height, bool shrink_width, bo
if (orientation == Vertical) {
/* use the item's own height and our computed width */
isize = Rect (previous_edge.x, previous_edge.y, previous_edge.x + uniform_size.width(), previous_edge.y + height);
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\t%1, use computed width to give %2\n", (*i)->whoami(), isize));
} else {
/* use the item's own width and our computed height */
isize = Rect (previous_edge.x, previous_edge.y, previous_edge.x + width, previous_edge.y + uniform_size.height());
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\t%1, use computed height to give %2\n", (*i)->whoami(), isize));
}
} else {
isize = Rect (previous_edge.x, previous_edge.y, previous_edge.x + width, previous_edge.y + height);
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\t%1, use item size to give %2\n", (*i)->whoami(), isize));
}
} else {
isize = Rect (previous_edge.x, previous_edge.y, previous_edge.x + width, previous_edge.y + height);
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\t%1, use item size (non-homogenous) to give %2\n", (*i)->whoami(), isize));
}
DEBUG_TRACE (DEBUG::CanvasBox|DEBUG::CanvasSizeAllocate, string_compose ("\t%1 allocating %2\n", (*i)->whoami(), isize));
(*i)->size_allocate (isize);
width = isize.width();