<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>2000</year><year>2013</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    
    </legalnotice>

    <title>The Packer</title>
    <prepared></prepared>
    <docno></docno>
    <date></date>
    <rev></rev>
    <file>gs_chapter7.xml</file>
  </header>

  <section>
    <title>The Packer</title>
    <p>This section describes the geometry manager in GS.</p>
    <p>When the user resizes a window, the application normally has to resize and move the graphical objects in the window to fit its new size. This can be handled by a so called <em>packer</em> or <em>geometry manager</em>.  In GS, the packer functionality is a property of the <c><![CDATA[frame]]></c> object.  A frame with the packer property may control the size and position of its children.</p>
    <p>A packer frame organises its children according to a grid pattern of rows and columns. Each row or column has a stretching property associated to it. Some columns may expand more than others and some may have a fixed size. The grid pattern is in itself invisible, but the objects contained by it snap to fit the grid.</p>
    <p>The packer controlled by the following options:</p>
    <p>Frame options:<br></br><c><![CDATA[{packer_x,Packlist}]]></c> where <c><![CDATA[Packlist]]></c> is list() of
      <c><![CDATA[PackOption]]></c>, and<br></br><c><![CDATA[{packer_y,Packlist}]]></c> where <c><![CDATA[Packlist]]></c> is list() of
      <c><![CDATA[PackOption]]></c>.</p>
    <p><c><![CDATA[PackOption]]></c> is:<br></br><c><![CDATA[{stretch, Weight}]]></c> where <c><![CDATA[Weight]]></c> is integer() &gt; 0, or<br></br><c><![CDATA[{stretch, Weight, MinPixelSize, or}]]></c><br></br><c><![CDATA[{stretch, Weight, MinPixelSize, MaxPixelSize}, or]]></c><br></br><c><![CDATA[{fixed, PixelSize}]]></c></p>
    <p>A <c><![CDATA[Weight]]></c> is a relative number that specifies how much of the total space of the frame a row or column will get. If the frame has three columns with the weights 2, 1, 3 it tells the geometry manager that the first column should have 2/6, the second 1/6 and the third 3/6 of the space.</p>
    <p>Note that giving a minimum or maximum width of one or more columns will change the relation and the way the space is divided.</p>
    <p>Then the objects contained by the frame use the following options to position themselves in the grid:<br></br><c><![CDATA[{pack_x,Column}]]></c> where <c><![CDATA[Column]]></c> is integer(), or<br></br><c><![CDATA[{pack_x,{StartColumn,EndColumn}}]]></c></p>
    <p>and<br></br><c><![CDATA[{pack_y,row}]]></c> where <c><![CDATA[row]]></c> is integer(), or<br></br><c><![CDATA[{pack_y,{Startrow,Endrow}}]]></c></p>
    <p>or, the the following option is a convenient shorthand:<br></br><c><![CDATA[{pack_xy,{Column,row}}]]></c></p>
    <p>Consider the following example.</p>
    <codeinclude file="examples/ex17.erl" tag="" type="erl"></codeinclude>
    <p>It defines a frame with three columns where the second should be twice as wide as the other but no column should be smaller than 50 pixels wide. The frame has two rows where the first has a fixed height of 30 pixels and the last row is totally flexible. Three buttons are placed next to each other on the first row, and below them an editor. The editor covers all three columns.</p>
    <marker id="pic:packer1"></marker>
    <image file="images/packer1.gif">
      <icaption>
Frame with three columns</icaption>
    </image>
    <p>The picture below illustrates what happens when the window is resized.</p>
    <marker id="pic:packer2"></marker>
    <image file="images/packer2.gif">
      <icaption>Resized Frame</icaption>
    </image>
    <p>To repack the objects, the size of the packer frame has to be set explicitly. This is done by using the height and width options as usual.  Since the packer frame controls the size of its children, using the standard x, y, width, height options, packer frames may be nested recursively.</p>
    <p>The packer is very useful since it simplifies the programming. The programmer will not have to spend time fine tuning x, y, width, height of each object, since these options are handled by the frame.</p>
  </section>
</chapter>

