Skip to content

Commit

Permalink
Delete onwheel, use dispatchEvent for continuous changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih-erikli committed Dec 22, 2023
1 parent 06efd31 commit 128004b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
8 changes: 0 additions & 8 deletions src/fontra/client/web-components/rotary-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ export class RotaryControl extends html.UnlitElement {
return html.div({ class: "rotary-control" }, [
(this.knob = html.div(
{
onwheel: (event) => {
const delta =
Math.abs(event.deltaX) > Math.abs(event.deltaY)
? -1 * event.deltaX
: event.deltaY;
this.value = this.value + delta;
this.dispatch();
},
class: "knob",
style: `transform: rotate(${this.value}deg);`,
onmousedown: (event) => {
Expand Down
21 changes: 17 additions & 4 deletions src/fontra/client/web-components/ui-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SimpleElement } from "../core/html-utils.js";
import { QueueIterator } from "../core/queue-iterator.js";
import { hyphenatedToCamelCase } from "../core/utils.js";
import { RangeSlider } from "/web-components/range-slider.js";
import { RotaryControl } from "/web-components/rotary-control.js";
import "/web-components/rotary-control.js";

export class Form extends SimpleElement {
static styles = `
Expand Down Expand Up @@ -200,14 +200,27 @@ export class Form extends SimpleElement {
this._fieldChanging(fieldItem.key, value);
rotaryControl.value = value;
};

let valueStream;
const rotaryControl = html.createDomElement("rotary-control", {
value: fieldItem.value,
onChangeCallback: (event) => {
const value = event.value * -1;
inputElement.value = value;
this._fieldChanging(fieldItem.key, value);
console.log(event);
if (event.dragBegin) {
valueStream = new QueueIterator(5, true);
this._fieldChanging(fieldItem.key, value, valueStream);
}
if (valueStream) {
valueStream.put(value);
this._dispatchEvent("doChange", { key: fieldItem.key, value: value });
if (event.dragEnd) {
valueStream.done();
valueStream = undefined;
this._dispatchEvent("endChange", { key: fieldItem.key });
}
} else {
this._fieldChanging(fieldItem.key, value, undefined);
}
},
});

Expand Down

0 comments on commit 128004b

Please sign in to comment.