From a964610cf2594923e637011a93a1e8e57b2ba571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Wed, 22 Mar 2017 21:57:21 +0100 Subject: Fix bug in layout.cc --- plugingui/layout.cc | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'plugingui/layout.cc') diff --git a/plugingui/layout.cc b/plugingui/layout.cc index 1b56315..509e32d 100644 --- a/plugingui/layout.cc +++ b/plugingui/layout.cc @@ -128,10 +128,21 @@ void VBoxLayout::layout() LayoutItemList::iterator i = items.begin(); while(i != items.end()) { - LayoutItem *item = *i; + LayoutItem* item = *i; if(resizeChildren) { - item->resize(w, parent->height() / items.size()); + auto num_items = items.size(); + auto empty_space = (num_items - 1) * spacing; + auto available_space = parent->height(); + + if (available_space >= empty_space) { + auto item_height = (available_space - empty_space) / num_items; + item->resize(w, item_height); + } + else { + // TODO: Should this case be handled differently? + item->resize(w, 0); + } } size_t x = 0; @@ -185,7 +196,19 @@ void HBoxLayout::layout() LayoutItem *item = *i; if(resizeChildren) { - item->resize(parent->width() / items.size(), h); + auto num_items = items.size(); + auto empty_space = (num_items - 1) * spacing; + auto available_space = parent->width(); + + if (available_space >= empty_space) { + auto item_width = (available_space - empty_space) / num_items; + item->resize(item_width, h); + } + else { + // TODO: Should this case be handled differently? + item->resize(0, h); + } + item->move(x, 0); } else -- cgit v1.2.3