
CHAPTER 4: User-Interface Tools Automatic layout 92
Determining a preferred size
Each element has a preferredSize property, which is initially defined with reasonable default
dimensions for the element. The default value is calculated by ScriptUI, and is based on constant
characteristics of each type of element, and variable characteristics such as the text string to be displayed
in a button or text element.
If an element’s
size property is not defined, the layout manager uses the value of preferredSize to
determine the dimensions of each element during the layout process. Generally, you should avoid setting
the
preferredSize property explicitly, and let ScriptUI determine the best value based on the state of an
element at layout time. This allows you to set the
text properties of your user-interface elements using
localizable strings (see “
Localization in ScriptUI objects” on page 103). The width and height of each
element are calculated at layout time based on the chosen language-specific text string, rather than
relying on the script to specify a fixed size for each element.
However, a script can explicitly set the
preferredSize property to give hints to the layout manager about
the intended sizes of elements for which a reasonable default size is not easily determined, such as an
IconButton element that has no initial image to measure.
You can set just one of the dimensions using the
preferredSize; a value of -1 for either width or height
causes the layout manager to calculate that dimension, while using the supplied value for the other.
You can also set a maximum and/or minimum size value for a control, that limit how it can be resized.
There is a default maximum size that prevents automatic layout from creating elements larger than the
screen.
You can explicitly resize the controls in a window to fit the current text contents, or after the window is
resized by the user, using the resize()
method of the layout object.
Creating more complex arrangements
You can easily create more complex arrangements by nesting Group containers within Panel containers
and other
Group containers.
Many dialogs consist of rows of information to be filled in, where each row has columns of related types of
controls. For instance, an edit field is typically in a row next to a static text label that identifies it, and a
series of such rows are arranged in a column. This example (created using Resource specifications
) shows a
simple dialog in which a user can enter information into two
EditText fields, each arranged in a row with
its
StaticText label. To create the layout, a Panel with a column orientation contains two Group elements
with row orientation. These groups contain the control rows. A third
Group, outside the panel, contains the
row of buttons.
res =
"dialog { \
Comentários a estes Manuais