OSDN Git Service

dc69deb321dd07fea869a52a4e0b4a1b67f455b8
[eos/base.git] / util / src / TclTk / tk8.6.12 / doc / grid.n
1 '\"
2 '\" Copyright (c) 1996 Sun Microsystems, Inc.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH grid n 8.5 Tk "Tk Built-In Commands"
8 .so man.macros
9 .BS
10 '\" Note:  do not modify the .SH NAME line immediately below!
11 .SH NAME
12 grid \- Geometry manager that arranges widgets in a grid
13 .SH SYNOPSIS
14 \fBgrid \fIoption arg \fR?\fIarg ...\fR?
15 .BE
16 .SH DESCRIPTION
17 .PP
18 The \fBgrid\fR command is used to communicate with the grid
19 geometry manager that arranges widgets in rows and columns inside
20 of another window, called the geometry container (or container window).
21 The \fBgrid\fR command can have any of several forms, depending
22 on the \fIoption\fR argument:
23 .TP
24 \fBgrid \fIwindow \fR?\fIwindow ...\fR? ?\fIoptions\fR?
25 .
26 If the first argument to \fBgrid\fR is suitable as the first window
27 argument to \fBgrid configure\fR, either a window name (any value
28 starting with \fB.\fR) or one of the characters \fBx\fR or \fB^\fR
29 (see the \fBRELATIVE PLACEMENT\fR section below), then the command is
30 processed in the same way as \fBgrid configure\fR.
31 .TP
32 \fBgrid anchor \fIwindow\fR ?\fIanchor\fR?
33 .
34 The anchor value controls how to place the grid within the container window
35 when no row/column has any weight.  See \fBTHE GRID ALGORITHM\fR below
36 for further details.  The default \fIanchor\fR is \fInw\fR.
37 .TP
38 \fBgrid bbox \fIwindow\fR ?\fIcolumn row\fR? ?\fIcolumn2 row2\fR?
39 .
40 With no arguments,
41 the bounding box (in pixels) of the grid is returned.
42 The return value consists of 4 integers.  The first two are the pixel
43 offset from the container window (x then y) of the top-left corner of the
44 grid, and the second two integers are the width and height of the grid,
45 also in pixels.  If a single \fIcolumn\fR and \fIrow\fR is specified on
46 the command line, then the bounding box for that cell is returned, where the
47 top left cell is numbered from zero.  If both \fIcolumn\fR and \fIrow\fR
48 arguments are specified, then the bounding box spanning the rows and columns
49 indicated is returned.
50 .TP
51 \fBgrid columnconfigure \fIwindow index \fR?\fI\-option value...\fR?
52 .
53 Query or set the column properties of the \fIindex\fR column of the
54 geometry container, \fIwindow\fR.
55 The valid options are \fB\-minsize\fR, \fB\-weight\fR, \fB\-uniform\fR
56 and \fB\-pad\fR.
57 If one or more options are provided, then \fIindex\fR may be given as
58 a list of column indices to which the configuration options will operate on.
59 Indices may be integers, window names or the keyword \fIall\fR. For \fIall\fR
60 the options apply to all columns currently occupied be content windows. For
61 a window name, that window must be a content of this container and the options
62 apply to all columns currently occupied be the content.
63 The \fB\-minsize\fR option sets the minimum size, in screen units,
64 that will be permitted for this column.
65 The \fB\-weight\fR option (an integer value)
66 sets the relative weight for apportioning
67 any extra spaces among
68 columns.
69 A weight of zero (0) indicates the column will not deviate from its requested
70 size.  A column whose weight is two will grow at twice the rate as a column
71 of weight one when extra space is allocated to the layout.
72 The \fB\-uniform\fR option, when a non-empty value is supplied, places
73 the column in a \fIuniform group\fR with other columns that have the
74 same value for \fB\-uniform\fR.  The space for columns belonging to a
75 uniform group is allocated so that their sizes are always in strict
76 proportion to their \fB\-weight\fR values.  See
77 \fBTHE GRID ALGORITHM\fR below for further details.
78 The \fB\-pad\fR option specifies the number of screen units that will be
79 added to the largest window contained completely in that column when the
80 grid geometry manager requests a size from the containing window.
81 If only an option is specified, with no value,
82 the current value of that option is returned.
83 If only the container window and index is specified, all the current settings
84 are returned in a list of
85 .QW "\-option value"
86 pairs.
87 .TP
88 \fBgrid configure \fIwindow \fR?\fIwindow ...\fR? ?\fIoptions\fR?
89 .
90 The arguments consist of the names of one or more content windows
91 followed by pairs of arguments that specify how
92 to manage the content.
93 The characters \fB\-\fR,  \fBx\fR and \fB^\fR,
94 can be specified instead of a window name to alter the default
95 location of a \fIwindow\fR, as described in the \fBRELATIVE PLACEMENT\fR
96 section, below.
97 The following options are supported:
98 .RS
99 .TP
100 \fB\-column \fIn\fR
101 .
102 Insert the window so that it occupies the \fIn\fRth column in the grid.
103 Column numbers start with 0.  If this option is not supplied, then the
104 window is arranged just to the right of previous window specified on this
105 call to \fBgrid\fR, or column
106 .QW 0
107 if it is the first window.  For each
108 \fBx\fR that immediately precedes the \fIwindow\fR, the column position
109 is incremented by one.  Thus the \fBx\fR represents a blank column
110 for this row in the grid.
111 .TP
112 \fB\-columnspan \fIn\fR
113 .
114 Insert the window so that it occupies \fIn\fR columns in the grid.
115 The default is one column, unless the window name is followed by a
116 \fB\-\fR, in which case the columnspan is incremented once for each immediately
117 following \fB\-\fR.
118 .TP
119 \fB\-in \fIcontainer\fR
120 .
121 Insert the window(s) in the container
122 window given by \fIcontainer\fR.  The default is the first window's
123 parent window.
124 .TP
125 \fB\-ipadx \fIamount\fR
126 .
127 The \fIamount\fR specifies how much horizontal internal padding to
128 leave on each side of the content.  This is space is added
129 inside the content border.
130 The \fIamount\fR must be a valid screen distance, such as \fB2\fR or \fB.5c\fR.
131 It defaults to 0.
132 .TP
133 \fB\-ipady \fIamount\fR
134 .
135 The \fIamount\fR specifies how much vertical internal padding to
136 leave on the top and bottom of the content.
137 This space is added inside the content border.
138 The \fIamount\fR  defaults to 0.
139 .TP
140 \fB\-padx \fIamount\fR
141 .
142 The \fIamount\fR specifies how much horizontal external padding to
143 leave on each side of the content, in screen units.
144 \fIAmount\fR may be a list
145 of two values to specify padding for left and right separately.
146 The \fIamount\fR defaults to 0.
147 This space is added outside the content border.
148 .TP
149 \fB\-pady \fIamount\fR
150 .
151 The \fIamount\fR specifies how much vertical external padding to
152 leave on the top and bottom of the content, in screen units.
153 \fIAmount\fR may be a list
154 of two values to specify padding for top and bottom separately.
155 The \fIamount\fR defaults to 0.
156 This space is added outside the content border.
157 .TP
158 \fB\-row \fIn\fR
159 .
160 Insert the content so that it occupies the \fIn\fRth row in the grid.
161 Row numbers start with 0.  If this option is not supplied, then the
162 content is arranged on the same row as the previous content specified on this
163 call to \fBgrid\fR, or the next row after the highest occupied row
164 if this is the first content.
165 .TP
166 \fB\-rowspan \fIn\fR
167 .
168 Insert the content so that it occupies \fIn\fR rows in the grid.
169 The default is one row.  If the next \fBgrid\fR command contains
170 \fB^\fR characters instead of \fIcontent\fR that line up with the columns
171 of this \fIcontent\fR, then the \fBrowspan\fR of this \fIcontent\fR is
172 extended by one.
173 .TP
174 \fB\-sticky \fIstyle\fR
175 .
176 If a content's cell is larger than its requested dimensions, this
177 option may be used to position (or stretch) the content within its cell.
178 \fIStyle\fR  is a string that contains zero or more of the characters
179 \fBn\fR, \fBs\fR, \fBe\fR or \fBw\fR.
180 The string can optionally contains spaces or
181 commas, but they are ignored.  Each letter refers to a side (north, south,
182 east, or west) that the content will
183 .QW stick
184 to.  If both \fBn\fR and \fBs\fR (or \fBe\fR and \fBw\fR) are
185 specified, the content will be stretched to fill the entire
186 height (or width) of its cavity.  The \fB\-sticky\fR option subsumes the
187 combination of \fB\-anchor\fR and \fB\-fill\fR that is used by \fBpack\fR.
188 The default is
189 .QW "" ,
190 which causes the content to be centered in its cavity, at its requested size.
191 .LP
192 If any of the content is already managed by the geometry manager
193 then any unspecified options for them retain their previous values rather
194 than receiving default values.
195 .RE
196 .TP
197 \fBgrid forget \fIwindow \fR?\fIwindow ...\fR?
198 .
199 Removes each of the \fIwindow\fRs from grid for its
200 container and unmaps their windows.
201 The content will no longer be managed by the grid geometry manager.
202 The configuration options for that window are forgotten, so that if the
203 window is managed once more by the grid geometry manager, the initial
204 default settings are used.
205 .TP
206 \fBgrid info \fIwindow\fR
207 .
208 Returns a list whose elements are the current configuration state of
209 the content given by \fIwindow\fR in the same option-value form that
210 might be specified to \fBgrid configure\fR.
211 The first two elements of the list are
212 .QW "\fB\-in \fIcontainer\fR"
213 where \fIcontainer\fR is the windows's container window.
214 .TP
215 \fBgrid location \fIwindow x y\fR
216 .
217 Given  \fIx\fR and \fIy\fR values in screen units relative to the container window,
218 the column and row number at that \fIx\fR and \fIy\fR location is returned.
219 For locations that are above or to the left of the grid, \fB\-1\fR is
220 returned.
221 .TP
222 \fBgrid propagate \fIwindow\fR ?\fIboolean\fR?
223 .
224 If \fIboolean\fR has a true boolean value such as \fB1\fR or \fBon\fR
225 then propagation is enabled for \fIwindow\fR, which must be a window
226 name (see \fBGEOMETRY PROPAGATION\fR below).
227 If \fIboolean\fR has a false boolean value then propagation is
228 disabled for \fIwindow\fR.
229 In either of these cases an empty string is returned.
230 If \fIboolean\fR is omitted then the command returns \fB0\fR or
231 \fB1\fR to indicate whether propagation is currently enabled
232 for \fIwindow\fR.
233 Propagation is enabled by default.
234 .TP
235 \fBgrid rowconfigure \fIwindow index \fR?\fI\-option value...\fR?
236 .
237 Query or set the row properties of the \fIindex\fR row of the
238 geometry window, \fIwindow\fR.
239 The valid options are \fB\-minsize\fR, \fB\-weight\fR, \fB\-uniform\fR
240 and \fB\-pad\fR.
241 If one or more options are provided, then \fIindex\fR may be given as
242 a list of row indices to which the configuration options will operate on.
243 Indices may be integers, window names or the keyword \fIall\fR. For \fIall\fR
244 the options apply to all rows currently occupied by content windows. For
245 a window name, that window must be a content window of this container and the options
246 apply to all rows currently occupied by the container window.
247 The \fB\-minsize\fR option sets the minimum size, in screen units,
248 that will be permitted for this row.
249 The \fB\-weight\fR option (an integer value)
250 sets the relative weight for apportioning
251 any extra spaces among
252 rows.
253 A weight of zero (0) indicates the row will not deviate from its requested
254 size.  A row whose weight is two will grow at twice the rate as a row
255 of weight one when extra space is allocated to the layout.
256 The \fB\-uniform\fR option, when a non-empty value is supplied, places
257 the row in a \fIuniform group\fR with other rows that have the
258 same value for \fB\-uniform\fR.  The space for rows belonging to a
259 uniform group is allocated so that their sizes are always in strict
260 proportion to their \fB\-weight\fR values.  See
261 \fBTHE GRID ALGORITHM\fR below for further details.
262 The \fB\-pad\fR option specifies the number of screen units that will be
263 added to the largest window contained completely in that row when the
264 grid geometry manager requests a size from the containing window.
265 If only an option is specified, with no value,
266 the current value of that option is returned.
267 If only the container window and index is specified, all the current settings
268 are returned in a list of
269 .QW "-option value"
270 pairs.
271 .TP
272 \fBgrid remove \fIwindow \fR?\fIwindow ...\fR?
273 .
274 Removes each of the \fIwindow\fRs from grid for its
275 container and unmaps their windows.
276 The content will no longer be managed by the grid geometry manager.
277 However, the configuration options for that window are remembered,
278 so that if the content window is managed once more by the grid
279 geometry manager, the previous values are retained.
280 .TP
281 \fBgrid size \fIcontainer\fR
282 .
283 Returns the size of the grid (in columns then rows) for \fIcontainer\fR.
284 The size is determined either by the \fIcontent\fR occupying the largest
285 row or column, or the largest column or row with a \fB\-minsize\fR,
286 \fB\-weight\fR, or \fB\-pad\fR that is non-zero.
287 .TP
288 \fBgrid slaves \fIwindow\fR ?\fI\-option value\fR?
289 .
290 If no options are supplied, a list of all of the content in \fIwindow\fR
291 are returned, most recently managed first.
292 \fIOption\fR can be either \fB\-row\fR or \fB\-column\fR which
293 causes only the content in the row (or column) specified by \fIvalue\fR
294 to be returned.
295 .VS "TIP 581"
296 .TP
297 \fBgrid content \fIwindow\fR ?\fI\-option value\fR?
298 .
299 Synonym for \fBgrid slaves \fIwindow\fR ?\fI\-option value\fR?.
300 .VE "TIP 581"
301 .SH "RELATIVE PLACEMENT"
302 .PP
303 The \fBgrid\fR command contains a limited set of capabilities that
304 permit layouts to be created without specifying the row and column
305 information for each content.  This permits content to be rearranged,
306 added, or removed without the need to explicitly specify row and
307 column information.
308 When no column or row information is specified for a \fIcontent\fR,
309 default values are chosen for
310 \fB\-column\fR, \fB\-row\fR, \fB\-columnspan\fR and \fB\-rowspan\fR
311 at the time the \fIcontent\fR is managed. The values are chosen
312 based upon the current layout of the grid, the position of the \fIcontent\fR
313 relative to other \fIcontent\fRs in the same grid command, and the presence
314 of the characters \fB\-\fR, \fBx\fR, and \fB^\fR in \fBgrid\fR
315 command where \fIcontent\fR names are normally expected.
316 .RS
317 .TP
318 \fB\-\fR
319 .
320 This increases the \fB\-columnspan\fR of the \fIcontent\fR to the left.  Several
321 \fB\-\fR's in a row will successively increase the number of columns spanned. A \fB\-\fR
322 may not follow a \fB^\fR or a \fBx\fR, nor may it be the first \fIcontent\fR
323 argument to \fBgrid configure\fR.
324 .TP
325 \fBx\fR
326 .
327 This leaves an empty column between the \fIcontent\fR on the left and
328 the \fIcontent\fR on the right.
329 .TP
330 \fB^\fR
331 .
332 This extends the \fB\-rowspan\fR of the \fIcontent\fR above the \fB^\fR's
333 in the grid.  The number of \fB^\fR's in a row must match the number of
334 columns spanned by the \fIcontent\fR above it.
335 .RE
336 .SH "THE GRID ALGORITHM"
337 .PP
338 The grid geometry manager lays out its content in three steps.
339 In the first step, the minimum size needed to fit all of the content
340 is computed, then (if propagation is turned on), a request is made
341 of the container window to become that size.
342 In the second step, the requested size is compared against the actual size
343 of the container.  If the sizes are different, then spaces is added to or taken
344 away from the layout as needed.
345 For the final step, each content is positioned in its row(s) and column(s)
346 based on the setting of its \fIsticky\fR flag.
347 .PP
348 To compute the minimum size of a layout, the grid geometry manager
349 first looks at all content whose \fB\-columnspan\fR and \fB\-rowspan\fR values are one,
350 and computes the nominal size of each row or column to be either the
351 \fIminsize\fR for that row or column, or the sum of the \fIpad\fRding
352 plus the size of the largest content, whichever is greater.  After that
353 the rows or columns in each uniform group adapt to each other.  Then
354 the content whose row-spans or column-spans are greater than one are
355 examined.  If a group of rows or columns need to be increased in size
356 in order to accommodate these content, then extra space is added to each
357 row or column in the group according to its \fIweight\fR.  For each
358 group whose weights are all zero, the additional space is apportioned
359 equally.
360 .PP
361 When multiple rows or columns belong to a uniform group, the space
362 allocated to them is always in proportion to their weights. (A weight
363 of zero is considered to be 1.)  In other words, a row or column
364 configured with \fB\-weight 1 \-uniform a\fR will have exactly the same
365 size as any other row or column configured with \fB\-weight 1 \-uniform
366 a\fR.  A row or column configured with \fB\-weight 2 \-uniform b\fR will
367 be exactly twice as large as one that is configured with \fB\-weight 1
368 \-uniform b\fR.
369 .PP
370 More technically, each row or column in the group will have a size
371 equal to \fIk*weight\fR for some constant \fIk\fR.  The constant
372 \fIk\fR is chosen so that no row or column becomes smaller than its
373 minimum size.  For example, if all rows or columns in a group have the
374 same weight, then each row or column will have the same size as the
375 largest row or column in the group.
376 .PP
377 For containers whose size is larger than the requested layout, the additional
378 space is apportioned according to the row and column weights.  If all of
379 the weights are zero, the layout is placed within its container according to
380 the \fIanchor\fR value.
381 For containers whose size is smaller than the requested layout, space is taken
382 away from columns and rows according to their weights.  However, once a
383 column or row shrinks to its minsize, its weight is taken to be zero.
384 If more space needs to be removed from a layout than would be permitted, as
385 when all the rows or columns are at their minimum sizes, the layout is
386 placed and clipped according to the \fIanchor\fR value.
387 .SH "GEOMETRY PROPAGATION"
388 .PP
389 The grid geometry manager normally computes how large a container must be to
390 just exactly meet the needs of its content, and it sets the
391 requested width and height of the container to these dimensions.
392 This causes geometry information to propagate up through a
393 window hierarchy to a top-level window so that the entire
394 sub-tree sizes itself to fit the needs of the leaf windows.
395 However, the \fBgrid propagate\fR command may be used to
396 turn off propagation for one or more containers.
397 If propagation is disabled then grid will not set
398 the requested width and height of the container window.
399 This may be useful if, for example, you wish for a container
400 window to have a fixed size that you specify.
401 .SH "RESTRICTIONS ON CONTAINER WINDOWS"
402 .PP
403 The container for each content must either be the content's parent
404 (the default) or a descendant of the content's parent.
405 This restriction is necessary to guarantee that the
406 content can be placed over any part of its container that is
407 visible without danger of the content being clipped by its parent.
408 In addition, all content in one call to \fBgrid\fR must have the same container.
409 .SH "STACKING ORDER"
410 .PP
411 If the container for a content is not its parent then you must make sure
412 that the content is higher in the stacking order than the container.
413 Otherwise the container will obscure the content and it will appear as
414 if the content has not been managed correctly.
415 The easiest way to make sure the content is higher than the container is
416 to create the container window first:  the most recently created window
417 will be highest in the stacking order.
418 .SH CREDITS
419 .PP
420 The \fBgrid\fR command is based on ideas taken from the \fIGridBag\fR
421 geometry manager written by Doug. Stein, and the \fBblt_table\fR geometry
422 manager, written by George Howlett.
423 .SH EXAMPLES
424 .PP
425 A toplevel window containing a text widget and two scrollbars:
426 .PP
427 .CS
428 # Make the widgets
429 toplevel .t
430 text .t.txt \-wrap none \-xscroll {.t.h set} \-yscroll {.t.v set}
431 scrollbar .t.v \-orient vertical   \-command {.t.txt yview}
432 scrollbar .t.h \-orient horizontal \-command {.t.txt xview}
433
434 # Lay them out
435 \fBgrid\fR .t.txt .t.v \-sticky nsew
436 \fBgrid\fR .t.h        \-sticky nsew
437
438 # Tell the text widget to take all the extra room
439 \fBgrid rowconfigure\fR    .t .t.txt \-weight 1
440 \fBgrid columnconfigure\fR .t .t.txt \-weight 1
441 .CE
442 .PP
443 Three widgets of equal width, despite their different
444 .QW natural
445 widths:
446 .PP
447 .CS
448 button .b \-text "Foo"
449 entry .e \-textvariable foo ; set foo "Hello World!"
450 label .l \-text "This is a fairly long piece of text"
451
452 \fBgrid\fR .b .e .l \-sticky ew
453 \fBgrid columnconfigure\fR . "all" \-uniform allTheSame
454 .CE
455 .SH "SEE ALSO"
456 pack(n), place(n)
457 .SH KEYWORDS
458 geometry manager, location, grid, cell, propagation, size, pack
459 '\" Local Variables:
460 '\" mode: nroff
461 '\" End: