Move object forward/backward

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

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Move object forward/backward

Post by CAsba » Mon Oct 17, 2022 3:58 pm

Hi all,
I have a column of buttons laid out neatrly on a rectangle, whos laid-out size is limited. I have more buttons to display than there is room for. So, I labelled the last button 'More', so the user can access more buttons. I have placed the cannot-be-accommodated buttons, each one, behind one of the displayed buttons, and I have been trying to write an 'on mouse up' command that will bring forward the backlying buttons. I see that there is a menu option in the inspector, object>move forward, and I have been trying to invoke this in my 'More' button code - with a notable lack of success ! Would anyone help me on this ?
Please ?

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Move object forward/backward

Post by Klaus » Mon Oct 17, 2022 4:20 pm

Hi CAsba,

that "menu option" is in the PROJECT Browser, not in the inspector and it will only affect the LAYER of an object,
so this may not be the way to go.

I would do it like this:
1. Create two or more groups of buttons and show/hide them
OR
2. Arrange ALL of your buttons as you need like
XX XX XX
XX XX XX
XX XX XX
...
XX XX XX
and then GROUP all these buttons, resize the group to your needs and just show its scrollbar.
OR
3. Just create a group from your cannot-be-accommodated buttons and only show/hide that accordingly.
Almost identical to you initial idea, but easier since we only have to deal with ONE object, the group of buttons.

Best

Klaus

P.S.
The correct name of the handler is -> on mouseup (mouseup = ONE word!)

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

Re: Move object forward/backward

Post by richmond62 » Mon Oct 17, 2022 4:28 pm

Personally I'd have 2 sets of buttons in 2 groups so you could
set the LAYER of each group of buttons when you needed them.
-
Screen Shot 2022-10-17 at 6.30.19 PM.png
Attachments
Layer-Cake.livecode.zip
Stack.
(1.12 KiB) Downloaded 132 times

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

Re: Move object forward/backward

Post by dunbarx » Mon Oct 17, 2022 5:57 pm

You must definitely use multiple groups. That is what they are for.

And all you need to do is something like:

Code: Select all

om mouseUp
   if the visible of group "ButtonGroupOne" is"true" then
    set the visible of group "ButtonGroupOne" to "false"
    set the visible of group "ButtonGroupOTwo" to "true"
  else
    set the visible of group "ButtonGroupOne" to "true"
    set the visible of group "ButtonGroupOTwo" to "false"
  end if
Craig

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

Re: Move object forward/backward

Post by dunbarx » Mon Oct 17, 2022 5:58 pm

It occurred to me that you might have more that two such groups. Can you handle (no pun intended) more?

Craig

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Move object forward/backward

Post by CAsba » Tue Oct 18, 2022 10:12 am

Hi Klaus,
Thanks for your reply.
I don't know how to make a group. I read up on it and it said to select objects then put them in a group. I don't know how to select more than one object (I understand 'select' to mean right clicking it.) Can you advise me what I should be doing to 'select' more than one object ?

Am I to understand that Livecode does not have the facility of coding for moving objects forward/backward at all ? I ask because I was planning on using that method for future situations I had planned.

I found the 'menu option' in the object inspector menu, the four options were send to back, bring to front, move backward, move forward. I just tried it out, I placed one button 'on top of' another and clicked on the menu options 'bring forward' and 'send to back' and the buttons alternated in being visible.

It is disappointing that there is a facility to do what I require, but that the facility cannot be coded. (Are you certain it can't be coded ?)

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Move object forward/backward

Post by CAsba » Tue Oct 18, 2022 10:26 am

Hi again,
Not to worry, I found the answer in 'talking livecode' Post by david_fff » Sat Jun 27, 2015 7:52 pm, with a simple answer.
My queries about selecting and grouping remain, though..

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

Re: Move object forward/backward

Post by richmond62 » Tue Oct 18, 2022 10:28 am

To select multiple objects click on each one while holding the SHIFT button down.

You'll find the GROUP command in the menus.

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Move object forward/backward

Post by CAsba » Tue Oct 18, 2022 10:35 am

Got it ! Many thanks.

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Move object forward/backward

Post by Klaus » Tue Oct 18, 2022 10:53 am

Hi CAsba,

I really advice to go through one or all of these stack to get hte basics of LC:
http://www.hyperactivesw.com/revscriptc ... ences.html
CAsba wrote:
Tue Oct 18, 2022 10:12 am
I don't know how to make a group. I read up on it and it said to select objects then put them in a group. I don't know how to select more than one object (I understand 'select' to mean right clicking it.) Can you advise me what I should be doing to 'select' more than one object?
1. Select the arrow pointer (Edit tool, topright oin the TOOLS palette
2. Click on the first object you want to select
3. Hold the SHIFT key and select all other controls you need
4. With all object selected use STRG-G as a shortcut or use -> Menu: Object: Group Seleted
CAsba wrote:
Tue Oct 18, 2022 10:12 am
Am I to understand that Livecode does not have the facility of coding for moving objects forward/backward at all ? I ask because I was planning on using that method for future situations I had planned.
of course this is possible, but using groups makes it easier to script!
Yun can of course e.g.:

Code: Select all

...
## Move buttons forward = raising their layer number on the card
set the layer of btn "button1" to 66
set the layer of btn "button22 tp 67
set the layer of btn "button999" to 68
etc.
Lot of typing, but if these btns are grouped it is a one-liner:

Code: Select all

set the layer of grp "all of my buttons" to top
CAsba wrote:
Tue Oct 18, 2022 10:12 am
I found the 'menu option' in the object inspector menu, the four options were send to back, bring to front, move backward, move forward. I just tried it out, I placed one button 'on top of' another and clicked on the menu options 'bring forward' and 'send to back' and the buttons alternated in being visible.
As I said "move for-/backward" will only change the layer of the object and may then "mask" the underlying objects.
Example:
You have two buttons "b1" and b2" and both have identical dimensions width/height and also identical LOCs.
If the layer of btn "b1" = 1 and layer of "b2" = 2 then "b1" will be UNDER "b2"
If the layer of btn "b2" = 1 and layer of "b1" = 2 then "b2" will be UNDER "b1"
Get it? Just like the "levels" in Photoshop or any other image editing application

Important hint for groups!
The global property "selectgroupedcontrols", in Menu: Edit: Select Grouped Controls, will make groups appear as ONE object.
If it is unchecked, when you select the group with the POINTER tool, the group will be treated as ONE object.
If CHECKED then you can select all objects in the group as individual objects.
Just try it out to get used to it!

Best

Klaus

Klaus
Posts: 14191
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Move object forward/backward

Post by Klaus » Tue Oct 18, 2022 10:55 am

CAsba wrote:
Tue Oct 18, 2022 10:26 am
Hi again,
Not to worry, I found the answer in 'talking livecode' Post by david_fff » Sat Jun 27, 2015 7:52 pm, with a simple answer.
My queries about selecting and grouping remain, though..
Next time please provide a link to that posting, thank you!

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: Move object forward/backward

Post by CAsba » Tue Oct 18, 2022 11:14 am

Thank you Klaus, for your patience and your advice.

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

Re: Move object forward/backward

Post by dunbarx » Tue Oct 18, 2022 2:21 pm

It is much simpler to show and hide the various groups instead of changing their layers. Why manage layers, especially if you have several?

Just think about this, an example with three groups, named "A", "B" and "C", each containing the buttons you want to show. A separate "control" button might have this in its script:

Code: Select all

on mouseUp
  answer "Show which group?" with "A" or "B" or "C"
  hide group "A"
  hide group "B"
  hide group "C"
  show group it
end mouseUp
You never need to know anything about the layers. Every time you select a group, that one appears, and all the others go away.

Craig

stam
Posts: 3070
Joined: Sun Jun 04, 2006 9:39 pm

Re: Move object forward/backward

Post by stam » Tue Oct 18, 2022 5:43 pm

dunbarx wrote:
Tue Oct 18, 2022 2:21 pm

Code: Select all

on mouseUp
  answer "Show which group?" with "A" or "B" or "C"
  hide group "A"
  hide group "B"
  hide group "C"
  show group it
end mouseUp
The only improvement to suggest is considering making this into a card-wide handler (eg in the card script) so it can be called in any number of ways. If I have groups (or buttons etc) I would give them names with a prefix that separates them from other groups so I can iterate through all the groups to hide all the relevant ones and then only show the intended group. In this case let’s say we call the groups showA, showB, showC:

Code: Select all

Command showGroup pGroupName
   Repeat with x = 1 to the number of groups of this card
       If the short name of group x of this card contains “show” then
          hide group x of this card
       end if
   End repeat
   Show group pGroupName
End showGroup
You can simply call that from any function or mouse event or an answer dialog with for example :

Code: Select all

ShowGroup “showA”
If your groups contain graphics you will probably want to throw in a “Lock Screen” at the start of the handler as on MacOS at least not doing that leads to visible flicker/delays…

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

Re: Move object forward/backward

Post by dunbarx » Tue Oct 18, 2022 6:53 pm

Stam.

We generally think alike. :wink:

CAsba.

I do not know how you intend to "navigate" between your several groups of buttons. You did early on mention a special button to do all the heavy lifting. Anyway, that is a user interface issue, can be done in many ways, and is really secondary to the main point here. So are you set on a method of presenting only the group of interest, and hiding the others?

Craig

Post Reply