]> git.mxchange.org Git - simgear.git/commitdiff
canvas::BoxLayout: fix hfw layouting (fix updating size hint cache).
authorThomas Geymayer <tomgey@gmail.com>
Sat, 28 Jun 2014 11:08:06 +0000 (13:08 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sat, 28 Jun 2014 11:08:06 +0000 (13:08 +0200)
simgear/canvas/layout/BoxLayout.cxx
simgear/canvas/layout/Layout.cxx
simgear/canvas/layout/NasalWidget.cxx
simgear/canvas/layout/canvas_layout_test.cxx

index f6c4c48aeb296c36f9ed62f5be6be80f0d81fcfd..e0155c229a408f86c1e27776208027bb92efb2d8 100644 (file)
@@ -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();
         }
       }
     }
index 7ebad9d47d31c12dfb70fcc74cb09ef5f7fb1fd2..ece4ddabe67ce35305a3ea51358f91ff3a5e26f7 100644 (file)
@@ -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 )
     {
index ef6a9f36521fce5574c1a31e16099df78374aadb..05a6873fcd75b12afdf0565d1760ac60b0af41f5 100644 (file)
@@ -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();
   }
 
   //----------------------------------------------------------------------------
index fc693e446089cc1568475b6249e354680eed8431..1077d30d4e84222f43b696feae78e36ac4f8dd3a 100644 (file)
@@ -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));
 }
 
 //------------------------------------------------------------------------------