#include <simgear/nasal/cppbind/from_nasal.hxx>
#include <simgear/nasal/cppbind/NasalHash.hxx>
+#include <simgear/nasal/cppbind/NasalObject.hxx>
namespace simgear
{
* 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;
/**
*
*/
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
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;