1.70 <AdwToggleGroup>

Class: <AdwToggleGroup>

It derives from <GtkWidget>.

A group of exclusive toggles.

<AdwToggleGroup> presents a set of exclusive toggles, represented as Toggle objects. Each toggle can display an icon, a label, an icon and a label, or a custom child.

Toggles are indexed by their position, with the first toggle being equivalent to 0, and so on. Use the ToggleGroup:active to get that position.

Toggles can also have optional names, set via the Toggle:name property. The name of the active toggle can be accessed via the ToggleGroup:active-name property.

<AdwToggle> objects can be retrieved via their index or name, using ToggleGroup.get_toggle or ToggleGroup.get_toggle_by_name respectively. <AdwToggleGroup> also provides a <GtkSelectionModel> of its toggles via the ToggleGroup:toggles property.

<AdwToggleGroup> is orientable, and the toggles can be displayed horizontally or vertically. This is mostly useful for icon-only toggles.

Use the ToggleGroup:homogeneous property to make the toggles take the same size, and the ToggleGroup:can-shrink to control whether the toggles can ellipsize.

Example of an <AdwToggleGroup> UI definition:

 <object class="AdwToggleGroup">
   <property name="active-name">picture</property>
   <child>
     <object class="AdwToggle">
       <property name="icon-name">camera-photo-symbolic</property>
       <property name="tooltip" translatable="yes">Picture Mode</property>
       <property name="name">picture</property>
     </object>
   </child>
   <child>
     <object class="AdwToggle">
       <property name="icon-name">camera-video-symbolic</property>
       <property name="tooltip" translatable="yes">Recording Mode</property>
       <property name="name">recording</property>
     </object>
   </child>
 </object>

See also: InlineViewSwitcher.

CSS nodes

<AdwToggleGroup> has a main CSS node with the name toggle-group.

Its toggles have CSS nodes with the name toggle, and its separators have nodes with the name separator.

Toggle nodes will have a different style classes depending on their content: .text-button for labels, .image-button for icons, .image-text-button for both or no style class for custom children.

The hidden separators use the .hidden style class.

Style classes

<AdwToggleGroup> can use the ‘.flat‘ style class to remove its background and make it look like a group of buttons.

It can also use the ‘.round‘ style class to make its toggles and the group itself rounded.

They can also be combined with each other.

Accessibility

<AdwToggleGroup> uses the Gtk.AccessibleRole.radio-group role. Its toggles use the Gtk.AccessibleRole.radio role.

Properties

Property: toggle-group:active self

The index of the active toggle.

Setting the index to a larger value than the number of toggles in the group unsets the current active toggle.

If no toggle is active, the property will be set to Gtk.INVALID_LIST_POSITION.

Its value is an unsigned 32-bit integer.

Set it with (set! (toggle-group:active self) value).

Property: toggle-group:active-name self

The name of the active toggle.

The name can be set via Toggle:name. If the currently active toggle doesn’t have a name, the property will be set to NULL.

Set it to NULL to unset the current active toggle.

Its value is a string, or #f.

Set it with (set! (toggle-group:active-name self) value).

Property: toggle-group:can-shrink self

Whether the toggles can be smaller than the natural size of their contents.

If set to TRUE, the toggle labels will ellipsize.

See button:can-shrink.

Its value is a boolean.

Set it with (set! (toggle-group:can-shrink self) value).

Property: toggle-group:homogeneous self

Whether all toggles take the same size.

Its value is a boolean.

Set it with (set! (toggle-group:homogeneous self) value).

Property: toggle-group:n-toggles self

The number of toggles within the group.

Its value is an unsigned 32-bit integer.

It is read only.

Property: toggle-group:toggles self

A selection model with the groups’s toggles.

This can be used to keep an up-to-date view. The model also implements <GtkSelectionModel> and can be used to track and change the active toggle.

Its value is a <GtkSelectionModel>, or #f.

It is read only.

Procedures

Method: toggle-group:add self toggle
Method: add self toggle

Adds a toggle to self.

self

Passed: a <AdwToggleGroup>.

a toggle group

toggle

Passed: a <AdwToggle>.

the toggle to add

Method: toggle-group:get-active self ⇒ %return
Method: get-active self ⇒ %return

Gets the index of the active toggle in self.

Returns Gtk.INVALID_LIST_POSITION if no toggle is active.

self

Passed: a <AdwToggleGroup>.

a toggle group

%return

Returned: an unsigned 32-bit integer.

the active toggle index

Method: toggle-group:get-active-name self ⇒ %return
Method: get-active-name self ⇒ %return

Gets the name of the active toggle in self.

Can be NULL if the currently active toggle doesn’t have a name.

See Toggle:name.

self

Passed: a <AdwToggleGroup>.

a toggle group

%return

Returned: a string, or #f.

the active toggle name

Method: toggle-group:get-can-shrink? self ⇒ %return
Method: get-can-shrink? self ⇒ %return

Gets whether the toggles can be smaller than the natural size of their contents.

self

Passed: a <AdwToggleGroup>.

a toggle group

%return

Returned: a boolean.

whether the toggles can shrink

Method: toggle-group:get-homogeneous? self ⇒ %return
Method: get-homogeneous? self ⇒ %return

Gets whether all toggles take the same size.

self

Passed: a <AdwToggleGroup>.

a toggle group

%return

Returned: a boolean.

whether all toggles take the same size

Method: toggle-group:get-n-toggles self ⇒ %return
Method: get-n-toggles self ⇒ %return

Gets the number of toggles within self.

self

Passed: a <AdwToggleGroup>.

a toggle group

%return

Returned: an unsigned 32-bit integer.

the number of toggles

Method: toggle-group:get-toggle self index ⇒ %return
Method: get-toggle self index ⇒ %return

Gets the toggle with index from self.

self

Passed: a <AdwToggleGroup>.

a toggle group

index

Passed: an unsigned 32-bit integer.

toggle’s index

%return

Returned: a <AdwToggle>, or #f.

the toggle

Method: toggle-group:get-toggle-by-name self name ⇒ %return
Method: get-toggle-by-name self name ⇒ %return

Gets the toggle with the name name from self.

self

Passed: a <AdwToggleGroup>.

a toggle group

name

Passed: a string.

toggle name

%return

Returned: a <AdwToggle>, or #f.

the toggle

Method: toggle-group:get-toggles self ⇒ %return
Method: get-toggles self ⇒ %return

Returns a <GListModel> that contains the toggles of the group.

This can be used to keep an up-to-date view. The model also implements <GtkSelectionModel> and can be used to track and change the active toggle.

self

Passed: a <AdwToggleGroup>.

a toggle group

%return

Returned: a <GtkSelectionModel>.

a <GtkSelectionModel> for the group’s toggles

Procedure: toggle-group:new ⇒ %return

Creates a new <AdwToggleGroup>.

%return

Returned: a <GtkWidget>.

the newly created <AdwToggleGroup>

Method: toggle-group:remove self toggle
Method: remove self toggle

Removes toggle from self.

self

Passed: a <AdwToggleGroup>.

a toggle group

toggle

Passed: a <AdwToggle>.

a toggle to remove

Method: toggle-group:remove-all self
Method: remove-all self

Removes all toggles from self.

self

Passed: a <AdwToggleGroup>.

a toggle group

Method: toggle-group:set-active self active
Method: set-active self active

Sets the active toggle for self.

If the index is larger than the number of toggles in self, unsets the current active toggle.

self

Passed: a <AdwToggleGroup>.

a toggle group

active

Passed: an unsigned 32-bit integer.

toggle index

Method: toggle-group:set-active-name self [name]
Method: set-active-name self [name]

Sets the active toggle for self.

The name can be set via Toggle:name.

If name is NULL, unset the current active toggle instead.

self

Passed: a <AdwToggleGroup>.

a toggle group

name

Passed, or left out: a string, or #f.

toggle name

Method: toggle-group:set-can-shrink self can-shrink
Method: set-can-shrink self can-shrink

Sets whether the toggles can be smaller than the natural size of their contents.

If can-shrink is TRUE, the toggle labels will ellipsize.

See button:can-shrink.

self

Passed: a <AdwToggleGroup>.

a toggle group

can-shrink

Passed: a boolean.

whether the toggles can shrink

Method: toggle-group:set-homogeneous self homogeneous
Method: set-homogeneous self homogeneous

Sets whether all toggles take the same size.

self

Passed: a <AdwToggleGroup>.

a toggle group

homogeneous

Passed: a boolean.

whether all toggles should take the same size