stk/Help/grid.n.html

332 lines
17 KiB
HTML

<HTML><HEAD><TITLE>Tk Built-In Commands - grid manual page</TITLE></HEAD>
<BR>
<BODY bgcolor = #c3c3ff>
<H2><IMG ALIGN=BOTTOM SRC="./Img/ManPageBlue.gif"> grid</H2>
<I>Geometry manager that arranges widgets in a grid</I><P><IMG ALIGN=TOP SRC="./Img/line-red.gif">
<H3><A NAME="M2">SYNOPSIS</A></H3>
(<B>grid </B><I>option arg </I>?<I>arg ...</I>?)<BR>
<H3><A NAME="M3">DESCRIPTION</A></H3>
The <B>grid</B> procedure is used to communicate with the grid
geometry manager that arranges widgets in rows and columns inside
of another window, called the geometry master (or master window).
The <B>grid</B> procedure can have any of several forms, depending
on the <I>option</I> argument:
<P>
<DL>
<DT><A NAME="M4">(<B>grid </B><I>slave </I>?<I>slave ...</I>? ?<I>options</I>?)</A><DD>
If the first argument to <B>grid</B> is a window name (any value
starting with ``.''), then the procedure is processed in the same
way as <B>grid configure</B>.
<P>
<DT><A NAME="M5">(<B>grid 'bbox </B><I>master</I>)</A><DD>
<DT><A NAME="M6">(<B>grid 'bbox </B><I>master column row</I>)</A><DD>
<DT><A NAME="M7">(<B>grid 'bbox </B><I>master column row column2 row2</I>)</A><DD>
With no arguments,
the bounding box (in pixels) of the grid is returned.
The return value consists of 4 integers. The first two are the pixel
offset from the master window (x then y) of the top-left corner of the
grid, and the second two integers are the width and height of the grid,
also in pixels. If a single <I>column</I> and <I>row</I> is specified on
the command line, then the bounding box for that cell is returned, where the
top left cell is numbered from zero. If both <I>column</I> and <I>row</I>
arguments are specified, then the bounding box spanning the rows and columns
indicated is returned.
<P>
<DT><A NAME="M8">(<B>grid 'columnconfigure </B><I>master index </I>?<I>:option value...</I>?)</A><DD>
Query or set the column properties of the <I>index</I> column of the
geometry master, <I>master</I>.
The valid options are <B>:minsize</B>, <B>:weight</B> and <B>:pad</B>.
If one or more options are provided, then <I>index</I> may be given as
a list of column indexes to which the configuration options will operate on.
The <B>:minsize</B> option sets the minimum size, in screen units,
that will be permitted for this column.
The <B>:weight</B> option (an integer value)
sets the relative weight for apportioning
any extra spaces among
columns.
A weight of zero (0) indicates the column will not deviate from its requested
size. A column whose weight is two will grow at twice the rate as a column
of weight one when extra space is allocated to the layout.
The <B>:pad</B> option specifies the number of screen units that will be
added to the largest window contained completely in that column when the
grid geometry manager requests a size from the containing window.
If only an option is specified, with no value,
the current value of that option is returned.
If only the master window and index is specified, all the current settings
are returned in an list of &quot;:option value&quot; pairs.
<P>
<DT><A NAME="M9">(<B>grid 'configure </B><I>slave </I>?<I>slave ...</I>? ?<I>options</I>?)</A><DD>
The arguments consist of the names of one or more slave windows
followed by pairs of arguments that specify how
to manage the slaves.
The characters <B>:</B>, <B>x</B> and <B>^</B>,
can be specified instead of a window name to alter the default
location of a <I>slave</I>, as described in the ``RELATIVE PLACEMENT''
section, below.
The following options are supported:
<P>
<P>
<DL>
<DT><A NAME="M10"><B>:column </B><I>n</I></A><DD>
Insert the slave so that it occupies the <I>n</I>th column in the grid.
Column numbers start with 0. If this option is not supplied, then the
slave is arranged just to the right of previous slave specified on this
call to <I>grid</I>, or column &quot;0&quot; if it is the first slave. For each
<B>x</B> that immediately precedes the <I>slave</I>, the column position
is incremented by one. Thus the <B>x</B> represents a blank column
for this row in the grid.
<P>
<DT><A NAME="M11"><B>:columnspan </B><I>n</I></A><DD>
Insert the slave so that it occupies <I>n</I> columns in the grid.
The default is one column, unless the window name is followed by a
<B>:</B>, in which case the columnspan is incremented once for each immediately
following <B>:</B>.
<P>
<DT><A NAME="M12"><B>:in </B><I>other</I></A><DD>
Insert the slave(s) in the master
window given by <I>other</I>. The default is the first slave's
parent window.
<P>
<DT><A NAME="M13"><B>:ipadx </B><I>amount</I></A><DD>
The <I>amount</I> specifies how much horizontal internal padding to
leave on each side of the slave(s). This is space is added
inside the slave(s) border.
The <I>amount</I> must be a valid screen distance, such as <B>2</B> or <B>.5c</B>.
It defaults to 0.
<P>
<DT><A NAME="M14"><B>:ipady </B><I>amount</I></A><DD>
The <I>amount</I> specifies how much vertical internal padding to
leave on on the top and bottom of the slave(s).
This space is added inside the slave(s) border.
The <I>amount</I> defaults to 0.
<P>
<DT><A NAME="M15"><B>:padx </B><I>amount</I></A><DD>
The <I>amount</I> specifies how much horizontal external padding to
leave on each side of the slave(s), in screen units.
The <I>amount</I> defaults to 0.
This space is added outside the slave(s) border.
<P>
<DT><A NAME="M16"><B>:pady </B><I>amount</I></A><DD>
The <I>amount</I> specifies how much vertical external padding to
leave on the top and bottom of the slave(s), in screen units.
The <I>amount</I> defaults to 0.
This space is added outside the slave(s) border.
<P>
<DT><A NAME="M17"><B>:row </B><I>n</I></A><DD>
Insert the slave so that it occupies the <I>n</I>th row in the grid.
Row numbers start with 0. If this option is not supplied, then the
slave is arranged on the same row as the previous slave specified on this
call to <B>grid</B>, or the first unoccupied row if this is the first slave.
<P>
<DT><A NAME="M18"><B>:rowspan </B><I>n</I></A><DD>
Insert the slave so that it occupies <I>n</I> rows in the grid.
The default is one row. If the next <B>grid</B> procedure contains
<B>^</B> characters instead of <I>slaves</I> that line up with the columns
of this <I>slave</I>, then the <B>rowspan</B> of this <I>slave</I> is
extended by one.
<P>
<DT><A NAME="M19"><B>:sticky </B><I>style</I></A><DD>
If a slave's cell is larger than its requested dimensions, this
option may be used to position (or stretch) the slave within its cell.
<I>Style</I> is a string that contains zero or more of the characters
<B>n</B>, <B>s</B>, <B>e</B> or <B>w</B>.
The string can optionally contains spaces or
commas, but they are ignored. Each letter refers to a side (north, south,
east, or west) that the slave will &quot;stick&quot; to. If both <B>n</B> and <B>s</B> (or
<B>e</B> and <B>w</B>) are specified, the slave will be stretched to fill the entire
height (or width) of its cavity. The <B>sticky</B> option subsumes the
combination of <B>:anchor</B> and <B>:fill</B> that is used by <B><A HREF="./pack.n.html">pack</A></B>.
The default is the empty string, which causes the slave to be centered
in its cavity, at its requested size.
<P>
</DL>
<UL>
<P>
If any of the slaves are already managed by the geometry manager
then any unspecified options for them retain their previous values rather
than receiving default values.
</UL>
<DT><A NAME="M20">(<B>grid 'forget </B><I>slave </I>?<I>slave ...</I>?)</A><DD>
Removes each of the <I>slave</I>s from grid for its
master and unmaps their windows.
The slaves will no longer be managed by the grid geometry manager.
The configuration options for that window are forgotten, so that if the
slave is managed once more by the grid geometry manager, the initial
default settings are used.
<P>
<DT><A NAME="M21">(<B>grid 'info </B><I>slave</I>)</A><DD>
Returns a list whose elements are the current configuration state of
the slave given by <I>slave</I> in the same option-value form that
might be specified to <B>grid configure</B>.
The first two elements of the list are ``<B>:in </B><I>master</I>'' where
<I>master</I> is the slave's master.
<P>
<DT><A NAME="M22">(<B>grid 'location </B><I>master x y</I>)</A><DD>
Given <I>x</I> and <I>y</I> values in screen units relative to the master window,
the column and row number at that <I>x</I> and <I>y</I> location is returned.
For locations that are above or to the left of the grid, <B>-1</B> is returned.
<P>
<DT><A NAME="M23">(<B>grid 'propagate </B><I>master</I>)</A><DD>
<DT><A NAME="M24">(<B>grid 'propagate </B><I>master</I> <I>boolean</I>)</A><DD>
If <I>boolean</I> has a true boolean value
then propagation is enabled for <I>master</I>, which must be a window
name (see ``GEOMETRY PROPAGATION'' below).
If <I>boolean</I> has a false boolean value then propagation is
disabled for <I>master</I>.
In either of these cases an empty list is returned.
If <I>boolean</I> is omitted then the procedure returns <B>#f</B> or
<B>#t</B> to indicate whether propagation is currently enabled
for <I>master</I>.
Propagation is enabled by default.
<P>
<DT><A NAME="M25">(<B>grid 'rowconfigure</B> <I>master index </I>)</A><DD>
<DT><A NAME="M26">(<B>grid 'rowconfigure</B> <I>master index </I><I>:option value...</I>)</A><DD>
Query or set the row properties of the <I>index</I> row of the
geometry master, <I>master</I>.
The valid options are <B>:minsize</B>, <B>:weight</B> and <B>:pad</B>.
If one or more options are provided, then <I>index</I> may be given as
a list of row indeces to which the configuration options will operate on.
The <B>:minsize</B> option sets the minimum size, in screen units,
that will be permitted for this row.
The <B>:weight</B> option (an integer value)
sets the relative weight for apportioning
any extra spaces among
rows.
A weight of zero (0) indicates the row will not deviate from its requested
size. A row whose weight is two will grow at twice the rate as a row
of weight one when extra space is allocated to the layout.
The <B>:pad</B> option specifies the number of screen units that will be
added to the largest window contained completely in that row when the
grid geometry manager requests a size from the containing window.
If only an option is specified, with no value,
the current value of that option is returned.
If only the master window and index is specified, all the current settings
are returned in an list of &quot;:option value&quot; pairs.
<P>
<DT><A NAME="M27">(<B>grid 'remove </B><I>slave </I>?<I>slave ...</I>?)</A><DD>
Removes each of the <I>slave</I>s from grid for its
master and unmaps their windows.
The slaves will no longer be managed by the grid geometry manager.
However, the configuration options for that window are remembered,
so that if the
slave is managed once more by the grid geometry manager, the previous
values are retained.
<P>
<DT><A NAME="M28">(<B>grid 'size </B><I>master</I>)</A><DD>
Returns the size of the grid (in columns then rows) for <I>master</I>.
The size is determined either by the <I>slave</I> occupying the largest
row or column, or the largest column or row with a <B>minsize</B>,
<B>weight</B>, or <B>pad</B> that is non-zero.
<P>
<DT><A NAME="M29">(<B>grid 'slaves </B><I>master</I>)</A><DD>
<DT><A NAME="M30">(<B>grid 'slaves </B><I>master</I> <I>:option value</I>)</A><DD>
If no options are supplied, a list of all of the slaves in <I>master</I>
are returned, most recently managed first.
<I>Option</I> can be either <B>:row</B> or <B>:column</B> which
causes only the slaves in the row (or column) specified by <I>value</I>
to be returned.
<P>
</DL>
<H3><A NAME="M31">RELATIVE PLACEMENT</A></H3>
The <B>grid</B> procedure contains a limited set of capabilities that
permit layouts to be created without specifying the row and column
information for each slave. This permits slaves to be rearranged,
added, or removed without the need to explicitly specify row and
column information.
When no column or row information is specified for a <I>slave</I>,
default values are chosen for
<B>column</B>, <B>row</B>, <B>columnspan</B> and <B>rowspan</B>
at the time the <I>slave</I> is managed. The values are chosen
based upon the current layout of the grid, the position of the <I>slave</I>
relative to other <I>slave</I>s in the same grid procedure, and the presence
of the characters <B>:</B>, <B>^</B>, and <B>^</B> in <B>grid</B>
procedure where <I>slave</I> names are normally expected.
<P>
<DL>
<DT><A NAME="M32"><B>-</B></A><DD>
This increases the columnspan of the <I>slave</I> to the left. Several
<B>-</B>'s in a row will successively increase the columnspan. A <B>-</B>
may not follow a <B>^</B> or a <B>x</B>.
<P>
<DT><A NAME="M33"><B>x</B></A><DD>
This leaves an empty column between the <I>slave</I> on the left and
the <I>slave</I> on the right.
<P>
<DT><A NAME="M34"><B>^</B></A><DD>
This extends the <B>rowspan</B> of the <I>slave</I> above the <B>^</B>'s
in the grid. The number of <B>^</B>'s in a row must match the number of
columns spanned by the <I>slave</I> above it.
<P>
</DL>
<H3><A NAME="M35">THE GRID ALGORITHM</A></H3>
The grid geometry manager lays out its slaves in three steps.
In the first step, the minimum size needed to fit all of the slaves
is computed, then (if propagation is turned on), a request is made
of the master window to become that size.
In the second step, the requested size is compared against the actual size
of the master. If the sizes are different, then spaces is added to or taken
away from the layout as needed.
For the final step, each slave is positioned in its row(s) and column(s)
based on the setting of its <I>sticky</I> flag.
<P>
To compute the minimum size of a layout, the grid geometry manager
first looks at all slaves whose columnspan and rowspan values are one,
and computes the nominal size of each row or column to be either the
<I>minsize</I> for that row or column, or the sum of the <I>pad</I>ding
plus the size of the largest slave, whichever is greater. Then the
slaves whose rowspans or columnspans are greater than one are
examined. If a group of rows or columns need to be increased in size
in order to accommodate these slaves, then extra space is added to each
row or column in the group according to its <I>weight</I>. For each
group whose weights are all zero, the additional space is apportioned
equally.
<P>
For masters whose size is larger than the requested layout, the additional
space is apportioned according to the row and column weights. If all of
the weights are zero, the layout is centered within its master.
For masters whose size is smaller than the requested layout, space is taken
away from columns and rows according to their weights. However, once a
column or row shrinks to its minsize, its weight is taken to be zero.
If more space needs to be removed from a layout than would be permitted, as
when all the rows or columns are at there minimum sizes, the layout is
clipped on the bottom and right.
<H3><A NAME="M36">GEOMETRY PROPAGATION</A></H3>
The grid geometry manager normally computes how large a master must be to
just exactly meet the needs of its slaves, and it sets the
requested width and height of the master to these dimensions.
This causes geometry information to propagate up through a
window hierarchy to a top-level window so that the entire
sub-tree sizes itself to fit the needs of the leaf windows.
However, the <B>grid propagate</B> procedure may be used to
turn off propagation for one or more masters.
If propagation is disabled then grid will not set
the requested width and height of the master window.
This may be useful if, for example, you wish for a master
window to have a fixed size that you specify.
<H3><A NAME="M37">RESTRICTIONS ON MASTER WINDOWS</A></H3>
The master for each slave must either be the slave's parent
(the default) or a descendant of the slave's parent.
This restriction is necessary to guarantee that the
slave can be placed over any part of its master that is
visible without danger of the slave being clipped by its parent.
In addition, all slaves in one call to <B>grid</B> must have the same master.
<H3><A NAME="M38">STACKING ORDER</A></H3>
If the master for a slave is not its parent then you must make sure
that the slave is higher in the stacking order than the master.
Otherwise the master will obscure the slave and it will appear as
if the slave hasn't been managed correctly.
The easiest way to make sure the slave is higher than the master is
to create the master window first: the most recently created window
will be highest in the stacking order.
<H3><A NAME="M39">CREDITS</A></H3>
The <B>grid</B> command is based on ideas taken from the <I>GridBag</I>
geometry manager written by Doug. Stein, and the <B>blt_table</B> geometry
manager, written by George Howlett.
<H3><A NAME="M40">SEE ALSO</A></H3>
<B><A HREF="./pack.n.html">pack</A></B>, <B><A HREF="./place.n.html">place</A></B>
<P><IMG ALIGN=TOP SRC="./Img/line-red.gif"><P>
<A HREF=./STk-hlp.html><IMG ALIGN=BOTTOM SRC="./Img/RefBookBlue.gif"> Back to the <B>STk</B> main page</A>
</BODY></HTML>