Dynamic buttons
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Dynamic buttons
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!
Thanks in advance for your help. I'm having fun learning!
Re: Dynamic buttons
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
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.
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
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!
Re: Dynamic buttons
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.
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.
Re: Dynamic buttons
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
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
Re: Dynamic buttons
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
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
Re: Dynamic buttons
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
Craig