Click on button behind another

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
raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Click on button behind another

Post by raugert » Fri Mar 23, 2018 11:44 pm

I have a button which has another "label button" on top of it. It's transparent and simply used for labelling. I would like to run the script of the button behind that "label button" when I click on it. I tried "set disabled true" on the label button (which then allows me to click the button below it), but then the text of the label button gets grayed out.. :? Can I set something in the properties that won't gray out the text when the button is disabled ?

Maybe there's a better way and I'm taking the wrong approach ?
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Click on button behind another

Post by FourthWorld » Fri Mar 23, 2018 11:50 pm

Perhaps the cover button may not be needed. What prevents you from using the lower button's label as its label?
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: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Click on button behind another

Post by dunbarx » Sat Mar 24, 2018 12:12 am

Hi.

What Richard said, if that is feasible.

If not, there was a thread a while back wondering if a new property could be added to a control that would make it invisible to mouse actions. So "mouseUp" (or anything) would pass through it to whatever lay below, either other controls or the card itself. This never got traction.

You can, of course, script the "label button" to explicitly send, say, "mouseUp" to the underlying button, but that has to be done for each instance of these "layered" controls. It is inelegant.

I still think that property is a good idea.

Craig Newman

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Click on button behind another

Post by dunbarx » Sat Mar 24, 2018 12:20 am

Another, better kluge is to disable the upper button. Disabled controls act as if the are not there at all, and the mouse click will be trapped by any handlers in the control below.

This assumes that the disabled appearance is acceptable.

Craig

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: Click on button behind another

Post by raugert » Sat Mar 24, 2018 1:19 am

Wow thanks for the quick replies.

I was doing that at first, but then I thought it would be easier to just put some labels on top. I should mention that these labels are defined by the user. The user simply overlays labels with different font sizes, colors and positions, without having to format the actual label of a button. It gives the user a lot of customization.

See attached example of what I'm trying to do. If the user clicks the button, I would basically like to execute the lower button script even though the user clicks on the text. Some controls will actually be images. I guess I should have mentioned that..

YES, the invisible button as Craig mentioned would be great ..

Sending mouseUp to the underlying control would work fine for me. What's the best approach for that ?

edit: How could I discover a button below the label without giving it's name or ID ? Is there a command for that ?

Richard
Attachments
Overlayed Buttons.livecode.zip
(3.74 KiB) Downloaded 149 times
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Click on button behind another

Post by FourthWorld » Sat Mar 24, 2018 3:22 am

Maybe I'm a bit slow, but I'm still not following: if you have things set up so that the user can adjust the label of the cover button, why not do that for the button you want?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Click on button behind another

Post by bogs » Sat Mar 24, 2018 5:44 am

Richard makes a good point, it would be easier all round to use the label on the button itself. Craig's first post would be my suggestion, using send mouseUp (or whatever event handler you want from the labels script). You already mentioned the disabled look doesn't work for you, so I'll skip over that one.
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Click on button behind another

Post by dunbarx » Sat Mar 24, 2018 3:45 pm

@Richard Gaskin..

If the OP is placing other fancy controls, like images, over the working button, then just setting a button label property is not going to cut it.

@ Richard OP...

I hope you understand what (the other) Richard means, that the label property of a button is different from its name property, and that the name appears on a button only if no label is set.

But then why have an underlying button at all? If you are going to take the tack to send a message from the user modified control, you can just send that message to the card script. In other words, whatever handler would have been in any particular underlying button can be placed in a general handler in the card script. So all your user-modified controls can just pass, say, "mouseUp". The card script will know the target, and can execute the appropriate code (pseudo):

Code: Select all

on mouseUp
  put the short name of the target into whichControlClicked
  switch whichControlClicked
    case label1
      do label1Stuff
      break
    case label2
      do label2Stuff
      ...
The advantages here are that the locs of the label control do not matter, that is, they need not overlie another control particularly, and that all modification can take place in a single location.

Or do I not have this right?

Craig

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: Click on button behind another

Post by raugert » Sat Mar 24, 2018 5:00 pm

Sorry for the late reply. Bogs is correct in that it is much easier to use mouseUp handler from the label script. I managed to get that working by using the "intersect' command to find the button below the label. I loop through a datagrid which contains a list of all the buttons. (I use this datagrid which also contains additional info for sending commands to a socket later on, so it already exists)

Now I have other bugs where it won't Add data to a Datagrid in the standalone. It works fine in the suspended IDE mode but not in standalone :? That's usually pretty easy but something is going on ?? Sorry I shouldn't put that in this thread..

Thanks for the usual awesome help and discussions... I really appreciate all the feedback.

Code: Select all

on mouseUp

        lock screen
      repeat with i = 1 to the dgNumberOfLines of group "Datagrid"
         put the dgDataOfLine[i] of group "Datagrid" into theDataA
         if theDataA["Type"]="button" and intersect(button ID theDataA["ID"], me) then 
            send mouseUp to button ID theDataA["ID"]
         end if
         lock screen
      end repeat
   end mouseUp
Richard
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”