Resizing newly created card in 5.5.1
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Resizing newly created card in 5.5.1
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
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
Re: Resizing newly created card in 5.5.1
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:
Mark
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
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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Resizing newly created card in 5.5.1
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
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
Re: Resizing newly created card in 5.5.1
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
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
Re: Resizing newly created card in 5.5.1
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.
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.
Re: Resizing newly created card in 5.5.1
Hi Andy,
the best is to calculate the new rect of an object and apply this at once:
Best
Klaus
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
Klaus