Blame doc/cookbook/layouts.xml

Packit Service bf98b9
Packit Service bf98b9
 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
Packit Service bf98b9
Packit Service bf98b9
Packit Service bf98b9
         xmlns:xi="http://www.w3.org/2003/XInclude">
Packit Service bf98b9
Packit Service bf98b9
  <title>Layout management</title>
Packit Service bf98b9
Packit Service bf98b9
  <epigraph>
Packit Service bf98b9
    <attribution>Abigail Adams, wife of John Adams, in a letter to John
Packit Service bf98b9
    Thaxter (1778-09-29)</attribution>
Packit Service bf98b9
    <para>If we do not lay out ourselves in the service of mankind,
Packit Service bf98b9
    whom should we serve?</para>
Packit Service bf98b9
  </epigraph>
Packit Service bf98b9
Packit Service bf98b9
  <section id="layouts-introduction">
Packit Service bf98b9
    <title>Introduction</title>
Packit Service bf98b9
Packit Service bf98b9
    <para>Layout management in Clutter controls how an actor and
Packit Service bf98b9
    children "inside" that actor are sized and positioned. More
Packit Service bf98b9
    specifically, layouts are managed by associating a parent with a
Packit Service bf98b9
    <type>ClutterLayoutManager</type>; the parent is usually either a
Packit Service bf98b9
    composite <type>ClutterActor</type> (composed of several
Packit Service bf98b9
    <type>ClutterActors</type>) or a <type>ClutterContainer</type>
Packit Service bf98b9
    (containing child <type>ClutterActors</type>). The
Packit Service bf98b9
    <type>ClutterLayoutManager</type> then manages:</para>
Packit Service bf98b9
Packit Service bf98b9
    <orderedlist>
Packit Service bf98b9
      <listitem>
Packit Service bf98b9
        <para>The <emphasis>size requisition</emphasis>
Packit Service bf98b9
        (determination of the desired height and width) of the
Packit Service bf98b9
        parent.</para>
Packit Service bf98b9
      </listitem>
Packit Service bf98b9
      <listitem>
Packit Service bf98b9
        <para>The <emphasis>allocation</emphasis> (size and position)
Packit Service bf98b9
        assigned to each composed or child ClutterActor.</para>
Packit Service bf98b9
      </listitem>
Packit Service bf98b9
    </orderedlist>
Packit Service bf98b9
Packit Service bf98b9
    <note>
Packit Service bf98b9
      <para>To make this more concrete, imagine you have a sheet of
Packit Service bf98b9
      paper and some coloured squares to place on it. Someone stands
Packit Service bf98b9
      next to you telling you how big the piece of paper should be,
Packit Service bf98b9
      how big the squares should be, and where to put each square on the
Packit Service bf98b9
      piece of paper.</para>
Packit Service bf98b9
      <para>The sheet of paper is analogous to the container or
Packit Service bf98b9
      composite actor; the squares are analogous to the child
Packit Service bf98b9
      <type>ClutterActors</type>; and the person giving you instructions
Packit Service bf98b9
      is analogous to the layout manager.</para>
Packit Service bf98b9
    </note>
Packit Service bf98b9
Packit Service bf98b9
    <para>The following sections give an overview of how layout
Packit Service bf98b9
    management works in Clutter.</para>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Using layouts</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>Although Clutter provides plenty of flexibility in how you
Packit Service bf98b9
      can use layout management, the simplest way to get started is to
Packit Service bf98b9
      use the built-in <type>ClutterActor</type> class with one of the
Packit Service bf98b9
      provided <type>ClutterLayoutManager</type> implementations.</para>
Packit Service bf98b9
Packit Service bf98b9
      <para>The pattern for doing this is:</para>
Packit Service bf98b9
Packit Service bf98b9
      <itemizedlist>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Create an instance of one of the
Packit Service bf98b9
          <type>ClutterLayoutManager</type> implementations (see
Packit Service bf98b9
          <link linkend="layouts-introduction-manager-types">the
Packit Service bf98b9
          following section</link>).</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Configure the layout manager's default policies
Packit Service bf98b9
          (e.g. how actors are aligned by default, whether to pack
Packit Service bf98b9
          actors horizontally or vertically, spacing between actors
Packit Service bf98b9
          in the layout).</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Create a <type>ClutterActor</type>, setting its layout
Packit Service bf98b9
          manager to the one you just created.</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Pack actors into the <type>ClutterActor</type>,
Packit Service bf98b9
          setting layout properties (if required) as each is added.</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Modify layout properties of child actors using
Packit Service bf98b9
          <function>clutter_layout_manager_child_set()</function>
Packit Service bf98b9
          (if required).</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
      </itemizedlist>
Packit Service bf98b9
Packit Service bf98b9
      <para>Individual recipes in this section give more examples of
Packit Service bf98b9
      how to make use of the different layout manager
Packit Service bf98b9
      implementations.</para>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section id="layouts-introduction-manager-types">
Packit Service bf98b9
      <title>Types of layout manager</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>Clutter provides a range of layout managers suitable
Packit Service bf98b9
      for different use cases:</para>
Packit Service bf98b9
Packit Service bf98b9
      <itemizedlist>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para><type>ClutterFixedLayout</type> arranges actors
Packit Service bf98b9
          at fixed positions on the stage. No alignment options are
Packit Service bf98b9
          available, so you have to manually compute and manage the
Packit Service bf98b9
          coordinates (or use <type>ClutterConstraints</type>) which
Packit Service bf98b9
          will align actors how you want them.</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para><type>ClutterBinLayout</type> arranges actors in a
Packit Service bf98b9
          depth-ordered stack on top of each other, aligned to the container.
Packit Service bf98b9
          This is useful for arranging actors inside composites (e.g.
Packit Service bf98b9
          creating a button widget from a <type>ClutterTexture</type>
Packit Service bf98b9
          with a <type>ClutterText</type> on top of it).</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para><type>ClutterBoxLayout</type> arranges actors in a
Packit Service bf98b9
          single horizontal row or vertical column. This type of layout is
Packit Service bf98b9
          common in UI elements like toolbars and menus.</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para><type>ClutterFlowLayout</type> arranges actors
Packit Service bf98b9
          in reflowing columns and rows. If the container's allocation
Packit Service bf98b9
          changes, the child actors are rearranged to fit inside its
Packit Service bf98b9
          new allocation. This can be useful for arranging actors
Packit Service bf98b9
          where you're not sure how many there might be; or where
Packit Service bf98b9
          new ones are going to be added into the UI, perhaps displacing
Packit Service bf98b9
          others. An example might be a photo viewer or an
Packit Service bf98b9
          RSS feed display.</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
      </itemizedlist>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section id="layouts-introduction-layout-properties">
Packit Service bf98b9
      <title>Layout properties</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>How actors are sized and positioned inside a container
Packit Service bf98b9
      associated with a layout manager depends on two things:</para>
Packit Service bf98b9
Packit Service bf98b9
      <orderedlist>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <formalpara>
Packit Service bf98b9
            <title>Properties which apply to all actors added to the layout</title>
Packit Service bf98b9
            <para>There will be one setting at the layout level which can't
Packit Service bf98b9
            be overridden per actor. This includes properties like spacing
Packit Service bf98b9
            between rows and columns, whether the layout is homogenous
Packit Service bf98b9
            (each actor gets the same allocation), etc.</para>
Packit Service bf98b9
          </formalpara>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <formalpara>
Packit Service bf98b9
            <title>Properties for each actor added to the layout</title>
Packit Service bf98b9
            <para>These are properties of the relationship between the
Packit Service bf98b9
            layout, the container associated with the layout, and the
Packit Service bf98b9
            children of the container. Each layout/container/actor
Packit Service bf98b9
            combination can have different settings for each of these
Packit Service bf98b9
            properties.</para>
Packit Service bf98b9
          </formalpara>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
      </orderedlist>
Packit Service bf98b9
Packit Service bf98b9
      <para>Each layout manager implementation supports a subset of the
Packit Service bf98b9
      following layout properties; different managers may have different
Packit Service bf98b9
      names or functions for setting them, but the functionality remains
Packit Service bf98b9
      the same. Individual recipes give more details about which
Packit Service bf98b9
      properties can be set for each layout manager implementation.</para>
Packit Service bf98b9
Packit Service bf98b9
      <itemizedlist>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <formalpara>
Packit Service bf98b9
            <title>Alignment</title>
Packit Service bf98b9
            <para>How an actor aligns to the container's axes, e.g.
Packit Service bf98b9
            aligned to the container's left, right, or center. For some
Packit Service bf98b9
            layouts (like <type>ClutterBinLayout</type>) alignment
Packit Service bf98b9
            is also used to set expand and fill properties.</para>
Packit Service bf98b9
          </formalpara>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <formalpara>
Packit Service bf98b9
            <title>Horizontal/vertical orientation</title>
Packit Service bf98b9
            <para>Whether actors are arranged in a horizontal row or
Packit Service bf98b9
            vertical column.</para>
Packit Service bf98b9
          </formalpara>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <formalpara>
Packit Service bf98b9
            <title>Homogenous rows and columns</title>
Packit Service bf98b9
            <para>Grid-like layouts (e.g. <type>ClutterFlowLayout</type>)
Packit Service bf98b9
            can be configured to have uniform rows and/or columns,
Packit Service bf98b9
            expanding to fit the largest actor they contain.</para>
Packit Service bf98b9
          </formalpara>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <formalpara>
Packit Service bf98b9
            <title>Row height and column width</title>
Packit Service bf98b9
            <para>Grid-like layouts arranged in rows and columns
Packit Service bf98b9
            can be configured with maximum and minimum row height and
Packit Service bf98b9
            column width.</para>
Packit Service bf98b9
          </formalpara>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <formalpara>
Packit Service bf98b9
            <title>Row and column spacing</title>
Packit Service bf98b9
            <para>Grid-like layouts enable you to define a space (in pixels)
Packit Service bf98b9
            between rows and columns.</para>
Packit Service bf98b9
          </formalpara>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <formalpara>
Packit Service bf98b9
            <title>Expand</title>
Packit Service bf98b9
            <para>Some layouts can be configured to minimize their size request
Packit Service bf98b9
            to fit the actors they contain (<emphasis>expand is FALSE</emphasis>);
Packit Service bf98b9
            or to increase the allocation of actors they contain so
Packit Service bf98b9
            that all available space in the layout is used
Packit Service bf98b9
            (<emphasis>expand is TRUE</emphasis>). In the latter case, you'd
Packit Service bf98b9
            also need to set a size for the container associated with
Packit Service bf98b9
            the layout, otherwise the container will just fit itself to the
Packit Service bf98b9
            actors inside it.</para>
Packit Service bf98b9
          </formalpara>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <formalpara>
Packit Service bf98b9
            <title>Fill</title>
Packit Service bf98b9
            <para>This property only has an effect when
Packit Service bf98b9
            <emphasis>expand</emphasis> is on. The <emphasis>fill</emphasis>
Packit Service bf98b9
            setting controls whether actors are resized to fill their
Packit Service bf98b9
            allocation (<emphasis>fill is TRUE</emphasis>); or if the
Packit Service bf98b9
            space around the actor is increased (<emphasis>fill is
Packit Service bf98b9
            FALSE</emphasis>).</para>
Packit Service bf98b9
          </formalpara>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <formalpara>
Packit Service bf98b9
            <title>Pack at start/end</title>
Packit Service bf98b9
            <para>This controls whether actors at prepended or appended
Packit Service bf98b9
            to the layout.</para>
Packit Service bf98b9
            <itemizedlist>
Packit Service bf98b9
              <listitem>
Packit Service bf98b9
                <para>If the orientation is vertical, prepended
Packit Service bf98b9
                actors are added to the top of the layout and appended
Packit Service bf98b9
                actors to the bottom.</para>
Packit Service bf98b9
              </listitem>
Packit Service bf98b9
              <listitem>
Packit Service bf98b9
                <para>If the orientation is horizontal, prepended
Packit Service bf98b9
                actors are added at the left of the layout and appended actors
Packit Service bf98b9
                on the right.</para>
Packit Service bf98b9
              </listitem>
Packit Service bf98b9
            </itemizedlist>
Packit Service bf98b9
          </formalpara>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
      </itemizedlist>
Packit Service bf98b9
Packit Service bf98b9
      <section>
Packit Service bf98b9
        <title>Setting layout properties</title>
Packit Service bf98b9
Packit Service bf98b9
        <para>Layout properties can be set in one or more of the following ways
Packit Service bf98b9
        (depending on the type of property and the layout manager):</para>
Packit Service bf98b9
Packit Service bf98b9
        <orderedlist>
Packit Service bf98b9
          <listitem>
Packit Service bf98b9
            <para>By setting a default value for the property on the
Packit Service bf98b9
            layout manager (e.g. using
Packit Service bf98b9
            <function>clutter_bin_layout_set_alignment()</function>,
Packit Service bf98b9
            <function>clutter_box_layout_set_expand()</function>). Any
Packit Service bf98b9
            actor added to the layout gets this value for the property,
Packit Service bf98b9
            unless it is overridden for that actor.</para>
Packit Service bf98b9
          </listitem>
Packit Service bf98b9
          <listitem>
Packit Service bf98b9
            <para>When adding an actor to a <type>ClutterBox</type> container
Packit Service bf98b9
            using <function>clutter_box_pack()</function>, you can set
Packit Service bf98b9
            properties on the actor which you're adding.</para>
Packit Service bf98b9
          </listitem>
Packit Service bf98b9
          <listitem>
Packit Service bf98b9
            <para>When adding an actor to a layout you can use a function
Packit Service bf98b9
            which enables setting properties simultaneously (e.g.
Packit Service bf98b9
            <function>clutter_box_layout_pack()</function>,
Packit Service bf98b9
            <function>clutter_bin_layout_add()</function>).</para>
Packit Service bf98b9
          </listitem>
Packit Service bf98b9
          <listitem>
Packit Service bf98b9
            <para>By using
Packit Service bf98b9
            <function>clutter_layout_manager_child_set()</function> on
Packit Service bf98b9
            the child of a layout.</para>
Packit Service bf98b9
          </listitem>
Packit Service bf98b9
        </orderedlist>
Packit Service bf98b9
Packit Service bf98b9
      </section>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section id="layouts-introduction-not-using-layout-managers">
Packit Service bf98b9
      <title>Not using layout managers</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>It is perfectly possible to arrange <type>ClutterActors</type>
Packit Service bf98b9
      without using layout managers; however, you may have to do
Packit Service bf98b9
      more of your own calculations about actor sizes and positions.</para>
Packit Service bf98b9
Packit Service bf98b9
      <para>There are two (not mutually-exclusive) approaches you can
Packit Service bf98b9
      take to do this, described below.</para>
Packit Service bf98b9
Packit Service bf98b9
      <section>
Packit Service bf98b9
        <title>Manual positioning and alignment</title>
Packit Service bf98b9
Packit Service bf98b9
        <para>This basically means using the <type>ClutterActor</type>
Packit Service bf98b9
        bounding box mechanism (see the <type>ClutterActor</type>
Packit Service bf98b9
        documentation for details) to set actor sizes and positions.
Packit Service bf98b9
        This is the approach you will see in a lot of older Clutter
Packit Service bf98b9
        code (written before layout managers were available).</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>This approach is simplest where the UI is relatively static
Packit Service bf98b9
        and is composed of a few known actors. It will work in larger,
Packit Service bf98b9
        more complex scenarios, but in those sorts of cases it is better
Packit Service bf98b9
        to make use of layout managers and constraints (see below) instead.</para>
Packit Service bf98b9
      </section>
Packit Service bf98b9
Packit Service bf98b9
      <section>
Packit Service bf98b9
        <title>Using <type>ClutterConstraint</type></title>
Packit Service bf98b9
Packit Service bf98b9
        <para>Constraints provide mechanisms for:</para>
Packit Service bf98b9
Packit Service bf98b9
        <itemizedlist>
Packit Service bf98b9
          <listitem>
Packit Service bf98b9
            <para>Aligning actors with each other
Packit Service bf98b9
            (<type>ClutterAlignConstraint</type>). For example, you
Packit Service bf98b9
            can align the top, bottom or center of one actor with the
Packit Service bf98b9
            top, bottom or center of another (on the y
Packit Service bf98b9
            axis). Similarly, you can align one actor to another
Packit Service bf98b9
            on the x axis.</para>
Packit Service bf98b9
          </listitem>
Packit Service bf98b9
          <listitem>
Packit Service bf98b9
            <para>Binding properties of one actor to those of
Packit Service bf98b9
            another. For example, you could ensure that two actors
Packit Service bf98b9
            always remain the same width; or you could specify
Packit Service bf98b9
            that two actors always have the same x
Packit Service bf98b9
            coordinate. In both these cases and others, you can
Packit Service bf98b9
            specify that the properties should be the same, or the same
Packit Service bf98b9
            +/- some offset.</para>
Packit Service bf98b9
          </listitem>
Packit Service bf98b9
        </itemizedlist>
Packit Service bf98b9
Packit Service bf98b9
        <note>
Packit Service bf98b9
          <para><type>ClutterConstraints</type> can be used in combination
Packit Service bf98b9
          with some layout managers, but you need to be careful that
Packit Service bf98b9
          constraints don't fight with the layout manager policies.
Packit Service bf98b9
          Unpredictable results could ensue.</para>
Packit Service bf98b9
        </note>
Packit Service bf98b9
Packit Service bf98b9
      </section>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
  </section>
Packit Service bf98b9
Packit Service bf98b9
  <section id="layouts-stacking">
Packit Service bf98b9
    <title>Stacking actors on top of each other</title>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Problem</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>You want to lay out several actors so that they are in
Packit Service bf98b9
      layers on top of each other (e.g. to create a button widget
Packit Service bf98b9
      composed from a rectangle with text on top of it).</para>
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section id="layouts-stacking-solution">
Packit Service bf98b9
      <title>Solution</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>The most flexible approach is to use a <type>ClutterBinLayout</type>
Packit Service bf98b9
      associated with a <type>ClutterActor</type>:</para>
Packit Service bf98b9
Packit Service bf98b9
      <informalexample>
Packit Service bf98b9
        <programlisting>
Packit Service bf98b9
Packit Service bf98b9
/* define some colors */
Packit Service bf98b9
const ClutterColor background_color = { 0xaa, 0x99, 0x00, 0xff };
Packit Service bf98b9
const ClutterColor text_color = { 0xff, 0xff, 0xff, 0xff };
Packit Service bf98b9
Packit Service bf98b9
ClutterLayoutManager *layout;
Packit Service bf98b9
ClutterActor *box;
Packit Service bf98b9
ClutterActor *background;
Packit Service bf98b9
ClutterActor *text;
Packit Service bf98b9
Packit Service bf98b9
/*
Packit Service bf98b9
 * create a layout, setting the default x and y alignment;
Packit Service bf98b9
 * actors fill the whole allocation of the layout's container
Packit Service bf98b9
 * by default
Packit Service bf98b9
 */
Packit Service bf98b9
layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
Packit Service bf98b9
                                 CLUTTER_BIN_ALIGNMENT_FILL);
Packit Service bf98b9
Packit Service bf98b9
/* create the box whose children the layout will manage */
Packit Service bf98b9
box = clutter_box_new (layout);
Packit Service bf98b9
Packit Service bf98b9
/*
Packit Service bf98b9
 * fill doesn't have much effect here
Packit Service bf98b9
 * unless the container has height and/or width
Packit Service bf98b9
 */
Packit Service bf98b9
clutter_actor_set_size (box, 100, 30);
Packit Service bf98b9
Packit Service bf98b9
/*
Packit Service bf98b9
 * background for the button; could equally be a texture
Packit Service bf98b9
 * with an image loaded into it or any other ClutterActor
Packit Service bf98b9
 */
Packit Service bf98b9
background = clutter_rectangle_new_with_color (&background_color);
Packit Service bf98b9
Packit Service bf98b9
/*
Packit Service bf98b9
 * add the background to the container;
Packit Service bf98b9
 * as it should use the default alignment, it can be added
Packit Service bf98b9
 * direct to the container, rather than via the layout
Packit Service bf98b9
 */
Packit Service bf98b9
clutter_actor_add_child (box, background);
Packit Service bf98b9
Packit Service bf98b9
/* text for the button */
Packit Service bf98b9
text = clutter_text_new_full ("Sans 15px", "Click me", &text_color);
Packit Service bf98b9
Packit Service bf98b9
/*
Packit Service bf98b9
 * the text requires a different alignment from the background
Packit Service bf98b9
 * (centered on the box)
Packit Service bf98b9
 * so we add it via the layout so the default
Packit Service bf98b9
 * alignment can be overridden
Packit Service bf98b9
 */
Packit Service bf98b9
clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout),
Packit Service bf98b9
                        text,
Packit Service bf98b9
                        CLUTTER_BIN_ALIGNMENT_CENTER,
Packit Service bf98b9
                        CLUTTER_BIN_ALIGNMENT_CENTER);
Packit Service bf98b9
Packit Service bf98b9
/*
Packit Service bf98b9
 * ensure the actors are arranged in the correct depth order;
Packit Service bf98b9
 * in this case, the text is on top
Packit Service bf98b9
 * (NB this is not strictly necesary here as text is added after
Packit Service bf98b9
 * background)
Packit Service bf98b9
 */
Packit Service bf98b9
clutter_actor_raise_top (text);
Packit Service bf98b9
]]>
Packit Service bf98b9
        </programlisting>
Packit Service bf98b9
      </informalexample>
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Discussion</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>This section covers some other aspects of using a
Packit Service bf98b9
      <type>ClutterBinLayout</type>.</para>
Packit Service bf98b9
Packit Service bf98b9
      <section>
Packit Service bf98b9
        <title>Setting and changing alignment</title>
Packit Service bf98b9
Packit Service bf98b9
        <para>Alignment is the only
Packit Service bf98b9
        <link linkend="layouts-introduction-layout-properties">layout
Packit Service bf98b9
        property</link> available for <type>ClutterBinLayout</type>. Each
Packit Service bf98b9
        actor can have a different setting for its alignment in one or both
Packit Service bf98b9
        of the x or y axes. However, as shown in the
Packit Service bf98b9
        solution above, alignment can also be used to expand an actor to
Packit Service bf98b9
        fill the container (<constant>CLUTTER_BIN_ALIGNMENT_FILL</constant>)
Packit Service bf98b9
        in one or both axes.</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>Setting alignment does not have any effect if the container
Packit Service bf98b9
        is the same size as all of the actors inside it: in this case,
Packit Service bf98b9
        every alignment produces the same layout. But if the container
Packit Service bf98b9
        associated with the layout is larger than the actor being aligned,
Packit Service bf98b9
        alignment will have an effect; see
Packit Service bf98b9
        <link linkend="layouts-stacking-size-requisitioning">this
Packit Service bf98b9
        section</link> for more details.</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>Changing an actor's alignment after it has been added
Packit Service bf98b9
        to a <type>ClutterBinLayout</type> may make the actor "jump"
Packit Service bf98b9
        (without animation) to a new position and/or change its size.
Packit Service bf98b9
        The exception is changing from some other alignment to
Packit Service bf98b9
        <constant>CLUTTER_BIN_ALIGNMENT_FIXED</constant>:
Packit Service bf98b9
        in this case, the actor will retain the position and size it
Packit Service bf98b9
        had before its alignment was fixed.</para>
Packit Service bf98b9
      </section>
Packit Service bf98b9
Packit Service bf98b9
      <section id="layouts-stacking-size-requisitioning">
Packit Service bf98b9
        <title>Size requisitioning</title>
Packit Service bf98b9
Packit Service bf98b9
        <para>A container with a <type>ClutterBinLayout</type> will by
Packit Service bf98b9
        default request the width of the widest actor in it, and the
Packit Service bf98b9
        height of the tallest. If you add actors smaller than those
Packit Service bf98b9
        dimensions, they will be aligned inside the container according
Packit Service bf98b9
        to the layout's policies. Here's an example where a
Packit Service bf98b9
        <type>ClutterBinLayout</type> requests a size to encompass the
Packit Service bf98b9
        tallest (light grey rectangle) and widest (dark grey rectangle)
Packit Service bf98b9
        actors inside it, with other actors aligned within
Packit Service bf98b9
        those bounds:</para>
Packit Service bf98b9
Packit Service bf98b9
        <screenshot>
Packit Service bf98b9
          <mediaobject>
Packit Service bf98b9
            <imageobject>
Packit Service bf98b9
              
Packit Service bf98b9
                         fileref="images/layouts-stacking-diff-actor-sizes.png" />
Packit Service bf98b9
            </imageobject>
Packit Service bf98b9
            <alt>
Packit Service bf98b9
              <para>Size requisition in a <type>ClutterBinLayout</type></para>
Packit Service bf98b9
            </alt>
Packit Service bf98b9
          </mediaobject>
Packit Service bf98b9
        </screenshot>
Packit Service bf98b9
Packit Service bf98b9
        <note>
Packit Service bf98b9
          <para>The screenshot also shows the 9 possible combinations
Packit Service bf98b9
          of start, center and end alignments on the x and
Packit Service bf98b9
          y axes. See
Packit Service bf98b9
          <link linkend="layouts-stacking-example-1">the sample
Packit Service bf98b9
          code</link> for more details.</para>
Packit Service bf98b9
        </note>
Packit Service bf98b9
Packit Service bf98b9
        <para>The white space is the stage visible behind the
Packit Service bf98b9
        <type>ClutterActor</type> holding the coloured rectangles.
Packit Service bf98b9
        Notice that the layout is the width of the widest actor
Packit Service bf98b9
        within it and the height of the tallest.</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>You can also manually set a size on the container associated
Packit Service bf98b9
        with a layout to override the automatically-computed size
Packit Service bf98b9
        requisition.</para>
Packit Service bf98b9
Packit Service bf98b9
      </section>
Packit Service bf98b9
Packit Service bf98b9
      <section>
Packit Service bf98b9
        <title>Depth ordering</title>
Packit Service bf98b9
Packit Service bf98b9
        <para>Another important consideration is the
Packit Service bf98b9
        <emphasis>depth ordering</emphasis> of actors inside a
Packit Service bf98b9
        <type>ClutterBinLayout</type>. By default, the depth ordering
Packit Service bf98b9
        mirrors the order in which actors are added to the layout: the
Packit Service bf98b9
        earlier an actor is added, the lower down in the depth order it
Packit Service bf98b9
        is. If this isn't what you want, you can fix the depth ordering using
Packit Service bf98b9
        <function>clutter_actor_set_child_above_sibling()</function>,
Packit Service bf98b9
        <function>clutter_actor_set_child_below_sibling()</function> and
Packit Service bf98b9
        their relatives.</para>
Packit Service bf98b9
      </section>
Packit Service bf98b9
Packit Service bf98b9
      <section>
Packit Service bf98b9
        <title>Other ways to stack actors</title>
Packit Service bf98b9
Packit Service bf98b9
        <para><type>ClutterBinLayout</type> makes it simple to lay out
Packit Service bf98b9
        large numbers of actors in a stack and align them to the
Packit Service bf98b9
        container; see <link linkend="layouts-stacking-example-2">the
Packit Service bf98b9
        example below</link> which shows layering of many actors on
Packit Service bf98b9
        top of each other.</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>However, if you have a small number of actors and you
Packit Service bf98b9
        need some simple alignment, an alternative is to use
Packit Service bf98b9
        manual positioning inside a <type>ClutterFixedLayout</type>, possibly
Packit Service bf98b9
        combined with <type>ClutterConstraints</type> to align actors with
Packit Service bf98b9
        each other and bind their widths and heights together. See
Packit Service bf98b9
        <link linkend="layouts-introduction-not-using-layout-managers">this
Packit Service bf98b9
        section</link> for more details.</para>
Packit Service bf98b9
Packit Service bf98b9
        <note><para>By default, <type>ClutterActor</type> uses a
Packit Service bf98b9
        <type>ClutterFixedLayout</type> as its layout manager.</para></note>
Packit Service bf98b9
      </section>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Full examples</title>
Packit Service bf98b9
Packit Service bf98b9
      <example id="layouts-stacking-example-1">
Packit Service bf98b9
        <title><type>ClutterBinLayout</type>, with actors in 9
Packit Service bf98b9
        combinations of start, center and end alignment combinations</title>
Packit Service bf98b9
        <programlisting>
Packit Service bf98b9
<xi:include href="examples/layouts-stacking-diff-sized-actors.c" parse="text">
Packit Service bf98b9
  <xi:fallback>a code sample should be here... but isn't</xi:fallback>
Packit Service bf98b9
</xi:include>
Packit Service bf98b9
        </programlisting>
Packit Service bf98b9
      </example>
Packit Service bf98b9
Packit Service bf98b9
      <example id="layouts-stacking-example-2">
Packit Service bf98b9
        <title>Layering multiple textures on top of each other
Packit Service bf98b9
        inside a <type>ClutterBinLayout</type></title>
Packit Service bf98b9
        <programlisting>
Packit Service bf98b9
<xi:include href="examples/layouts-stacking.c" parse="text">
Packit Service bf98b9
  <xi:fallback>a code sample should be here... but isn't</xi:fallback>
Packit Service bf98b9
</xi:include>
Packit Service bf98b9
        </programlisting>
Packit Service bf98b9
      </example>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
  </section>
Packit Service bf98b9
Packit Service bf98b9
  <section id="layouts-bind-constraint">
Packit Service bf98b9
    <title>Binding the size of one actor to the size of another</title>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Problem</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>You want one actor (the "target") to automatically change
Packit Service bf98b9
      its width or height (or both) when the size of another
Packit Service bf98b9
      actor (the "source") changes.</para>
Packit Service bf98b9
Packit Service bf98b9
      <para>Example use cases:</para>
Packit Service bf98b9
Packit Service bf98b9
      <itemizedlist>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Making an actor adjust itself to the size of the stage
Packit Service bf98b9
          (particularly when the stage is resizable).</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Putting one actor on top of another and keeping their
Packit Service bf98b9
          sizes in sync.</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
      </itemizedlist>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Solution</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>Create a <type>ClutterBindConstraint</type> bound to the
Packit Service bf98b9
      width and/or height of one actor (the "source"). Add that constraint
Packit Service bf98b9
      to an actor (the "target") whose size should follow the
Packit Service bf98b9
      size of the source.</para>
Packit Service bf98b9
Packit Service bf98b9
      <para>This short example shows how to create and add a constraint;
Packit Service bf98b9
      <varname>source</varname> and <varname>target</varname> can
Packit Service bf98b9
      be any two <type>ClutterActors</type>:</para>
Packit Service bf98b9
Packit Service bf98b9
      <informalexample>
Packit Service bf98b9
        <programlisting>
Packit Service bf98b9
<emphasis>ClutterConstraint *width_constraint;</emphasis>
Packit Service bf98b9
Packit Service bf98b9
/* create a constraint which binds a target actor's width to 100px less than
Packit Service bf98b9
 * the width of the source actor (use CLUTTER_BIND_HEIGHT to create a
Packit Service bf98b9
 * constraint based on an actor's height)
Packit Service bf98b9
 *
Packit Service bf98b9
 * the third argument is a positive or negative offset from the actor's
Packit Service bf98b9
 * dimension, in pixels; this is added to the height or width of the source
Packit Service bf98b9
 * actor before the constraint is applied to the target actor
Packit Service bf98b9
 */
Packit Service bf98b9
<emphasis>width_constraint = clutter_bind_constraint_new (source, CLUTTER_BIND_WIDTH, -100);</emphasis>
Packit Service bf98b9
Packit Service bf98b9
/* add the constraint to an actor */
Packit Service bf98b9
<emphasis>clutter_actor_add_constraint (target, width_constraint);</emphasis>
Packit Service bf98b9
        </programlisting>
Packit Service bf98b9
      </informalexample>
Packit Service bf98b9
Packit Service bf98b9
      <para>Below is a full example, showing how to incorporate a
Packit Service bf98b9
      constraint into a Clutter application.</para>
Packit Service bf98b9
Packit Service bf98b9
      <example id="layouts-bind-constraint-example-1">
Packit Service bf98b9
        <title>Constraining the size of a texture to
Packit Service bf98b9
        the size of the stage using <type>ClutterBindConstraint</type></title>
Packit Service bf98b9
        <programlisting>
Packit Service bf98b9
<xi:include href="examples/layouts-bind-constraint-stage.c" parse="text">
Packit Service bf98b9
  <xi:fallback>a code sample should be here... but isn't</xi:fallback>
Packit Service bf98b9
</xi:include>
Packit Service bf98b9
        </programlisting>
Packit Service bf98b9
      </example>
Packit Service bf98b9
Packit Service bf98b9
      <para>The texture in this example is 100px smaller than the stage,
Packit Service bf98b9
      leaving a border of visible stage around the texture; and the texture
Packit Service bf98b9
      has a tiled image on it. The tiling changes as the texture changes
Packit Service bf98b9
      size. Also note that two <type>ClutterAlignConstraints</type> are
Packit Service bf98b9
      added to center the actor on the stage.</para>
Packit Service bf98b9
Packit Service bf98b9
      <para>The result looks like this:</para>
Packit Service bf98b9
Packit Service bf98b9
      <screenshot>
Packit Service bf98b9
          <mediaobject>
Packit Service bf98b9
            <imageobject>
Packit Service bf98b9
              
Packit Service bf98b9
                         fileref="images/layouts-bind-constraint-stage.png" />
Packit Service bf98b9
            </imageobject>
Packit Service bf98b9
            <alt>
Packit Service bf98b9
              <para>A texture bound to the height and width of the
Packit Service bf98b9
              stage using <type>ClutterBindConstraint</type></para>
Packit Service bf98b9
            </alt>
Packit Service bf98b9
          </mediaobject>
Packit Service bf98b9
        </screenshot>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Discussion</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>Sizing constraints are a good solution in these cases:</para>
Packit Service bf98b9
Packit Service bf98b9
      <itemizedlist>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Where you can't use a layout manager. For
Packit Service bf98b9
          example, you can't apply a layout manager to the stage
Packit Service bf98b9
          directly; so if you want to control the size of an actor
Packit Service bf98b9
          based on the size of the stage (as in
Packit Service bf98b9
          <link linkend="layouts-bind-constraint-example-1">the example
Packit Service bf98b9
          above</link>), constraints are a good substitute for a layout
Packit Service bf98b9
          manager .</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Where the layout of a UI is fairly simple (perhaps
Packit Service bf98b9
          up to half a dozen actors) and fairly static. An example
Packit Service bf98b9
          might be something like a text editor, where the arrangement
Packit Service bf98b9
          of the UI (menu bar, toolbar, editing panel, footer) changes
Packit Service bf98b9
          infrequently. Of course, it is possible to arrange top-level
Packit Service bf98b9
          components using constraints, but still use layout
Packit Service bf98b9
          managers inside individual components (e.g. a flow layout
Packit Service bf98b9
          manager to manage buttons in the toolbar).</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Where you have an actor whose size can change erratically,
Packit Service bf98b9
          but you still want to be able to track its size to control
Packit Service bf98b9
          another actor's size. An example might be an application like
Packit Service bf98b9
          a drawing program, where a user can create their own actors:
Packit Service bf98b9
          you might want the user to be able to describe loose, custom
Packit Service bf98b9
          constraints between actors like "keep these actors at the
Packit Service bf98b9
          same width", then allow those actors to be moved around and
Packit Service bf98b9
          resized in a free-form way as a group. In this situation, a
Packit Service bf98b9
          layout manager is too rigid and not appropriate;
Packit Service bf98b9
          but adding <type>ClutterConstraints</type> to actors
Packit Service bf98b9
          in response to user actions could work well.</para>
Packit Service bf98b9
Packit Service bf98b9
          <para>The <link linkend="layouts-bind-constraint-example-2">sample
Packit Service bf98b9
          code in the appendix</link> is the kind of thing you might include
Packit Service bf98b9
          in a drawing program: you can resize a texture with a key press
Packit Service bf98b9
          (+ to increase size, - to decrease), and
Packit Service bf98b9
          click on the actor to select/deselect it (a semi-transparent overlay is
Packit Service bf98b9
          toggled on the texture). The size of the overlay is bound and
Packit Service bf98b9
          aligned to the texture, so that it covers and slightly overlaps the
Packit Service bf98b9
          texture regardless of its size.</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
      </itemizedlist>
Packit Service bf98b9
Packit Service bf98b9
      <note>
Packit Service bf98b9
        <para>You can bind an actor to a single dimension (just height or
Packit Service bf98b9
        depth) of another actor: you don't have to bind both height
Packit Service bf98b9
        and width. Also, you don't have to bind both dimensions of the
Packit Service bf98b9
        target to the same source: for example, you could bind the target's
Packit Service bf98b9
        height to one source (actor A) and its width to another source
Packit Service bf98b9
        (actor B).</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>A <type>ClutterBindConstraint</type> can also be used to
Packit Service bf98b9
        constrain a target actor's position on the x and
Packit Service bf98b9
        y axes to the position of a source actor. This is
Packit Service bf98b9
        covered in another recipe.</para>
Packit Service bf98b9
      </note>
Packit Service bf98b9
Packit Service bf98b9
      <section>
Packit Service bf98b9
        <title>Another way to bind actors' sizes together</title>
Packit Service bf98b9
Packit Service bf98b9
        <para>There is another way to control the size of a target
Packit Service bf98b9
        actor, based on the size of a source: you can create a handler
Packit Service bf98b9
        for the allocation-changed signal
Packit Service bf98b9
        of the source, emitted when its size and/or position
Packit Service bf98b9
        changes. This signal includes all the data
Packit Service bf98b9
        about the source's new allocation (height, width, x and y
Packit Service bf98b9
        coordindates), which the handler function can then use to
Packit Service bf98b9
        resize the target.</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>Alternatively, if you're only interested in
Packit Service bf98b9
        a change to width or height, you can create a handler
Packit Service bf98b9
        for the notify::width or
Packit Service bf98b9
        notify::height signal (respectively), and modify
Packit Service bf98b9
        the target's width/height in the handler.</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>This approach may be useful if you need a type of
Packit Service bf98b9
        control over alignment and size which is not possible using
Packit Service bf98b9
        constraints alone (e.g. one actor's size should be
Packit Service bf98b9
        a proportion of another's). See
Packit Service bf98b9
        <link linkend="layouts-bind-constraint-example-3">the code in
Packit Service bf98b9
        this section</link> for an example where the size
Packit Service bf98b9
        of one actor is dynamically set to 10% more than the
Packit Service bf98b9
        size of another.</para>
Packit Service bf98b9
Packit Service bf98b9
        <note>
Packit Service bf98b9
          <para><link linkend="actors-allocation-notify">This recipe</link>
Packit Service bf98b9
          explains more about monitoring changes to an actor's size.</para>
Packit Service bf98b9
        </note>
Packit Service bf98b9
      </section>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Full examples</title>
Packit Service bf98b9
Packit Service bf98b9
      <example id="layouts-bind-constraint-example-2">
Packit Service bf98b9
        <title>Creating an automatically-resizing overlay for a
Packit Service bf98b9
        texture using <type>ClutterBindConstraint</type></title>
Packit Service bf98b9
        <programlisting>
Packit Service bf98b9
<xi:include href="examples/layouts-bind-constraint-overlay.c" parse="text">
Packit Service bf98b9
  <xi:fallback>a code sample should be here... but isn't</xi:fallback>
Packit Service bf98b9
</xi:include>
Packit Service bf98b9
        </programlisting>
Packit Service bf98b9
      </example>
Packit Service bf98b9
Packit Service bf98b9
      <example id="layouts-bind-constraint-example-3">
Packit Service bf98b9
        <title>Using the allocation-changed
Packit Service bf98b9
        signal of one actor to trigger proportional size changes in
Packit Service bf98b9
        another</title>
Packit Service bf98b9
        <programlisting>
Packit Service bf98b9
<xi:include href="examples/layouts-bind-constraint-allocation.c" parse="text">
Packit Service bf98b9
  <xi:fallback>a code sample should be here... but isn't</xi:fallback>
Packit Service bf98b9
</xi:include>
Packit Service bf98b9
        </programlisting>
Packit Service bf98b9
      </example>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
  </section>
Packit Service bf98b9
Packit Service bf98b9
  <section id="layouts-box">
Packit Service bf98b9
    <title>Arranging actors in a single row or column</title>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Problem</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>You want to layout several actors in a single row
Packit Service bf98b9
      or column.</para>
Packit Service bf98b9
Packit Service bf98b9
      <para>Example use cases:</para>
Packit Service bf98b9
Packit Service bf98b9
      <itemizedlist>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Creating an application menu.</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
        <listitem>
Packit Service bf98b9
          <para>Showing message subject lines as a list in an
Packit Service bf98b9
          email client.</para>
Packit Service bf98b9
        </listitem>
Packit Service bf98b9
      </itemizedlist>
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Solution</title>
Packit Service bf98b9
Packit Service bf98b9
      <para>Create a <type>ClutterActor</type> with a
Packit Service bf98b9
      <type>ClutterBoxLayout</type> as its layout manager.</para>
Packit Service bf98b9
Packit Service bf98b9
      <para>A <type>ClutterBoxLayout</type> can hold a single row or
Packit Service bf98b9
      column of <type>ClutterActors</type>, and has configurable spacing,
Packit Service bf98b9
      actor alignments, and expand and fill options.</para>
Packit Service bf98b9
Packit Service bf98b9
      <para>The code fragment below is excerpted from the
Packit Service bf98b9
      <link linkend="layouts-box-example-1">full example</link>. It
Packit Service bf98b9
      demonstrates how to lay out three rectangles in a vertical
Packit Service bf98b9
      column. A different approach is used to set the <varname>x-fill</varname>
Packit Service bf98b9
      property on each rectangle, so each fills the horizontal space in
Packit Service bf98b9
      the layout (each rectangle is 100 pixels wide, while the
Packit Service bf98b9
      box they are inside is 200 pixels wide).</para>
Packit Service bf98b9
Packit Service bf98b9
      <informalexample>
Packit Service bf98b9
        <programlisting>
Packit Service bf98b9
Packit Service bf98b9
/* create a ClutterBoxLayout */
Packit Service bf98b9
box_layout = clutter_box_layout_new ();
Packit Service bf98b9
Packit Service bf98b9
/* configure it to lay out actors vertically */
Packit Service bf98b9
clutter_box_layout_set_vertical (CLUTTER_BOX_LAYOUT (box_layout), TRUE);
Packit Service bf98b9
Packit Service bf98b9
/* put 5px of spacing between actors */
Packit Service bf98b9
clutter_box_layout_set_spacing (CLUTTER_BOX_LAYOUT (box_layout), 5);
Packit Service bf98b9
Packit Service bf98b9
/* actors are packed into this box; we set its width, but
Packit Service bf98b9
 * allow its height to be determined by the children it contains
Packit Service bf98b9
 */
Packit Service bf98b9
box = clutter_actor_new ();
Packit Service bf98b9
clutter_actor_set_layout_manager (box, box_layout);
Packit Service bf98b9
clutter_actor_set_background_color (box, &box_color);
Packit Service bf98b9
clutter_actor_set_position (box, 100, 50);
Packit Service bf98b9
clutter_actor_set_width (box, 200);
Packit Service bf98b9
Packit Service bf98b9
/* pack an actor into the layout and set all layout properties on it
Packit Service bf98b9
 * at the same time
Packit Service bf98b9
 */
Packit Service bf98b9
yellow = clutter_rectangle_new_with_color (&yellow_color);
Packit Service bf98b9
clutter_actor_set_size (yellow, 100, 100);
Packit Service bf98b9
Packit Service bf98b9
clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (box_layout),
Packit Service bf98b9
                         yellow,
Packit Service bf98b9
                         FALSE,                         /* expand */
Packit Service bf98b9
                         TRUE,                          /* x-fill */
Packit Service bf98b9
                         FALSE,                         /* y-fill */
Packit Service bf98b9
                         CLUTTER_BOX_ALIGNMENT_START,   /* x-align */
Packit Service bf98b9
                         CLUTTER_BOX_ALIGNMENT_START);  /* y-align */
Packit Service bf98b9
Packit Service bf98b9
/* add an actor to the box as a container and set layout properties
Packit Service bf98b9
 * afterwards; the latter is useful if you want to change properties on
Packit Service bf98b9
 * actors already inside a layout, but note that you have to
Packit Service bf98b9
 * pass the function both the layout AND the container
Packit Service bf98b9
 */
Packit Service bf98b9
red = clutter_rectangle_new_with_color (&red_color);
Packit Service bf98b9
clutter_actor_set_size (red, 100, 100);
Packit Service bf98b9
Packit Service bf98b9
clutter_actor_add_child (box, blue);
Packit Service bf98b9
Packit Service bf98b9
clutter_layout_manager_child_set (box_layout,
Packit Service bf98b9
                                  CLUTTER_CONTAINER (box),
Packit Service bf98b9
                                  blue,
Packit Service bf98b9
                                  "x-fill", TRUE,
Packit Service bf98b9
                                  NULL);
Packit Service bf98b9
Packit Service bf98b9
blue = clutter_rectangle_new_with_color (&blue_color);
Packit Service bf98b9
clutter_actor_set_size (blue, 100, 100);
Packit Service bf98b9
Packit Service bf98b9
clutter_actor_add_child (box, blue);
Packit Service bf98b9
Packit Service bf98b9
clutter_layout_manager_child_set (box_layout,
Packit Service bf98b9
                                  CLUTTER_CONTAINER (box),
Packit Service bf98b9
                                  blue,
Packit Service bf98b9
                                  "x-fill", TRUE,
Packit Service bf98b9
                                  NULL);
Packit Service bf98b9
Packit Service bf98b9
/* put the box on the stage */
Packit Service bf98b9
clutter_actor_add_child (stage, box);
Packit Service bf98b9
]]>
Packit Service bf98b9
        </programlisting>
Packit Service bf98b9
      </informalexample>
Packit Service bf98b9
Packit Service bf98b9
      <para>The result looks like this:</para>
Packit Service bf98b9
Packit Service bf98b9
      <screenshot>
Packit Service bf98b9
        <mediaobject>
Packit Service bf98b9
          <imageobject>
Packit Service bf98b9
            
Packit Service bf98b9
                       fileref="images/layouts-box.png" />
Packit Service bf98b9
          </imageobject>
Packit Service bf98b9
          <alt>
Packit Service bf98b9
            <para>A simple vertical <type>ClutterBoxLayout</type></para>
Packit Service bf98b9
          </alt>
Packit Service bf98b9
        </mediaobject>
Packit Service bf98b9
      </screenshot>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Discussion</title>
Packit Service bf98b9
Packit Service bf98b9
      <para><type>ClutterBoxLayout</type> is not a reflowing layout:
Packit Service bf98b9
      that is, if the layout's container changes size, the actors inside
Packit Service bf98b9
      aren't automatically repositioned to occupy or find new positions
Packit Service bf98b9
      in its available area. If you want that behaviour, use
Packit Service bf98b9
      <type>ClutterFlowLayout</type> instead.</para>
Packit Service bf98b9
Packit Service bf98b9
      <para>If you want the container to be resizable, but find that
Packit Service bf98b9
      resizing the container obscures its child actors, you could put
Packit Service bf98b9
      the container inside a scrollable area. Then the container's actors
Packit Service bf98b9
      can be scrolled to if they go out of sight.
Packit Service bf98b9
      <link linkend="events-mouse-scroll">This recipe</link> explains
Packit Service bf98b9
      how to make a container scrollable.</para>
Packit Service bf98b9
Packit Service bf98b9
      <section>
Packit Service bf98b9
        <title>Layout properties</title>
Packit Service bf98b9
Packit Service bf98b9
        <para><type>ClutterBoxLayout</type> is very flexible, with
Packit Service bf98b9
        several properties which influence the appearance of the
Packit Service bf98b9
        layout and its children. As with other layouts, these properties
Packit Service bf98b9
        are either applicable to the layout itself, or to individual
Packit Service bf98b9
        children of the layout.</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>As most of these properties are documented in the API reference,
Packit Service bf98b9
        they aren't covered in much detail here. However, below is a brief
Packit Service bf98b9
        overview of the properties available, as well as details of properties
Packit Service bf98b9
        particular to <type>ClutterBoxLayout</type>.</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>The main issue you may face when applying these properties
Packit Service bf98b9
        is understanding how they interact. As this is harder to describe
Packit Service bf98b9
        than to show, you can run the
Packit Service bf98b9
        <link linkend="layouts-box-example-3">example</link>
Packit Service bf98b9
        below to toggle and tweak various properties and see
Packit Service bf98b9
        how they affect the layout's appearance.</para>
Packit Service bf98b9
Packit Service bf98b9
        <note>
Packit Service bf98b9
          <para>The "toggle and tweak"
Packit Service bf98b9
          <link linkend="layouts-box-example-3">example</link> sets
Packit Service bf98b9
          child properties (fill, alignment, expand) on all children
Packit Service bf98b9
          of the layout when those properties are changed. If you want
Packit Service bf98b9
          to see the effect of setting these to different values for
Packit Service bf98b9
          <emphasis>each</emphasis> child, you will have to experiment
Packit Service bf98b9
          yourself.</para>
Packit Service bf98b9
        </note>
Packit Service bf98b9
Packit Service bf98b9
        <section>
Packit Service bf98b9
          <title><type>ClutterBoxLayout</type> properties</title>
Packit Service bf98b9
Packit Service bf98b9
          <para><type>ClutterBoxLayout</type> has the following properties
Packit Service bf98b9
          which affect the appearance of all children inside the container.</para>
Packit Service bf98b9
Packit Service bf98b9
          <note>
Packit Service bf98b9
            <para>Animation properties are covered separately
Packit Service bf98b9
            <link linkend="layouts-box-animating-layout-changes">later</link>.
Packit Service bf98b9
            </para>
Packit Service bf98b9
          </note>
Packit Service bf98b9
Packit Service bf98b9
          <itemizedlist>
Packit Service bf98b9
              <listitem>
Packit Service bf98b9
                <formalpara>
Packit Service bf98b9
                  <title><varname>vertical</varname>; set with
Packit Service bf98b9
                  <function>clutter_box_layout_set_vertical()</function></title>
Packit Service bf98b9
Packit Service bf98b9
                  <para>Set to <constant>TRUE</constant> to lay out
Packit Service bf98b9
                  child actors in a column; if <constant>FALSE</constant>
Packit Service bf98b9
                  (the default), actors are laid out horizontally.</para>
Packit Service bf98b9
                </formalpara>
Packit Service bf98b9
              </listitem>
Packit Service bf98b9
Packit Service bf98b9
              <listitem>
Packit Service bf98b9
                <formalpara>
Packit Service bf98b9
                  <title><varname>homogeneous</varname>; set with
Packit Service bf98b9
                  <function>clutter_box_layout_set_homogeneous()</function></title>
Packit Service bf98b9
Packit Service bf98b9
                  <para>Set to <constant>TRUE</constant> to allocate all
Packit Service bf98b9
                  child actors the same amount of space in the row or column
Packit Service bf98b9
                  (depending on the setting for <varname>vertical</varname>).
Packit Service bf98b9
                  This overrides per-actor <varname>expand</varname> settings
Packit Service bf98b9
                  and preferred sizes for child actors. The default value for
Packit Service bf98b9
                  this property is <constant>FALSE</constant>.</para>
Packit Service bf98b9
                </formalpara>
Packit Service bf98b9
              </listitem>
Packit Service bf98b9
Packit Service bf98b9
              <listitem>
Packit Service bf98b9
                <formalpara>
Packit Service bf98b9
                  <title><varname>spacing</varname>; set with
Packit Service bf98b9
                  <function>clutter_box_layout_set_spacing()</function></title>
Packit Service bf98b9
Packit Service bf98b9
                  <para>Sets the number of pixels to place between actors
Packit Service bf98b9
                  in the layout.</para>
Packit Service bf98b9
                </formalpara>
Packit Service bf98b9
Packit Service bf98b9
                <para>Note that if you increase spacing too much, actors
Packit Service bf98b9
                may go outside the edges of the layout's container (if
Packit Service bf98b9
                the container has a fixed size).</para>
Packit Service bf98b9
              </listitem>
Packit Service bf98b9
Packit Service bf98b9
              <listitem>
Packit Service bf98b9
                <formalpara>
Packit Service bf98b9
                  <title><varname>pack-start</varname>; set with
Packit Service bf98b9
                  <function>clutter_box_layout_set_pack_start()</function></title>
Packit Service bf98b9
Packit Service bf98b9
                  <para>Set <varname>pack-start</varname> to
Packit Service bf98b9
                  <constant>TRUE</constant> to configure the layout to
Packit Service bf98b9
                  prepend actors to the row or column; the default is
Packit Service bf98b9
                  <constant>FALSE</constant>, meaning that actors are
Packit Service bf98b9
                  appended to the row or column when added.</para>
Packit Service bf98b9
                </formalpara>
Packit Service bf98b9
Packit Service bf98b9
                <para>Changing this property on a layout which already has
Packit Service bf98b9
                actors in it will reverse the order of those actors, as
Packit Service bf98b9
                well as changing how new actors are added to the layout.</para>
Packit Service bf98b9
              </listitem>
Packit Service bf98b9
            </itemizedlist>
Packit Service bf98b9
Packit Service bf98b9
          </section>
Packit Service bf98b9
Packit Service bf98b9
          <section>
Packit Service bf98b9
            <title>Child properties</title>
Packit Service bf98b9
Packit Service bf98b9
            <para>These properties apply to individual children within
Packit Service bf98b9
            the layout's container. Each child can have different values
Packit Service bf98b9
            for each of these properties.</para>
Packit Service bf98b9
Packit Service bf98b9
            <para>To set properties, you can use
Packit Service bf98b9
            <function>clutter_box_layout_pack()</function> or
Packit Service bf98b9
            <function>clutter_box_pack()</function> (if using a
Packit Service bf98b9
            <type>ClutterBox</type>) while packing actors into the layout.
Packit Service bf98b9
            You can also set properties later using
Packit Service bf98b9
            <function>clutter_layout_manager_child_set()</function>
Packit Service bf98b9
            etc. See the <link linkend="layouts-introduction">layouts
Packit Service bf98b9
            introduction</link> for more details.</para>
Packit Service bf98b9
Packit Service bf98b9
            <itemizedlist>
Packit Service bf98b9
              <listitem>
Packit Service bf98b9
                <para><varname>x-fill</varname> and <varname>y-fill</varname>
Packit Service bf98b9
                set whether an actor will fill its allocated horizontal
Packit Service bf98b9
                or vertical space (respectively) within the layout. Setting
Packit Service bf98b9
                these properties only has an effect where an actor is smaller
Packit Service bf98b9
                (on the appropriate fill axes) than the layout's container.</para>
Packit Service bf98b9
Packit Service bf98b9
                <para>Note that the actor's actual size is not changed
Packit Service bf98b9
                if it is set to fill: the reported width and height are
Packit Service bf98b9
                unaffected.</para>
Packit Service bf98b9
              </listitem>
Packit Service bf98b9
Packit Service bf98b9
              <listitem>
Packit Service bf98b9
                <para><varname>expand</varname> sets whether an actor
Packit Service bf98b9
                will be expanded inside the layout. If
Packit Service bf98b9
                <varname>expand</varname> is <constant>TRUE</constant>
Packit Service bf98b9
                and <varname>fill</varname> is <constant>TRUE</constant>
Packit Service bf98b9
                for the orientation axis, the actor is resized to fill
Packit Service bf98b9
                its whole allocation on that axis; if <varname>expand</varname>
Packit Service bf98b9
                is <constant>TRUE</constant> but <varname>fill</varname>
Packit Service bf98b9
                is <constant>FALSE</constant>, extra padding is added
Packit Service bf98b9
                around the actor to fill the allocation.</para>
Packit Service bf98b9
              </listitem>
Packit Service bf98b9
Packit Service bf98b9
              <listitem>
Packit Service bf98b9
                <para><varname>x-align</varname> and <varname>y-align</varname>
Packit Service bf98b9
                set how an actor is aligned within its allocation, in
Packit Service bf98b9
                cases where it doesn't fill that allocation. In practical
Packit Service bf98b9
                terms, these properties come into effect if a child is set
Packit Service bf98b9
                to expand but <varname>fill</varname> is set to
Packit Service bf98b9
                <constant>FALSE</constant> on the align axis.</para>
Packit Service bf98b9
Packit Service bf98b9
                <para>For example, if <varname>expand</varname> is
Packit Service bf98b9
                <constant>TRUE</constant> but <varname>x-fill</varname>
Packit Service bf98b9
                is <constant>FALSE</constant>, some padding is added
Packit Service bf98b9
                around the actor to fill its allocation. In this case,
Packit Service bf98b9
                the <varname>x-align</varname> property can be set to
Packit Service bf98b9
                align the actor to the left, center or right of the
Packit Service bf98b9
                allocation; any whitespace would be redistributed around
Packit Service bf98b9
                the actor's new position after alignment.</para>
Packit Service bf98b9
              </listitem>
Packit Service bf98b9
            </itemizedlist>
Packit Service bf98b9
Packit Service bf98b9
            <para>These properties are only useful where you have
Packit Service bf98b9
            actors of non-uniform sizes and/or a container which is
Packit Service bf98b9
            either wider or taller (or both) than one or more of the
Packit Service bf98b9
            child actors it contains.</para>
Packit Service bf98b9
Packit Service bf98b9
          </section>
Packit Service bf98b9
Packit Service bf98b9
      </section>
Packit Service bf98b9
Packit Service bf98b9
      <section id="layouts-box-animating-layout-changes">
Packit Service bf98b9
        <title>Animating layout changes</title>
Packit Service bf98b9
Packit Service bf98b9
        <para>If actors are added to a layout, or if the layout's
Packit Service bf98b9
        properties or its children's properties are changed, the
Packit Service bf98b9
        appearance of the layout may also change. The
Packit Service bf98b9
        <varname>use-animations</varname> property (set with
Packit Service bf98b9
        <function>clutter_box_layout_set_use_animations()</function>)
Packit Service bf98b9
        determines whether such changes to the layout are animated: if set
Packit Service bf98b9
        to <constant>TRUE</constant>, any changes to actor
Packit Service bf98b9
        allocations resulting from the changes (movements, resizings)
Packit Service bf98b9
        are animated.</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>If this property is <constant>FALSE</constant> (the default)
Packit Service bf98b9
        changes to other properties or addition of new actors will
Packit Service bf98b9
        cause actors to be laid out instantaneously. For example, if
Packit Service bf98b9
        a new actor is prepended with animations on, the new actor is
Packit Service bf98b9
        added to the layout and the other actors shifted to make room
Packit Service bf98b9
        for it; if animations are off, child actors jump to their new
Packit Service bf98b9
        positions at the same instant as the new actor is added.</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>To change the appearance of the animations, you can use
Packit Service bf98b9
        <function>clutter_box_layout_set_easing_mode()</function> and
Packit Service bf98b9
        <function>clutter_box_layout_set_duration()</function> (see the
Packit Service bf98b9
        <link linkend="animations-introduction">animations
Packit Service bf98b9
        introduction</link> for more about easing and duration
Packit Service bf98b9
        properties).</para>
Packit Service bf98b9
Packit Service bf98b9
        <para>The <link linkend="layouts-box-example-3">"toggle and tweak"
Packit Service bf98b9
        example</link> uses animation for layout changes, and can give
Packit Service bf98b9
        you some idea of what to expect in your own animated layouts.</para>
Packit Service bf98b9
Packit Service bf98b9
      </section>
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
    <section>
Packit Service bf98b9
      <title>Full examples</title>
Packit Service bf98b9
Packit Service bf98b9
      <example id="layouts-box-example-1">
Packit Service bf98b9
        <title>Different approaches to setting child layout properties
Packit Service bf98b9
        in a <type>ClutterBoxLayout</type></title>
Packit Service bf98b9
        <programlisting>
Packit Service bf98b9
<xi:include href="examples/layouts-box.c" parse="text">
Packit Service bf98b9
  <xi:fallback>a code sample should be here... but isn't</xi:fallback>
Packit Service bf98b9
</xi:include>
Packit Service bf98b9
        </programlisting>
Packit Service bf98b9
      </example>
Packit Service bf98b9
Packit Service bf98b9
      <example id="layouts-box-example-2">
Packit Service bf98b9
        <title>A simple <type>ClutterBoxLayout</type> menu</title>
Packit Service bf98b9
        <programlisting>
Packit Service bf98b9
<xi:include href="examples/layouts-box-menu.c" parse="text">
Packit Service bf98b9
  <xi:fallback>a code sample should be here... but isn't</xi:fallback>
Packit Service bf98b9
</xi:include>
Packit Service bf98b9
        </programlisting>
Packit Service bf98b9
      </example>
Packit Service bf98b9
Packit Service bf98b9
      <example id="layouts-box-example-3">
Packit Service bf98b9
        <title>A demonstrator for "toggling and tweaking" a
Packit Service bf98b9
        <type>ClutterBoxLayout's</type> properties</title>
Packit Service bf98b9
        <programlisting>
Packit Service bf98b9
<xi:include href="examples/layouts-box-property-effects.c" parse="text">
Packit Service bf98b9
  <xi:fallback>a code sample should be here... but isn't</xi:fallback>
Packit Service bf98b9
</xi:include>
Packit Service bf98b9
        </programlisting>
Packit Service bf98b9
      </example>
Packit Service bf98b9
Packit Service bf98b9
    </section>
Packit Service bf98b9
Packit Service bf98b9
  </section>
Packit Service bf98b9
Packit Service bf98b9
</chapter>