]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/layout/NasalWidget.hxx
canvas::Layout: support height-for-width layouting.
[simgear.git] / simgear / canvas / layout / NasalWidget.hxx
1 ///@file Glue for GUI widgets implemented in Nasal space
2 //
3 // Copyright (C) 2014  Thomas Geymayer <tomgey@gmail.com>
4 //
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.
9 //
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.
14 //
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
18
19 #ifndef SG_CANVAS_NASAL_WIDGET_HXX_
20 #define SG_CANVAS_NASAL_WIDGET_HXX_
21
22 #include "LayoutItem.hxx"
23
24 #include <simgear/nasal/cppbind/from_nasal.hxx>
25 #include <simgear/nasal/cppbind/NasalHash.hxx>
26 #include <simgear/nasal/cppbind/NasalObject.hxx>
27
28 namespace simgear
29 {
30 namespace canvas
31 {
32
33   /**
34    * Baseclass/ghost to create widgets with Nasal.
35    */
36   class NasalWidget:
37     public LayoutItem,
38     public nasal::Object
39   {
40     public:
41
42       typedef boost::function<void (nasal::Me, const SGRecti&)> SetGeometryFunc;
43       typedef boost::function<int (nasal::Me, int)> HeightForWidthFunc;
44
45       /**
46        *
47        * @param impl    Initial implementation hash (nasal part of
48        *                implementation)
49        */
50       NasalWidget(naRef impl);
51
52       virtual void setGeometry(const SGRecti& geom);
53
54       void setSetGeometryFunc(const SetGeometryFunc& func);
55       void setHeightForWidthFunc(const HeightForWidthFunc& func);
56       void setMinimumHeightForWidthFunc(const HeightForWidthFunc& func);
57
58       void setSizeHint(const SGVec2i& s);
59       void setMinimumSize(const SGVec2i& s);
60       void setMaximumSize(const SGVec2i& s);
61
62       virtual bool hasHeightForWidth() const;
63       virtual int heightForWidth(int w) const;
64       virtual int minimumHeightForWidth(int w) const;
65
66       /**
67        * @param ns  Namespace to register the class interface
68        */
69       static void setupGhost(nasal::Hash& ns);
70
71     protected:
72       SetGeometryFunc       _set_geometry;
73       HeightForWidthFunc    _height_for_width,
74                             _min_height_for_width;
75
76       int callHeightForWidthFunc( const HeightForWidthFunc& hfw,
77                                   int w ) const;
78
79       virtual SGVec2i sizeHintImpl() const;
80       virtual SGVec2i minimumSizeImpl() const;
81       virtual SGVec2i maximumSizeImpl() const;
82
83   };
84
85   typedef SGSharedPtr<NasalWidget> NasalWidgetRef;
86
87 } // namespace canvas
88 } // namespace simgear
89
90
91 #endif /* SG_CANVAS_NASAL_WIDGET_HXX_ */