This is not necessarily the current version of this TIP.
| TIP: | 37 |
| Title: | Uniform Rows and Columns in Grid |
| Version: | $Revision: 1.2 $ |
| Author: | Peter Spjuth <peter dot spjuth at space dot se> |
| State: | Draft |
| Type: | Project |
| Tcl-Version: | 8.4 |
| Vote: | Pending |
| Created: | Tuesday, 19 June 2001 |
This TIP proposes to add a -uniform option to grid rowconfigure and grid columnconfigure so as to make it easier to create layouts where cells are constrained to have identical dimensions.
The geometry managers in Tk are very powerful and can do most things needed to layout a GUI. One thing that is tricky to do though is to put widgets in rows or columns of the same width. This would be useful for example to layout a row of buttons symmetrically. This could easily be done with the grid manager if an additional option is added.
Anywhere column is used below, the same applies to row too.
A new option, -uniform, is added to grid columnconfigure. The option takes an arbitrary string, the default value being the empty string. Any column with a non-empty value will be grouped with other columns with the same value. Each column in a group will get the size k*-weight (in this aspect a -weight value of 0 is used as 1) , where k is set so that no column becomes smaller. E.g., if all columns in a group have the same -weight they will all get the size of the largest member.
In the grid algorithm -uniform and -weight will be used in the calculation of the requested size, but for the distribution of extra size only -weight will be considered.
To only consider -weight in the extra size distribution is mainly a matter of simplicity. It gives a simpler algorithm that is both easier to explain to the user and to code.
To uphold the uniform property it would be needed to force any zero -weight value in a group where any non-zero -weight exists to be set to one before doing the resize calculations. A bit complicated and the only benefit for the user would be to only have to specify -weight for one column in a group. But in practice this is hardly no gain at all since a typical usage looks like this:
grid columnconfigure . {0 1 2} -uniform a -weight 1
I'm not sure if someone would have a use for the effect you would get by mixing zero and non-zero weights in a group but this leaves you the freedom to do so.
A quick try shows that this is fairly straightforward to implement. The memory cost for the change is a Tk_Uid field in the column slot structure to hold the option, and the CPU overhead is small for a grid that don't use the option.
This document has been placed in the public domain.
This is not necessarily the current version of this TIP.