Toc Gallery Index Tree Gtk.Layout

Screenshot

No screeshot

Hierarchy

Description

A Gtk_Layout is a widget that can have an almost infinite size, without occupying a lot of memory. Its children can be located anywhere within it, but will only appear on the screen if the visible area of the layout contains them. Just like a Gtk_Viewport, its visible area is indicated by two Gtk_Adjustment widgets, and thus a Gtk_Layout can be put as is in a Gtk_Scrolled_Window. As for Gtk_Fixed containers, the children can be located anywhere in the layout (no automatic organization is done). But, as opposed to Gtk_Fixed widgets, a Gtk_Layout does not try to resize itself to show all its children.

Starting from GtkAda 2.0, you have to call Set_Size and specify the maximum size of the layout, otherwise children added with Put outside the size defined for the layout will never be visible. One way to do this is to systematically call Set_Size before calling Put, and make sure you specify a size big enough for the layout.

Types

Subprograms

  • procedure Gtk_New (Layout : out Gtk_Layout; Hadjustment : Adjustment.Gtk_Adjustment := null; Vadjustment : Adjustment.Gtk_Adjustment := null);
    Create new layout. You can either give an explicit couple of adjustments, that will indicate the current visible area. If you don't specify any, they will be created automatically by GtkAda, which is the usual way to do. The Layout does not occupy any area on the screen, and you have to explicitly specify one with Set_Size below.
  • procedure Initialize (Layout : access Gtk_Layout_Record'Class; Hadjustment : Gtk.Adjustment.Gtk_Adjustment; Vadjustment : Gtk.Adjustment.Gtk_Adjustment);
    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_Layout.
  • procedure Put (Layout : access Gtk_Layout_Record; Widget : access Gtk.Widget.Gtk_Widget_Record'Class; X : Gint; Y : Gint);
    Insert a new child in the layout. The child will be displayed on the screen only if at least part of it intersects the visible area of the layout. The layout does not resize itself to automatically show the widget. You also need to call Set_Size, if the size you initially defined is smaller than (X, Y), or the child will never be visible even if the layout is scrolled.
  • procedure Move (Layout : access Gtk_Layout_Record; Widget : access Gtk.Widget.Gtk_Widget_Record'Class; X : Gint; Y : Gint);
    Move a child of the layout. Nothing is done if Widget is not already a child of Layout.
  • function Get_Bin_Window (Widget : access Gtk_Layout_Record) return Gdk.Window.Gdk_Window;
    Return the window associated with the layout. You should use this one rather than Gtk.Widget.Get_Window.
  • procedure Set_Size (Layout : access Gtk_Layout_Record; Width : Guint; Height : Guint);
    procedure Get_Size (Layout : access Gtk_Layout_Record; Width : out Guint; Height : out Guint);
    Specify an absolute size for the layout. This is not the size on the screen, but the internal size of the widget. The screen's size can be set with Gtk.Widget.Set_Usize.
  • procedure Set_Hadjustment (Layout : access Gtk_Layout_Record; Adjustment : Gtk.Adjustment.Gtk_Adjustment);
    function Get_Hadjustment (Layout : access Gtk_Layout_Record) return Gtk.Adjustment.Gtk_Adjustment;
    Return the adjustment that indicate the horizontal visual area of the layout. You generally do not have to modify the value of this adjustment yourself, since this is done automatically when the layout has been put in a Gtk_Scrolled_Window.
  • procedure Set_Vadjustment (Layout : access Gtk_Layout_Record; Adjustment : Gtk.Adjustment.Gtk_Adjustment);
    function Get_Vadjustment (Layout : access Gtk_Layout_Record) return Gtk.Adjustment.Gtk_Adjustment;
    Return the adjustment that indicate the vertical visual area of the layout. You generally do not have to modify the value of this adjustment yourself, since this is done automatically when the layout has been put in a Gtk_Scrolled_Window.

Signals

Properties

  • Hadjustment_Property
    Gtk_Adjustment_Record'Class
    The GtkAdjustment for the horizontal position.
    See: Set_Hadjustment and Get_Hadjustment
  • Height_Property
    Guint
    The height of the layout.
    See: Set_Size and Get_Height
  • Vadjustment_Property
    Gtk_Adjustment_Record'Class
    The GtkAdjustment for the vertical position.
    See: Set_Vadjustment and Get_Vadjustment
  • Width_Property
    Guint
    The width of the layout.
    See: Set_Size and Get_Width

Child Properties

  • X_Property
    Int
    X position of child widget
  • Y_Property
    Int
    Y position of child widget

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) 2000 -- -- 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 Gdk.Drawable; use Gdk.Drawable; with Gdk.Event; use Gdk.Event; with Gdk.Rectangle; use Gdk.Rectangle; with Gdk.Window; use Gdk.Window; with Glib; use Glib; with Gtk.Adjustment; use Gtk.Adjustment; with Gtk.Button; use Gtk.Button; with Gtk.Enums; use Gtk.Enums; with Gtk.Frame; use Gtk.Frame; with Gtk.Handlers; use Gtk.Handlers; with Gtk.Label; use Gtk.Label; with Gtk.Layout; use Gtk.Layout; with Gtk.Scrolled_Window; use Gtk.Scrolled_Window; with Gtk.Style; use Gtk.Style; package body Create_Layout is package Event_Cb is new Gtk.Handlers.Return_Callback (Gtk_Layout_Record, Boolean); ---------- -- Help -- ---------- function Help return String is begin return "A @bGtk_Layout@B is a mixture between a @bGtk_Viewport@B and" & " a @bGtk_Fixed@B. Its children can be located anywhere, the layout" & " does not try to align them in any way. As opposed to a" & " @bGtk_Fixed@B, there is no limit to the size of a @bGtk_Layout@B" & " and it won't use as much memory as a @bGtk_Fixed@B." & ASCII.LF & "The area that is currently visible is indicated by two" & " @bGtk_Alignment@B widgets. It can thus be put directly into a" & " @bGtk_Scrolled_Window@B widget, as is the case in this demo." & ASCII.LF & "In this demo, the background is painted by a callback on the" & " expose_event, and thus does not occupy any memory." & " The Layout has a size of 1600 by 128000."; end Help; -------------------- -- Expose_Handler -- -------------------- function Expose_Handler (Layout : access Gtk_Layout_Record'Class; Event : Gdk_Event_Expose) return Boolean is Area : constant Gdk_Rectangle := Get_Area (Event); Imin, Imax : Guint; Jmin, Jmax : Guint; begin Imin := Guint (Area.X) / 10; Imax := (Guint (Area.X) + Guint (Area.Width) + 9) / 10; Jmin := Guint (Area.Y) / 10; Jmax := (Guint (Area.Y) + Guint (Area.Height) + 9) / 10; Clear_Area (Get_Window (Layout), Area.X, Area.Y, Gint (Area.Width), Gint (Area.Height)); for I in Imin .. Imax - 1 loop for J in Jmin .. Jmax - 1 loop if (I + J) mod 2 /= 0 then Draw_Rectangle (Get_Bin_Window (Layout), Get_Black_GC (Get_Style (Layout)), True, Gint (10 * I), Gint (10 * J), Gint (1 + I mod 10), Gint (1 + J mod 10)); end if; end loop; end loop; return True; end Expose_Handler; --------- -- Run -- --------- procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is Scrolled : Gtk_Scrolled_Window; Layout : Gtk_Layout; Button : Gtk_Button; Label : Gtk_Label; begin Set_Label (Frame, "Layout"); Gtk_New (Scrolled); Set_Shadow_Type (Scrolled, Shadow_In); Add (Frame, Scrolled); Set_Placement (Scrolled, Corner_Top_Right); Gtk_New (Layout); Set_Events (Layout, Exposure_Mask); Add (Scrolled, Layout); Set_Step_Increment (Get_Hadjustment (Layout), 10.0); Set_Step_Increment (Get_Vadjustment (Layout), 10.0); Event_Cb.Connect (Layout, "expose_event", Event_Cb.To_Marshaller (Expose_Handler'Access)); Set_Size (Layout, 1600, 128000); for I in 0 .. Gint'(15) loop for J in 0 .. Gint'(15) loop if (I + J) mod 2 /= 0 then Gtk_New (Button, "Button " & Gint'Image (I) & " " & Gint'Image (J)); Put (Layout, Button, J * 100, I * 100); else Gtk_New (Label, "Label " & Gint'Image (I) & " " & Gint'Image (J)); Put (Layout, Label, J * 100, I * 100); end if; end loop; end loop; for I in 16 .. Gint'(1279) loop if I mod 2 /= 0 then Gtk_New (Button, "Button " & Gint'Image (I) & " 0"); Put (Layout, Button, 0, I * 100); else Gtk_New (Label, "Label " & Gint'Image (I) & " 0"); Put (Layout, Label, 0, I * 100); end if; end loop; Show_All (Frame); end Run; end Create_Layout;

Alphabetical Index