
CHAPTER 4: User-Interface Tools Automatic layout 87
The script programmer has considerable control over the automatic layout process. Each container has an
associated layout manager object, specified in the
layout property. The layout manager controls the sizes
and positions of the contained elements, and also sizes the container itself.
There is a default layout manager object, or you can create a new one:
myWin.layout = new AutoLayoutManager(myWin);
Default layout behavior
By default, the autoLayoutManager object implements the default layout behavior. A script can modify
the properties of the default layout manager object, or create a new, custom layout manager if it needs
more specialized layout behavior. See “
Custom layout-manager example” on page 95.
Child elements of a container can be organized in a single row or column, or in a stack, where the elements
overlap one other in the same region of the container, and only the top element is fully visible. This is
controlled by the container’s
orientation property, which can have the value row, column, or stack.
You can nest
Panel and Group containers to create more complex organizations. For example, to display
two columns of controls, you can create a panel with a row orientation that in turn contains two groups,
each with a column orientation.
Containers have properties to control inter-element spacing and margins within their edges. The layout
manager provides defaults if these are not set.
The alignment of child elements within a container is controlled by the
alignChildren property of the
container, and the
alignment property of the individual controls. The alignChildren property
determines an overall strategy for the container, which can be overridden by a particular child element’s
alignment value.
A layout manager can determine the best size for a child element through the element’s
preferredSize
property. The value defaults to dimensions determined by ScriptUI based on characteristics of the control
type and variable characteristics such as a displayed text string, and the font and size used to display text.
A value of -1 for either the width or height in the
preferredSize value causes the layout manager to
calculate that dimension, while using the specified value for the other.
For details of how you can set these property values to affect the automatic layout, see “
Automatic layout
properties” on page 87.
N
OTE: The default font and font size are chosen differently on different platforms, and by different
applications on the same platform, so ScriptUI windows that are created the same way can appear
different in different contexts.
Automatic layout properties
Your script establishes rules for the layout manager by setting the values of certain properties, both in the
container object and in the child elements. The following examples show the effects of various
combinations of values for these properties. The examples are based on a simple window containing a
StaticText, Button and EditText element, created (using Resource specifications) as follows:
var w = new Window(
"window { \
orientation: ’row’, \
st: StaticText { }, \
pb: Button { text: ’OK’ }, \
Comentarios a estos manuales