\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#146: Add Overall Anchoring to the Grid Geometry Manager}
\date{August 05, 2003}
\author{Peter Spjuth}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#146}&\textbf{Add Overall Anchoring to the Grid Geometry Manager}\\\hline
Author&

Peter Spjuth \tipmail{peter.spjuth}{space.se}
\\
Created&Tuesday, \(\text{5}^{\text{th}}\) August 2003\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.16 $\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

This TIP proposes to add an anchor option to grid managers to control the behaviour of a grid where all weights are zero.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{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.

\section{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.
\begin{enumerate}
\item{}
Always clip the bottom/right. i.e. behave as now.
\setcounter{enumi}{1}
\item{}
Clip according to anchor.
\setcounter{enumi}{2}
\item{}
Try to shrink all columns/rows, and only clip when minsize stops further shrinking. (Clip according to anchor)
\end{enumerate}

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.
\begin{enumerate}
\setcounter{enumi}{1}
\item{}
a With default anchor \textit{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.
\setcounter{enumi}{1}
\item{}
b With default anchor \textit{nw}. Anyone relying on the centering will find things ending up in the nw corner. Probably just a visual difference.
\end{enumerate}

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.

\section{Specification}

A new subcommand \textit{grid anchor} is added. It is similar to \textit{grid propagate} in that it configures an aspect of a grid manager.

The syntax is \textit{grid anchor master ?value?} where \textit{value} is a standard anchor value with \textit{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.

\section{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''
\begingroup\small\begin{verbatim}
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
\end{verbatim}
\endgroup

\section{Reference Implementation}

Not implemented yet.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
