Qt: Add normalized float values to SettingWidgetBinder

This commit is contained in:
Connor McLaughlin 2020-02-10 22:44:00 +09:00
parent 9ac7b002e2
commit a81a0c0f21

View file

@ -163,6 +163,20 @@ void BindWidgetToIntSetting(QtHostInterface* hi, WidgetType* widget, const char*
});
}
template<typename WidgetType>
void BindWidgetToNormalizedSetting(QtHostInterface* hi, WidgetType* widget, const char* setting_name, float range)
{
using Accessor = SettingAccessor<WidgetType>;
Accessor::setIntValue(widget, static_cast<int>(hi->getSettingValue(setting_name).toFloat() * range));
Accessor::connectValueChanged(widget, [hi, widget, setting_name, range]() {
const float new_value = (static_cast<float>(Accessor::getIntValue(widget)) / range);
hi->putSettingValue(setting_name, new_value);
hi->applySettings();
});
}
template<typename WidgetType>
void BindWidgetToStringSetting(QtHostInterface* hi, WidgetType* widget, const char* setting_name)
{