]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/layout/NasalWidget.cxx
canvas::Layout: support for alignment.
[simgear.git] / simgear / canvas / layout / NasalWidget.cxx
index d3feb9b47f26ebc428d767852ec42f58b2b9e384..5c027e8518359be9470a54f39c766ae63b5313e8 100644 (file)
@@ -19,6 +19,7 @@
 #include "NasalWidget.hxx"
 
 #include <simgear/canvas/Canvas.hxx>
+#include <simgear/nasal/cppbind/NasalContext.hxx>
 #include <simgear/nasal/cppbind/Ghost.hxx>
 
 namespace simgear
@@ -45,53 +46,12 @@ namespace canvas
     onRemove();
   }
 
-  //----------------------------------------------------------------------------
-  void NasalWidget::invalidate()
-  {
-    LayoutItem::invalidate();
-    _flags |= LAYOUT_DIRTY;
-  }
-
-  //----------------------------------------------------------------------------
-  void NasalWidget::setGeometry(const SGRect<int>& geom)
-  {
-    if( _geometry != geom )
-      _geometry = geom;
-    else if( !(_flags & LAYOUT_DIRTY) || !_set_geometry )
-      return;
-
-    naContext c = naNewContext();
-    try
-    {
-      _set_geometry(nasal::to_nasal(c, this), geom);
-      _flags &= ~LAYOUT_DIRTY;
-    }
-    catch( std::exception const& ex )
-    {
-      SG_LOG(
-        SG_GUI,
-        SG_WARN,
-        "NasalWidget::setGeometry: callback error: '" << ex.what() << "'"
-      );
-    }
-    naFreeContext(c);
-  }
-
   //----------------------------------------------------------------------------
   void NasalWidget::onRemove()
   {
-    if( !_nasal_impl.valid() )
-      return;
-
-    typedef boost::function<void(nasal::Me)> Deleter;
-
-    naContext c = naNewContext();
     try
     {
-      Deleter del =
-        nasal::get_member<Deleter>(c, _nasal_impl.get_naRef(), "onRemove");
-      if( del )
-        del(nasal::to_nasal(c, this));
+      callMethod<void>("onRemove");
     }
     catch( std::exception const& ex )
     {
@@ -101,7 +61,6 @@ namespace canvas
         "NasalWidget::onRemove: callback error: '" << ex.what() << "'"
       );
     }
-    naFreeContext(c);
   }
 
   //----------------------------------------------------------------------------
@@ -192,22 +151,6 @@ namespace canvas
     return !_height_for_width.empty() || !_min_height_for_width.empty();
   }
 
-  //----------------------------------------------------------------------------
-  int NasalWidget::heightForWidth(int w) const
-  {
-    return callHeightForWidthFunc( _height_for_width.empty()
-                                 ? _min_height_for_width
-                                 : _height_for_width, w );
-  }
-
-  //----------------------------------------------------------------------------
-  int NasalWidget::minimumHeightForWidth(int w) const
-  {
-    return callHeightForWidthFunc( _min_height_for_width.empty()
-                                 ? _height_for_width
-                                 : _min_height_for_width, w );
-  }
-
   //----------------------------------------------------------------------------
   static naRef f_makeNasalWidget(const nasal::CallContext& ctx)
   {
@@ -291,5 +234,62 @@ namespace canvas
     );
   }
 
+
+  //----------------------------------------------------------------------------
+  int NasalWidget::heightForWidthImpl(int w) const
+  {
+    return callHeightForWidthFunc( _height_for_width.empty()
+                                 ? _min_height_for_width
+                                 : _height_for_width, w );
+  }
+
+  //----------------------------------------------------------------------------
+  int NasalWidget::minimumHeightForWidthImpl(int w) const
+  {
+    return callHeightForWidthFunc( _min_height_for_width.empty()
+                                 ? _height_for_width
+                                 : _min_height_for_width, w );
+  }
+
+
+  //----------------------------------------------------------------------------
+  void NasalWidget::contentsRectChanged(const SGRect<int>& rect)
+  {
+    if( !_set_geometry )
+      return;
+
+    try
+    {
+      nasal::Context c;
+      _set_geometry(nasal::to_nasal(c, this), rect);
+      _flags &= ~LAYOUT_DIRTY;
+    }
+    catch( std::exception const& ex )
+    {
+      SG_LOG(
+        SG_GUI,
+        SG_WARN,
+        "NasalWidget::setGeometry: callback error: '" << ex.what() << "'"
+      );
+    }
+  }
+
+  //----------------------------------------------------------------------------
+  void NasalWidget::visibilityChanged(bool visible)
+  {
+    try
+    {
+      callMethod<void>("visibilityChanged", visible);
+    }
+    catch( std::exception const& ex )
+    {
+      SG_LOG(
+        SG_GUI,
+        SG_WARN,
+        "NasalWidget::visibilityChanged: callback error: '" << ex.what() << "'"
+      );
+    }
+  }
+
 } // namespace canvas
 } // namespace simgear