How to mimic a menu behaviour ?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Jacques Hausser
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9
Joined: Fri Nov 17, 2006 9:48 am

How to mimic a menu behaviour ?

Post by Jacques Hausser » Tue Dec 03, 2013 4:50 pm

When using a menu (e.g. combo box or option), you can press the mouse on the button part, what shows the menu field, and then slide over the menu, with the mouse still down. The lines under the mouse are hilited in succession, and when you release the mouse, the text of the selected line is put on the label field.
I want to mimic this behaviour, but I do not find how to do it: when I start to move the "downed" mouse, a "dragStart" message is sent (I tried to catch it, no success), after which LC seems to be absolutely deaf until the mouse is released.
Any hint ? Thank you !

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to mimic a menu behaviour ?

Post by FourthWorld » Tue Dec 03, 2013 5:39 pm

To set the value of an option control you can set its menuHistory property.

If you also want to emulate the behavior with popping it up and highlighting items as it traverses the list, I don't know of a solution for that beyond perhaps some of the specialized user action recording tools tools like Eggplant.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: How to mimic a menu behaviour ?

Post by dunbarx » Tue Dec 03, 2013 5:57 pm

Hi.

When you say you want to "mimic this behavior", what do you mean? Using other objects like fields? The menu style buttons in LC already give this functionality. Please write back. I did play for a minute with one part of your query, which was that you could not trap a message with the mouse down while it was being dragged. There are ways to do this, say, with a field, using, say, the "mouseMove" message, and tracking the mouseLoc in relation to the contents of that field. Another more crude method, using a locked list field with this in the field script:

Code: Select all

on mousestillDown
   put the mouseText
end mousestillDown
Put a little data in that field and you will see the text in msg as you click and drag. Any of this sort of fooling around can be exploited to create a gadget to your liking. But, again, what sort of gadget did you want?

Craig Newman

Jacques Hausser
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9
Joined: Fri Nov 17, 2006 9:48 am

Re: How to mimic a menu behaviour ?

Post by Jacques Hausser » Tue Dec 03, 2013 7:26 pm

Thank you Richard and Craig.

@ Craig: Well, I want to do something working like a combo box, but with a different layout (e.g., with the button at the left side of a hidden list field and a "Label field" located somewhere else). So I grouped a button, a "Label field" and a list field together. When I press the mouse down (without clicking) in the button, the list field pops up, and I want to move the mouse (still down) over the field and hilite the (successive) line(s) under the mouse; then the release of the mouse should transfert the text of the hilited line to the "Label field" and finally hide the list field.

But as I told, after the message "dragStart" is sent, I cannot trigger any action anywhere BEFORE releasing the mouse (including using mouseMove or mouseStillDown). Only after the mouse is released are "mouseRelease", "mouseLeave" and "mouseEnter" sent, and I have to press the mouse again to select a line.

Richard doesn't see a solution except outside LiveCode and I'm afraid he is right, and I have to be satisfied with a "mouseUp - mouseDown" to select the choosen line...

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

Re: How to mimic a menu behaviour ?

Post by dunbarx » Tue Dec 03, 2013 8:25 pm

Still not getting this.

If the mouseStillDown message will show you where you are and what you are doing as you drag around, what action do you want (besides mouseUp, which is what I would have thought was the right move) to terminate the process and select the line that was hovered over?

But in any case, make a locked list field and name it "hidden". Set its textHeight to, say, 14. Put several lines of text into it. Make another field somewhere else on the card. Put this into the card script:

Code: Select all

on mousestillDown
   if the mouseLoc is within the rect of fld "hidden" then 
      put the top of fld "hidden" into tTop
      put the textheight of fld "hidden" into tHeight
      put "Line" && round((item 2 of the mouseLoc - tTop) / tHeight)  && ":" && line round((item 2 of the mouseLoc - tTop) / tHeight) of fld "hidden" into fld 2
   end if
end mousestillDown
Works fine even if the field is hidden. Isn't this enough information to make what you need? In fact, releasing the mouse makes no difference, really, though it seems to. What am I missing?

Craig

Jacques Hausser
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9
Joined: Fri Nov 17, 2006 9:48 am

Re: How to mimic a menu behaviour ?

Post by Jacques Hausser » Tue Dec 03, 2013 9:55 pm

@Craig
Yes, your script works if I press the mouseDown outside any control. But I want to press the mouse down IN A BUTTON, and then move over the field without releasing it. And in this case, it doesn't work. It's the situation I described previously (DragStart locking everything until the mouse is released).

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

Re: How to mimic a menu behaviour ?

Post by dunbarx » Tue Dec 03, 2013 10:29 pm

OK.

Add a button to the mix. Put this into its script:

Code: Select all

on mouseDown
   checkFieldStuff
end mouseDown
in the card script:

Code: Select all

on checkFieldStuff
   if the mouseLoc is within the rect of fld "hidden" and the mouse is down then 
      put the top of fld "hidden" into tTop
      put the textheight of fld "hidden" into tHeight
      put "Line" && round((item 2 of the mouseLoc - tTop) / tHeight)  && ":" && line round((item 2 of the mouseLoc - tTop) / tHeight) of fld "hidden" into fld 2
   else if the mouse is down then --in case the mouseLoc is out of the field rect but still down
      send "checkFieldStuff" to this card in 1
   else --mouse is up
      exit to top
   end if
   send "checkFieldStuff" to this card in 1
end checkFieldStuff
Craig

Jacques Hausser
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9
Joined: Fri Nov 17, 2006 9:48 am

Re: How to mimic a menu behaviour ?

Post by Jacques Hausser » Tue Dec 03, 2013 11:28 pm

@ Craig. Yesss ! It's the good track ! Many thanks !

Jacques

Jacques Hausser
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9
Joined: Fri Nov 17, 2006 9:48 am

Re: How to mimic a menu behaviour ?

Post by Jacques Hausser » Sun Dec 08, 2013 12:32 pm

At least my "pseudo-combo" is working as expected. Still very coarse (overuse of lazy script locals), but easy to improve and complete (I have several ideas: autocomplete typing, setProp - getProp functions to set the default "label" or to set and get the list, and so on). The layout can be different from the standart combo-box one (e.g, button to the left).
Tey are 3 grouped controls: a button "BCombo", a field "FLabel" and a scrolling list field "FChoice" (autoHilite on, listBehavior on). All the code is at the group level, so it can be easily transfered into a behaviour button.
Still many thanks to Craig !

Code: Select all

Local LLine,LTime,LTop,LBottom,LTHeight,LFHeight

on mouseDown
   put the short name of the target into tTarget
   switch tTarget
      case "BCombo"
         show fld "FChoice"
         put the top of fld "FChoice" into LTop
         put the bottom of fld "FChoice" into LBottom
         put the effective textHeight of fld "FChoice" into LTHeight
         put the formattedHeight of fld "FChoice" into LFHeight
         select line 1 of fld "FChoice"
         put the milliseconds into LTime
         break
      case "FChoice"
         put the selectedText into LLine
         break
      default
         pass mouseDown
   end switch
end mouseDown

on mouseUp
   put the short name of the target into tTarget
   switch tTarget
      case "BCombo"
         if the milliseconds - LTime > 250 then
            hide fld "FChoice"
         end if
         break
      case "FChoice"
         put LLine into fld "FLabel"
         hide fld "FChoice"
         break
      default
         pass mouseUp
   end switch
end mouseUp

on mouseLeave
   if the short name of the target = "FChoice" then
      hide fld "FChoice"
   else
      pass mouseLeave
   end if
end mouseLeave

on dragStart
   if the short name of the target = "BCombo" then
      checkFChoice
   else
      pass dragStart
   end if
end dragStart

command checkFChoice
   if the mouseloc is within the rect of fld "FChoice" then
      if the mouse is down then
         checkFScroll
         put trunc((item 2 of the mouseloc - LTop)/LTHeight)+1 into tLine
         if tLine > 0 and tLine <= (LFHeight - LTHeight) then
            put tLine + round (the vScroll of fld "FChoice"/LTHeight) into tLine
            put the vScroll of fld "FChoice"
            select line tLine of fld "FCHoice"
            put the text of line tLine of fld "FChoice" into LLine
         end if
      else
         put LLine into fld "FLabel"
         hide fld "FChoice"
         exit to top
      end if
   end if
   send "checkFChoice" to me in 1 milliseconds
end checkFChoice

command checkFScroll
   put the vScroll of fld "FChoice" into vs
   if item 2 of the mouseLoc < LTop + round(LTHeight/2) and vs > 0 then
      set the vScroll of fld "FChoice" to max (0,vs - LTHeight)
   else
      if item 2 of the mouseLoc > LBottom - round(LTHeight/2) and vs < LFHeight - LTHeight then
         set the vScroll of fld "FChoice" to max (LFHeight - LTHeight,vs + LTHeight)
      end if
   end if
end checkFScroll

Post Reply