Add button to end of scroller
Moderators: heatherlaine, kevinmiller, robinmiller, malte, splash21
Add button to end of scroller
Sorry, but I feel like Im burning up the forum with all my posts!
Question, I understand how to create a button and place it in a group, and I have the basic understanding of how to place that button in a certain location on the card, but am having issues with placing that newly created button at the end of a native scroller. For instance....I have a scroller that contains lets say 5 buttons. I would like to be able to have a button the user clicks to create a new button and then have that button placed at the bottom of a group in that scroller. I have attempted to get the location of "bottom" and "left" of the scroller and place the values in tBot and tLeft and then tell the newly created button to place itself in that location, but I cannot seem to hammer out the code and make it work....any suggestions?
Question, I understand how to create a button and place it in a group, and I have the basic understanding of how to place that button in a certain location on the card, but am having issues with placing that newly created button at the end of a native scroller. For instance....I have a scroller that contains lets say 5 buttons. I would like to be able to have a button the user clicks to create a new button and then have that button placed at the bottom of a group in that scroller. I have attempted to get the location of "bottom" and "left" of the scroller and place the values in tBot and tLeft and then tell the newly created button to place itself in that location, but I cannot seem to hammer out the code and make it work....any suggestions?
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Add button to end of scroller
Hi Kenny,
I think I understand this one.
Look up templatebutton, it's the grownup way of doing this (not mine).
I would add the buttons and somewhere in the scrolling script there should be a formattedHeight, set the height to cover them (don't use formattedHeight). When you add a new button change the height to include the new button. Make sure you set the top button to the top of the scrolling group.
Remember that you cannot save to a standalone so you'd have to record the new height in your myFile.txt.
For those of you reading along thinking I'm not making any sense, I know what Kenny is building and am using shorthand.
Simon
I think I understand this one.
Look up templatebutton, it's the grownup way of doing this (not mine).
I would add the buttons and somewhere in the scrolling script there should be a formattedHeight, set the height to cover them (don't use formattedHeight). When you add a new button change the height to include the new button. Make sure you set the top button to the top of the scrolling group.
Remember that you cannot save to a standalone so you'd have to record the new height in your myFile.txt.
For those of you reading along thinking I'm not making any sense, I know what Kenny is building and am using shorthand.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Add button to end of scroller
Ha! I just visited this thread to keep up on what is going on with mobGUI and saw your post! Thanks for helping on this Simon....I'm going to kick this around a bit today and see what happens....I'll report back and post some script in the case I get it figured out. Plus, it might help someone else trying to add a button to the end of a native scroller....btw....I just submitted my first app to iTunes Connect...crossing my fingers for a good bill of health for my app. I couldn't have done it without your help man...
Re: Add button to end of scroller
Ok...I am back on this again! LOL....I have been playing with some code and have this "sort of" figured out with a few exceptions....I am now able to add a button to the end of the scroller but only once. The next button seems to be created off to the right of the "scroller" and isn't even the correct size that I specified in the script. Plus, after the first new button is created, the scroller will not scroll down far enough to display the newly created button. If the bounce effect is on in the scroller, you can pull it up far enough to verify the button was added correctly...frustrating....I will be playing with this a little more....I am going to add my code in the hopes that someone can build on it and help me out a little....I will warn you...my code is kindergarden compared to you guys so don't laugh!
Code: Select all
on mouseUp
#Open Scroller group for editing
start editing group id 1316
#Obvious
create button "New"
set the width of btn "New" to 116
set the height of btn "New" to 106
#Places all the button names in variable tName & stores the number of buttons in tNumber
repeat with i = 1 to the number of buttons on this cd
add 1 to tNumber
put the name btn i & cr after tName
end repeat
#Gives me the next to last button number in tNumber and puts the new value in vNum
put tNumber -1 into vNum
#Places the name of the next to last button in tResult
put line vNum of tName into tResult
#Position the button after the last button in the scroller
set the left of btn "New" to the left of tResult
set the top of btn "New" to the bottom of tResult + 20
stop editing group id 1316 card "card id 1176"
set the vScroll of group id 1316 to 0
end mouseUp
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Add button to end of scroller
Fun!
This shows you the power of "last"
OK I hope your buttons were entered in sequential order or this wont work.
Simon
Code: Select all
on mouseUp
put the id of the last btn of this cd into tButton
create button --name as you like
set the width of the last btn to 116
set the height of the last btn to 106
set the topLeft of the last button to the bottomLeft of button ID tButton
end mouseUp
This shows you the power of "last"
OK I hope your buttons were entered in sequential order or this wont work.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Add button to end of scroller
Sorry answered half your question:
Simon
You are setting the formattedHeight of kGroup in the preOpenCard, you need to run that again after building the new buttons.the scroller will not scroll down far enough
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Add button to end of scroller
Hey Simon ....thanks for the help once more! I found your code much easier to follow than mime. It occurred to me after your first post that in order to update the scroller after adding a new button, I had to use the mobgui command "updatescroller kgroup" and all was fine...I'm going to post my script tomorrow so others can see how this is done...but ultimately I had to edit my scroll group, add the button and position it to the bottom of the last button in the group then stop editing the group. It wasn't as bad as I made it out to be...been doing quite a bit of reading and playing with the code...hopefully this will help someone else...thanks again buddy for the help