]> git.mxchange.org Git - simgear.git/blobdiff - simgear/canvas/layout/NasalWidget.hxx
canvas::NasalWidget: check for empty setGeometry callback.
[simgear.git] / simgear / canvas / layout / NasalWidget.hxx
index d9e80450ba323d930980ff28db3ff3cfc2f0f416..a55fa228723c29b3f00b0c10c5e09762a39b273d 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <simgear/nasal/cppbind/from_nasal.hxx>
 #include <simgear/nasal/cppbind/NasalHash.hxx>
+#include <simgear/nasal/cppbind/NasalObject.hxx>
 
 namespace simgear
 {
@@ -33,11 +34,13 @@ namespace canvas
    * Baseclass/ghost to create widgets with Nasal.
    */
   class NasalWidget:
-    public LayoutItem
+    public LayoutItem,
+    public nasal::Object
   {
     public:
 
       typedef boost::function<void (nasal::Me, const SGRecti&)> SetGeometryFunc;
+      typedef boost::function<int (nasal::Me, int)> HeightForWidthFunc;
 
       /**
        *
@@ -46,18 +49,44 @@ namespace canvas
        */
       NasalWidget(naRef impl);
 
+      ~NasalWidget();
+
+      virtual void invalidate();
       virtual void setGeometry(const SGRecti& geom);
+      virtual void onRemove();
 
       void setSetGeometryFunc(const SetGeometryFunc& func);
+      void setHeightForWidthFunc(const HeightForWidthFunc& func);
+      void setMinimumHeightForWidthFunc(const HeightForWidthFunc& func);
 
-      void setImpl(naRef obj);
-      naRef getImpl() const;
-
+      /** Set size hint.
+       *
+       * Overrides default size hint. Set to (0, 0) to fall back to default size
+       * hint.
+       */
       void setSizeHint(const SGVec2i& s);
+
+      /** Set minimum size.
+       *
+       * Overrides default minimum size. Set to (0, 0) to fall back to default
+       * minimum size.
+       */
       void setMinimumSize(const SGVec2i& s);
+
+      /** Set maximum size.
+       *
+       * Overrides default maximum size hint. Set to LayoutItem::MAX_SIZE to
+       * fall back to default maximum size.
+       */
       void setMaximumSize(const SGVec2i& s);
 
-      bool _set(naContext c, const std::string& key, naRef val);
+      void setLayoutSizeHint(const SGVec2i& s);
+      void setLayoutMinimumSize(const SGVec2i& s);
+      void setLayoutMaximumSize(const SGVec2i& s);
+
+      virtual bool hasHeightForWidth() const;
+      virtual int heightForWidth(int w) const;
+      virtual int minimumHeightForWidth(int w) const;
 
       /**
        * @param ns  Namespace to register the class interface
@@ -65,10 +94,25 @@ namespace canvas
       static void setupGhost(nasal::Hash& ns);
 
     protected:
-      SetGeometryFunc       _set_geometry;
-      nasal::ObjectHolder<> _nasal_impl;
+      enum WidgetFlags
+      {
+        LAYOUT_DIRTY = LayoutItem::LAST_FLAG << 1,
+        LAST_FLAG = LAYOUT_DIRTY
+      };
 
-      static naRef getParents(NasalWidget&, naContext);
+      SetGeometryFunc       _set_geometry;
+      HeightForWidthFunc    _height_for_width,
+                            _min_height_for_width;
+
+      SGVec2i _layout_size_hint,
+              _layout_min_size,
+              _layout_max_size,
+              _user_size_hint,
+              _user_min_size,
+              _user_max_size;
+
+      int callHeightForWidthFunc( const HeightForWidthFunc& hfw,
+                                  int w ) const;
 
       virtual SGVec2i sizeHintImpl() const;
       virtual SGVec2i minimumSizeImpl() const;