ToggleButton

A gtk.ToggleButton is a 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 ToggleButton.new or ToggleButton.newWithLabel. If using the former, it is advisable to pack a widget, (such as a gtk.Label and/or a gtk.Image), into the toggle button’s container. (See gtk.Button for more information).

The state of a gtk.ToggleButton can be set specifically using ToggleButton.setActive, and retrieved using ToggleButton.getActive.

To simply switch the state of a toggle button, use ToggleButton.toggled.

CSS nodes

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

Creating two gtk.ToggleButton 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);
}

Constructors

this
this(GtkToggleButton* gtkToggleButton, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this(string label, bool mnemonic)

Creates a new toggle button with a text label.

this
this()

Creates a new toggle button. A widget should be packed into the button, as in Button.new.

Members

Functions

addOnToggled
gulong addOnToggled(void delegate(ToggleButton) dlg, ConnectFlags connectFlags)

Should be connected if you wish to perform an action whenever the gtk.ToggleButton's state is changed.

getActive
bool getActive()

Queries a gtk.ToggleButton and returns its current state. Returns TRUE if the toggle button is pressed in and FALSE if it is raised.

getInconsistent
bool getInconsistent()

Gets the value set by ToggleButton.setInconsistent.

getMode
bool getMode()

Retrieves whether the button is displayed as a separate indicator and label. See ToggleButton.setMode.

getStruct
void* getStruct()

the main Gtk struct as a void*

getToggleButtonStruct
GtkToggleButton* getToggleButtonStruct(bool transferOwnership)

Get the main Gtk struct

setActive
void setActive(bool isActive)

Sets the status of the toggle button. Set to TRUE if you want the GtkToggleButton to be “pressed in”, and FALSE to raise it. This action causes the toggled signal and the clicked signal to be emitted.

setInconsistent
void setInconsistent(bool setting)

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, ToggleButton.setInconsistent only affects visual appearance, it doesn’t affect the semantics of the button.

setMode
void setMode(bool drawIndicator)

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.

toggled
void toggled()

Emits the toggled signal on the gtk.ToggleButton There is no good reason for an application ever to call this function.

Static functions

getType
GType getType()

Variables

gtkToggleButton
GtkToggleButton* gtkToggleButton;

the main Gtk struct

Inherited Members

From Button

gtkButton
GtkButton* gtkButton;

the main Gtk struct

getButtonStruct
GtkButton* getButtonStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

setIconSize
void setIconSize(IconSize iconSize)
getIconSize
IconSize getIconSize()
getType
GType getType()
clicked
void clicked()

Emits a clicked signal to the given gtk.Button

enter
void enter()

Emits a enter signal to the given gtk.Button

getAlignment
void getAlignment(float xalign, float yalign)

Gets the alignment of the child in the button.

getAlwaysShowImage
bool getAlwaysShowImage()

Returns whether the button will ignore the gtk-button-images setting and always show the image, if available.

getEventWindow
Window getEventWindow()

Returns the button’s event window if it is realized, NULL otherwise. This function should be rarely needed.

getFocusOnClick
bool getFocusOnClick()

Returns whether the button grabs focus when it is clicked with the mouse. See Button.setFocusOnClick.

getImage
Widget getImage()

Gets the widget that is currenty set as the image of button. This may have been explicitly set by Button.setImage or constructed by Button.newFromStock.

getImagePosition
GtkPositionType getImagePosition()

Gets the position of the image relative to the text inside the button.

getLabel
string getLabel()

Fetches the text from the label of the button, as set by Button.setLabel. If the label text has not been set the return value will be NULL. This will be the case if you create an empty button with Button.new to use as a container.

getRelief
GtkReliefStyle getRelief()

Returns the current relief style of the given gtk.Button

getUseStock
bool getUseStock()

Returns whether the button label is a stock item.

getUseUnderline
bool getUseUnderline()

Returns whether an embedded underline in the button label indicates a mnemonic. See gtk_button_set_use_underline ().

leave
void leave()

Emits a leave signal to the given gtk.Button

pressed
void pressed()

Emits a pressed signal to the given gtk.Button

released
void released()

Emits a released signal to the given gtk.Button

setAlignment
void setAlignment(float xalign, float yalign)

Sets the alignment of the child. This property has no effect unless the child is a gtk.Misc or a gtk.Alignment

setAlwaysShowImage
void setAlwaysShowImage(bool alwaysShow)

If TRUE, the button will ignore the gtk-button-images setting and always show the image, if available.

setFocusOnClick
void setFocusOnClick(bool focusOnClick)

Sets whether the button will grab focus when it is clicked with the mouse. Making mouse clicks not grab focus is useful in places like toolbars where you don’t want the keyboard focus removed from the main area of the application.

setImage
void setImage(Widget image)

Set the image of button to the given widget. The image will be displayed if the label text is NULL or if always-show-image is TRUE. You don’t have to call Widget.show on image yourself.

setImagePosition
void setImagePosition(GtkPositionType position)

Sets the position of the image relative to the text inside the button.

setLabel
void setLabel(string label)

Sets the text of the label of the button to str. This text is also used to select the stock item if Button.setUseStock is used.

setRelief
void setRelief(GtkReliefStyle relief)

Sets the relief style of the edges of the given gtk.Button widget. Two styles exist, GTK_RELIEF_NORMAL and GTK_RELIEF_NONE. The default style is, as one can guess, GTK_RELIEF_NORMAL. The deprecated value GTK_RELIEF_HALF behaves the same as GTK_RELIEF_NORMAL.

setUseStock
void setUseStock(bool useStock)

If TRUE, the label set on the button is used as a stock id to select the stock item for the button.

setUseUnderline
void setUseUnderline(bool useUnderline)

If true, an underline in the text of the button label indicates the next character should be used for the mnemonic accelerator key.

addOnActivate
gulong addOnActivate(void delegate(Button) dlg, ConnectFlags connectFlags)

The ::activate signal on GtkButton is an action signal and emitting it causes the button to animate press then release. Applications should never connect to this signal, but use the clicked signal.

addOnClicked
gulong addOnClicked(void delegate(Button) dlg, ConnectFlags connectFlags)

Emitted when the button has been activated (pressed and released).

addOnEnter
gulong addOnEnter(void delegate(Button) dlg, ConnectFlags connectFlags)

Emitted when the pointer enters the button.

addOnLeave
gulong addOnLeave(void delegate(Button) dlg, ConnectFlags connectFlags)

Emitted when the pointer leaves the button.

addOnPressed
gulong addOnPressed(void delegate(Button) dlg, ConnectFlags connectFlags)

Emitted when the button is pressed.

addOnReleased
gulong addOnReleased(void delegate(Button) dlg, ConnectFlags connectFlags)

Emitted when the button is released.