grid.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:18k
- '"
- '" Copyright (c) 1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: grid.n,v 1.5.4.3 2004/10/29 07:52:08 dkf Exp $
- '"
- .so man.macros
- .TH grid n 8.4 Tk "Tk Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- grid - Geometry manager that arranges widgets in a grid
- .SH SYNOPSIS
- fBgrid fIoption arg fR?fIarg ...fR?
- .BE
- .SH DESCRIPTION
- .PP
- The fBgridfR command 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 fBgridfR command can have any of several forms, depending
- on the fIoptionfR argument:
- .TP
- fBgrid fIslave fR?fIslave ...fR? ?fIoptionsfR?
- If the first argument to fBgridfR is suitable as the first slave
- argument to fBgrid configurefR, either a window name (any value
- starting with fB.fP) or one of the characters fBxfP or fB^fP
- (see the fBRELATIVE PLACEMENTfR section below), then the command is
- processed in the same way as fBgrid configurefR.
- .TP
- fBgrid bbox fImasterfR ?fIcolumn rowfR? ?fIcolumn2 row2fR?
- 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 fIcolumnfP and fIrowfP 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 fIcolumnfP and fIrowfP
- arguments are specified, then the bounding box spanning the rows and columns
- indicated is returned.
- .TP
- fBgrid columnconfigure fImaster index fR?fI-option value...fR?
- Query or set the column properties of the fIindexfP column of the
- geometry master, fImasterfP.
- .VS 8.4
- The valid options are fB-minsizefP, fB-weightfP, fB-uniformfP
- and fB-padfP.
- .VE 8.4
- If one or more options are provided, then fIindexfP may be given as
- a list of column indices to which the configuration options will operate on.
- The fB-minsizefP option sets the minimum size, in screen units,
- that will be permitted for this column.
- The fB-weightfP 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.
- .VS 8.4
- The fB-uniformfP option, when a non-empty value is supplied, places
- the column in a fIuniform groupfP with other columns that have the
- same value for fB-uniformfP. The space for columns belonging to a
- uniform group is allocated so that their sizes are always in strict
- proportion to their fB-weightfP values. See
- fBTHE GRID ALGORITHMfR below for further details.
- .VE 8.4
- The fB-padfP 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 a list of "-option value" pairs.
- .TP
- fBgrid configure fIslave fR?fIslave ...fR? ?fIoptionsfR?
- 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 fB-fP, fBxfP and fB^fP,
- can be specified instead of a window name to alter the default
- location of a fIslavefP, as described in the fBRELATIVE PLACEMENTfR
- section, below.
- The following options are supported:
- .RS
- .TP
- fB-column fInfR
- Insert the slave so that it occupies the fInfPth 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 fIgridfP, or column "0" if it is the first slave. For each
- fBxfP that immediately precedes the fIslavefP, the column position
- is incremented by one. Thus the fBxfP represents a blank column
- for this row in the grid.
- .TP
- fB-columnspan fInfR
- Insert the slave so that it occupies fInfP columns in the grid.
- The default is one column, unless the window name is followed by a
- fB-fP, in which case the columnspan is incremented once for each immediately
- following fB-fP.
- .TP
- fB-in fIotherfR
- Insert the slave(s) in the master
- window given by fIotherfR. The default is the first slave's
- parent window.
- .TP
- fB-ipadx fIamountfR
- The fIamountfR 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 fIamountfR must be a valid screen distance, such as fB2fR or fB.5cfR.
- It defaults to 0.
- .TP
- fB-ipady fIamountfR
- The fIamountfR specifies how much vertical internal padding to
- leave on the top and bottom of the slave(s).
- This space is added inside the slave(s) border.
- The fIamountfR defaults to 0.
- .TP
- fB-padx fIamountfR
- The fIamountfR specifies how much horizontal external padding to
- leave on each side of the slave(s), in screen units.
- fIAmountfR may be a list
- of two values to specify padding for left and right separately.
- The fIamountfR defaults to 0.
- This space is added outside the slave(s) border.
- .TP
- fB-pady fIamountfR
- The fIamountfR specifies how much vertical external padding to
- leave on the top and bottom of the slave(s), in screen units.
- fIAmountfR may be a list
- of two values to specify padding for top and bottom separately.
- The fIamountfR defaults to 0.
- This space is added outside the slave(s) border.
- .TP
- fB-row fInfR
- Insert the slave so that it occupies the fInfPth 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 fBgridfP, or the first unoccupied row if this is the first slave.
- .TP
- fB-rowspan fInfR
- Insert the slave so that it occupies fInfP rows in the grid.
- The default is one row. If the next fBgridfP command contains
- fB^fP characters instead of fIslavesfP that line up with the columns
- of this fIslavefP, then the fBrowspanfP of this fIslavefP is
- extended by one.
- .TP
- fB-sticky fIstylefR
- 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.
- fIStylefR is a string that contains zero or more of the characters
- fBnfP, fBsfP, fBefP or fBwfP.
- 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 "stick" to. If both fBnfP and fBsfP (or
- fBefP and fBwfP) are specified, the slave will be stretched to fill the entire
- height (or width) of its cavity. The fBstickyfP option subsumes the
- combination of fB-anchorfP and fB-fillfP that is used by fBpackfP.
- The default is fB{}fP, which causes the slave to be centered in its cavity,
- at its requested size.
- .LP
- 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.
- .RE
- .TP
- fBgrid forget fIslave fR?fIslave ...fR?
- Removes each of the fIslavefRs 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.
- .TP
- fBgrid info fIslavefR
- Returns a list whose elements are the current configuration state of
- the slave given by fIslavefR in the same option-value form that
- might be specified to fBgrid configurefR.
- The first two elements of the list are ``fB-in fImasterfR'' where
- fImasterfR is the slave's master.
- .TP
- fBgrid location fImaster x yfR
- Given fIxfP and fIyfP values in screen units relative to the master window,
- the column and row number at that fIxfP and fIyfP location is returned.
- For locations that are above or to the left of the grid, fB-1fP is returned.
- .TP
- fBgrid propagate fImasterfR ?fIbooleanfR?
- If fIbooleanfR has a true boolean value such as fB1fR or fBonfR
- then propagation is enabled for fImasterfR, which must be a window
- name (see fBGEOMETRY PROPAGATIONfR below).
- If fIbooleanfR has a false boolean value then propagation is
- disabled for fImasterfR.
- In either of these cases an empty string is returned.
- If fIbooleanfR is omitted then the command returns fB0fR or
- fB1fR to indicate whether propagation is currently enabled
- for fImasterfR.
- Propagation is enabled by default.
- .TP
- fBgrid rowconfigure fImaster index fR?fI-option value...fR?
- Query or set the row properties of the fIindexfP row of the
- geometry master, fImasterfP.
- .VS 8.4
- The valid options are fB-minsizefP, fB-weightfP, fB-uniformfP
- and fB-padfP.
- .VE 8.4
- If one or more options are provided, then fIindexfP may be given as
- a list of row indices to which the configuration options will operate on.
- The fB-minsizefP option sets the minimum size, in screen units,
- that will be permitted for this row.
- The fB-weightfP 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.
- .VS 8.4
- The fB-uniformfP option, when a non-empty value is supplied, places
- the row in a fIuniform groupfP with other rows that have the
- same value for fB-uniformfP. The space for rows belonging to a
- uniform group is allocated so that their sizes are always in strict
- proportion to their fB-weightfP values. See
- fBTHE GRID ALGORITHMfR below for further details.
- .VE 8.4
- The fB-padfP 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 a list of "-option value" pairs.
- .TP
- fBgrid remove fIslave fR?fIslave ...fR?
- Removes each of the fIslavefRs 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.
- .TP
- fBgrid size fImasterfR
- Returns the size of the grid (in columns then rows) for fImasterfP.
- The size is determined either by the fIslavefP occupying the largest
- row or column, or the largest column or row with a fBminsizefP,
- fBweightfP, or fBpadfP that is non-zero.
- .TP
- fBgrid slaves fImasterfR ?fI-option valuefR?
- If no options are supplied, a list of all of the slaves in fImasterfR
- are returned, most recently manages first.
- fIOptionfP can be either fB-rowfP or fB-columnfP which
- causes only the slaves in the row (or column) specified by fIvaluefP
- to be returned.
- .SH "RELATIVE PLACEMENT"
- .PP
- The fBgridfP command 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 fIslavefP,
- default values are chosen for
- fBcolumnfP, fBrowfP, fBcolumnspanfP and fBrowspanfP
- at the time the fIslavefP is managed. The values are chosen
- based upon the current layout of the grid, the position of the fIslavefP
- relative to other fIslavefPs in the same grid command, and the presence
- of the characters fB-fP, fBxfP, and fB^fP in fBgridfP
- command where fIslavefP names are normally expected.
- .RS
- .TP
- fB-fP
- This increases the columnspan of the fIslavefP to the left. Several
- fB-fP's in a row will successively increase the columnspan. A fB-fP
- may not follow a fB^fP or a fBxfP, nor may it be the first fIslavefP
- argument to fBgrid configurefR.
- .TP
- fBxfP
- This leaves an empty column between the fIslavefP on the left and
- the fIslavefP on the right.
- .TP
- fB^fP
- This extends the fBrowspanfP of the fIslavefP above the fB^fP's
- in the grid. The number of fB^fP's in a row must match the number of
- columns spanned by the fIslavefP above it.
- .RE
- .SH "THE GRID ALGORITHM"
- .PP
- 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 fIstickyfP flag.
- .PP
- 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
- fIminsizefP for that row or column, or the sum of the fIpadfPding
- plus the size of the largest slave, whichever is greater. After that
- the rows or columns in each uniform group adapt to each other. 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 fIweightfP. For each
- group whose weights are all zero, the additional space is apportioned
- equally.
- .PP
- When multiple rows or columns belong to a uniform group, the space
- allocated to them is always in proportion to their weights. (A weight
- of zero is considered to be 1.) In other words, a row or column
- configured with fB-weight 1 -uniform afP will have exactly the same
- size as any other row or column configured with fB-weight 1 -uniform
- afP. A row or column configured with fB-weight 2 -uniform bfR will
- be exactly twice as large as one that is configured with fB-weight 1
- -uniform bfP.
- .PP
- More technically, each row or column in the group will have a size
- equal to fIk*weightfP for some constant fIkfP. The constant
- fIkfP is chosen so that no row or column becomes smaller than its
- minimum size. For example, if all rows or columns in a group have the
- same weight, then each row or column will have the same size as the
- largest row or column in the group.
- .PP
- 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 their minimum sizes, the layout is
- clipped on the bottom and right.
- .SH "GEOMETRY PROPAGATION"
- .PP
- 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 fBgrid propagatefR command 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.
- .SH "RESTRICTIONS ON MASTER WINDOWS"
- .PP
- 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 fBgridfP must have the same master.
- .SH "STACKING ORDER"
- .PP
- 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.
- .SH CREDITS
- .PP
- The fBgridfP command is based on ideas taken from the fIGridBagfP
- geometry manager written by Doug. Stein, and the fBblt_tablefR geometry
- manager, written by George Howlett.
- .SH EXAMPLES
- A toplevel window containing a text widget and two scrollbars:
- .CS
- # Make the widgets
- toplevel .t
- text .t.txt -wrap none -xscroll {.t.h set} -yscroll {.t.v set}
- scrollbar .t.v -orient vertical -command {.t.txt xview}
- scrollbar .t.h -orient horizontal -command {.t.txt xview}
- # Lay them out
- fBgridfR .t.txt .t.v -sticky nsew
- fBgridfR .t.h -sticky nsew
- # Tell the text widget to take all the extra room
- fBgrid rowconfigurefR .t 0 -weight 1
- fBgrid columnconfigurefR .t 0 -weight 1
- .CE
- .PP
- Three widgets of equal width, despite their different "natural" widths:
- .CS
- button .b -text "Foo"
- entry .e -variable foo
- label .l -text "This is a fairly long piece of text"
- fBgridfR .b .e .l -sticky ew
- fBgrid columnconfigurefR . {0 1 2} -uniform allTheSame
- .CE
- .SH "SEE ALSO"
- pack(n), place(n)
- .SH KEYWORDS
- geometry manager, location, grid, cell, propagation, size, pack