diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-07-24 13:47:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-24 13:47:18 +0200 |
commit | 513b39882ae44a5ee0ff0d9bb0c4ddf700449422 (patch) | |
tree | 8ba8a5288b209594c99c307517c6ad3be646830f /scene/gui | |
parent | 93b50a62e333cd05702fb749ebcdc18127abe01b (diff) | |
parent | 04ea6ec88dac45679458f8752ddc4c2ae285e103 (diff) |
Merge pull request #40436 from DanielZTing/master
Evenly distribute stretched Nodes in BoxContainer
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/box_container.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index 191110a669..f130726837 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -104,6 +104,7 @@ void BoxContainer::_resort() { has_stretched = true; bool refit_successful = true; //assume refit-test will go well + float error = 0; // Keep track of accumulated error in pixels for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); @@ -119,8 +120,9 @@ void BoxContainer::_resort() { if (msc.will_stretch) { //wants to stretch //let's see if it can really stretch - - int final_pixel_size = stretch_avail * c->get_stretch_ratio() / stretch_ratio_total; + float final_pixel_size = stretch_avail * c->get_stretch_ratio() / stretch_ratio_total; + // Add leftover fractional pixels to error accumulator + error += final_pixel_size - (int)final_pixel_size; if (final_pixel_size < msc.min_size) { //if available stretching area is too small for widget, //then remove it from stretching area @@ -132,6 +134,11 @@ void BoxContainer::_resort() { break; } else { msc.final_size = final_pixel_size; + // Dump accumulated error if one pixel or more + if (error >= 1) { + msc.final_size += 1; + error -= 1; + } } } } |