Page 1 of 1

Stack Location: jumping all over

Posted: Thu Jun 28, 2012 10:01 pm
by townsend
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

Re: Stack Location: jumping all over

Posted: Thu Jun 28, 2012 10:13 pm
by sturgis
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.

Re: Stack Location: jumping all over

Posted: Thu Jun 28, 2012 10:14 pm
by Mark
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

Re: Stack Location: jumping all over

Posted: Fri Jun 29, 2012 5:53 pm
by townsend
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.