Skip to content

Commit

Permalink
fix: 🐛 spawn colour picker at pointer location (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
webfiltered authored Dec 15, 2024
1 parent 62469a4 commit e5482ae
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions web/mtb_widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,21 +536,34 @@ export const MtbWidgets = {
picker.type = 'color'
picker.value = this.value

picker.style.position = 'absolute'
picker.style.left = '999999px' //(window.innerWidth / 2) + "px";
picker.style.top = '999999px' //(window.innerHeight / 2) + "px";

document.body.appendChild(picker)
Object.assign(picker.style, {
position: "fixed",
left: `${e.clientX}px`,
top: `${e.clientY}px`,
height: "0px",
width: "0px",
padding: "0px",
opacity: 0,
})

picker.addEventListener('change', () => {
this.value = picker.value
picker.addEventListener("blur", () => {
this.callback?.(this.value)
node.graph._version++
node.setDirtyCanvas(true, true)
picker.remove()
})
picker.addEventListener("input", () => {
if (!picker.value) return

this.value = picker.value
app.canvas.setDirty(true)
})

document.body.appendChild(picker)

picker.click()
requestAnimationFrame(() => {
picker.showPicker()
picker.focus()
})
}
}
}
Expand Down

0 comments on commit e5482ae

Please sign in to comment.