Skip to content

Commit

Permalink
feat(ui): make color picker movable
Browse files Browse the repository at this point in the history
Signed-off-by: Mathis Mensing <[email protected]>
  • Loading branch information
matmen committed Mar 14, 2022
1 parent 4e69c21 commit 2ed0563
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/components/ui/AppColorPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@
$circle
</v-icon>
</template>
<v-card>
<v-card ref="card">
<v-card-title
v-if="title"
class="card-heading mb-2"
color="blue"
@mousedown="startDrag"
>
{{ title }}
</v-card-title>
<v-card-text>
<v-icon
:color="primaryColor.hexString"
Expand Down Expand Up @@ -154,6 +162,7 @@ export default class AppColorPicker extends Vue {
dot!: boolean
menu = false
dragging = false
primaryColor: AppColor = {
hexString: '#ffffff',
Expand Down Expand Up @@ -262,6 +271,33 @@ export default class AppColorPicker extends Vue {
debouncedChange (channel: string, color: IroColor) {
this.$emit('change', { channel, color })
}
startDrag () {
this.dragging = true
}
stopDrag () {
this.dragging = false
}
doDrag (event: MouseEvent) {
if (this.dragging) {
const parent = (this.$refs.card as Vue).$el.parentElement as HTMLElement
parent.style.left = parseInt(parent.style.left) + event.movementX + 'px'
parent.style.top = parseInt(parent.style.top) + event.movementY + 'px'
}
}
mounted () {
window.addEventListener('mousemove', this.doDrag)
window.addEventListener('mouseup', this.stopDrag)
}
beforeUnmount () {
window.removeEventListener('mousemove', this.doDrag)
window.removeEventListener('mouseup', this.stopDrag)
}
}
</script>

Expand Down
1 change: 1 addition & 0 deletions src/components/widgets/outputs/OutputLed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<app-color-picker
:primary="primaryColor"
:white="whiteColor"
:title="led.prettyName"
dot
@change="handleColorChange"
/>
Expand Down

0 comments on commit 2ed0563

Please sign in to comment.