Originally posted by **ben-cottrell-nz** May 24, 2023
Within a component, I would like to get the mouse position always, not just when dragging. In the below snippet, I only see cursor position when clicking and moving.
```
export component TanksGameView inherits Window {
width: 1024px;
height: 768px;
forward-focus: player-key-handler;
touchArea := TouchArea {
width: parent.width;
height: parent.height;
moved => {
debug(touchArea.mouse-x / 1px + "," + touchArea.mouse-y / 1px)
}
}
}
```
Has there been any progress on this? I am also in need of this feature and it doesn't seem very complicated to add as the moved callback already exists.
@MahitMehta: I took the liberty to create a PR for this. Is that something that works for you? Any testing would be welcome.
@hunger Wow, thank you so much! This is perfect, I just cloned your branch, and it works flawlessly for my needs. However, would making these changes remove the functionality to detect mouse-dragging events (the current functionality)?
Yes, this is a incompatibility. @ogoffart also pointed that out in review.
We could add a new callback, maybe even providing button information and modifiers pressed? So that people can easily implement shift-control-middle-mouse-button drags... but that might just be overdoing it.
Would you need more complex drag operations? My impression is that UIs even on the desktop are heavily inspired by phone UIs these days, so maybe it is a good thing to not expose all those knobs to UI designers anymore? It will at least push towards more finger-friendly UIs that way.
I was also thinking of making a separate callback to retain the current functionality. However, I agree that it may be unnecessary and even better not to expose too many "knobs". For my purposes, I just need the mouse move events, so the behavior change is fine by me.
Discussed in https://github.com/slint-ui/slint/discussions/2769
Hey,
it should be possible without pressed. This code snippet works for me:
Documentation: https://slint-ui.com/releases/1.0.2/docs/slint/src/builtins/elements.html#id23
I think the issue is then that the
moved
callback is only called when the cursor is pressed.We could change that to be called all the time. I wonder if that would be a breaking change.
I saw a similar request for this (always invoke, not only when pressed). I think it's a good idea.
Has there been any progress on this? I am also in need of this feature and it doesn't seem very complicated to add as the moved callback already exists.
@MahitMehta: I took the liberty to create a PR for this. Is that something that works for you? Any testing would be welcome.
@hunger Wow, thank you so much! This is perfect, I just cloned your branch, and it works flawlessly for my needs. However, would making these changes remove the functionality to detect mouse-dragging events (the current functionality)?
Yes, this is a incompatibility. @ogoffart also pointed that out in review.
We could add a new callback, maybe even providing button information and modifiers pressed? So that people can easily implement shift-control-middle-mouse-button drags... but that might just be overdoing it.
Would you need more complex drag operations? My impression is that UIs even on the desktop are heavily inspired by phone UIs these days, so maybe it is a good thing to not expose all those knobs to UI designers anymore? It will at least push towards more finger-friendly UIs that way.
I was also thinking of making a separate callback to retain the current functionality. However, I agree that it may be unnecessary and even better not to expose too many "knobs". For my purposes, I just need the mouse move events, so the behavior change is fine by me.