Drag-Drop vs. Mouse Click

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Drag-Drop vs. Mouse Click

Post by ittarter » Wed Apr 26, 2017 6:15 pm

Hello,

So I have a data grid with a vertical scrollbar. While the mousewheel easily manipulates the scrollbar without sending the MouseUp message, if a user without a mousewheel tries to drag the grid up or down to see other rows, when the mouse button is let go, a mouseup command is sent, which I only want to happen when they "click" on a row, i.e. when the mouseup and the mousedown are close together

Bottom line, what is the best way to avoid this problem? Can I easily just block the dragEnd command so that it doesn't ALSO trigger the mouseup? or do I have to record the time of the mousedown-mouseup gap and then only trigger the code when they're say within 200 milliseconds?

Thanks in advance

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Drag-Drop vs. Mouse Click

Post by dunbarx » Wed Apr 26, 2017 7:18 pm

Hi.

Standard practice is to trap the unwanted message in the control of interest. Put this in the script:

Code: Select all

on mouseUp
end mouseUp
This prevents the message from traveling out of that control.

Craig Newman

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Drag-Drop vs. Mouse Click

Post by ittarter » Thu Apr 27, 2017 7:51 am

Hi Craig, thanks for your reply.

I know about that but I still want the user to be able to select an index through mouseup and I'm not sure how to trap the long drag but not the quick "click" other than writing code to measure that the amount of time between mousedown and mouseup was under x milliseconds. I was hoping for a more elegant solution than that and to learn something in the process.

Another option is to change the selection trigger to doublemouseup, I guess, but I'd prefer to keep mouseup as the way to select a row.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Drag-Drop vs. Mouse Click

Post by dunbarx » Thu Apr 27, 2017 2:10 pm

Hi.

That is not what I meant. I intended you to place that handler, not in the group script, but in the script of the vertical scrollbar. Remember that a DG is comprised of ordinary LC controls and behaviors. You would:

Code: Select all

edit the script of scrollbar "dgscrollbar"
and then place the handler only in that control. Now the rest of the DG will respond to mouseUp messages, just not that scrollbar.

Or am I still not getting it?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Drag-Drop vs. Mouse Click

Post by dunbarx » Thu Apr 27, 2017 3:31 pm

select an index through mouseup and I'm not sure how to trap the long drag but not the quick "click" other than writing code to measure that the amount of time between mousedown and mouseup
Rereading your posts, are you saying that you want the user to be able to select a row from the scrollbar? How would you do that? There is no "marker" or other indicator, aside from which row is currently at the top or bottom of the DG itself, which would identify any particular row. And if you simply want to line up the cursor to a particular row, why not just click in the row?

Craig

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Drag-Drop vs. Mouse Click

Post by ittarter » Thu Apr 27, 2017 5:58 pm

dunbarx wrote:That is not what I meant. I intended you to place that handler, not in the group script, but in the script of the vertical scrollbar. Remember that a DG is comprised of ordinary LC controls and behaviors. You would:

Code: Select all

edit the script of scrollbar "dgscrollbar"
and then place the handler only in that control. Now the rest of the DG will respond to mouseUp messages, just not that scrollbar.
That's a great solution! I didn't know that you could isolate the scrollbar as an object with its own script.

Users still can't drag the row of indexes itself to show further indexes down the line, but that's not a big deal. Thank you so much!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Drag-Drop vs. Mouse Click

Post by dunbarx » Thu Apr 27, 2017 6:43 pm

OK. Glad to help.

Given that:
Remember that a DG is comprised of ordinary LC controls and behaviors.
try this. Make a new DG on a card. In the message box;

Code: Select all

answer the number of controls of grp 1
It should be a no-brainer to write a short handler to delineate the names and other info about each of those controls.

Craig

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Drag-Drop vs. Mouse Click

Post by ittarter » Thu Apr 27, 2017 6:52 pm

OK, good idea.

Honestly, even "edit the script of object" was a big eye-opener. Now I can finally count my total lines of code, for inappropriate bragging to non-coder friends and family. :wink: :wink:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Drag-Drop vs. Mouse Click

Post by dunbarx » Thu Apr 27, 2017 6:55 pm

Users still can't drag the row of indexes itself to show further indexes down the line,
How about (this time in the group script):

Code: Select all

 on mouseMove
   if the mouseLoc is within the rect of grp 1 and the mouse is down then set the thumbpos of scrollbar "dgScrollbar" of grp 1 to trunc(the mouseV)
end mouseMove
This needs scaling and location services, but you get the idea.

Craig

Post Reply