1 // Glue for GUI layout items 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 #include "NasalWidget.hxx"
21 #include <simgear/canvas/Canvas.hxx>
22 #include <simgear/nasal/cppbind/Ghost.hxx>
29 //----------------------------------------------------------------------------
30 NasalWidget::NasalWidget(naRef impl):
36 //----------------------------------------------------------------------------
37 void NasalWidget::setGeometry(const SGRect<int>& geom)
39 if( _geometry == geom )
46 naContext c = naNewContext();
49 _set_geometry(nasal::to_nasal(c, this), geom);
51 catch( std::exception const& ex )
56 "NasalWidget::setGeometry: callback error: '" << ex.what() << "'"
62 //----------------------------------------------------------------------------
63 void NasalWidget::setSetGeometryFunc(const SetGeometryFunc& func)
68 //----------------------------------------------------------------------------
69 void NasalWidget::setSizeHint(const SGVec2i& s)
76 // TODO just invalidate size_hint? Probably not a performance issue...
80 //----------------------------------------------------------------------------
81 void NasalWidget::setMinimumSize(const SGVec2i& s)
90 //----------------------------------------------------------------------------
91 void NasalWidget::setMaximumSize(const SGVec2i& s)
100 //----------------------------------------------------------------------------
101 static naRef f_makeNasalWidget(const nasal::CallContext& ctx)
103 return ctx.to_nasal(NasalWidgetRef(
104 new NasalWidget( ctx.requireArg<naRef>(0) )
108 //----------------------------------------------------------------------------
109 void NasalWidget::setupGhost(nasal::Hash& ns)
111 nasal::Ghost<NasalWidgetRef>::init("canvas.Widget")
112 .bases<LayoutItemRef>()
113 .bases<nasal::ObjectRef>()
114 .method("setSetGeometryFunc", &NasalWidget::setSetGeometryFunc)
115 .method("setSizeHint", &NasalWidget::setSizeHint)
116 .method("setMinimumSize", &NasalWidget::setMinimumSize)
117 .method("setMaximumSize", &NasalWidget::setMaximumSize);
119 nasal::Hash widget_hash = ns.createHash("Widget");
120 widget_hash.set("new", &f_makeNasalWidget);
123 //----------------------------------------------------------------------------
124 SGVec2i NasalWidget::sizeHintImpl() const
129 //----------------------------------------------------------------------------
130 SGVec2i NasalWidget::minimumSizeImpl() const
135 //----------------------------------------------------------------------------
136 SGVec2i NasalWidget::maximumSizeImpl() const
141 } // namespace canvas
142 } // namespace simgear