BYU Home pageBRIGHAM YOUNG UNIVERSITY
  Office of Digital Humanities
Back     BYU LiveCode Lessons Gateway

DigHT 310
Managing Changes in Stack Size and Orientation

As you already know, the LiveCode development environment provides several useful tools for simplifying potentially complex tasks. For instance, there is a Menu Builder tool for quickly creating menus, and the Alignment Palette for aligning and spacing multiple objects. Today we'll look at some other useful tools.

Normally, when you create a stack, add objects to it, then resize it, the contents of the card do not automatically adjust to the new size. The LiveCode language provides several tools to help you adjust the sizes of objects in a stack when the stack is resized. The most important of these is the resizeStack message. This message is sent automatically to the current card when the stack is resized. By writing a resizeStack handler you can specify how to reposition and resize each individual object.

The resizeStack message includes four arguments, or pieces of information, that are sent every time the stack's size is changed. They are as follows:

resizeStack newWidth,newHeight,oldWidth,oldHeight

newWidth = the width of the stack after the resize event
newHeight = the height of the stack after the resize event
oldWidth = the width of the stack before the resize event
oldHeight = the height of the stack before the resize event

Let's say you have a simple stack with a single field, which you want to grow or shrink in size as the stack is resized.

stack with single field

The following resizeStack handler in the card script could accomplish this:

on resizeStack pNewWdth,pNewHgt
  set the width of fld "main" to pNewWdth - 20
  set the height of fld "main" to pNewHgt - 20
  set the topLeft of fld "main" to 10,10
end resizeStack

For each new control you added you would need to add a similar list of commands, taking care to keep controls from overlapping and obscuring each other while they resize. Obviously, this can become complicated, but if you are careful and methodical the resizeStack message is a very straightforward way to reconfigure cards to handle resizing of the stack (for desktop applications) or reorientation of stacks (for mobile applications.)

The Geometry Manager

For relatively simple card setups there is a built-in tool provided in LiveCode: the Geometry Manager. The Geometry Manager is accessible from the Geometry pane of each object's property inspector. It lets you automatically change the size and location of objects to reflect changes to the size of the window they're in.

While the Geometry Manager can greatly simplify the task of resizing objects in your stack, it can be confining, since the Geometry Manager makes assumptions about how to resize and reposition that you may not want to make. So it's good to keep the resizeStack message in mind in case you need to do some fine tuning.

Mac OS X note: liveResizing

Update Feb 2016: As of LiveCode 6.7 this note no longer applies to Mac OS; Live resizing is now the only option for Mac OS X stack windows.

On the Mac OS X operating system there are two resizing "modes." The mode is determined by the liveResizing property. When the liveResizing is false—the default setting—the resizeStack message is sent after the resizing operation has completed; i.e., after the user has released the mouse after dragging the window's resize gadget. When the liveResizing is true, the resizeStack message is sent continuously during the resize action, resulting in a smooth visual appearance while resizing. This property is ignored on other operating systems, where the live resizing behavior is the norm.


Back     BYU LiveCode Lessons Gateway
Maintained by Devin Asay.
Copyright © 2005 Brigham Young University.
This page last updated on February 12, 2016 12:52:14.