configuration: Implement slider

This commit is contained in:
lat9nq 2023-05-08 17:33:10 -04:00
parent e40f887355
commit f9310ec1e8
7 changed files with 188 additions and 71 deletions

View file

@ -200,6 +200,8 @@ public:
virtual bool RuntimeModfiable() const = 0;
virtual void SetGlobal(bool global) {}
virtual constexpr u32 Id() const = 0;
virtual std::string MinVal() const = 0;
virtual std::string MaxVal() const = 0;
virtual bool UsingGlobal() const {
return false;
}
@ -336,7 +338,7 @@ protected:
if constexpr (std::is_same<Type, std::string>()) {
return value_;
} else if constexpr (std::is_same<Type, std::optional<u32>>()) {
return value_.has_value() ? std::to_string(*value_) : "0";
return value_.has_value() ? std::to_string(*value_) : "none";
} else if constexpr (std::is_same<Type, bool>()) {
return value_ ? "true" : "false";
} else {
@ -401,7 +403,7 @@ public:
if constexpr (std::is_same<Type, std::string>()) {
this->SetValue(input);
} else if constexpr (std::is_same<Type, std::optional<u32>>()) {
this->SetValue(static_cast<u32>(std::stoll(input)));
this->SetValue(static_cast<u32>(std::stoul(input)));
} else if constexpr (std::is_same<Type, bool>()) {
this->SetValue(input == "true");
} else {
@ -435,6 +437,13 @@ public:
return id;
}
virtual std::string MinVal() const override {
return this->ToString(minimum);
}
virtual std::string MaxVal() const override {
return this->ToString(maximum);
}
protected:
Type value{}; ///< The setting
const Type default_value{}; ///< The default value