Skip to content

Commit d2337e1

Browse files
committed
refactor: ♻️ Sync knob display with external angle/value
1 parent 592c312 commit d2337e1

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/components/rotary-knob/continuous-rotary-knob.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,15 @@ export class ContinuousRotaryKnob {
139139
return this.dom_;
140140
}
141141

142+
/**
143+
* Sync the knob display to match an externally-set angle.
144+
* Does NOT trigger callback - this is for updating the visual
145+
* to match state that was set elsewhere.
146+
*/
142147
sync(newAngle: number): void {
143-
this.setAngle_(newAngle);
148+
this.angle = newAngle;
149+
this.totalRotations = Math.floor(this.angle / 360);
150+
this.updateDisplay();
144151
}
145152

146153
static create(

src/components/rotary-knob/rotary-knob.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,22 @@ export class RotaryKnob {
148148
return this.dom_;
149149
}
150150

151+
/**
152+
* Sync the knob display to match an externally-set value.
153+
* Does NOT trigger callback or sounds - this is for updating the visual
154+
* to match state that was set elsewhere.
155+
*/
151156
sync(newValue: number): void {
152-
this.setValue_(newValue);
157+
// Clamp to valid range
158+
newValue = Math.max(this.min, Math.min(this.max, newValue));
159+
160+
// Round to 3 decimal places to avoid floating point issues
161+
newValue = Number(newValue.toFixed(3));
162+
163+
// Update internal value and display without callback
164+
this.value = newValue;
165+
this.updateAngleFromValue_();
166+
this.updateDisplay();
153167
}
154168

155169
static create(

0 commit comments

Comments
 (0)