Switch


Object Hierarchy:

Gtk.Switch Gtk.Switch Gtk.Switch Gtk.Widget Gtk.Widget Gtk.Widget->Gtk.Switch GLib.InitiallyUnowned GLib.InitiallyUnowned GLib.InitiallyUnowned->Gtk.Widget GLib.Object GLib.Object GLib.Object->GLib.InitiallyUnowned Atk.Implementor Atk.Implementor Atk.Implementor->Gtk.Switch Atk.Implementor->Gtk.Widget Gtk.Buildable Gtk.Buildable Gtk.Buildable->Gtk.Switch Gtk.Buildable->Gtk.Widget Gtk.Actionable Gtk.Actionable Gtk.Actionable->Gtk.Switch Gtk.Activatable Gtk.Activatable Gtk.Activatable->Gtk.Switch

Description:

[ CCode ( type_id = "gtk_switch_get_type ()" ) ]
public class Switch : Widget, Implementor, Actionable, Activatable, Buildable

Switch is a widget that has two states: on or off.

The user can control which state should be active by clicking the empty area, or by dragging the handle.

GtkSwitch can also handle situations where the underlying state changes with a delay. See state_set for details.

CSS nodes

switch
╰── slider
witch has two css nodes, the main node with the name switch and a subnode named slider. Neither of them is using any style classes.

GtkSwitch

Example: Switch:

public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.Switch";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);

// The button:
Gtk.Switch _switch = new Gtk.Switch ();
this.add (_switch);

_switch.notify["active"].connect (() => {
if (_switch.active) {
print ("The switch is on!\n");
} else {
print ("The switch is off!\n");
}
});

// Changes the state to on:
_switch.set_active (true);
}

public static int main (string[] args) {
Gtk.init (ref args);

Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;
}
}

valac --pkg gtk+-3.0 Gtk.Switch.vala


Namespace: Gtk
Package: gtk+-3.0

Content:

Properties:

Creation methods:

Methods:

Signals:

Inherited Members:

All known members inherited from class Gtk.Widget
All known members inherited from interface Atk.Implementor