]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/layout/BoxLayout.cxx
canvas::Layout: support for contents margins.
[simgear.git] / simgear / canvas / layout / BoxLayout.cxx
index c7a5f123b9249b97a22c99c52ab6c0e5ca1a481d..3e1d37ffde09a9336e6019e8de3f9fbd6481454e 100644 (file)
@@ -125,8 +125,8 @@ namespace canvas
 
     LayoutItems::iterator it = _layout_items.begin() + index;
     LayoutItemRef item = it->layout_item;
-    item->setParent(LayoutItemWeakRef());
     item->onRemove();
+    item->setParent(LayoutItemWeakRef());
     _layout_items.erase(it);
 
     invalidate();
@@ -141,8 +141,8 @@ namespace canvas
                                it != _layout_items.end();
                              ++it )
     {
-      it->layout_item->setParent(LayoutItemWeakRef());
       it->layout_item->onRemove();
+      it->layout_item->setParent(LayoutItemWeakRef());
     }
     _layout_items.clear();
     invalidate();
@@ -229,26 +229,6 @@ namespace canvas
     return _layout_data.has_hfw;
   }
 
-  //----------------------------------------------------------------------------
-  int BoxLayout::heightForWidth(int w) const
-  {
-    if( !hasHeightForWidth() )
-      return -1;
-
-    updateWFHCache(w);
-    return _hfw_height;
-  }
-
-  //----------------------------------------------------------------------------
-  int BoxLayout::minimumHeightForWidth(int w) const
-  {
-    if( !hasHeightForWidth() )
-      return -1;
-
-    updateWFHCache(w);
-    return _hfw_min_height;
-  }
-
   //----------------------------------------------------------------------------
   void BoxLayout::setCanvas(const CanvasWeakPtr& canvas)
   {
@@ -305,9 +285,9 @@ namespace canvas
       }
 
       // Add sizes of all children in layout direction
-      safeAdd(min_size.x(),  item_data.min_size);
-      safeAdd(max_size.x(),  item_data.max_size);
-      safeAdd(size_hint.x(), item_data.size_hint);
+      SGMisc<int>::addClipOverflowInplace(min_size.x(),  item_data.min_size);
+      SGMisc<int>::addClipOverflowInplace(max_size.x(),  item_data.max_size);
+      SGMisc<int>::addClipOverflowInplace(size_hint.x(), item_data.size_hint);
 
       // Take maximum in fixed (non-layouted) direction
       min_size.y()  = std::max( min_size.y(),
@@ -320,9 +300,9 @@ namespace canvas
       _layout_data.has_hfw = _layout_data.has_hfw || item.hasHeightForWidth();
     }
 
-    safeAdd(min_size.x(),  _layout_data.padding);
-    safeAdd(max_size.x(),  _layout_data.padding);
-    safeAdd(size_hint.x(), _layout_data.padding);
+    SGMisc<int>::addClipOverflowInplace(min_size.x(),  _layout_data.padding);
+    SGMisc<int>::addClipOverflowInplace(max_size.x(),  _layout_data.padding);
+    SGMisc<int>::addClipOverflowInplace(size_hint.x(), _layout_data.padding);
 
     _layout_data.min_size = min_size.x();
     _layout_data.max_size = max_size.x();
@@ -400,6 +380,27 @@ namespace canvas
     return _max_size;
   }
 
+
+  //----------------------------------------------------------------------------
+  int BoxLayout::heightForWidthImpl(int w) const
+  {
+    if( !hasHeightForWidth() )
+      return -1;
+
+    updateWFHCache(w);
+    return _hfw_height;
+  }
+
+  //----------------------------------------------------------------------------
+  int BoxLayout::minimumHeightForWidthImpl(int w) const
+  {
+    if( !hasHeightForWidth() )
+      return -1;
+
+    updateWFHCache(w);
+    return _hfw_min_height;
+  }
+
   //----------------------------------------------------------------------------
   void BoxLayout::doLayout(const SGRecti& geom)
   {