Skip to content

Commit

Permalink
made 'click-event' handling consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianStremel committed Sep 22, 2024
1 parent 7648ef5 commit e6ddd9c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 2 additions & 3 deletions nodes/widgets/ui_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module.exports = function (RED) {
let payload = null
let payloadType = null

msg._event = msg._event || {"type": "inject"}
msg._event = msg._event || { type: 'inject' }

switch (msg._event.type) {
case 'pointerup':
payload = config.pointerupPayload
Expand Down Expand Up @@ -111,7 +111,6 @@ module.exports = function (RED) {
beforeSend,
onInput: async function (msg) {
if (config.emulateClick) {

msg = await beforeSend(msg)

if (config.topic || config.topicType) {
Expand Down
19 changes: 19 additions & 0 deletions ui/src/widgets/ui-button/UIButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@click="action"
@pointerdown="pointerdown"
@pointerup="pointerup"
@pointermove="checkIsPointerOverButton"
>
<template v-if="prependIcon" #prepend>
<v-icon :color="iconColor" />
Expand All @@ -28,6 +29,11 @@ export default {
props: { type: Object, default: () => ({}) },
state: { type: Object, default: () => ({}) }
},
data () {
return {
isPointerOverButton: true // Tracks if the pointer is still over the button
}
},
computed: {
...mapState('data', ['messages']),
prependIcon () {
Expand Down Expand Up @@ -64,6 +70,9 @@ export default {
},
methods: {
action ($evt) {
if (!this.isPointerOverButton) {
return
}
const evt = {
type: $evt.type,
clientX: $evt.clientX,
Expand Down Expand Up @@ -104,6 +113,16 @@ export default {
$evt.target.releasePointerCapture($evt.pointerId)
this.$socket.emit('widget-action', this.id, msg)
},
checkIsPointerOverButton: function ($evt) {
// Check if pointer is still over the button
const buttonRect = $evt.target.getBoundingClientRect()
this.isPointerOverButton = (
$evt.clientX >= buttonRect.left &&
$evt.clientX <= buttonRect.right &&
$evt.clientY >= buttonRect.top &&
$evt.clientY <= buttonRect.bottom
)
},
makeMdiIcon (icon) {
return 'mdi-' + icon.replace(/^mdi-/, '')
Expand Down

0 comments on commit e6ddd9c

Please sign in to comment.