Add multi parameter for slider and number settings
This commit is contained in:
parent
0332027963
commit
6cac091c27
|
@ -24,11 +24,7 @@ export default class ArraySetting extends Setting {
|
|||
this.args.schemes = this.schemes.map(scheme => new SettingsScheme(scheme));
|
||||
this.args.items = this.value ? this.value.map(item => this.createItem(item.args || item)) : [];
|
||||
|
||||
this._setValue(this.items.map(item => {
|
||||
if (!item) return;
|
||||
item.setSaved();
|
||||
return item.strip();
|
||||
}));
|
||||
this._setValue(this.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,12 +131,14 @@ export default class ArraySetting extends Setting {
|
|||
* @return {SettingsSet} The new set
|
||||
*/
|
||||
createItem(item) {
|
||||
if (item instanceof SettingsSet)
|
||||
return item;
|
||||
|
||||
const set = new SettingsSet({
|
||||
settings: Utils.deepclone(this.settings),
|
||||
schemes: this.schemes
|
||||
}, item ? item.args || item : undefined);
|
||||
|
||||
// if (item) set.merge(item.args || item);
|
||||
set.setSaved();
|
||||
set.on('settings-updated', () => this.updateValue());
|
||||
return set;
|
||||
|
@ -160,12 +158,21 @@ export default class ArraySetting extends Setting {
|
|||
* This only exists for use by array settings.
|
||||
* @return {Promise}
|
||||
*/
|
||||
updateValue(emit_multi = true, emit = true) {
|
||||
return this.setValue.call(this, this.items.map(item => {
|
||||
getValue() {
|
||||
return this.items.map(item => {
|
||||
if (!item) return;
|
||||
item.setSaved();
|
||||
return item.strip();
|
||||
}), emit_multi, emit);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the value of this array setting.
|
||||
* This only exists for use by array settings.
|
||||
* @return {Promise}
|
||||
*/
|
||||
updateValue(emit_multi = true, emit = true) {
|
||||
return this.setValue(this.getValue(), emit_multi, emit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,4 +12,22 @@ import Setting from './basesetting';
|
|||
|
||||
export default class NumberSetting extends Setting {
|
||||
|
||||
/**
|
||||
* The current value.
|
||||
*/
|
||||
get value() {
|
||||
return this.args.value * this.multi;
|
||||
}
|
||||
|
||||
set value(value) {
|
||||
this.setValue(value / this.multi);
|
||||
}
|
||||
|
||||
/**
|
||||
* A number to multiply the value by.
|
||||
*/
|
||||
get multi() {
|
||||
return this.args.multi || 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,17 @@ import Setting from './basesetting';
|
|||
|
||||
export default class SliderSetting extends Setting {
|
||||
|
||||
/**
|
||||
* The current value.
|
||||
*/
|
||||
get value() {
|
||||
return this.args.value * this.multi;
|
||||
}
|
||||
|
||||
set value(value) {
|
||||
this.setValue(value / this.multi);
|
||||
}
|
||||
|
||||
/**
|
||||
* The value to use when the setting doesn't have a value.
|
||||
*/
|
||||
|
@ -47,6 +58,13 @@ export default class SliderSetting extends Setting {
|
|||
return this.args.unit || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* A number to multiply the value by.
|
||||
*/
|
||||
get multi() {
|
||||
return this.args.multi || 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object mapping points on the slider to labels.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue