Add button to end of scroller

This is the place to discuss anything relating to MobGUI

Moderators: heatherlaine, kevinmiller, robinmiller, malte, splash21

Post Reply
KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Add button to end of scroller

Post by KennyR » Tue Apr 17, 2012 11:39 am

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?

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

Re: Add button to end of scroller

Post by Simon » Fri Feb 22, 2013 8:52 am

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. :D

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: Add button to end of scroller

Post by KennyR » Sat Feb 23, 2013 3:52 pm

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...

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: Add button to end of scroller

Post by KennyR » Fri Mar 22, 2013 5:39 am

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

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

Re: Add button to end of scroller

Post by Simon » Fri Mar 22, 2013 5:57 am

Fun!

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!

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

Re: Add button to end of scroller

Post by Simon » Fri Mar 22, 2013 10:20 pm

Sorry answered half your question:
the scroller will not scroll down far enough
You are setting the formattedHeight of kGroup in the preOpenCard, you need to run that again after building the new buttons.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: Add button to end of scroller

Post by KennyR » Sat Mar 23, 2013 3:10 am

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

Post Reply

Return to “MobGUI”