Dynamic buttons

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
athelene
Posts: 18
Joined: Sun Jul 26, 2015 9:19 pm

Dynamic buttons

Post by athelene » Sun Jul 26, 2015 9:45 pm

I am trying to create a new set of buttons on a specific area of a card dynamically. For example, user clicks on an object on the left and two or three buttons appear on the right depending on what they select. I found the templateButton and "create button" features in LiveCode. So I think I can create the buttons I need. However, I'm having trouble figuring out how to get them where they belong since I can't know in advance how many there will be. I know there is a position property. But how can I dynamically set that parameter with appropriate settings? Any other thoughts about how to accomplish this in a better way?

Thanks in advance for your help. I'm having fun learning!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Dynamic buttons

Post by Simon » Mon Jul 27, 2015 12:23 am

Hi athelene,
Welcome to the forums!

Since you sound like a keen learner I'll start by just giving you some hints;
You might be going at this the hard way, if it were me I'd just group the bunch of buttons on the right that corresponded to say Left button 1 and then just hide/show the group.

Left button 1 code

Code: Select all

on mouseUp
show group 1
hide group 2
hide group 3
hide group ... --can you see how to use a repeat loop here?
end mouseUp
Simon
Edit; Oh, don't worry if you need more help just ask :)
Edit 2; The way I scripted the above is very wrong as the groups should have proper names like,
hide group "myGroup2"
hide group "my Group3" etc. That will also make your repeat loop a little more fun, but more important it will make working with the correct group not get crazy.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

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

Re: Dynamic buttons

Post by SparkOut » Mon Jul 27, 2015 7:31 am

I agree, making a pane that is tailored to the required view and then showing or hiding it is easiest.
But just for info: left, right, top, bottom, topleft, bottomright, width, height, rect and loc are all settable (and gettable) properties, so for instance, you can

set the top of button "btn2" to the bottom of button "btn1" + 10
set the top of button "btn3" to the bottom of button "btn2" + 10

That will spread the buttons out evenly with a 10 px gap between them. Of course you would want to process this in a loop with dynamic reference to each button programmatically rather than write out each positioning statement line by line, but you see how to put things how you want now, I hope.

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

Re: Dynamic buttons

Post by dunbarx » Mon Jul 27, 2015 2:17 pm

Hi.

The question for me is this: are whatever buttons that are to be shown already fixed? In other words, if you click on that left-hand object, does this always to show a fixed "group" of buttons on the right, or will those buttons change depending on other factors?

If fixed, then the suggestions by the others is best; hide and show pre-existing groups of buttons as needed. But if the suite of buttons varies, then we need to talk. You have already found clues to making this all work, and it is a simple task. We will work all that out shortly.

But which way is it?

Craig Newman

athelene
Posts: 18
Joined: Sun Jul 26, 2015 9:19 pm

Re: Dynamic buttons

Post by athelene » Tue Jul 28, 2015 3:44 pm

Thank you all for your input! As Dunbarx notes, the buttons are not fixed. For example, one user may see two and another user may see 10. I think Soarkout's solution would probably work in general. I'm wondering, however, what will happen in that scenario when the screen size changes due to a difference in device. For example, if I use the following for X number of buttons (set up with a loop), what happens for a user who has 10 buttons when they look at their app on their phone versus their tablet?

set the top of button "btn2" to the bottom of button "btn1" + 10
set the top of button "btn3" to the bottom of button "btn2" + 10

I very much appreciate the help! This is fun!

Athelene

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

Re: Dynamic buttons

Post by dunbarx » Tue Jul 28, 2015 3:49 pm

Sparkout gave you an idea, not a general solution. To your point, if the screen size changes, then the button size must as well, not to mention perhaps the inter-button spacing. This has to be known beforehand, based on the environment. Fortunately, LC can detect all this, and you can adjust the dimensions and layout of all controls to fit.

Craig

Post Reply