Author: Peter Spjuth <peter.spjuth@space.se>
State: Final
Type: Project
Vote: Done
Created: 05-Aug-2003
Post-History:
Tcl-Version: 8.5
Abstract
This TIP proposes to add an anchor option to grid managers to control the behaviour of a grid where all weights are zero.
Rationale
Have you ever found yourself adding "-weight" to an unused row or column in a grid? That is usually the workaround to use when you have no "-weight" on any column but you don't want things to sit in the middle of the grid when the window is grown.
By adding an anchor option it lets the code directly reflect the intention of the programmer and it makes the code more maintainable since you can add and remove columns without having to update the dummy weight.
Shrinking a Grid
When growing a grid, the behaviour is rather simple. Follow the weights and when 0, follow the anchor.
When shrinking a grid without weight things get more interesting.
The previous behaviour of the grid is a bit inconsistent in that when grown it centers the slaves (as in anchor "center") and when shrunk it shows the upper left part (as in anchor "nw").
Thus, following the new anchor will not be backwardly compatible, even though I doubt it can be common for people to rely on that behaviour.
For shrinking a grid without weight there are three options.
Always clip the bottom/right. i.e. behave as now.
Clip according to anchor.
Try to shrink all columns/rows, and only clip when minsize stops further shrinking. (Clip according to anchor)
I think 2. makes more sense than 1., but it does mean a minor compatiblity breach. Also, with 2., behaviour 1. and 3. can be emulated but the other way around is harder.
With 2, there are also two choises how to break compatibility depending on the default anchor.
a With default anchor center. Anyone relying on the bottom/left clipping will find things clip all around. Potentially an important widget in the nw corner can end up outside.
b With default anchor nw. Anyone relying on the centering will find things ending up in the nw corner. Probably just a visual difference.
I can't see that any of those two are significantly worse than the other.
Finally, the question "what would you do if backwards compatiblity was not an aspect?" clearly answers "2b", leading to the specification in this TIP.
Specification
A new subcommand grid anchor is added. It is similar to grid propagate in that it configures an aspect of a grid manager.
The syntax is grid anchor master ?value? where value is a standard anchor value with nw as default.
Whenever there is extra space in the grid manager and all weights are zero, the layout is placed within its master according to the master's anchor value.
Whenever there is too little space in the grid manager and all weights are zero or all columns have reached their minimumn size, the layout is clipped according to the master's anchor value.
Shrink example
To clarify the shrinking options here is an example.
a: Current behaviour or, "1" with anchor "center".
b: "2" with anchor "center"
c: "2" with anchor "nw"
d: "3" with anchor "nw"
foreach top {.a .b .c .d} {
toplevel $top
frame $top.f
for {set row 0} {$row < 2} {incr row} {
for {set col 0} {$col < 4} {incr col} {
set w $top.f.b${row}x$col
button $w -text HejHopp
grid $w -row $row -column $col
}
}
}
# Current behaviour
pack .a.f -fill both -expand 1
# Anchor "center" with clipping
place .b.f -relx 0.5 -rely 0.5 -anchor center
wm geometry .b 150x50
# Anchor "nw" with clipping
pack .c.f -side top -anchor w
# Anchor "nw" with shrinking
pack .d.f -side top -anchor w
grid rowconfigure .d.f {0 1} -weight 1
grid columnconfigure .d.f {0 1 2 3} -weight 1
Reference Implementation
Not implemented yet.
Copyright
This document has been placed in the public domain.