I wanted to have a thin stack that could be enlarged to show additional controls when required. I added a resize button to the card that simply toggled the width of the stack between two values, the full code may be viewed in the attached stack file (all the code is in the two button scripts), the toggle is conducted by an if statement:
Code: Select all
if tWidth = kWide then
set the width of this stack to kNarrow
else
set the width of this stack to kWide
end if
The solution is to recognise that in my example I want both versions of my stack (narrow or wide) to be drawn the same distance from the left hand edge of the screen. This means that the location of the stack has to be changed when the width is changed, so some extra code is needed:
Code: Select all
on mouseUp
constant kWide= 920
constant kNarrow= 220
constant kHeight = 260
set the height of this stack to kHeight
# The width of the stack toggles between two widths
# If just the width is changed the stack appears to jump on the screen
# So, some calculation is required to maintain a constant position
# Read the present width
Put the width of this stack into tWidth
# Read the location and break out the X and Y positions to the centre of the stack
Put the loc of this stack into tLoc
put item 1 of tLoc into tstackX
put item 2 of tLoc into tstackY
# Calculate the location of the left margin which we wish to remain unchanged
put tstackX-(tWidth / 2) into tLeftMargin
# The new X co-ordinate of location is calculated using : NewLocX= tLeftMargin+(NewWidth/2)
if tWidth = kWide then
set the width of this stack to kNarrow
# Now adjust the location to account for the new width
put tLeftMargin+(kNarrow / 2) into tNewX
else
set the width of this stack to kWide
# Now adjust the location to account for the new width
put tLeftMargin+(kWide / 2) into tNewX
end if
#Update the location of the stack
set the loc of this stack to tNewX,tstackY
end mouseUp