Stack Location: jumping all over

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
townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

Stack Location: jumping all over

Post by townsend » Thu Jun 28, 2012 10:01 pm

I've got a stack that is resized based on content.
Content is just a single text field.

I can save the loc and use that next time the window opens,
but since the loc numbers are based on the center of the object,
this stack jumps all over, depending on the sequence of the content size.

I'm really stumped here. How can I save the location a or stack
based on just one corner? (top, left would be ideal)

This code resizes the stack nicely, but I can't save a consistent loc value
because the center of the stack is always changing.

Code: Select all

     set the width of fld "msg.text" to the width of this stack
     set the height of field "msg.text" to the formattedheight of field "msg.text" 
     set the height of this stack to the height of fld "msg.text" 
     set the width of this stack to the width of fld "msg.text"
     put the rect of fld "msg.text" into temp
     replace item 1 of temp with "1" in temp
     replace item 2 of temp with "1" in temp
     set the rect of fld "msg.text" to temp

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Stack Location: jumping all over

Post by sturgis » Thu Jun 28, 2012 10:13 pm

Instead of the loc you can use the topleft of the stack

set the mystacklocation of stack "mystack" to the topleft of stack "mystack"

To restore it of course

set the topleft of stack "mystack" to the mystakclocation of stack "mystack"

Need to be careful with this though. If you're on a dual monitor system and later remove a monitor or change the configuration you can lose your stack into non-existent screen real estate.

To avoid this you can check the screenrects and see if the location is valid, if not set it to a default spot.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Stack Location: jumping all over

Post by Mark » Thu Jun 28, 2012 10:14 pm

Hi,

If you change the height and width of the stack, it will resize while it stays (approximately) centered on the screen. If you do this a few times, your stack might end up in a different location. The correct way to do this is to change the rect of the stack. For example:

Code: Select all

put the rect of this stack into myRect
put item 2 of myRect + 256 into item 4 of myRect
set the rect of this stack to myRect
This script sets the height of the stack to 256 without making it jump all over the place.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

Re: Stack Location: jumping all over

Post by townsend » Fri Jun 29, 2012 5:53 pm

Thanks Sturgis! That was exactly what I needed!
1 line of code to replace my 8.

And Mark! Wow-- your little algorithm is is FANTASTIC!
That solved a problem I didn't even know I had.
There 3 lines of code replaced my 10.

Everybody should save those three lines (above)
to their clip library. It's not obvious, but works great.

Post Reply