]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/layout/NasalWidget.hxx
canvas::Layout: support for alignment.
[simgear.git] / simgear / canvas / layout / NasalWidget.hxx
1 ///@file
2 /// Glue for GUI widgets implemented in Nasal space.
3 //
4 // Copyright (C) 2014  Thomas Geymayer <tomgey@gmail.com>
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Library General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Library General Public License for more details.
15 //
16 // You should have received a copy of the GNU Library General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
19
20 #ifndef SG_CANVAS_NASAL_WIDGET_HXX_
21 #define SG_CANVAS_NASAL_WIDGET_HXX_
22
23 #include "LayoutItem.hxx"
24
25 #include <simgear/nasal/cppbind/from_nasal.hxx>
26 #include <simgear/nasal/cppbind/NasalHash.hxx>
27 #include <simgear/nasal/cppbind/NasalObject.hxx>
28
29 namespace simgear
30 {
31 namespace canvas
32 {
33
34   /**
35    * Base class/ghost to implement gui widgets in Nasal space.
36    */
37   class NasalWidget:
38     public LayoutItem,
39     public nasal::Object
40   {
41     public:
42
43       typedef boost::function<void (nasal::Me, const SGRecti&)> SetGeometryFunc;
44       typedef boost::function<int (nasal::Me, int)> HeightForWidthFunc;
45
46       /**
47        *
48        * @param impl    Initial implementation hash (nasal part of
49        *                implementation)
50        */
51       NasalWidget(naRef impl);
52
53       ~NasalWidget();
54
55       virtual void onRemove();
56
57       void setSetGeometryFunc(const SetGeometryFunc& func);
58       void setHeightForWidthFunc(const HeightForWidthFunc& func);
59       void setMinimumHeightForWidthFunc(const HeightForWidthFunc& func);
60
61       /** Set size hint.
62        *
63        * Overrides default size hint. Set to (0, 0) to fall back to default size
64        * hint.
65        */
66       void setSizeHint(const SGVec2i& s);
67
68       /** Set minimum size.
69        *
70        * Overrides default minimum size. Set to (0, 0) to fall back to default
71        * minimum size.
72        */
73       void setMinimumSize(const SGVec2i& s);
74
75       /** Set maximum size.
76        *
77        * Overrides default maximum size hint. Set to LayoutItem::MAX_SIZE to
78        * fall back to default maximum size.
79        */
80       void setMaximumSize(const SGVec2i& s);
81
82       void setLayoutSizeHint(const SGVec2i& s);
83       void setLayoutMinimumSize(const SGVec2i& s);
84       void setLayoutMaximumSize(const SGVec2i& s);
85
86       virtual bool hasHeightForWidth() const;
87
88       /**
89        * @param ns  Namespace to register the class interface
90        */
91       static void setupGhost(nasal::Hash& ns);
92
93     protected:
94       enum WidgetFlags
95       {
96         LAYOUT_DIRTY = LayoutItem::LAST_FLAG << 1,
97         LAST_FLAG = LAYOUT_DIRTY
98       };
99
100       SetGeometryFunc       _set_geometry;
101       HeightForWidthFunc    _height_for_width,
102                             _min_height_for_width;
103
104       SGVec2i _layout_size_hint,
105               _layout_min_size,
106               _layout_max_size,
107               _user_size_hint,
108               _user_min_size,
109               _user_max_size;
110
111       int callHeightForWidthFunc( const HeightForWidthFunc& hfw,
112                                   int w ) const;
113
114       virtual SGVec2i sizeHintImpl() const;
115       virtual SGVec2i minimumSizeImpl() const;
116       virtual SGVec2i maximumSizeImpl() const;
117
118       virtual int heightForWidthImpl(int w) const;
119       virtual int minimumHeightForWidthImpl(int w) const;
120
121       virtual void contentsRectChanged(const SGRecti& rect);
122
123       virtual void visibilityChanged(bool visible);
124
125   };
126
127   typedef SGSharedPtr<NasalWidget> NasalWidgetRef;
128
129 } // namespace canvas
130 } // namespace simgear
131
132
133 #endif /* SG_CANVAS_NASAL_WIDGET_HXX_ */