Resizing newly created card in 5.5.1

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: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
andyH
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 38
Joined: Sun Nov 15, 2009 11:45 pm
Contact:

Resizing newly created card in 5.5.1

Post by andyH » Wed Jul 04, 2012 10:41 pm

I have created a simple stack for my own notes on the screen. The stack has a splash screen and a separate stack in the documents folder. Initially the separate notes stack has a number of cards. The contain a grouped background of a field, buttons and a label. The controls geometry has been set, and all these cards resize properly in the standalone.

However, when I create a new card in my notes stack (in the documents folder) the background is created, but will not resize! Is this a known issue, or have I missed something out.

Will I have to write my own resize handler to deal with this?

Andy

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

Re: Resizing newly created card in 5.5.1

Post by Mark » Thu Jul 05, 2012 2:26 pm

Hi Andy,

I never use the geometry manager and always write my own resizing scripts. Since you have set up the geometry manager to resize your controls already, you might send the resizeStack message on preOpenCard:

Code: Select all

on preOpenCard
  resizeStack
end preOpenCard
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

andyH
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 38
Joined: Sun Nov 15, 2009 11:45 pm
Contact:

Re: Resizing newly created card in 5.5.1

Post by andyH » Thu Jul 05, 2012 7:43 pm

Hi Mark

Thanks for the suggestion. Still does not work at runtime on new cards created at runtime.

Had already started writing my own resizeStack handlers. This was just for a field that I wanted to rescale - with the topLeft position fixed and the bottomRight to change.

on resizeStack

reScaleObject "field","NotesField",10,40,10,25

pass resizeStack

end resizeStack

on reScaleObject pType,pObjectName,pLeft,pTop,pRightDiff,pBottomDiff
put the width of this stack into theWidth
put the height of this stack into theHeight

if pType is "field" then

set the left of field pObjectName to pLeft
set the top of field pObjectName to pTop

put theWidth - pRightDiff into ObjectRight
set the right of field pObjectName to ObjectRight

put theHeight - pBottomDiff into ObjectBottom
set the bottom of field pObjectName to ObjectBottom

end if

end reScaleObject

The BottomRight moves as expected. However, the TopLeft position does not remain fixed!

Using 5.5.1 and OSX 10.7.4

Andy

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Resizing newly created card in 5.5.1

Post by bn » Fri Jul 06, 2012 10:17 am

Hi Andy,

you only set the locations, not the size of the fields. By setting the right of an object the whole object moves to the designated location, etc.
The last location you set is the bottomRight, that is where the field ends up.

When Livecode resizes an object it does so by adding width symmetrically to the location of the object.
lets say you have a square object that is 100 px wide and is located at 200,200. Now you set the width of the object to 160. The location will still 200,200. But the topleft (and others) will change. The topLeft will change from 150,150 to 120,150.

In other words to resize an object and retain its topLeft:
store the current topLeft before changing size
calculate the desired size of the object by taking into account the right and bottom border
set the size adjustments of the object
and lastly set the topLeft of the object

Now you have the object resized and the topLeft (as well as the other borders) at the desired location.
Sounds more complicated than it is.

Kind regards
Bernd

andyH
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 38
Joined: Sun Nov 15, 2009 11:45 pm
Contact:

Re: Resizing newly created card in 5.5.1

Post by andyH » Fri Jul 06, 2012 11:52 am

Hi Bernd

Thanks for this.

Noticed this this morning and code for the width and height, and coded other handlers to position objects when being resized. It seems to work.

Thanks again.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Resizing newly created card in 5.5.1

Post by Klaus » Fri Jul 06, 2012 12:40 pm

Hi Andy,

the best is to calculate the new rect of an object and apply this at once:

Code: Select all

on reScaleObject pType,pObjectName,pLeft,pTop,pRightDiff,pBottomDiff

  ## Always a good idea when manipulating objects:
  lock screen

  put the width of this stack into theWidth
  put the height of this stack into theHeight
  
  if pType is "field" then
    
    ## Calculate new bottom right coordiantes
    put theWidth - pRightDiff into ObjectRight   
    put theHeight - pBottomDiff into ObjectBottom
    
    ## Apply new RECT at once:
    set the rect of fld pObjectName to pLeft,pTop,ObjectRight,ObjectBottom
  end if

  unlock screen
end reScaleObject
Best

Klaus

Post Reply