_set_geometry = func;
}
+ //----------------------------------------------------------------------------
+ void NasalWidget::setHeightForWidthFunc(const HeightForWidthFunc& func)
+ {
+ _height_for_width = func;
+ invalidateParent();
+ }
+
+ //----------------------------------------------------------------------------
+ void NasalWidget::setMinimumHeightForWidthFunc(const HeightForWidthFunc& func)
+ {
+ _min_height_for_width = func;
+ invalidateParent();
+ }
+
//----------------------------------------------------------------------------
void NasalWidget::setSizeHint(const SGVec2i& s)
{
invalidateParent();
}
+ //----------------------------------------------------------------------------
+ bool NasalWidget::hasHeightForWidth() const
+ {
+ return !_height_for_width.empty() || !_min_height_for_width.empty();
+ }
+
+ //----------------------------------------------------------------------------
+ int NasalWidget::heightForWidth(int w) const
+ {
+ return callHeightForWidthFunc( _height_for_width.empty()
+ ? _min_height_for_width
+ : _height_for_width, w );
+ }
+
+ //----------------------------------------------------------------------------
+ int NasalWidget::minimumHeightForWidth(int w) const
+ {
+ return callHeightForWidthFunc( _min_height_for_width.empty()
+ ? _height_for_width
+ : _min_height_for_width, w );
+ }
+
//----------------------------------------------------------------------------
static naRef f_makeNasalWidget(const nasal::CallContext& ctx)
{
.bases<LayoutItemRef>()
.bases<nasal::ObjectRef>()
.method("setSetGeometryFunc", &NasalWidget::setSetGeometryFunc)
+ .method("setMinimumHeightForWidthFunc",
+ &NasalWidget::setMinimumHeightForWidthFunc)
+ .method("setHeightForWidthFunc", &NasalWidget::setHeightForWidthFunc)
.method("setSizeHint", &NasalWidget::setSizeHint)
.method("setMinimumSize", &NasalWidget::setMinimumSize)
.method("setMaximumSize", &NasalWidget::setMaximumSize);
widget_hash.set("new", &f_makeNasalWidget);
}
+ //----------------------------------------------------------------------------
+ int NasalWidget::callHeightForWidthFunc( const HeightForWidthFunc& hfw,
+ int w ) const
+ {
+ if( hfw.empty() )
+ return -1;
+
+ naContext c = naNewContext();
+ try
+ {
+ return hfw(nasal::to_nasal(c, const_cast<NasalWidget*>(this)), w);
+ }
+ catch( std::exception const& ex )
+ {
+ SG_LOG(
+ SG_GUI,
+ SG_WARN,
+ "NasalWidget.heightForWidth: callback error: '" << ex.what() << "'"
+ );
+ }
+ naFreeContext(c);
+
+ return -1;
+ }
+
//----------------------------------------------------------------------------
SGVec2i NasalWidget::sizeHintImpl() const
{