I am trying to achieve a drag and drop feature. The layout of my UI looks similar to below:
--- --- ---
| 1 | 2 | |
--- --- 5 |
| 3 | 4 | |
--- --- ---
Boxes 1, 2, 3 and 4 are images and will have a white border surrounding it when selected by a user. This selection action is executed with a left press
.
Box 5 displays some basic information of the selected image.
The images in Boxes 1, 2, 3 and 4 can be dragged and dropped into Box 5. On a successful dropped, a thumbnail of the dropped image will also be displayed in Box 5.
I have no issues executing a drag and drop action which is achieved using RxPy
. My code for the drag and drop looks as follows:
drag_start = self.viewer.events \
.filter(lambda ev: ev.type == MouseEventType.LeftPress)
drag_move = self.viewer.events \
.filter(lambda ev: ev.type == MouseEventType.MouseMove)
drag = drag_start \
.flat_map(lambda ev: \
drag_move \
.first()
)
drag.subscribe(lambda ev: self.start_drag())
# and yes, i do not have a takeUntil mouse release event in my stream. this is done intentionally.
i have a thumbnail implemented in start_drag
that follows wherever the cursor moves. i have left this part of the code out since it is not the highlight of the problem i am facing.
The problem i have is this. If I were to select an image, and no matter how much later I do a mouse move
, start_drag
will be fired and creates the thumbnail. if the mouse move
event occurs after a certain time frame since the last left press
, it should not be viewed as a drag event and not fire start_drag
. Instead, an 'instant' left press
+ mouse move
event will be seen as a drag event
what should be added to my event stream such that i will be able to determine the duration between the left press
and mouse move
events? subsequently, if this duration is more than the time frame, i will ignore and not fire start_drag
. or is there a better solution to this problem?
delay
, debounce
basically either pushes or delays the stream and i cannot achieve what i want with those operators.