Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

124 Can't change default value to Slider after it has been created. #125

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/DoubleSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
30 changes: 26 additions & 4 deletions src/Slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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)
Expand Down Expand Up @@ -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)}`;

Expand Down
34 changes: 32 additions & 2 deletions src/SliderBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Loading