Skip to content
Open
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
48 changes: 44 additions & 4 deletions src/components/CircleSlider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@ import CircleSliderState from '../modules/circle_slider_state.js'
export default {
name: 'CircleSlider',
created () {
this.stepsCount = 1 + (this.max - this.min) / this.stepSize
this.currentMin = this.min;
this.currentMax = this.max;
if(this.infinite) {
this.currentMin = this.value - 5;
this.currentMax = this.value + 5;
}

this.stepsCount = 1 + (this.currentMax - this.currentMin) / this.stepSize
this.steps = Array.from({
length: this.stepsCount
}, (_, i) => this.min + i * this.stepSize)
}, (_, i) => this.currentMin + i * this.stepSize)

this.circleSliderState = new CircleSliderState(this.steps, this.startAngleOffset, this.value)
this.angle = this.circleSliderState.angleValue
this.currentStepValue = this.circleSliderState.currentStep

this.lastStepValue = this.currentStepValue;
this.infiniteValue = this.currentStepValue;

let maxCurveWidth = Math.max(this.cpMainCircleStrokeWidth, this.cpPathStrokeWidth)
this.radius = (this.side / 2) - Math.max(maxCurveWidth, this.cpKnobRadius * 2) / 2
this.updateFromPropValue(this.value)
Expand Down Expand Up @@ -114,6 +124,10 @@ export default {
type: Number,
required: false,
default: 10
},
infinite: {
type: Boolean,
default: false,
}
// limitMin: {
// type: Number,
Expand All @@ -135,7 +149,12 @@ export default {
currentStepValue: 0,
mousePressed: false,
circleSliderState: null,
mousemoveTicks: 0
mousemoveTicks: 0,
currentMin: this.min,
currentMax: this.max,
canChangeLimit: true,
lastStepValue: 0,
infiniteValue: 0,
}
},
computed: {
Expand Down Expand Up @@ -275,7 +294,7 @@ export default {
*/
updateSlider () {
const angle = this.touchPosition.sliderAngle
if (Math.abs(angle - this.angle) < Math.PI) {
if (Math.abs(angle - this.angle) < Math.PI || this.infinite) {
this.updateAngle(angle)
}
},
Expand All @@ -302,6 +321,27 @@ export default {
watch: {
value (val) {
this.updateFromPropValue(val)
},
currentStepValue(val) { // Check current step against last step to determine is user is advancing or reverting the slider
if(val !== this.lastStepValue && this.infinite) {
if(val > this.lastStepValue) {
if(val === this.currentMax && this.lastStepValue === this.currentMin) { // user reverted
if(this.infiniteValue > this.min)
this.infiniteValue -= this.stepSize;
} else {
this.infiniteValue += this.stepSize;
}
} else if (val < this.lastStepValue) {
if(val === this.currentMin && this.lastStepValue === this.currentMax) { // user advanced
this.infiniteValue += this.stepSize;
} else {
if(this.infiniteValue > this.min)
this.infiniteValue -= this.stepSize;
}
}
this.$emit('infiniteValue', this.infiniteValue);
this.lastStepValue = val;
}
}
}
}
Expand Down