Multiple resolutions, resize stack a solution

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

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

Multiple resolutions, resize stack a solution

Post by Simon » Mon Apr 22, 2013 2:18 am

This is only 1 possible way to do it, there are more.
Hello,
There have been many requests on how to handle resizing of stacks for multiple resolutions and frankly I'm tired of answering them. Here is a script that will scale and position your controls proportionally.

Code: Select all

on mouseUp
   put the height of this stack into tHeight
   put the width of this stack into tWidth
   put "on resizeStack" & cr & "put the height of this stack into tHeight" & cr & "put the width of this stack into tWidth" & cr into tResize
   repeat with i = 1 to the number of controls of this cd
      put the long id of control i into tName
      if tName = the long id of me then next repeat
      put wordOffset("stack",tName) into tWord
      put word 1 to (tWord -2) of tName into tName
      put the rect of control i into tSize
      put round(item 1 of tSize / tWidth,3) into tLeft
      put round(item 2 of tSize /tHeight,3) into tTop
      put round(item 3 of tSize / tWidth,3) into tRight
      put round(item 4 of tSize / tHeight,3) into tBottom
      put "set the rect of" && tName && "to" && "round(" & tLeft & "* tWidth)" & comma & "round(" & tTop & "* tHeight)" & comma & \
            "round(" & tRight & "* tWidth)" & comma & "round(" & tBottom & "* tHeight)" & cr after tResize
   end repeat
   put "end resizeStack" after tResize
   set the clipboardData["text"] to tResize
   answer information "The script has been copied to the clipboard, paste it into the stack script" titled "Now paste it"
end mouseUp
Position your controls on the smallest size stack you will be using (e.g. 320x460) once you've got it looking nice place a button anywhere and add the above script.
Click on the button and a resize script will be placed in the clipboard.
Paste the script into the stack script.
Delete the new button.
Knock your socks off resizing.

I figured this out from the lessons:
http://lessons.runrev.com/s/lessons/m/4 ... esolutions
and here:
http://runrev.com/developers/documentat ... rs-course/

NOTES:
This scales proportionally i.e. If you have a square object and do not resize the stack proportionally it won't be square anymore.
This only deals with 1 card, the script can be easily modified for all your cards.
This does not include any image handling, if your button icons use images you have to figure out how to make them look nice. Would have used strikethrough but not an option here.
Import your graphics including button icons at the largest size for your app (possibly iPad retina) and set their quality to "good", manually resize them so they look good on your smallest stack size.
This does not change font sizes.
This is only a starting point, there can be many cases where it just makes things look funny, refine it for yourself.

I hope someone will post a aspect ratio scaler script.

Have fun learning LiveCode, :D
Simon
EDIT: Here are links to other resizing resources:
Great Chipp Walters plugin, watch the video to see how to use it.
http://youtu.be/vY6r46O0cVA
then download the plugin
http://www.gadgetplugins.com/altplugins ... esizer.rev
And splash21's
http://mobgui.com/morph.php
Last edited by Simon on Sat Apr 25, 2015 5:05 pm, edited 1 time in total.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

CoffeeCone
Posts: 64
Joined: Fri Apr 26, 2013 8:38 am

Re: Multiple resolutions, resize stack a solution

Post by CoffeeCone » Sat May 04, 2013 12:54 am

Hi, this is nice. What about the text inside the objects? For example, the label for the button?

EDIT:
"This does not change font sizes."
OOps :oops:
Learning LiveCode, one step at a time.

archer2009BUSknbj
Posts: 72
Joined: Sat Apr 06, 2013 8:09 am
Location: London

Re: Multiple resolutions, resize stack a solution

Post by archer2009BUSknbj » Thu May 16, 2013 5:41 am

That resizing script is pretty clever, actually it's pretty amazing that it's not built right into LiveCode,

The ability to resize the text and perhaps keep the aspect ratio consistent by adding some padding to the top / bottom or left and right would be perfect ... no idea how to do that myself. But I'm most impressed :-)

archer2009BUSknbj
Posts: 72
Joined: Sat Apr 06, 2013 8:09 am
Location: London

Re: Multiple resolutions, resize stack a solution

Post by archer2009BUSknbj » Thu May 16, 2013 6:22 am

Simon wrote:This is only 1 possible way to do it, there are more.
Hello,
There have been many requests on how to handle resizing of stacks for multiple resolutions and frankly I'm tired of answering them. Here is a script that will scale and position your controls proportionally.

Code: Select all

on mouseUp
   put the height of this stack into tHeight
   put the width of this stack into tWidth
   put "on resizeStack" & cr & "put the height of this stack into tHeight" & cr & "put the width of this stack into tWidth" & cr into tResize
   repeat with i = 1 to the number of controls of this cd
      put the long id of control i into tName
      if tName = the long id of me then next repeat
      put wordOffset("stack",tName) into tWord
      put word 1 to (tWord -2) of tName into tName
      put the rect of control i into tSize
      put round(item 1 of tSize / tWidth,3) into tLeft
      put round(item 2 of tSize /tHeight,3) into tTop
      put round(item 3 of tSize / tWidth,3) into tRight
      put round(item 4 of tSize / tHeight,3) into tBottom
      put "set the rect of" && tName && "to" && "round(" & tLeft & "* tWidth)" & comma & "round(" & tTop & "* tHeight)" & comma & \
            "round(" & tRight & "* tWidth)" & comma & "round(" & tBottom & "* tHeight)" & cr after tResize
   end repeat
   put "end resizeStack" after tResize
   set the clipboardData["text"] to tResize
   answer information "The script has been copied to the clipboard, paste it into the stack script" titled "Now paste it"
end mouseUp
Position your controls on the smallest size stack you will be using (e.g. 320x460) once you've got it looking nice place a button anywhere and add the above script.
Click on the button and a resize script will be placed in the clipboard.
Paste the script into the stack script.
Delete the new button.
Knock your socks off resizing.
This script is simply amazing, I can't stop playing with my stack and constantly resizing it for fun.

If you figure out a way to keep the aspect ratio consistent you're going to make a lot of people very happy. I believe the iPhone 4 and iPhone 5 have slightly different aspect ratios and the way Apple dealt with iPhone 4 Apps was to simply add some padding to the top and bottom of the app on iPhone 5's to keep everything looking consistent, some kind of padding would be perfect, but Thanks so much for this script it's actually taken a lot of weight off my mind knowing this kind of thing is possible :-)

archer2009BUSknbj
Posts: 72
Joined: Sat Apr 06, 2013 8:09 am
Location: London

Re: Multiple resolutions, resize stack a solution

Post by archer2009BUSknbj » Thu May 16, 2013 6:37 am

BTW if you use a PNG image for your background is there a way to get this to resize as well?

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

Re: Multiple resolutions, resize stack a solution

Post by Simon » Thu May 16, 2013 6:41 am

Thanks Archer,
I spent a Sunday afternoon on it so it's not tested everywhere like RunRev would do it. The method is simple so it's pretty stable.

Because I expect this script to be used on mobile devices you'll have to cut graphic buttons so I didn't think font size was as big an issue.

Text input should use a native control (eg mobileControlCreate "multiline", "myMultiLineTextInput") will size correctly I belive.

If you try altMobileResizer, Chipp has a method for aspect ratio.

Keep knocking your socks off! :)

Simon

EDIT: You can import an image for the background rather than using the "backgroundPattern" .
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: Multiple resolutions, resize stack a solution

Post by KennyR » Sat May 18, 2013 3:20 pm

Simon, this is a great script! The only thing I will point out, and don't shoot me for saying, but if you have a native mobGUI ios scroller, it will not allow you to scroll to the bottom...for some reason it stops the scrolling about 4/5 of the way down.....otherwise, it is awesome and such a time saver!!

*Edit--Well I figured this out...I put this line at the end of the Stack Script to update the scroller for mobGUI "scrollerUpdate "MyScroller" (where MyScroller is obviously the name of your scroller) The height of the scrollable area resized nicely...

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

Re: Multiple resolutions, resize stack a solution

Post by Simon » Sat May 18, 2013 9:22 pm

Hi Kenny,
Thanks for your addition.
I don't use mobGUI so I never tested with it. Actually I wouldn't have thought mobGUI or altMobileResizer would work with this as they have their own resizing scripts.

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: Multiple resolutions, resize stack a solution

Post by KennyR » Thu Jun 06, 2013 6:44 pm

Simon... or anyone who uses this handler...I have been using this with great success on a program I currently have in development. I have been pleased with how it resizes for any screen. But what I am curious about is if anyone has figured out how to get the resize handler to resize the screen prior to the card opening...(for IOS or android). It's a bit of an eye sore when you open a card for the first time and it has to resize for lets say the iphone 5. This only happens once (being the first time the user visits the card), but it would be much nicer and smooth if the resize happened without the users knowledge. I have tried to lock the screen and place the handler in the preOpen card handler of the script, but nothing seems to work for me. You see the screen jump and resize....I know I'm looking the gift horse in the mouth here since Simon did a brilliant job of crafting this handler, but this would take it over the top for me...Thanks in advance as always for any input anyone has on this...

Kenny

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

Re: Multiple resolutions, resize stack a solution

Post by Simon » Thu Jun 06, 2013 8:55 pm

Hi Kenny,
A few questions for you:
1) Is this on the emulator or on real devices?
2) What was your change for use on multiple cards?
3) Approximately how many controls are on each card?
4) Are DataGrids being used? (Not that that really matters it's just something I didn't test so I'd like to know if the code works with them).:)

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

Klaus
Posts: 11211
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Multiple resolutions, resize stack a solution

Post by Klaus » Thu Jun 06, 2013 9:08 pm

Hi Simon,
Simon wrote:4) Are DataGrids being used? (Not that that really matters it's just something I didn't test so I'd like to know if the code works with them).
I HIGHLY doubt this!

The IDE successfully HIDES the real content of DataGrid groups, which can contain several 100 (and even more!) single objects and lots of "sub"groups.
And a script does NOT know per se if a group is a datagrid and will surely render a working and carefully set up datagrid useless and leave a TOTAL mess on the screen!
Know what I mean?

But please try this script with a datagrid on a card, make a screenshot and post it here :-D


Best

Klaus

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

Re: Multiple resolutions, resize stack a solution

Post by KennyR » Thu Jun 06, 2013 9:17 pm

Hey guys...I use this resize handler on all my cards and across all platforms now....I also use dataGrids....I actually have 2 on one card and they resize nicely. I have no problems what so ever using this other than what I stated above....Oh yeah, some of my cards have a multitude of buttons/controls etc. And I use this handler in both the simulator/IDE and on my iPhone for testing purposes....the program I am currently creating requires the iphone to communicate with the Mac/Win desktop....really nothing more than the pc/mac pulling data from the server....
Attachments
bd.tiff

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

Re: Multiple resolutions, resize stack a solution

Post by Simon » Thu Jun 06, 2013 11:07 pm

It works with dataGrids????
WOW, I really didn't think it would.

Kenny, and how did you spread it across multiple cards? I'm thinking you may have put it in the card script?

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: Multiple resolutions, resize stack a solution

Post by KennyR » Thu Jun 06, 2013 11:27 pm

Simon, I thought I was just following your directions so I did nothing special other than what you said to do....I simply put the resize handler in each card of my stack...Did you have other ideas for what to do when you put this out? I'm telling you, this handler needs to be incorporated with LC releases...sooooo easy!!

edit* wait....are you guys asking if the individual fields and controls within the DG are resized when the window is resized? If that is what you are asking then no...you still have to use the behavior script of the DG to resize the fields and controls to the DG viewing area.....the resize handler as far as I can tell only affects the viewing area (outer perimeter) of the DG. Sorry if I was not getting the message in our previous discussion...

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

Re: Multiple resolutions, resize stack a solution

Post by Simon » Fri Jun 07, 2013 12:15 am

Hi Kenny,
I have no input on dataGrids but glad that you found a way to get it to work.

As for the script I was hoping users would add another loop for multiple cards:
repeat for the number of cd of this stack

Then keeping the script in the stack script, all resizing would happen at openStack (or wherever the user put it (Wait a sec! One doesn't have to call on resizeStack because it happens automatically when the stack opens and resizes itself to the new screen.).
I think this could be a solution to your problem.

Ya Dig Man? Catch my drift? Groovey to the idea? Grok that?

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

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”