1 ///@file Glue for GUI widgets implemented in Nasal space
3 // Copyright (C) 2014 Thomas Geymayer <tomgey@gmail.com>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef SG_CANVAS_NASAL_WIDGET_HXX_
20 #define SG_CANVAS_NASAL_WIDGET_HXX_
22 #include "LayoutItem.hxx"
24 #include <simgear/nasal/cppbind/from_nasal.hxx>
25 #include <simgear/nasal/cppbind/NasalHash.hxx>
26 #include <simgear/nasal/cppbind/NasalObject.hxx>
34 * Baseclass/ghost to create widgets with Nasal.
42 typedef boost::function<void (nasal::Me, const SGRecti&)> SetGeometryFunc;
43 typedef boost::function<int (nasal::Me, int)> HeightForWidthFunc;
47 * @param impl Initial implementation hash (nasal part of
50 NasalWidget(naRef impl);
54 virtual void invalidate();
55 virtual void setGeometry(const SGRecti& geom);
56 virtual void onRemove();
58 void setSetGeometryFunc(const SetGeometryFunc& func);
59 void setHeightForWidthFunc(const HeightForWidthFunc& func);
60 void setMinimumHeightForWidthFunc(const HeightForWidthFunc& func);
64 * Overrides default size hint. Set to (0, 0) to fall back to default size
67 void setSizeHint(const SGVec2i& s);
71 * Overrides default minimum size. Set to (0, 0) to fall back to default
74 void setMinimumSize(const SGVec2i& s);
78 * Overrides default maximum size hint. Set to LayoutItem::MAX_SIZE to
79 * fall back to default maximum size.
81 void setMaximumSize(const SGVec2i& s);
83 void setLayoutSizeHint(const SGVec2i& s);
84 void setLayoutMinimumSize(const SGVec2i& s);
85 void setLayoutMaximumSize(const SGVec2i& s);
87 virtual bool hasHeightForWidth() const;
88 virtual int heightForWidth(int w) const;
89 virtual int minimumHeightForWidth(int w) const;
92 * @param ns Namespace to register the class interface
94 static void setupGhost(nasal::Hash& ns);
99 LAYOUT_DIRTY = LayoutItem::LAST_FLAG << 1,
100 LAST_FLAG = LAYOUT_DIRTY
103 SetGeometryFunc _set_geometry;
104 HeightForWidthFunc _height_for_width,
105 _min_height_for_width;
107 SGVec2i _layout_size_hint,
114 int callHeightForWidthFunc( const HeightForWidthFunc& hfw,
117 virtual SGVec2i sizeHintImpl() const;
118 virtual SGVec2i minimumSizeImpl() const;
119 virtual SGVec2i maximumSizeImpl() const;
123 typedef SGSharedPtr<NasalWidget> NasalWidgetRef;
125 } // namespace canvas
126 } // namespace simgear
129 #endif /* SG_CANVAS_NASAL_WIDGET_HXX_ */