From a81a0c0f2165a5a75d25e58aba29c58d64461975 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 10 Feb 2020 22:44:00 +0900 Subject: [PATCH] Qt: Add normalized float values to SettingWidgetBinder --- src/duckstation-qt/settingwidgetbinder.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/duckstation-qt/settingwidgetbinder.h b/src/duckstation-qt/settingwidgetbinder.h index 0f7a46979..4d7832627 100644 --- a/src/duckstation-qt/settingwidgetbinder.h +++ b/src/duckstation-qt/settingwidgetbinder.h @@ -163,6 +163,20 @@ void BindWidgetToIntSetting(QtHostInterface* hi, WidgetType* widget, const char* }); } +template +void BindWidgetToNormalizedSetting(QtHostInterface* hi, WidgetType* widget, const char* setting_name, float range) +{ + using Accessor = SettingAccessor; + + Accessor::setIntValue(widget, static_cast(hi->getSettingValue(setting_name).toFloat() * range)); + + Accessor::connectValueChanged(widget, [hi, widget, setting_name, range]() { + const float new_value = (static_cast(Accessor::getIntValue(widget)) / range); + hi->putSettingValue(setting_name, new_value); + hi->applySettings(); + }); +} + template void BindWidgetToStringSetting(QtHostInterface* hi, WidgetType* widget, const char* setting_name) {