From: Thomas Geymayer Date: Sat, 28 Jun 2014 11:08:06 +0000 (+0200) Subject: canvas::BoxLayout: fix hfw layouting (fix updating size hint cache). X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=38b766f845a7420bb1d3aefc23598233a5ffff10;p=simgear.git canvas::BoxLayout: fix hfw layouting (fix updating size hint cache). --- diff --git a/simgear/canvas/layout/BoxLayout.cxx b/simgear/canvas/layout/BoxLayout.cxx index f6c4c48a..e0155c22 100644 --- a/simgear/canvas/layout/BoxLayout.cxx +++ b/simgear/canvas/layout/BoxLayout.cxx @@ -394,13 +394,16 @@ namespace canvas data.layout_item->minimumSize().x(), data.layout_item->maximumSize().x() ); - int d = data.layout_item->minimumHeightForWidth(w) - data.min_size; - data.min_size += d; - _layout_data.min_size += d; - - d = data.layout_item->heightForWidth(w) - data.size_hint; - data.size_hint += d; - _layout_data.size_hint += d; + data.min_size = data.mhfw(w); + data.size_hint = data.hfw(w); + + // Update size hints for layouting with difference to size hints + // calculated by using the size hints provided (without trading + // height for width) + _layout_data.min_size += data.min_size + - data.layout_item->minimumSize().y(); + _layout_data.size_hint += data.size_hint + - data.layout_item->sizeHint().y(); } } } diff --git a/simgear/canvas/layout/Layout.cxx b/simgear/canvas/layout/Layout.cxx index 7ebad9d4..ece4ddab 100644 --- a/simgear/canvas/layout/Layout.cxx +++ b/simgear/canvas/layout/Layout.cxx @@ -124,7 +124,11 @@ namespace canvas SG_LOG( SG_GUI, SG_DEBUG, - "Layout::distribute(" << num_children << " items)" ); + "Layout::distribute(" << space.size << "px for " + << num_children << " items, s.t." + << " min=" << space.min_size + << ", hint=" << space.size_hint + << ", max=" << space.max_size << ")" ); if( space.size < space.min_size ) { diff --git a/simgear/canvas/layout/NasalWidget.cxx b/simgear/canvas/layout/NasalWidget.cxx index ef6a9f36..05a6873f 100644 --- a/simgear/canvas/layout/NasalWidget.cxx +++ b/simgear/canvas/layout/NasalWidget.cxx @@ -108,14 +108,14 @@ namespace canvas void NasalWidget::setHeightForWidthFunc(const HeightForWidthFunc& func) { _height_for_width = func; - invalidateParent(); + invalidate(); } //---------------------------------------------------------------------------- void NasalWidget::setMinimumHeightForWidthFunc(const HeightForWidthFunc& func) { _min_height_for_width = func; - invalidateParent(); + invalidate(); } //---------------------------------------------------------------------------- @@ -127,7 +127,7 @@ namespace canvas _size_hint = s; // TODO just invalidate size_hint? Probably not a performance issue... - invalidateParent(); + invalidate(); } //---------------------------------------------------------------------------- @@ -137,7 +137,7 @@ namespace canvas return; _min_size = s; - invalidateParent(); + invalidate(); } //---------------------------------------------------------------------------- @@ -147,7 +147,7 @@ namespace canvas return; _max_size = s; - invalidateParent(); + invalidate(); } //---------------------------------------------------------------------------- diff --git a/simgear/canvas/layout/canvas_layout_test.cxx b/simgear/canvas/layout/canvas_layout_test.cxx index fc693e44..1077d30d 100644 --- a/simgear/canvas/layout/canvas_layout_test.cxx +++ b/simgear/canvas/layout/canvas_layout_test.cxx @@ -395,9 +395,17 @@ BOOST_AUTO_TEST_CASE( boxlayout_hfw ) vbox.setGeometry(SGRecti(0, 0, 50, 122)); - BOOST_CHECK_EQUAL(w1->geometry(), SGRecti(0, 0, 50, 44)); - BOOST_CHECK_EQUAL(w2->geometry(), SGRecti(0, 49, 50, 70)); - BOOST_CHECK_EQUAL(w_no_hfw->geometry(), SGRecti(0, 124, 50, 56)); + BOOST_CHECK_EQUAL(w1->geometry(), SGRecti(0, 0, 50, 25)); + BOOST_CHECK_EQUAL(w2->geometry(), SGRecti(0, 30, 50, 51)); + BOOST_CHECK_EQUAL(w_no_hfw->geometry(), SGRecti(0, 86, 50, 36)); + + // Same geometry as before -> should get same widget geometry + // (check internal size hint cache updates correctly) + vbox.setGeometry(SGRecti(0, 0, 24, 122)); + + BOOST_CHECK_EQUAL(w1->geometry(), SGRecti(0, 0, 24, 33)); + BOOST_CHECK_EQUAL(w2->geometry(), SGRecti(0, 38, 24, 47)); + BOOST_CHECK_EQUAL(w_no_hfw->geometry(), SGRecti(0, 90, 24, 32)); } //------------------------------------------------------------------------------