diff options
Diffstat (limited to 'src/common/settings_setting.h')
| -rw-r--r-- | src/common/settings_setting.h | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h index e10843c73..7be6f26f7 100644 --- a/src/common/settings_setting.h +++ b/src/common/settings_setting.h | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <string> | 10 | #include <string> |
| 11 | #include <typeindex> | 11 | #include <typeindex> |
| 12 | #include <typeinfo> | 12 | #include <typeinfo> |
| 13 | #include <fmt/core.h> | ||
| 13 | #include "common/common_types.h" | 14 | #include "common/common_types.h" |
| 14 | #include "common/settings_common.h" | 15 | #include "common/settings_common.h" |
| 15 | #include "common/settings_enums.h" | 16 | #include "common/settings_enums.h" |
| @@ -115,8 +116,12 @@ protected: | |||
| 115 | } else if constexpr (std::is_same_v<Type, AudioEngine>) { | 116 | } else if constexpr (std::is_same_v<Type, AudioEngine>) { |
| 116 | // Compatibility with old AudioEngine setting being a string | 117 | // Compatibility with old AudioEngine setting being a string |
| 117 | return CanonicalizeEnum(value_); | 118 | return CanonicalizeEnum(value_); |
| 119 | } else if constexpr (std::is_floating_point_v<Type>) { | ||
| 120 | return fmt::format("{:f}", value_); | ||
| 121 | } else if constexpr (std::is_enum_v<Type>) { | ||
| 122 | return std::to_string(static_cast<u32>(value_)); | ||
| 118 | } else { | 123 | } else { |
| 119 | return std::to_string(static_cast<u64>(value_)); | 124 | return std::to_string(value_); |
| 120 | } | 125 | } |
| 121 | } | 126 | } |
| 122 | 127 | ||
| @@ -180,13 +185,15 @@ public: | |||
| 180 | this->SetValue(static_cast<u32>(std::stoul(input))); | 185 | this->SetValue(static_cast<u32>(std::stoul(input))); |
| 181 | } else if constexpr (std::is_same_v<Type, bool>) { | 186 | } else if constexpr (std::is_same_v<Type, bool>) { |
| 182 | this->SetValue(input == "true"); | 187 | this->SetValue(input == "true"); |
| 183 | } else if constexpr (std::is_same_v<Type, AudioEngine>) { | 188 | } else if constexpr (std::is_same_v<Type, float>) { |
| 184 | this->SetValue(ToEnum<Type>(input)); | 189 | this->SetValue(std::stof(input)); |
| 185 | } else { | 190 | } else { |
| 186 | this->SetValue(static_cast<Type>(std::stoll(input))); | 191 | this->SetValue(static_cast<Type>(std::stoll(input))); |
| 187 | } | 192 | } |
| 188 | } catch (std::invalid_argument&) { | 193 | } catch (std::invalid_argument&) { |
| 189 | this->SetValue(this->GetDefault()); | 194 | this->SetValue(this->GetDefault()); |
| 195 | } catch (std::out_of_range&) { | ||
| 196 | this->SetValue(this->GetDefault()); | ||
| 190 | } | 197 | } |
| 191 | } | 198 | } |
| 192 | 199 | ||
| @@ -215,11 +222,27 @@ public: | |||
| 215 | } | 222 | } |
| 216 | } | 223 | } |
| 217 | 224 | ||
| 225 | [[nodiscard]] constexpr bool IsFloatingPoint() const final { | ||
| 226 | return std::is_floating_point_v<Type>; | ||
| 227 | } | ||
| 228 | |||
| 229 | [[nodiscard]] constexpr bool IsIntegral() const final { | ||
| 230 | return std::is_integral_v<Type>; | ||
| 231 | } | ||
| 232 | |||
| 218 | [[nodiscard]] std::string MinVal() const override final { | 233 | [[nodiscard]] std::string MinVal() const override final { |
| 219 | return this->ToString(minimum); | 234 | if constexpr (std::is_arithmetic_v<Type> && !ranged) { |
| 235 | return this->ToString(std::numeric_limits<Type>::min()); | ||
| 236 | } else { | ||
| 237 | return this->ToString(minimum); | ||
| 238 | } | ||
| 220 | } | 239 | } |
| 221 | [[nodiscard]] std::string MaxVal() const override final { | 240 | [[nodiscard]] std::string MaxVal() const override final { |
| 222 | return this->ToString(maximum); | 241 | if constexpr (std::is_arithmetic_v<Type> && !ranged) { |
| 242 | return this->ToString(std::numeric_limits<Type>::max()); | ||
| 243 | } else { | ||
| 244 | return this->ToString(maximum); | ||
| 245 | } | ||
| 223 | } | 246 | } |
| 224 | 247 | ||
| 225 | [[nodiscard]] constexpr bool Ranged() const override { | 248 | [[nodiscard]] constexpr bool Ranged() const override { |