]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/layout/NasalWidget.hxx
Canvas: basic layouting system.
[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
27 namespace simgear
28 {
29 namespace canvas
30 {
31
32   /**
33    * Baseclass/ghost to create widgets with Nasal.
34    */
35   class NasalWidget:
36     public LayoutItem
37   {
38     public:
39
40       typedef boost::function<void (nasal::Me, const SGRecti&)> SetGeometryFunc;
41
42       /**
43        *
44        * @param impl    Initial implementation hash (nasal part of
45        *                implementation)
46        */
47       NasalWidget(naRef impl);
48
49       virtual void setGeometry(const SGRecti& geom);
50
51       void setSetGeometryFunc(const SetGeometryFunc& func);
52
53       void setImpl(naRef obj);
54       naRef getImpl() const;
55
56       void setSizeHint(const SGVec2i& s);
57       void setMinimumSize(const SGVec2i& s);
58       void setMaximumSize(const SGVec2i& s);
59
60       bool _set(naContext c, const std::string& key, naRef val);
61
62       /**
63        * @param ns  Namespace to register the class interface
64        */
65       static void setupGhost(nasal::Hash& ns);
66
67     protected:
68       SetGeometryFunc       _set_geometry;
69       nasal::ObjectHolder<> _nasal_impl;
70
71       static naRef getParents(NasalWidget&, naContext);
72
73       virtual SGVec2i sizeHintImpl() const;
74       virtual SGVec2i minimumSizeImpl() const;
75       virtual SGVec2i maximumSizeImpl() const;
76
77   };
78
79   typedef SGSharedPtr<NasalWidget> NasalWidgetRef;
80
81 } // namespace canvas
82 } // namespace simgear
83
84
85 #endif /* SG_CANVAS_NASAL_WIDGET_HXX_ */