Toc Gallery Index Tree Gtk.Spin_Button

Screenshot

No screeshot

Hierarchy

Description

A Gtk_Spin_Button is a single line text editing widget for text that represents a number. At the right hand side of the text line there are small up- and down arrow buttons for incrementing or decrementing (spinning) the number within a given range. It allows the value to have zero or a number of decimal places and to be incremented/decremented in configurable steps. The action of holding down one of the buttons optionally results in an acceleration of change in the value according to how long it is depressed.

See Gtk.GEntry for a text editing widget without spin buttons.

Types

  • type Gtk_Spin_Button is access all Gtk_Spin_Button_Record'Class;
  • type Gtk_Spin_Button_Record is new Gtk.GEntry.Gtk_Entry_Record with private;
  • type Gtk_Spin_Button_Update_Policy is (Update_Always, -- Update always, errors are ignored while converting text into a -- numeric value. Update_If_Valid -- The spin button's value gets changed if the text input is a numeric -- value that is within the range specified by the adjustment. );
    Determine the update policy of the spin button which affects the behaviour when parsing inserted text and syncing its value with the values of the adjustment.
  • type Gtk_Spin_Type is (Spin_Step_Forward, Spin_Step_Backward, Spin_Page_Forward, Spin_Page_Backward, Spin_Home, Spin_End, Spin_User_Defined);
    Determine how manual spinning should be done. See also the Spin procedure.
  • type Property_Spin_Button_Update_Policy_Type is new Spin_Button_Update_Policy_Properties.Property;

Subprograms

  • procedure Gtk_New (Spin_Button : out Gtk_Spin_Button; Adjustment : Gtk.Adjustment.Gtk_Adjustment; Climb_Rate : Gdouble; The_Digits : Gint);
    Create a spin button with the given parameters. Adjustment contains the range, current value, step value and "page" value. The step value is the increment/decrement when pressing mouse button 1 on a button; the page value when mouse button 2 is pressed. Additionally, mouse button 3 can be used to jump directly to the or lower values when used to select one of the buttons. Climb_Rate takes a value between 0.0 and 1.0 and indicates the amount of acceleration that the Spin Button has. The_Digits is the number of digits behind the decimal point to be displayed for the value.
  • procedure Gtk_New (Spin_Button : out Gtk_Spin_Button; Min : Gdouble; Max : Gdouble; Step : Gdouble);
    Same as above, but with explicit range instead of an adjustment. The adjustment associated with Spin_Button is created internally.
  • procedure Initialize (Spin_Button : access Gtk_Spin_Button_Record'Class; Adjustment : Gtk.Adjustment.Gtk_Adjustment; Climb_Rate : Gdouble; The_Digits : Gint);
    Internal initialization function. See the section "Creating your own widgets" in the documentation.
  • procedure Initialize (Spin_Button : access Gtk_Spin_Button_Record'Class; Min : Gdouble; Max : Gdouble; Step : Gdouble);
    Internal initialization function.
  • function Get_Type return Gtk.Gtk_Type;
    Return the internal value associated with a Gtk_Spin_Button.
  • procedure Set_Adjustment (Spin_Button : access Gtk_Spin_Button_Record; Adjustment : Gtk.Adjustment.Gtk_Adjustment);
    function Get_Adjustment (Spin_Button : access Gtk_Spin_Button_Record) return Gtk.Adjustment.Gtk_Adjustment;
    Set or Get the adjustment settings of the spin button.
  • procedure Set_Digits (Spin_Button : access Gtk_Spin_Button_Record; The_Digits : Guint);
    function Get_Digits (Spin_Button : access Gtk_Spin_Button_Record) return Guint;
    Set or Get number of decimals of the spin button.
  • procedure Set_Increments (Spin_Button : access Gtk_Spin_Button_Record; Step : Gdouble; Page : Gdouble);
    procedure Get_Increments (Spin_Button : access Gtk_Spin_Button_Record; Step : out Gdouble; Page : out Gdouble);
    Set or Get the increments for a single step and a page move.
  • procedure Set_Range (Spin_Button : access Gtk_Spin_Button_Record; Min : Gdouble; Max : Gdouble);
    procedure Get_Range (Spin_Button : access Gtk_Spin_Button_Record; Min : out Gdouble; Max : out Gdouble);
    Set or Get range of the spin button.
  • procedure Set_Value (Spin_Button : access Gtk_Spin_Button_Record; Value : Gdouble);
    function Get_Value (Spin_Button : access Gtk_Spin_Button_Record) return Gdouble;
    Set or Get the current value of the spin button in a double.
  • function Get_Value_As_Int (Spin_Button : access Gtk_Spin_Button_Record) return Gint;
    Return the current value of the spin button in an integer.
  • procedure Set_Update_Policy (Spin_Button : access Gtk_Spin_Button_Record; Policy : Gtk_Spin_Button_Update_Policy);
    function Get_Update_Policy (Spin_Button : access Gtk_Spin_Button_Record) return Gtk_Spin_Button_Update_Policy;
    Set the update policy of the spin button. See Gtk_Spin_Button_Update_Policy for the meaning of Policy.
  • procedure Set_Numeric (Spin_Button : access Gtk_Spin_Button_Record; Numeric : Boolean);
    function Get_Numeric (Spin_Button : access Gtk_Spin_Button_Record) return Boolean;
    If Numeric is True, then only a numeric value can be typed in the text entry, otherwise also nonnumeric text.
  • procedure Spin (Spin_Button : access Gtk_Spin_Button_Record; Direction : Gtk_Spin_Type; Step : Gdouble);
    Set the value of the spin button relative to its current value. Depending on Direction, it will be incremented or decremented with the step value.
  • procedure Set_Wrap (Spin_Button : access Gtk_Spin_Button_Record; Wrap : Boolean);
    function Get_Wrap (Spin_Button : access Gtk_Spin_Button_Record) return Boolean;
    Set whether the spin button should "wrap around" when exceeding the upper and lower limits.
  • procedure Set_Snap_To_Ticks (Spin_Button : access Gtk_Spin_Button_Record; Snap_To_Ticks : Boolean);
    function Get_Snap_To_Ticks (Spin_Button : access Gtk_Spin_Button_Record) return Boolean;
    Set the spin button to round the value to the nearest step value which is set within its adjustment settings.
  • procedure Update (Spin_Button : access Gtk_Spin_Button_Record);
    Manually force an update of the spin button.

Signals

  • change_value
    procedure Handler (Spin : access Gtk_Spin_Button_Record'Class; Typ : Gtk_Scroll_Type);
    You should emit this signal to request a change in the value of the spin button. This is mostly useful as a keybinding, and is bound, by default, to the arrow keys, PageUp, PageDown, Home and End keys.
  • input
    procedure Handler (Spin : access Gtk_Spin_Button_Record'Class; Value : out Gint);
    ???
  • output
    procedure Handler (Spin : access Gtk_Spin_Button_Record'Class);
    ???
  • value_changed
    procedure Handler (Spin : access Gtk_Spin_Button_Record'Class);
    Emitted when the value of the spin button has changed.

Properties

  • Adjustment_Property
    Object
    The adjustment that holds the value of the spinbutton
  • Climb_Rate_Property
    Double
    The acceleration rate when you hold down a button
  • Digits_Property
    Uint
    The number of decimal places to display
  • Numeric_Property
    Boolean
    Whether non-numeric characters should be ignored
  • Snap_To_Ticks_Property
    Boolean
    Whether erroneous values are automatically changed to a spin
  • Update_Policy_Property
    Enum
    Whether the spin button should update always, or only when the
  • Value_Property
    Double
    Reads the current value, or sets a new value
  • Wrap_Property
    Boolean
    Whether a spin button should wrap upon reaching its limits

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.Adjustment; use Gtk.Adjustment; with Gtk.Box; use Gtk.Box; with Gtk.Button; use Gtk.Button; with Gtk.Check_Button; use Gtk.Check_Button; with Gtk.Handlers; use Gtk.Handlers; with Gtk.Label; use Gtk.Label; with Gtk.Spin_Button; use Gtk.Spin_Button; with Gtk.Toggle_Button; use Gtk.Toggle_Button; with Gtk; use Gtk; package body Create_Spin is type My_Button_Record is new Gtk_Button_Record with record Label : Gtk_Label; end record; type My_Button is access all My_Button_Record; -- This is basic Gtk_Button, except that is has an extra internal -- data. package Spin_O_Cb is new Handlers.Callback (Gtk_Spin_Button_Record); package Spin_Cb is new Handlers.User_Callback (Gtk_Toggle_Button_Record, Gtk_Spin_Button); package Button_Cb is new Handlers.User_Callback (My_Button_Record, Gint); Spinner1 : Gtk_Spin_Button; ---------- -- Help -- ---------- function Help return String is begin return "A @bGtk_Spin_Button@B is a widget that allows the user to" & " choose a value from a specific range. You can only associate" & " the spin button with numeric values." & ASCII.LF & "This demo also creates a child of @bGtk_Button@B for the two" & " buttons at the bottom. These are basic buttons, but they also" & " contain a pointer to the label where to display the value."; end Help; ------------------- -- Change_Digits -- ------------------- procedure Change_Digits (Spin : access Gtk_Spin_Button_Record'Class) is begin Set_Digits (Spinner1, Guint (Get_Value_As_Int (Spin))); end Change_Digits; ----------------- -- Toggle_Snap -- ----------------- procedure Toggle_Snap (Widget : access Gtk_Toggle_Button_Record'Class; Spin : in Gtk_Spin_Button) is begin Set_Snap_To_Ticks (Spin, Get_Active (Widget)); end Toggle_Snap; -------------------- -- Toggle_Numeric -- -------------------- procedure Toggle_Numeric (Widget : access Gtk_Toggle_Button_Record'Class; Spin : in Gtk_Spin_Button) is begin Set_Numeric (Spin, Get_Active (Widget)); end Toggle_Numeric; --------------- -- Get_Value -- --------------- procedure Get_Value (Widget : access My_Button_Record'Class; Data : in Gint) is Spin : constant Gtk_Spin_Button := Spinner1; begin if Data = 1 then Set_Text (Widget.Label, Gint'Image (Get_Value_As_Int (Spin))); else Set_Text (Widget.Label, Gdouble'Image (Get_Value (Spin))); end if; end Get_Value; --------- -- Run -- --------- procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is Main_Box : Gtk_Box; VBox : Gtk_Box; Hbox : Gtk_Box; Vbox2 : Gtk_Box; Label : Gtk_Label; Adj : Gtk_Adjustment; Spinner : Gtk_Spin_Button; Spinner2 : Gtk_Spin_Button; Frame2 : Gtk_Frame; Check : Gtk_Check_Button; Myb : My_Button; begin Set_Label (Frame, "Spin Buttons"); Gtk_New_Vbox (Main_Box, False, 5); Set_Border_Width (Main_Box, 10); Add (Frame, Main_Box); Gtk_New (Frame2, "Not accelerated"); Pack_Start (Main_Box, Frame2, False, False, 0); Gtk_New_Vbox (VBox, False, 0); Set_Border_Width (VBox, 5); Add (Frame2, VBox); -- Day, month, year spinners Gtk_New_Hbox (Hbox, False, 0); Pack_Start (VBox, Hbox, False, False, 5); Gtk_New_Vbox (Vbox2, False, 0); Pack_Start (Hbox, Vbox2, False, False, 5); Gtk_New (Label, "Day:"); Set_Alignment (Label, 0.0, 0.5); Pack_Start (Vbox2, Label, False, False, 0); Gtk_New (Adj, 1.0, 1.0, 31.0, 1.0, 5.0, 0.0); Gtk_New (Spinner, Adj, 0.0, 0); Set_Wrap (Spinner, True); Pack_Start (Vbox2, Spinner, False, False, 0); Gtk_New_Vbox (Vbox2, False, 0); Pack_Start (Hbox, Vbox2, False, False, 5); Gtk_New (Label, "Month:"); Set_Alignment (Label, 0.0, 0.5); Pack_Start (Vbox2, Label, False, False, 0); Gtk_New (Adj, 1.0, 1.0, 12.0, 1.0, 5.0, 0.0); Gtk_New (Spinner, Adj, 0.0, 0); Set_Wrap (Spinner, True); Pack_Start (Vbox2, Spinner, False, False, 0); Gtk_New_Vbox (Vbox2, False, 0); Pack_Start (Hbox, Vbox2, False, False, 5); Gtk_New (Label, "Year:"); Set_Alignment (Label, 0.0, 0.5); Pack_Start (Vbox2, Label, False, False, 0); Gtk_New (Adj, 1998.0, 0.0, 2100.0, 1.0, 100.0, 0.0); Gtk_New (Spinner, Adj, 0.0, 0); Set_Wrap (Spinner, True); Set_USize (Spinner, 55, 0); Pack_Start (Vbox2, Spinner, False, False, 0); Gtk_New (Frame2, "Accelerated"); Pack_Start (Main_Box, Frame2, False, False, 0); Gtk_New_Vbox (VBox, False, 0); Set_Border_Width (VBox, 5); Add (Frame2, VBox); Gtk_New_Hbox (Hbox, False, 0); Pack_Start (VBox, Hbox, False, False, 5); Gtk_New_Vbox (Vbox2, False, 0); Pack_Start (Hbox, Vbox2, False, False, 5); Gtk_New (Label, "Value:"); Set_Alignment (Label, 0.0, 0.5); Pack_Start (Vbox2, Label, False, False, 0); Gtk_New (Adj, 0.0, -10000.0, 10000.0, 0.5, 100.0, 0.0); Gtk_New (Spinner1, Adj, 1.0, 2); Set_Wrap (Spinner1, True); Set_USize (Spinner1, 100, 0); Set_Update_Policy (Spinner1, Update_Always); Pack_Start (Vbox2, Spinner1, False, False, 0); Gtk_New_Vbox (Vbox2, False, 0); Pack_Start (Hbox, Vbox2, False, False, 5); Gtk_New (Label, "Digits:"); Set_Alignment (Label, 0.0, 0.5); Pack_Start (Vbox2, Label, False, False, 0); Gtk_New (Adj, 2.0, 1.0, 5.0, 1.0, 1.0, 0.0); Gtk_New (Spinner2, Adj, 0.0, 0); Set_Wrap (Spinner2, True); Spin_O_Cb.Object_Connect (Adj, "value_changed", Spin_O_Cb.To_Marshaller (Change_Digits'Access), Slot_Object => Spinner2); Pack_Start (Vbox2, Spinner2, False, False, 0); Gtk_New_Hbox (Hbox, False, 0); Pack_Start (VBox, Hbox, False, False, 5); Gtk_New (Check, "Snap to 0.5-ticks"); Spin_Cb.Connect (Check, "clicked", Spin_Cb.To_Marshaller (Toggle_Snap'Access), Spinner1); Pack_Start (VBox, Check, False, False, 0); Set_Active (Check, True); Gtk_New (Check, "Snap Numeric only input mode"); Spin_Cb.Connect (Check, "clicked", Spin_Cb.To_Marshaller (Toggle_Numeric'Access), Spinner1); Pack_Start (VBox, Check, False, False, 0); Set_Active (Check, True); Gtk_New (Label, ""); Gtk_New_Hbox (Hbox, False, 0); Pack_Start (VBox, Hbox, False, False, 5); Myb := new My_Button_Record; Initialize (Myb, "Value as Int"); Myb.Label := Label; Button_Cb.Connect (Myb, "clicked", Button_Cb.To_Marshaller (Get_Value'Access), 1); Pack_Start (Hbox, Myb, False, False, 5); Myb := new My_Button_Record; Initialize (Myb, "Value as Float"); Myb.Label := Label; Button_Cb.Connect (Myb, "clicked", Button_Cb.To_Marshaller (Get_Value'Access), 2); Pack_Start (Hbox, Myb, False, False, 5); Pack_Start (VBox, Label, False, False, 0); Set_Text (Label, "0"); Show_All (Frame); end Run; end Create_Spin;

Alphabetical Index