Page 1 of 2

how to make a whole group into a target

Posted: Thu Jan 10, 2019 12:02 am
by kaveh1000
I have a group with several different controls. I want to make the whole rectangle into a target, so clicking anywhere will send a message to the group. I can't find a way of doing that except to put a button as a backdrop. But that has other complications.

Any way of ensuring the whole area of a group is clickable?

Re: how to make a whole group into a target

Posted: Thu Jan 10, 2019 4:11 am
by dunbarx
Hi.

I suspect there is a more straightForward way to do what you want, but you can always use native LiveCode behavior. In the card script:

Code: Select all

on mouseUp
  if the clickLoc is within the rect of grp "yourRecalcitrantGroup" then answer random(99)
end mouseUp
Craig Newman

Re: how to make a whole group into a target

Posted: Thu Jan 10, 2019 5:18 am
by trevordevore
@Kaveh - A group won't receive mouse event messages. You would need to add a transparent button or graphic in order for clicks to to send message like mouseUp. While not ideal, this approach does allow you to put your mouseUp/mouseDown/whatever message in the group script.

Re: how to make a whole group into a target

Posted: Thu Jan 10, 2019 8:00 am
by kaveh1000
Thanks Craig and Trevor

I ended up putting a transparent button behind the other controls. That way mouse messages can be sent directly to each control in the field, but then trapped by the back button if not caught by others.

What would the advantage be to having the transparent button in front?

Re: how to make a whole group into a target

Posted: Thu Jan 10, 2019 10:43 am
by Klaus
kaveh1000 wrote:
Thu Jan 10, 2019 8:00 am
What would the advantage be to having the transparent button in front?
That would eat up ALL mouse-events, and gladly noone proposed this so far! 8)

Re: how to make a whole group into a target

Posted: Thu Jan 10, 2019 10:48 am
by kaveh1000
Ah, I should read posts more carefully. I thought Trevor was suggesting a button on top. My error and my confusion. Thanks all. :-)

Re: how to make a whole group into a target

Posted: Thu Jan 10, 2019 9:01 pm
by dunbarx
Many ways to do this. Know that if you move the group you also have to move the button, unless you have placed that button within the group itself. It was not clear to me that you had done so.

There was a thread a while back wondering if the empty space within the rect of a group might be allowed to react to a mouse click. This is exactly what you are talking about here.

Craig

Re: how to make a whole group into a target

Posted: Thu Jan 10, 2019 9:09 pm
by kaveh1000
Hi Craig

Indeed I put the button inside the group. I am hiding and showing different elements of the group so the size changes. I have put several sizes in the custom properties of the button, so just call those as needed. Looking ok.

I think an option to have a "backdrop" to a group would make logical sense.

Regards
Kaveh

Re: how to make a whole group into a target

Posted: Thu Jan 10, 2019 9:22 pm
by dunbarx
What would the advantage be to having the transparent button in front?
What Klaus said.

The kluge to fix that, since such a button would indeed intercept all messages, would be to:

Code: Select all

on mouseUp
  send "mouseUp" to grp "yourUnderLyingGroup"
But we want to minimize kluges if possible, though sometimes they allow us to have it our way.

Do you like that way better than the card script handler I proposed? I only ask because they are both kluges. In one, the card reacts to a mouse click, and checks the rect of the group, and in the other, the button reacts; they both, you might say, underlie the group, and trap those messages that pass right through.

I think a group, which is natively invisible (apart from its child controls), ought to be able to be merely transparent.

Craig

Re: how to make a whole group into a target

Posted: Fri Jan 11, 2019 9:29 am
by kaveh1000
Hi Craig. It's great there are so many ways to fix things in LiveCode. I do like your method. For the moment the "backdrop" seems to be working ok...

Re: how to make a whole group into a target

Posted: Thu Apr 01, 2021 5:43 pm
by Fermin
I don't know if it has to do exactly with this topic but:
In an app I'm making to create calendars I have a group containing 42 boxes (graphic objects). In the script of the group:

on mouseup
answer me & cr & the target
end mouseup
---
The result when clicking anywhere in the group is:

group "esp_b01GrupoParri"
graphic "cas_b01f24"

The name of the graphic depends on which box I have clicked on.

Re: how to make a whole group into a target

Posted: Thu Apr 01, 2021 7:14 pm
by dunbarx
Hi.

Not exactly sure what the question is, but when you ask for "me" you are asking for the contents of a control, This could be the text of a field, or even a button. But a graphic is not a container, and you will not get much asking for what it, er, contains.

With that line of code, when you click on a graphic, you will get its owner and its name. If the graphic was not owned by a group, you would get the card and its name.

So the question is this: what do you really want LC to send back to you when you click on a graphic?

Craig

Re: how to make a whole group into a target

Posted: Thu Apr 01, 2021 8:09 pm
by Fermin
Well, it wasn't really a question. What happened is that I had read above:
A group won't receive mouse event messages. You would need to add a transparent button, etc...

and I only meant to comment that, in my experience, a group can receive messages... But I guess the subject of the post is a bit more complex and I didn't quite understand it. Anyway thanks, Craig, for your explanation. :)

Re: how to make a whole group into a target

Posted: Thu Apr 01, 2021 8:42 pm
by dunbarx
OK, I see.

It is important to know, I guess, that a group is only a group on paper; it is not an object in its own right. That is, empty space in a group is just that, empty space.

This is slightly odd because a group has an "opaque" property, and you can color that empty space as you like. But any colored empty area still does not quite seem to exist.

But even a load of empty space still has a rect. So I still think that the idea of checking to see if the clickLoc is within that rect is a nice kludge.

Craig

Re: how to make a whole group into a target

Posted: Fri Apr 02, 2021 5:58 pm
by jacque
dunbarx wrote:
Thu Apr 01, 2021 7:14 pm
when you ask for "me" you are asking for the contents of a control, This could be the text of a field, or even a button.
Almost. "Me " refers to the control whose script is referring to "me". It doesn't deal with the contents of that control, just its identity.