CtkSwitch

CtkSwitch — A “light switch” style toggle

Functions

Properties

gboolean active Read / Write
gboolean state Read / Write

Signals

void activate Action
gboolean state-set Run Last

Types and Values

struct CtkSwitch
struct CtkSwitchClass

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── CtkWidget
            ╰── CtkSwitch

Implemented Interfaces

CtkSwitch implements AtkImplementorIface, CtkBuildable, CtkActionable and CtkActivatable.

Includes

#include <ctk/ctk.h>

Description

CtkSwitch 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.

CtkSwitch can also handle situations where the underlying state changes with a delay. See “state-set” for details.

CSS nodes

1
2
switch
╰── slider

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

Functions

ctk_switch_new ()

CtkWidget *
ctk_switch_new (void);

Creates a new CtkSwitch widget.

Returns

the newly created CtkSwitch instance

Since: 3.0


ctk_switch_set_active ()

void
ctk_switch_set_active (CtkSwitch *sw,
                       gboolean is_active);

Changes the state of sw to the desired one.

Parameters

sw

a CtkSwitch

 

is_active

TRUE if sw should be active, and FALSE otherwise

 

Since: 3.0


ctk_switch_get_active ()

gboolean
ctk_switch_get_active (CtkSwitch *sw);

Gets whether the CtkSwitch is in its “on” or “off” state.

Parameters

sw

a CtkSwitch

 

Returns

TRUE if the CtkSwitch is active, and FALSE otherwise

Since: 3.0


ctk_switch_set_state ()

void
ctk_switch_set_state (CtkSwitch *sw,
                      gboolean state);

Sets the underlying state of the CtkSwitch.

Normally, this is the same as “active”, unless the switch is set up for delayed state changes. This function is typically called from a “state-set” signal handler.

See “state-set” for details.

Parameters

sw

a CtkSwitch

 

state

the new state

 

Since: 3.14


ctk_switch_get_state ()

gboolean
ctk_switch_get_state (CtkSwitch *sw);

Gets the underlying state of the CtkSwitch.

Parameters

sw

a CtkSwitch

 

Returns

the underlying state

Since: 3.14

Types and Values

struct CtkSwitch

struct CtkSwitch;

The CtkSwitch contains private data and it should only be accessed using the provided API.


struct CtkSwitchClass

struct CtkSwitchClass {
  CtkWidgetClass parent_class;

  void (* activate) (CtkSwitch *sw);

  gboolean (* state_set) (CtkSwitch *sw, gboolean state);
};

Members

activate ()

An action signal and emitting it causes the switch to animate.

 

state_set ()

Class handler for the ::state-set signal.

 

Property Details

The “active” property

  “active”                   gboolean

Whether the CtkSwitch widget is in its on or off state.

Owner: CtkSwitch

Flags: Read / Write

Default value: FALSE


The “state” property

  “state”                    gboolean

The backend state that is controlled by the switch. See “state-set” for details.

Owner: CtkSwitch

Flags: Read / Write

Default value: FALSE

Since: 3.14

Signal Details

The “activate” signal

void
user_function (CtkSwitch *widget,
               gpointer   user_data)

The ::activate signal on CtkSwitch is an action signal and emitting it causes the switch to animate. Applications should never connect to this signal, but use the notify::active signal.

Parameters

widget

the object which received the signal.

 

user_data

user data set when the signal handler was connected.

 

Flags: Action


The “state-set” signal

gboolean
user_function (CtkSwitch *widget,
               gboolean   state,
               gpointer   user_data)

The ::state-set signal on CtkSwitch is emitted to change the underlying state. It is emitted when the user changes the switch position. The default handler keeps the state in sync with the “active” property.

To implement delayed state change, applications can connect to this signal, initiate the change of the underlying state, and call ctk_switch_set_state() when the underlying state change is complete. The signal handler should return TRUE to prevent the default handler from running.

Visually, the underlying state is represented by the trough color of the switch, while the “active” property is represented by the position of the switch.

Parameters

widget

the object on which the signal was emitted

 

state

the new state of the switch

 

user_data

user data set when the signal handler was connected.

 

Returns

TRUE to stop the signal emission

Flags: Run Last

Since: 3.14

See Also

CtkToggleButton