Gtk.Toggle_Button

Entities

Tagged Types

Access Types

Constants

Subprograms

Generic Instantiations

Description

A Gtk.Toggle_Button.Gtk_Toggle_Button is a Gtk.Button.Gtk_Button which will remain "pressed-in" when clicked. Clicking again will cause the toggle button to return to its normal state.

A toggle button is created by calling either gtk_toggle_button_new or Gtk.Toggle_Button.Gtk_New. If using the former, it is advisable to pack a widget, (such as a Gtk.Label.Gtk_Label and/or a Gtk.Image.Gtk_Image), into the toggle button's container. (See Gtk.Button.Gtk_Button for more information).

The state of a Gtk.Toggle_Button.Gtk_Toggle_Button can be set specifically using Gtk.Toggle_Button.Set_Active, and retrieved using Gtk.Toggle_Button.Get_Active.

To simply switch the state of a toggle button, use Gtk.Toggle_Button.Toggled.

# CSS nodes

GtkToggleButton has a single CSS node with name button. To differentiate it from a plain Gtk.Button.Gtk_Button, it gets the .toggle style class.

## Creating two Gtk.Toggle_Button.Gtk_Toggle_Button widgets.

static void output_state (GtkToggleButton *source, gpointer user_data) {
  printf ("Active: %d\n", gtk_toggle_button_get_active (source));
}

void make_toggles (void) {
  GtkWidget *window, *toggle1, *toggle2;
  GtkWidget *box;
  const char *text;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);

  text = "Hi, I'm a toggle button.";
  toggle1 = gtk_toggle_button_new_with_label (text);

  // Makes this toggle button invisible
  gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle1),
                              TRUE);

  g_signal_connect (toggle1, "toggled",
                    G_CALLBACK (output_state),
                    NULL);
  gtk_container_add (GTK_CONTAINER (box), toggle1);

  text = "Hi, I'm a toggle button.";
  toggle2 = gtk_toggle_button_new_with_label (text);
  gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle2),
                              FALSE);
  g_signal_connect (toggle2, "toggled",
                    G_CALLBACK (output_state),
                    NULL);
  gtk_container_add (GTK_CONTAINER (box), toggle2);

  gtk_container_add (GTK_CONTAINER (window), box);
  gtk_widget_show_all (window);
}

You should consider using a Gtk_Check_Button instead, since it looks nicer and provides more visual clues that the button can be toggled.

<screenshot>gtk-toggle_button</screenshot> <group>Buttons and Toggles</group> <testgtk>create_toggle_buttons.adb</testgtk>

"+"

function "+"
  (Widget : access Gtk_Toggle_Button_Record'Class)
return Gtk.Actionable.Gtk_Actionable
Parameters
Widget
Return Value

"+"

function "+"
  (Widget : access Gtk_Toggle_Button_Record'Class)
return Gtk.Activatable.Gtk_Activatable
Parameters
Widget
Return Value

"+"

function "+"
  (Widget : access Gtk_Toggle_Button_Record'Class)
return Gtk.Buildable.Gtk_Buildable
Parameters
Widget
Return Value

"-"

function "-"
  (Interf : Gtk.Actionable.Gtk_Actionable)
return Gtk_Toggle_Button
Parameters
Interf
Return Value

"-"

function "-"
  (Interf : Gtk.Activatable.Gtk_Activatable)
return Gtk_Toggle_Button
Parameters
Interf
Return Value

"-"

function "-"
  (Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_Toggle_Button
Parameters
Interf
Return Value

Active_Property

Active_Property : constant Glib.Properties.Property_Boolean;

Cb_GObject_Void

type Cb_GObject_Void is not null access procedure
  (Self : access Glib.Object.GObject_Record'Class);
Parameters
Self

Cb_Gtk_Toggle_Button_Void

type Cb_Gtk_Toggle_Button_Void is not null access procedure
  (Self : access Gtk_Toggle_Button_Record'Class);
Parameters
Self

Do_Set_Related_Action

procedure Do_Set_Related_Action
   (Self   : not null access Gtk_Toggle_Button_Record;
    Action : not null access Gtk.Action.Gtk_Action_Record'Class)
Parameters
Self
Action

Draw_Indicator_Property

Draw_Indicator_Property : constant Glib.Properties.Property_Boolean;

Get_Action_Name

function Get_Action_Name
   (Self : not null access Gtk_Toggle_Button_Record) return UTF8_String
Parameters
Self
Return Value

Get_Action_Target_Value

function Get_Action_Target_Value
   (Self : not null access Gtk_Toggle_Button_Record)
    return Glib.Variant.Gvariant
Parameters
Self
Return Value

Get_Active

function Get_Active
   (Toggle_Button : not null access Gtk_Toggle_Button_Record)
    return Boolean

Queries a Gtk.Toggle_Button.Gtk_Toggle_Button and returns its current state. Returns True if the toggle button is pressed in and False if it is raised.

Parameters
Toggle_Button
Return Value

a Boolean value.

Get_Inconsistent

function Get_Inconsistent
   (Toggle_Button : not null access Gtk_Toggle_Button_Record)
    return Boolean

Gets the value set by Gtk.Toggle_Button.Set_Inconsistent.

Parameters
Toggle_Button
Return Value

True if the button is displayed as inconsistent, False otherwise

Get_Mode

function Get_Mode
   (Toggle_Button : not null access Gtk_Toggle_Button_Record)
    return Boolean

Retrieves whether the button is displayed as a separate indicator and label. See Gtk.Toggle_Button.Set_Mode.

Parameters
Toggle_Button
Return Value

True if the togglebutton is drawn as a separate indicator and label.

Get_Related_Action

function Get_Related_Action
   (Self : not null access Gtk_Toggle_Button_Record)
    return Gtk.Action.Gtk_Action
Parameters
Self
Return Value

Get_Type

function Get_Type return Glib.GType
Return Value

Get_Use_Action_Appearance

function Get_Use_Action_Appearance
   (Self : not null access Gtk_Toggle_Button_Record) return Boolean
Parameters
Self
Return Value

Gtk_New

procedure Gtk_New
   (Toggle_Button : out Gtk_Toggle_Button;
    Label         : UTF8_String := "")

Initialize a button. If Label is "", then no label is created inside the button and you will have to provide your own child through a call to Gtk.Container.Add. This is the recommended way to put a pixmap inside a toggle button. Initialize does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Toggle_Button
Label

a string containing the message to be placed in the toggle button.

Gtk_New_With_Mnemonic

procedure Gtk_New_With_Mnemonic
   (Toggle_Button : out Gtk_Toggle_Button;
    Label         : UTF8_String)

Creates a new Gtk.Toggle_Button.Gtk_Toggle_Button containing a label. The label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so underscores in Label indicate the mnemonic for the button. Initialize_With_Mnemonic does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Toggle_Button
Label

the text of the button, with an underscore in front of the mnemonic character

Gtk_Toggle_Button

type Gtk_Toggle_Button is access all Gtk_Toggle_Button_Record'Class;

Gtk_Toggle_Button_New_With_Label

function Gtk_Toggle_Button_New_With_Label
   (Label : UTF8_String := "") return Gtk_Toggle_Button

Initialize a button. If Label is "", then no label is created inside the button and you will have to provide your own child through a call to Gtk.Container.Add. This is the recommended way to put a pixmap inside a toggle button.

Parameters
Label

a string containing the message to be placed in the toggle button.

Return Value

Gtk_Toggle_Button_New_With_Mnemonic

function Gtk_Toggle_Button_New_With_Mnemonic
   (Label : UTF8_String) return Gtk_Toggle_Button

Creates a new Gtk.Toggle_Button.Gtk_Toggle_Button containing a label. The label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so underscores in Label indicate the mnemonic for the button.

Parameters
Label

the text of the button, with an underscore in front of the mnemonic character

Return Value

Gtk_Toggle_Button_Record

type Gtk_Toggle_Button_Record is new Gtk_Button_Record with null record;

Implements_Gtk_Actionable

package Implements_Gtk_Actionable is new Glib.Types.Implements
  (Gtk.Actionable.Gtk_Actionable, Gtk_Toggle_Button_Record, Gtk_Toggle_Button);

Implements_Gtk_Activatable

package Implements_Gtk_Activatable is new Glib.Types.Implements
  (Gtk.Activatable.Gtk_Activatable, Gtk_Toggle_Button_Record, Gtk_Toggle_Button);

Implements_Gtk_Buildable

package Implements_Gtk_Buildable is new Glib.Types.Implements
  (Gtk.Buildable.Gtk_Buildable, Gtk_Toggle_Button_Record, Gtk_Toggle_Button);

Inconsistent_Property

Inconsistent_Property : constant Glib.Properties.Property_Boolean;

Initialize

procedure Initialize
   (Toggle_Button : not null access Gtk_Toggle_Button_Record'Class;
    Label         : UTF8_String := "")

Initialize a button. If Label is "", then no label is created inside the button and you will have to provide your own child through a call to Gtk.Container.Add. This is the recommended way to put a pixmap inside a toggle button. Initialize does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Toggle_Button
Label

a string containing the message to be placed in the toggle button.

Initialize_With_Mnemonic

procedure Initialize_With_Mnemonic
   (Toggle_Button : not null access Gtk_Toggle_Button_Record'Class;
    Label         : UTF8_String)

Creates a new Gtk.Toggle_Button.Gtk_Toggle_Button containing a label. The label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so underscores in Label indicate the mnemonic for the button. Initialize_With_Mnemonic does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Toggle_Button
Label

the text of the button, with an underscore in front of the mnemonic character

On_Toggled

procedure On_Toggled
   (Self  : not null access Gtk_Toggle_Button_Record;
    Call  : Cb_GObject_Void;
    Slot  : not null access Glib.Object.GObject_Record'Class;
    After : Boolean := False)

Should be connected if you wish to perform an action whenever the Gtk.Toggle_Button.Gtk_Toggle_Button's state is changed.

Parameters
Self
Call
Slot
After

On_Toggled

procedure On_Toggled
   (Self  : not null access Gtk_Toggle_Button_Record;
    Call  : Cb_Gtk_Toggle_Button_Void;
    After : Boolean := False)

Should be connected if you wish to perform an action whenever the Gtk.Toggle_Button.Gtk_Toggle_Button's state is changed.

Parameters
Self
Call
After

Set_Action_Name

procedure Set_Action_Name
   (Self        : not null access Gtk_Toggle_Button_Record;
    Action_Name : UTF8_String := "")
Parameters
Self
Action_Name

Set_Action_Target_Value

procedure Set_Action_Target_Value
   (Self         : not null access Gtk_Toggle_Button_Record;
    Target_Value : Glib.Variant.Gvariant)
Parameters
Self
Target_Value

Set_Active

procedure Set_Active
   (Toggle_Button : not null access Gtk_Toggle_Button_Record;
    Is_Active     : Boolean)

Change the state of the button. When Is_Active is True, the button is drawn as a pressed button

Parameters
Toggle_Button
Is_Active

True or False.

Set_Detailed_Action_Name

procedure Set_Detailed_Action_Name
   (Self                 : not null access Gtk_Toggle_Button_Record;
    Detailed_Action_Name : UTF8_String)
Parameters
Self
Detailed_Action_Name

Set_Inconsistent

procedure Set_Inconsistent
   (Toggle_Button : not null access Gtk_Toggle_Button_Record;
    Setting       : Boolean := True)

If the user has selected a range of elements (such as some text or spreadsheet cells) that are affected by a toggle button, and the current values in that range are inconsistent, you may want to display the toggle in an "in between" state. This function turns on "in between" display. Normally you would turn off the inconsistent state again if the user toggles the toggle button. This has to be done manually, Gtk.Toggle_Button.Set_Inconsistent only affects visual appearance, it doesn't affect the semantics of the button.

Parameters
Toggle_Button
Setting

True if state is inconsistent

Set_Mode

procedure Set_Mode
   (Toggle_Button  : not null access Gtk_Toggle_Button_Record;
    Draw_Indicator : Boolean)

Sets whether the button is displayed as a separate indicator and label. You can call this function on a checkbutton or a radiobutton with Draw_Indicator = False to make the button look like a normal button. This can be used to create linked strip of buttons that work like a Gtk.Stack_Switcher.Gtk_Stack_Switcher. This function only affects instances of classes like Gtk.Check_Button.Gtk_Check_Button and Gtk.Radio_Button.Gtk_Radio_Button that derive from Gtk.Toggle_Button.Gtk_Toggle_Button, not instances of Gtk.Toggle_Button.Gtk_Toggle_Button itself.

Parameters
Toggle_Button
Draw_Indicator

if True, draw the button as a separate indicator and label; if False, draw the button like a normal button

Set_Related_Action

procedure Set_Related_Action
   (Self   : not null access Gtk_Toggle_Button_Record;
    Action : not null access Gtk.Action.Gtk_Action_Record'Class)
Parameters
Self
Action

Set_Use_Action_Appearance

procedure Set_Use_Action_Appearance
   (Self           : not null access Gtk_Toggle_Button_Record;
    Use_Appearance : Boolean)
Parameters
Self
Use_Appearance

Signal_Toggled

Signal_Toggled : constant Glib.Signal_Name := "toggled";

Should be connected if you wish to perform an action whenever the Gtk.Toggle_Button.Gtk_Toggle_Button's state is changed.

Sync_Action_Properties

procedure Sync_Action_Properties
   (Self   : not null access Gtk_Toggle_Button_Record;
    Action : access Gtk.Action.Gtk_Action_Record'Class)
Parameters
Self
Action

Toggled

procedure Toggled
   (Toggle_Button : not null access Gtk_Toggle_Button_Record)

Emits the Gtk.Toggle_Button.Gtk_Toggle_Button::toggled signal on the Gtk.Toggle_Button.Gtk_Toggle_Button. There is no good reason for an application ever to call this function.

Parameters
Toggle_Button