settings page completely moved to xml

This commit is contained in:
MihailRis
2024-04-20 15:52:55 +03:00
parent 9cdf3ff016
commit b9ea88b988
15 changed files with 111 additions and 107 deletions
+9
View File
@@ -23,3 +23,12 @@ std::string IntegerSetting::toString() const {
return "invalid format";
}
}
std::string FlagSetting::toString() const {
switch (getFormat()) {
case setting_format::simple:
return value ? "true" : "false";
default:
return "invalid format";
}
}
+43
View File
@@ -156,4 +156,47 @@ public:
virtual std::string toString() const override;
};
class FlagSetting : public Setting {
protected:
bool initial;
bool value;
std::vector<consumer<bool>> consumers;
public:
FlagSetting(
bool value,
setting_format format=setting_format::simple
) : Setting(format),
initial(value),
value(value)
{}
bool& operator*() {
return value;
}
bool get() const {
return value;
}
void set(bool value) {
if (value == this->value) {
return;
}
this->value = value;
for (auto& callback : consumers) {
callback(value);
}
}
void observe(consumer<bool> callback) {
consumers.push_back(callback);
}
virtual void resetToDefault() override {
value = initial;
}
virtual std::string toString() const override;
};
#endif // DATA_SETTING_H_