diff --git a/src/DoubleSlider.ts b/src/DoubleSlider.ts index c663dab8..0f3b2138 100644 --- a/src/DoubleSlider.ts +++ b/src/DoubleSlider.ts @@ -222,6 +222,8 @@ export class DoubleSlider extends SliderBase protected updateSlider1() { + this.updateProgress(this.value1, this.value2); + this._slider1.x = (this.bg?.width / 100 * this.progressStart) - (this._slider1.width / 2); this._slider1.y = this.bg?.height / 2; @@ -244,6 +246,8 @@ export class DoubleSlider extends SliderBase protected updateSlider2() { + this.updateProgress(this.value1, this.value2); + this._slider2.x = ((this.bg?.width / 100) * this.progress) - (this._slider2.width / 2); this._slider2.y = this.bg?.height / 2; diff --git a/src/Slider.ts b/src/Slider.ts index 472d7618..ee5ce5a2 100644 --- a/src/Slider.ts +++ b/src/Slider.ts @@ -45,10 +45,8 @@ export class Slider extends SliderBase }); this.sliderOptions = options; - - this.progress = ((options.value ?? this.min) - this.min) / (this.max - this.min) * 100; - this.value = options.value ?? this.min; + this.updateSlider(); } /** Return selected value. */ @@ -72,6 +70,28 @@ export class Slider extends SliderBase this.onUpdate?.emit(this.value); } + override set max(value: number) + { + super.max = value; + this.updateSlider(); + } + + override get max(): number + { + return super.max; + } + + override set min(value: number) + { + super.min = value; + this.updateSlider(); + } + + override get min(): number + { + return super.min; + } + /** Set slider instance ot texture. */ // eslint-disable-next-line accessor-pairs set slider(value: Container | string) @@ -100,10 +120,12 @@ export class Slider extends SliderBase protected updateSlider() { + this.progress = ((this.value ?? this.min) - this.min) / (this.max - this.min) * 100; + this._slider1.x = ((this.bg?.width / 100) * this.progress) - (this._slider1.width / 2); this._slider1.y = this.bg?.height / 2; - if (this.sliderOptions.showValue) + if (this.sliderOptions?.showValue) { this.value1Text.text = `${Math.round(this.value)}`; diff --git a/src/SliderBase.ts b/src/SliderBase.ts index 03ce71e6..6d305d48 100644 --- a/src/SliderBase.ts +++ b/src/SliderBase.ts @@ -40,10 +40,10 @@ export class SliderBase extends ProgressBar protected dragging = 0; /** Minimal value. */ - min = 0; + protected _min = 0; /** Maximal value. */ - max = 100; + protected _max = 100; protected startX!: number; protected startUpdateValue1!: number; @@ -222,4 +222,34 @@ export class SliderBase extends ProgressBar { // override me } + + /** + * Set max value. + * @param value + */ + set max(value: number) + { + this._max = value; + } + + /** Get max value. */ + get max(): number + { + return this._max; + } + + /** + * Set min value. + * @param value + */ + set min(value: number) + { + this._min = value; + } + + /** Get min value. */ + get min(): number + { + return this._min; + } }