mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-03 14:38:08 +00:00
Added precision to ISchema::DoubleEntry
This commit is contained in:
parent
b2f4f7fde6
commit
157071ed9d
@ -71,6 +71,7 @@ namespace musik { namespace core { namespace sdk {
|
||||
Entry entry;
|
||||
double minValue;
|
||||
double maxValue;
|
||||
int precision;
|
||||
double defaultValue;
|
||||
};
|
||||
|
||||
@ -141,7 +142,7 @@ namespace musik { namespace core { namespace sdk {
|
||||
const std::string& name,
|
||||
int defaultValue,
|
||||
int min = INT_MIN,
|
||||
int max = INT_MAX)
|
||||
int max = INT_MAX)
|
||||
{
|
||||
auto entry = new IntEntry();
|
||||
entry->entry.type = ISchema::Type::Int;
|
||||
@ -154,8 +155,9 @@ namespace musik { namespace core { namespace sdk {
|
||||
}
|
||||
|
||||
TSchema& AddDouble(
|
||||
const std::string& name,
|
||||
double defaultValue,
|
||||
const std::string& name,
|
||||
double defaultValue,
|
||||
int precision = 2,
|
||||
double min = DBL_MIN,
|
||||
double max = DBL_MAX)
|
||||
{
|
||||
@ -163,6 +165,7 @@ namespace musik { namespace core { namespace sdk {
|
||||
entry->entry.type = ISchema::Type::Double;
|
||||
entry->entry.name = AllocString(name);
|
||||
entry->defaultValue = defaultValue;
|
||||
entry->precision = precision;
|
||||
entry->minValue = min;
|
||||
entry->maxValue = max;
|
||||
entries.push_back(reinterpret_cast<Entry*>(entry));
|
||||
@ -181,7 +184,7 @@ namespace musik { namespace core { namespace sdk {
|
||||
TSchema& AddEnum(
|
||||
const std::string& name,
|
||||
const std::vector<std::string>&& values,
|
||||
const std::string& defaultValue)
|
||||
const std::string& defaultValue)
|
||||
{
|
||||
auto entry = new EnumEntry();
|
||||
entry->entry.type = ISchema::Type::Enum;
|
||||
@ -211,7 +214,11 @@ namespace musik { namespace core { namespace sdk {
|
||||
|
||||
const char* AllocString(const std::string& str) {
|
||||
char* result = new char[str.size() + 1];
|
||||
#ifdef WIN32
|
||||
strncpy_s(result, str.size() + 1, str.c_str(), str.size());
|
||||
#else
|
||||
strncpy(result, str.c_str(), str.size());
|
||||
#endif
|
||||
result[str.size()] = 0;
|
||||
return result;
|
||||
}
|
||||
|
@ -91,10 +91,11 @@ static std::function<std::string(int)> INT_FORMATTER =
|
||||
return std::to_string(value);
|
||||
};
|
||||
|
||||
static std::function<std::string(double)> DOUBLE_FORMATTER =
|
||||
[](double value) -> std::string {
|
||||
return stringValueForDouble(value);
|
||||
};
|
||||
static std::function<std::string(double)> doubleFormatter(int precision) {
|
||||
return [precision](double value) -> std::string {
|
||||
return stringValueForDouble(value, precision);
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool bounded(T minimum, T maximum) {
|
||||
@ -129,8 +130,12 @@ static std::string stringValueFor(
|
||||
return prefs->GetBool(name, DEFAULT(BoolEntry)) ? "true" : "false";
|
||||
case ISchema::Type::Int:
|
||||
return std::to_string(prefs->GetInt(name, DEFAULT(IntEntry)));
|
||||
case ISchema::Type::Double:
|
||||
return stringValueForDouble(prefs->GetDouble(name, DEFAULT(DoubleEntry)));
|
||||
case ISchema::Type::Double: {
|
||||
auto doubleEntry = reinterpret_cast<const ISchema::DoubleEntry*>(entry);
|
||||
auto defaultValue = doubleEntry->defaultValue;
|
||||
auto precision = doubleEntry->precision;
|
||||
return stringValueForDouble(prefs->GetDouble(name, defaultValue), precision);
|
||||
}
|
||||
case ISchema::Type::String:
|
||||
return prefs->GetString(name, DEFAULT(StringEntry));
|
||||
case ISchema::Type::Enum:
|
||||
@ -334,11 +339,13 @@ class SchemaAdapter: public ScrollAdapterBase {
|
||||
void ShowDoubleOverlay(const ISchema::DoubleEntry* entry) {
|
||||
auto name = entry->entry.name;
|
||||
|
||||
auto formatter = doubleFormatter(entry->precision);
|
||||
|
||||
auto title = numberInputTitle(
|
||||
name, entry->minValue, entry->maxValue, DOUBLE_FORMATTER);
|
||||
name, entry->minValue, entry->maxValue, formatter);
|
||||
|
||||
auto validator = std::make_shared<NumberValidator<double>>(
|
||||
entry->minValue, entry->maxValue, DOUBLE_FORMATTER);
|
||||
entry->minValue, entry->maxValue, formatter);
|
||||
|
||||
auto width = std::max(u8cols(title) + 4, DEFAULT_INPUT_WIDTH);
|
||||
|
||||
|
@ -66,7 +66,7 @@ extern "C" DLLEXPORT void SetPreferences(IPreferences* prefs) {
|
||||
|
||||
extern "C" DLLEXPORT musik::core::sdk::ISchema* GetSchema() {
|
||||
auto schema = new TSchema<>();
|
||||
schema->AddDouble(PREF_MULTIPLIER, 1.0, 0.25, 1000.0);
|
||||
schema->AddDouble(PREF_MULTIPLIER, 1.0, 2, 0.25, 1000.0);
|
||||
return schema;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user