GRIDPLUS2 - Resizable Windows
Home Reference Manpage Examples Download License Contact

GRIDPLUS Resizing

GRIDPLUS has facilities to control the resizing behaviour of windows.

Note: At release 2.11, GRIDPLUS has a new syntax for specifying resize behaviour. It is clear to me now that the previous design was not good for anything other than very simple cases - Many appologies!! For backward compatibility the old syntax is still supported (Documented here).

By default, GRIDPLUS creates a window with the minimum size neccessary to contain the required widgets with the requested sizes. Resizing this (as it stands) is unlikely to produce the desired result. In partucular, resizing the window to a smaller size is likely to result in a very messy display. To see the result, enable resizing by putting "wm resizable . 1 1" at the begining of your application. Then try resizing, both larger and smaller. The result is probably not very pretty.

To make resizing work properly, additional work is required to specify what is to happen to the widget positions and sizes when the window is resized. This is achieved using the new layout options and the gridplus pack command.

Many window layouts do not lend themselves to useful resizing, but those with text, tree and tablelist are most likely to benefit from resizing (See Example 7).

Note: The gridplus pack command must be used (rather than the normal Tk pack command) when a GRIDPLUS created window is to be resizable.

GRIDPLUS Layout Resizing Options

Each layout cell may optionally have a delimited sticky indicator, n, s, e, w (Default) or c (Centre). The sticky delimeter is ":".

GRIDPLUS has the following options which can be used to control the grid weight for applications which have resizable windows.

>Set indicated row to have a weight of 1.
vSet indicated column to have a weight of 1.
~Set column/row weight have a weight of 0.

Column weight indicators, if specified, must be in a line by themselves at the top of the layout. Row weight indicators, if specified, must be the first item in a layout row.

Note: If column weight indicators are specified, the line at the top containing the indicators is not considered to be a layout row.

As the default for columns/rows is to have a weight of 0, the "~" option is generally intended to be used as a "placeholder" when specifying column resizing. It is otherwise optional.

Examples:

gridplus layout .mylayout {
     ~        v
     .mygrid1 .mygrid2 .mygrid3
     .mygrid4 .mygrid5 .mygrid6
   > .mygrid7 .mygrid8 .mygrid9
}
...Sets the second column and third row to have a weight of 1. All other columns/rows will have a weight of 0. The "~" option is used as a placeholder to indicate that the first column weight is 0. This also demontrates that it is not necessary to specify any column weight indicators to the right of the last "v".


gridplus layout .mylayout {
     ~        v        ~
   ~ .mygrid1 .mygrid2 .mygrid3
   ~ .mygrid4 .mygrid5 .mygrid6
   > .mygrid7 .mygrid8 .mygrid9
}
...Has the same effect as the previous example. Demontrates that the "~" option can be specified for all other columns/rows.

Examples

This section contains examples which illustrate the GRIDPLUS resizing facility features.

The following examples assumes that the reader is familiar with the contents of the Grid/Layout, Button, Tree, Text and Entry pages. Information given on those pages will not be duplicated here.

The comments below concentrate on the Layout weighting options and the GRIDPLUS pack command mode.

Note: The examples assume that the GRIDPLUS package has already been "required" and the commands imported.


Resize Example 1

Resizing Behaviour Required:

Window:

Resized...

Source Code:

gridplus button .toolbar -style Toolbutton -space 0 -padding {0 0 0 0} {
   {.back :navback22} {.home :navhome22} {.forward :navforward22}
}

gridplus tree .mytree -width 100 -height 15 -scroll y -title "Tree"

gridplus text .mytext -width 35 -height 10 -scroll xy -title "Text"

gridplus entry .myentry1 -width 30 -title "Entry Grid One" {
   {"Entry One"   .entry1}
   {"Entry Two"   .entry2}
   {"Entry Three" .entry3}
}

gridplus entry .myentry2 -title "Entry Grid Two" {
   {"Entry One"   .entry1} {"Entry Four" .entry4} {"Entry Seven" .entry7}
   {"Entry Two"   .entry2} {"Entry Five" .entry5} {"Entry Eight" .entry8}
   {"Entry Three" .entry3} {"Entry Six"  .entry6} {"Entry Nine"  .entry9}
}

gridplus button .mybutton {
   {"Button One" .button1} {"Button Two" .button2}
}

gridplus layout .main -wtitle "Resize Example" {
      v
      .toolbar:w     -
      =              -
   >  .mytree:nsew   .mytext:nsew
      ^              .myentry1
      .myentry2:ew   -
      =              -
      .mybutton:ew   -
}

gridplus pack .main -resize xy

Comments:

gridplus layout .main -wtitle "Resize Example" {
      v
      .toolbar:w     -
      =              -
   >  .mytree:nsew   .mytext:nsew
      ^              .myentry1
      .myentry2:ew   -
      =              -
      .mybutton:ew   -
}

Creates a layout called ".main". The first column and third row are set to a weight of 1.
gridplus pack .main -resize xy

Packs the ".main" layout and specifies that the window may be resized in both the X and Y directions.

By default the gridplus pack command will not allow the window to resized smaller than its creation size. See Example 7 for a sample of an application which allows the window to be resized smaller than its creation size.


As an example of how the use of the sticky delimiters column/row weight options effect the look of the window when it is resized this is how the resized window looks when they are not specified.

gridplus layout .main -wtitle "Resize Example" {
   .toolbar:w      -
   =               -
   .mytree:nsew    .mytext:nsew
   ^               .myentry1
   .myentry2:ew    -
   =               -
   .mybutton:ew    -
}

When resized...


Copyright © 2014 Adrian Davis.