diff options
author | André Nusser <andre.nusser@googlemail.com> | 2017-03-22 21:57:21 +0100 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2017-04-01 16:33:49 +0200 |
commit | a964610cf2594923e637011a93a1e8e57b2ba571 (patch) | |
tree | a337c8ac512086be6f545735f20a6ae0d37dbb6a | |
parent | 2497577c09b13a55430a95fcf311448fda11cae3 (diff) |
Fix bug in layout.cc
-rw-r--r-- | plugingui/layout.cc | 29 |
1 files changed, 26 insertions, 3 deletions
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 |