Toc Gallery Index Tree Gtk.Box

Screenshot

No screeshot

Hierarchy

Description

A box is a container that can have multiple children, organized either horizontally or vertically. Two subtypes are provided, Gtk_Hbox and Gtk_Vbox, to conform to the C API. In Ada, you do not need to distinguish between the two, but note that the Gtk_Box type is conceptually an abstract type: there is no way to create a "Gtk_Box", only ways to create either an horizontal box, or a vertical box.

Children can be added to one of two positions in the box, either at the beginning (ie left or top) or at the end (ie right or bottom). Each of these positions can contain multiple widgets.

Every time a child is added to the start, it is placed to the right (resp. the bottom) of the previous widget added to the start.

Every time a child is added to the end, it is placed to the left (resp. the top) of the previous widget added to the end.

There are a number of parameters to specify the behavior of the box when it is resized, and how the children should be reorganized and/or resized.

See the testgtk example in the GtkAda distribution to see concrete examples on how all the parameters for the boxes work.

Types

  • type Gtk_Box is access all Gtk_Box_Record'Class;
  • type Gtk_Box_Record is new Gtk.Container.Gtk_Container_Record with private;
  • type Gtk_Hbox is Gtk_Box;
  • type Gtk_Hbox_Record is Gtk_Box_Record;
  • type Gtk_Vbox is Gtk_Box;
  • type Gtk_Vbox_Record is Gtk_Box_Record;

Subprograms

  • procedure Gtk_New_Vbox (Box : out Gtk_Box; Homogeneous : Boolean := False; Spacing : Gint := 0);
    Create a new vertical box. Its children will be placed one above the other. If Homogeneous is True, all the children will be allocated exactly the same screen real-estate, whereas if it is False, each child can have its own size. Spacing is the space left between two adjacent children.
  • procedure Gtk_New_Hbox (Box : out Gtk_Box; Homogeneous : Boolean := False; Spacing : Gint := 0);
    Create a new horizontal box. Its children will be placed one besides the other. If Homogeneous is True, all the children will be allocated exactly the same screen real-estate, whereas if it is False, each child can have its own size. Spacing is the space left between two adjacent children.
  • procedure Initialize_Vbox (Box : access Gtk_Box_Record'Class; Homogeneous : Boolean := False; Spacing : Gint := 0);
    Internal initialization function. See the section "Creating your own widgets" in the documentation.
  • procedure Initialize_Hbox (Box : access Gtk_Box_Record'Class; Homogeneous : Boolean := False; Spacing : Gint := 0);
    Internal initialization function. See the section "Creating your own widgets" in the documentation.
  • function Get_Type return Gtk.Gtk_Type;
    Return the internal value associated with a Gtk_Box.
  • function Get_Hbox_Type return Gtk.Gtk_Type;
    Return the internal value associated with a Gtk_HBox.
  • function Get_Vbox_Type return Gtk.Gtk_Type;
    Return the internal value associated with a Gtk_VBox.
  • procedure Pack_Start (In_Box : access Gtk_Box_Record; Child : access Gtk.Widget.Gtk_Widget_Record'Class; Expand : Boolean := True; Fill : Boolean := True; Padding : Gint := 0);
    Add a new child to the beginning of the box (ie left or top part). It is added to the right (resp. the bottom) of the previous child added to the beginning of the box. Note that a child added to the beginning of the box will always remain on the left (resp. top) of all the children added to the end of the box.

    If Expand is False, the size allocated for each size will be the one requested by the widget (or the largest child if Homogeneous was set to true when the box was created). Otherwise, the total size of the box is divided between all the children. Note that this does not mean that the children have to occupy all the space given to them...

    If Fill is True, then the widget will be resized so as to occupy all the space allocated to them. This is only relevant if Expand is True, since otherwise the space allocated is the same one as the child's size.

    Padding is the amount of space left around the widget when it is drawn.

  • procedure Pack_End (In_Box : access Gtk_Box_Record; Child : access Gtk.Widget.Gtk_Widget_Record'Class; Expand : Boolean := True; Fill : Boolean := True; Padding : Gint := 0);
    Add a new child to the end of the box (ie right or bottom part). It is added to the left (resp. top) of the previous child added to the end of the box. Note that a child added to the end of the box will always remain on the right (resp. bottom) of all the children added to the beginning of the box.

    See Pack_Start for an explanation of all the parameters.

  • procedure Pack_Start_Defaults (In_Box : access Gtk_Box_Record; Child : access Gtk.Widget.Gtk_Widget_Record'Class);
    This is the same as Pack_Start if you use the default parameter values. It is provided for backward compatibility only.
  • procedure Pack_End_Defaults (In_Box : access Gtk_Box_Record; Child : access Gtk.Widget.Gtk_Widget_Record'Class);
    This is the same as Pack_End if you use the default parameter values. It is provided for backward compatibility only.
  • procedure Set_Homogeneous (In_Box : access Gtk_Box_Record; Homogeneous : Boolean);
    function Get_Homogeneous (In_Box : access Gtk_Box_Record) return Boolean;
    Modify or get the homogeneous parameter for the box. If the box is homogeneous, then all its children will be allocated the same amount of space, even if they are not resized to occupy it (depending on the parameters given to Pack_Start and Pack_End).
  • procedure Set_Spacing (In_Box : access Gtk_Box_Record; Spacing : Gint);
    function Get_Spacing (In_Box : access Gtk_Box_Record) return Gint;
    Modify the spacing for the box. I.e. the amount of space left between two adjacent children.
  • procedure Reorder_Child (In_Box : access Gtk_Box_Record; Child : access Gtk.Widget.Gtk_Widget_Record'Class; Pos : Guint);
    Move the Child to a new position. Nothing is done if Child is not in the box. Pos starts at 0, and indicates the position of the child relative to all other children, no matter where they were packed (the beginning or the end of the box).
  • procedure Set_Child_Packing (In_Box : access Gtk_Box_Record; Child : access Gtk.Widget.Gtk_Widget_Record'Class; Expand : Boolean; Fill : Boolean; Padding : Gint; Pack_Type : Gtk.Enums.Gtk_Pack_Type);
    procedure Query_Child_Packing (In_Box : access Gtk_Box_Record; Child : access Gtk.Widget.Gtk_Widget_Record'Class; Expand : out Boolean; Fill : out Boolean; Padding : out Gint; PackType : out Gtk.Enums.Gtk_Pack_Type);
    Get information on how the child was packed in the box. The results are undefined if Child is not in the box.
  • function Get_Child (Box : access Gtk_Box_Record; Num : Gint) return Gtk.Widget.Gtk_Widget;
    Return the Num-th child of the box, or null if there is no such child.

Signals

Properties

  • Homogeneous_Property
    Boolean
    Whether the childrenshould all be the same size.
    See: Set_Homogeneous
  • Spacing_Property
    Gint
    The amount of space between children.
    See: Set_Spacing and Get_Spacing

Child Properties

  • Expand_Property
    Boolean
    Whether the child should receive extra space when the parent
  • Fill_Property
    Boolean
    Whether extra space given to the child should be allocated to the
  • Pack_Type_Property
    Enum
    A GtkPackType indicating whether the child is packed with
  • Padding_Property
    Uint
    Extra space to put between the child and its neighbors, in pixels
  • Position_Property
    Int
    The index of the child in the parent

Testgtk source code

This code is part of testgtk, a demo application packaged with GtkAda. Testgtk demonstrates the various widgets of GtkAda
----------------------------------------------------------------------- -- GtkAda - Ada95 binding for the Gimp Toolkit -- -- -- -- Copyright (C) 1998-1999 -- -- Emmanuel Briot, Joel Brobecker and Arnaud Charlet -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public -- -- License as published by the Free Software Foundation; either -- -- version 2 of the License, or (at your option) any later version. -- -- -- -- This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- General Public License for more details. -- -- -- -- You should have received a copy of the GNU General Public -- -- License along with this library; if not, write to the -- -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- -- Boston, MA 02111-1307, USA. -- -- -- -- -- -- -- -- -- -- ----------------------------------------------------------------------- with Glib; use Glib; with Gtk.Box; use Gtk.Box; with Gtk.Button; use Gtk.Button; with Gtk.Frame; use Gtk.Frame; with Gtk.Label; use Gtk.Label; with Gtk.Separator; use Gtk.Separator; with Gtk; use Gtk; package body Create_Box is procedure Add_Buttons (Vbox : Gtk_Box; Message : String; Homogeneous : Boolean; Expand : Boolean := False; Fill : Boolean := False); -- Add the buttons within Vbox ---------- -- Help -- ---------- function Help return String is begin return "This demo show how you can efficiently use the @bGtk_Box@B " & "container." & ASCII.LF & ASCII.LF & "The upper half shows the different " & "combinations of the parameters @bHomogeneous@B, @bExpand@B and " & "@bFill@B. Note that for homogeneous boxes, @bExpand@B is irrelevant." & ASCII.LF & " - @bHomogeneous@B: If True all the widgets in the box will have the " & "same size as the largest child." & ASCII.LF & " - @bExpand@B: If True, the widget size will be bigger than the " & "minimum requested if more space is available. Its exact size " & "depends on the @bFill@B parameter" & ASCII.LF & " - @bFill@B: If False, the widget will be surrounded by empty space," & " but its real size will be the minimum it requested." & ASCII.LF & ASCII.LF & "The second part of the demo shows the difference between " & "@bPack_Start@B and @bPack_End@B. The two resulting groups are " & "separated by a space that expands when the box is resized. This " & "space of course exists only when the widgets do not expand. " & "The buttons are inserted in the order specified (first button, " & " second button, ...)"; end Help; ----------------- -- Add_Buttons -- ----------------- procedure Add_Buttons (Vbox : Gtk_Box; Message : String; Homogeneous : Boolean; Expand : Boolean := False; Fill : Boolean := False) is Button : Gtk_Button; Box : Gtk_Box; Label : Gtk_Label; begin Gtk_New (Label, Message); Pack_Start (Vbox, Label, Expand => False, Fill => False); Gtk_New_Hbox (Box, Homogeneous => Homogeneous); Pack_Start (Vbox, Box, Expand => False, Fill => False); Gtk_New (Button, "Small"); Pack_Start (Box, Button, Expand => Expand, Fill => Fill); Gtk_New (Button, "A bit longer"); Pack_Start (Box, Button, Expand => Expand, Fill => Fill); Gtk_New (Button, "The longest button"); Pack_Start (Box, Button, Expand => Expand, Fill => Fill); end Add_Buttons; --------- -- Run -- --------- procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is Vbox : Gtk_Box; Box : Gtk_Box; Button : Gtk_Button; Sep : Gtk_Separator; begin Gtk.Frame.Set_Label (Frame, "Boxes"); Gtk_New_Vbox (Vbox, Homogeneous => False, Spacing => 25); Add (Frame, Vbox); Gtk_New_Vbox (Box, Homogeneous => True); Pack_Start (Vbox, Box, Expand => False, Fill => False); Add_Buttons (Box, "Homogeneous => False, Expand => False", Homogeneous => False, Expand => False, Fill => False); Add_Buttons (Box, "Homogeneous => False, Expand => True, Fill => False", Homogeneous => False, Expand => True, Fill => False); Add_Buttons (Box, "Homogeneous => False, Expand => True, Fill => True", Homogeneous => False, Expand => True, Fill => True); Add_Buttons (Box, "Homogeneous => True, Fill => False", Homogeneous => True, Fill => False); Add_Buttons (Box, "Homogeneous => True, Fill => True", Homogeneous => True, Fill => True); Gtk_New_Hseparator (Sep); Pack_Start (Vbox, Sep, Expand => False, Fill => True); Gtk_New_Vbox (Box, Homogeneous => False); Pack_Start (Vbox, Box, Expand => True, Fill => True, Padding => 10); Gtk_New (Button, "Pack_Start, First Button"); Pack_Start (Box, Button, Expand => False, Fill => False); Gtk_New (Button, "Pack_Start, Second Button"); Pack_Start (Box, Button, Expand => False, Fill => False); Gtk_New (Button, "Pack_Start, Third Button"); Pack_Start (Box, Button, Expand => False, Fill => False); Gtk_New (Button, "Pack_End, First Button"); Pack_End (Box, Button, Expand => False, Fill => False); Gtk_New (Button, "Pack_End, Second Button"); Pack_End (Box, Button, Expand => False, Fill => False); Gtk_New (Button, "Pack_End, Third Button"); Pack_End (Box, Button, Expand => False, Fill => False); Show_All (Frame); end Run; end Create_Box;

Alphabetical Index