From 3734277263f8d82f68e70ae449e6306d47edafd3 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 30 Aug 2021 17:40:06 -0600 Subject: [PATCH] canvas: improve box packing - compute child dimensions more correctly --- libs/canvas/box.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libs/canvas/box.cc b/libs/canvas/box.cc index df45a176a5..88e72dcdd2 100644 --- a/libs/canvas/box.cc +++ b/libs/canvas/box.cc @@ -27,6 +27,9 @@ using namespace ArdourCanvas; +using std::cerr; +using std::endl; + Box::Box (Canvas* canvas, Orientation o) : Rectangle (canvas) , orientation (o) @@ -284,19 +287,24 @@ Box::reposition_children (Distance width, Distance height, bool shrink_width, bo 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); - const Distance item_width = (contents_width - ((_items.size() - 1) * spacing)); - const Distance item_height = (contents_height - ((_items.size() - 1) * spacing));; + + Distance item_width; + Distance item_height; if (orientation == Vertical) { - if ((largest_width < item_width)) { - largest_width = item_width; - } + item_width = contents_width; + item_height = (contents_height - ((_items.size() - 1) * spacing));; + } else { + item_width = (contents_width - ((_items.size() - 1) * spacing)); + item_height = contents_height; + } + + if (orientation == Vertical) { + largest_width = std::max (largest_width, item_width); } if (orientation == Horizontal) { - if ((largest_height < item_height)) { - largest_height = item_height; - } + largest_height = std::max (largest_height, item_height); } uniform_size = Rect (0, 0, largest_width, largest_height);