]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/layout/NasalWidget.hxx
canvas::Layout: support for contents margins.
[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       ~NasalWidget();
53
54       virtual void onRemove();
55
56       void setSetGeometryFunc(const SetGeometryFunc& func);
57       void setHeightForWidthFunc(const HeightForWidthFunc& func);
58       void setMinimumHeightForWidthFunc(const HeightForWidthFunc& func);
59
60       /** Set size hint.
61        *
62        * Overrides default size hint. Set to (0, 0) to fall back to default size
63        * hint.
64        */
65       void setSizeHint(const SGVec2i& s);
66
67       /** Set minimum size.
68        *
69        * Overrides default minimum size. Set to (0, 0) to fall back to default
70        * minimum size.
71        */
72       void setMinimumSize(const SGVec2i& s);
73
74       /** Set maximum size.
75        *
76        * Overrides default maximum size hint. Set to LayoutItem::MAX_SIZE to
77        * fall back to default maximum size.
78        */
79       void setMaximumSize(const SGVec2i& s);
80
81       void setLayoutSizeHint(const SGVec2i& s);
82       void setLayoutMinimumSize(const SGVec2i& s);
83       void setLayoutMaximumSize(const SGVec2i& s);
84
85       virtual bool hasHeightForWidth() const;
86
87       /**
88        * @param ns  Namespace to register the class interface
89        */
90       static void setupGhost(nasal::Hash& ns);
91
92     protected:
93       enum WidgetFlags
94       {
95         LAYOUT_DIRTY = LayoutItem::LAST_FLAG << 1,
96         LAST_FLAG = LAYOUT_DIRTY
97       };
98
99       SetGeometryFunc       _set_geometry;
100       HeightForWidthFunc    _height_for_width,
101                             _min_height_for_width;
102
103       SGVec2i _layout_size_hint,
104               _layout_min_size,
105               _layout_max_size,
106               _user_size_hint,
107               _user_min_size,
108               _user_max_size;
109
110       int callHeightForWidthFunc( const HeightForWidthFunc& hfw,
111                                   int w ) const;
112
113       virtual SGVec2i sizeHintImpl() const;
114       virtual SGVec2i minimumSizeImpl() const;
115       virtual SGVec2i maximumSizeImpl() const;
116
117       virtual int heightForWidthImpl(int w) const;
118       virtual int minimumHeightForWidthImpl(int w) const;
119
120       virtual void contentsRectChanged(const SGRecti& rect);
121
122       virtual void visibilityChanged(bool visible);
123
124   };
125
126   typedef SGSharedPtr<NasalWidget> NasalWidgetRef;
127
128 } // namespace canvas
129 } // namespace simgear
130
131
132 #endif /* SG_CANVAS_NASAL_WIDGET_HXX_ */