Can LC set an objet to the top laye of a group with script? - Solved

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
DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Can LC set an objet to the top laye of a group with script? - Solved

Post by DR White » Mon May 25, 2020 11:21 am

Can LC set an objet to the top laye of a group with script?

Thanks,

David
Last edited by DR White on Mon May 25, 2020 11:52 pm, edited 1 time in total.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Can LC set an objet to the top laye of a group with script?

Post by jmburnod » Mon May 25, 2020 12:44 pm

Hi David
Yes LC can
Something like that:

Code: Select all

on setLayerControl pControl,pGroup
   put getMaxLayerInGrp(pGroup) into tTopLayerOfGrp
   set the relayerGroupedControls to true
   relayer control pControl  after control tTopLayerOfGrp
   set the relayerGroupedControls to false
end setLayerControl

function getMaxLayerInGrp pGroup
   put the num of controls of group pGroup into tNbControls
   put the short name of control tNbControls of group pGroup into rMaxLayerInGrp
   return rMaxLayerInGrp
end getMaxLayerInGrp
Best regards
Jean-Marc
https://alternatic.ch

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Can LC set an objet to the top laye of a group with script?

Post by richmond62 » Mon May 25, 2020 12:45 pm

Screenshot 2020-05-25 at 14.44.24.png
-
So . . . I would be inclined to ungroup the group, reorder the objects and then regroup them again.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Can LC set an objet to the top laye of a group with script?

Post by richmond62 » Mon May 25, 2020 1:03 pm

Screenshot 2020-05-25 at 15.01.05.png
-
2 lines of code!

Code: Select all

on mouseUp
   ungroup group "bunch"
   group img "three" and img "two" and img "one"
end mouseUp
Attachments
ReLayer.livecode.zip
Here's the stack.
(8.25 KiB) Downloaded 247 times

DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Re: Can LC set an objet to the top laye of a group with script?

Post by DR White » Mon May 25, 2020 1:53 pm

Thanks for the suggestions.

The group I am working with is in a mobile scroller with more than 40 items in the group,
witch are being inserted by the user. I need to keep my pointer on top of the newly inserted
objects. As a work around, i am currently deleting and copying the pointer after each new object is
inserted to keep the pointer on top. It works OK, but I thought the might be a better way.

Thanks both of you for your help,

David

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Can LC set an objet to the top laye of a group with script?

Post by jmburnod » Mon May 25, 2020 3:08 pm

Hi David,
Did you try to adapt scripts i posted to your context ?
https://alternatic.ch

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

Re: Can LC set an objet to the top laye of a group with script?

Post by dunbarx » Mon May 25, 2020 3:29 pm

Richmond.

That was adorable.

David.

But is it necessary to do anything more than:

Code: Select all

set the screenMouseLoc to the loc of last control
(You have to do the usual calcs to adjust loc of the card window to screen "0,0".)

This begs whatever method you use adding the newly created control to the group. The only reason I am posting is because the original question was how to "locate" the newly added control, not how to add the control to the group. For example, you could copy the new control to the group, and then delete the original.

Fun stuff...

Craig

DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Re: Can LC set an objet to the top laye of a group with script?

Post by DR White » Mon May 25, 2020 8:51 pm

Craig,

I don't see how "set the screenMouseLoc to the loc of last control" is going to change a layer property.

Jean-Marc,

I don't understand what "getMaxLayerInGrp(pGroup)" is.

Thanks,

David

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

Re: Can LC set an objet to the top laye of a group with script?

Post by dunbarx » Mon May 25, 2020 9:48 pm

David.
I don't see how "set the screenMouseLoc to the loc of last control" is going to change a layer property.
It doesn't. I guess I misunderstand what you are trying to do.

You said you wanted to set the pointer to the loc of the most recent control, which is created by the user. My only point was one way to do that. Relayering is not required.

It is is another matter entirely to include that control in the group. If other actions create, say, other controls in other groups, then certainly managing the members of each group is important.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: Can LC set an objet to the top laye of a group with script?

Post by richmond62 » Mon May 25, 2020 9:59 pm

You could have a list field where each line contains the name of an object within a group:
new ones being added at the start of the list.

Then you could have a script that set the object in line 1 of your list to the top layer inside your group.

DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Re: Can LC set an objet to the top laye of a group with script?

Post by DR White » Mon May 25, 2020 10:06 pm

Thanks everyone for all the good suggestions, but they seem like too much work.
I think I will just keep deleting the pointer group and then coping it back after
new control is copied to keep it on top layer.

SparkOut
Posts: 2946
Joined: Sun Sep 23, 2007 4:58 pm

Re: Can LC set an objet to the top laye of a group with script?

Post by SparkOut » Mon May 25, 2020 10:42 pm

Ahem...

A closer look at RELAYER in the dictionary will show you that you can

Code: Select all

relayer <objectref> to front of group <groupref>
(or to back, to put it to the lowest layer of the group)

You can deal with nesting of groups by including "the owner" as a self-reference

Code: Select all

relay me to front of the owner of me
will set the layer to the topmost layer of the group it is in, without bleeding into any other nested groups.

A bit more discussion is here: https://forums.livecode.com/viewtopic.php?f=9&t=31153

DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Re: Can LC set an objet to the top laye of a group with script?

Post by DR White » Mon May 25, 2020 11:38 pm

SparkOut,

WOW!

The code "relayer <objectref> to front of group <groupref>" works Great!


Thanks SO MUCH,

David

Post Reply