******************** DUIM-Layouts Library ******************** .. current-library:: duim-layouts .. current-module:: duim-layouts Overview ======== The DUIM-Layouts library contains interfaces that define a number of layouts for use in your GUI applications, as well as the necessary functions, generic functions, and macros for creating, manipulating, and calculating them automatically. The library contains a single module, *duim-layouts*, from which all the interfaces described in this chapter are exposed. `DUIM-Layouts Module`_ contains complete reference entries for each exposed interface. Layouts are sheet objects that determine how the interface elements are presented on the screen. A layout object takes a number of children, expressed as a vector, and lays out those children according to certain constraints. Each child of a layout must be an instance of a DUIM class. The class hierarchy for DUIM-Layouts ==================================== This section presents an overview of the available classes of layout, and describes the class hierarchy present. The class and its subclasses ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The base class for the majority of DUIM layouts is the :class:`` class, which is itself a subclass of :class:``. All other layout-oriented classes are subclasses of :class:``. The immediate subclasses of :class:`` that are exposed by the DUIM-Layouts library are shown in `The class hierarchy for DUIM-Layouts`_. Only :class:``, :class:``, and :class:`` have any subclasses defined. See `Subclasses of \`_ for details of the subclasses of :class:``. .. table:: Overall class hierarchy for the DUIM-Layouts library +---------+------------------------+---------------------------------+ | | | | +---------+------------------------+---------------------------------+ | | | | +---------+------------------------+---------------------------------+ | | | | +---------+------------------------+---------------------------------+ | | | | +---------+------------------------+---------------------------------+ | | | See `Subclasses of \`_ | +---------+------------------------+---------------------------------+ | | | | +---------+------------------------+---------------------------------+ | | | | +---------+------------------------+---------------------------------+ | | | | +---------+------------------------+---------------------------------+ | | | | +---------+------------------------+---------------------------------+ | | | | +---------+------------------------+---------------------------------+ All the actual layouts provided by the DUIM-Layouts library are subclasses of the base :class:`` class, and are described in `Subclasses of \`_. In addition, a number of different types of pane are supplied by the DUIM-Layouts library. - :class:`` This is a basic type of pane that is used to create any sheet that can contain children. It has two subclasses, one used for sheets that take only a single child, and one for sheets that can take several children. - :class:`` This type of pane is used to create sheets on which geometric objects are drawn, for example, using the function provided by the DUIM-Geometry module or the DUIM-Graphics module. For more information on these modules, see :doc:`geom`, and :doc:`graphics`, respectively. - :class:`` This class is used for any sheets that are at the top level of the hierarchy of windows on the screen: that is, there is no other sheet that is the parent of an instance of :class:``. - :class:`` In contrast to :class:``, an instance of :class:`` cannot have any children, and is at the end of the hierarchy of windows on the screen. - :class:`` This class is the most basic type of pane, and is used when no other more suitable class is available. Subclasses of ^^^^^^^^^^^^^^^^^^^^^^ The subclasses of :class:`` are shown in :ref:`subclasses-of-the-layout-class` .. _subclasses-of-the-layout-class: .. table:: Subclasses of the class +----------+-------------------+---------------+ | | | | +----------+-------------------+---------------+ | | | | +----------+-------------------+---------------+ | | | | +----------+-------------------+---------------+ | | | | +----------+-------------------+---------------+ | | | | +----------+-------------------+---------------+ | | | | +----------+-------------------+---------------+ | | | | +----------+-------------------+---------------+ | | | | +----------+-------------------+---------------+ The layouts provided by DUIM fall roughly into two categories: - Layout classes that calculate the position and size of their children for you, subject to some constraints. - Layout classes that let you specify precisely the position of their children, and, optionally, the size of the children as well. The classes of layout available are as follows: - :class:`` This class lays out its children in a single column, with all its children left-aligned by default. - :class:`` This class lays out its children in a single row. - :class:`` This class lays out its children one on top of another, aligned at the top left corner by default. It is specifically for windows that contain a number of layouts, only one of which is visible at any one time, such as property sheets, tab controls, or wizards. - :class:`` This class lays out its children in a table, according to a specified number of rows and columns. - :class:`` This does not constrain the position of its children in any way. It is up to you to position each child individually, like pins on a pinboard. - :class:`` This class is like :class:``, in that you must specify the position of each child. Unlike :class:``, however, you must also specify the size of each child. In addition to the basic types of layout described above, a subclass of :class:`` is provided, as follows: - :class:`` This is a specialized version of :class:``, in which all the cells in the table are forced to be the same size. .. figure:: images/layouts-3.png :align: center Column, row, and pinboard layouts DUIM-Layouts Module =================== This section contains a complete reference of all the interfaces that are exported from the *duim-layouts* module. .. generic-function:: allocate-space :open: Allocates space within a layout for its children. :signature: allocate-space *pane* *width height* => () :parameter pane: An instance of type :class:``. :parameter width: An instance of type :drm:``. :parameter height: An instance of type :drm:``. :description: Allocates space within a layout for its children. During the space allocation pass, a composite pane arranges its children within the available space and allocates space to them according to their space requirements and its own composition rules by calling :gf:`allocate-space` on each of the child panes. For example, :class:`` arranges all its children in a vertical column. The *width* and *height* arguments are the width and height of *pane* in device units, that is, pixels. These arguments give the amount of space into which all children must fit. This function actually calls :class:`do-allocate-space` to perform the calculations. Client code may specialize :class:`do-allocate-space`, but not call it. Call :gf:`allocate-space` instead. :seealso: - :gf:`do-allocate-space` .. class:: The class of basic user panes. :superclasses: :class:`` :keyword region: An instance of type :class:``. Default value: :const`$nowhere`. :keyword transform: An instance of type :class:``. Default value: :const:`$identity-transform`. :keyword port: An instance of type ``false-or()``. Default value: ``#f``. :keyword style-descriptor: An instance of type ``false-or()``. Default value: ``#f``. :keyword help-context: An instance of type :drm:``. Default value: ``make()``. :keyword help-source: An instance of type :drm:``. Default value: ``make()``. :description: The class of basic user panes. This is the class that gets subclassed by :macro:`define pane`. You specify where on the screen the pane is to be displayed using the *region:* init-keyword. The region specified should be relative to the top left corner of the pane's parent, since the pane must be displayed within the confines of its parent. If you wish the location of the pane to be transformed in some way, use the *transform:* init-keyword. If you wish to use a port other than the default port, use the *port:* init-keyword. You can specify the appearance for text in the pane using the *style-descriptor:* init-keyword. The *help-source:* and *help-context:* keywords let you specify pointers to valid information available in any online help you supply with your application. The *help-context:* keyword should specify a context-ID present in the online help. This context-ID identifies the help topic that is applicable to the current pane. The *help-source:* init-keyword identifies the source file in which the help topic identified by *help-context:* can be found. A list of context-IDs should be provided by the author of the online help system. :seealso: - :macro:`define pane` .. class:: :open: :abstract: :instantiable: The class of column layouts. :superclasses: :class:`` :keyword border: An instance of type :drm:``. Default value: 0. :keyword spacing: An instance of type :drm:``. Default value: 0. :keyword y-spacing: An instance of type :drm:``. Default value: 0. :keyword equalize-heights?: An instance of type :drm:``. Default value: ``#f``. :keyword equalize-widths?: An instance of type :drm:``. Default value: ``#f``. :keyword x-alignment: An instance of type ``one-of(#"left", #"right", #"center")``. Default value: ``#"left"``. :keyword ratios: An instance of type ``false-or(limited(), of: ))``. Default value: ``#f``. :keyword y-ratios: An instance of type ``false-or(limited(), of: ))``. Default value: ``#f``. :description: The class of column layouts. A column layout arranges its children in a column, automatically calculating the size and placement of each child within the specified parameters. .. figure:: images/layouts-4.png :align: center Three buttons arranged in a column layout The ``border:`` init-keyword provides a border of whitespace around the children in the layout, and the value of this init-keyword represents the size of the border in pixels. This basically has the same effect as using the macro :macro:`with-border` around the layout, except it uses a simpler syntax. The ``spacing:`` or ``y-spacing:`` init-keywords let you specify how much vertical space should be inserted, in pixels, between the children of the layout. These two init-keywords can be used interchangeably. If true, ``equalize-heights?:`` ensures that all the children of the layout have the same height. If true, ``equalize-widths?:`` ensures that all the children of the layout have the same width. By default, all the children of a column layout are left-aligned. You can specify that they should be right or center-aligned using the ``x-alignment:`` keyword. The ``ratios:`` or ``y-ratios:`` init-keywords let you specify the proportion of the total layout that should be taken up by each individual child. These two init-keywords can be used interchangeably. The value passed to ``ratios:`` needs to be a sequence of as many integers as there are children in the layout. Each child is then allocated the appropriate portion of vertical space in the layout. For example, if the value ``#(1, 2, 3)`` is specified for the ``ratios:`` init-keyword of a column layout containing three children, then the first child would claim a sixth of the available vertical space, the second child would claim a third of the vertical space, and the third child would claim half the vertical space, as shown in the diagram below. .. figure:: images/layouts-5.png :align: center :alt: :example: .. code-block:: dylan contain(make(, children: vector(make(