Klasse ToggleGroup

Alle implementierten Schnittstellen:
PointerInterface

public class ToggleGroup extends Widget
A group of exclusive toggles.

<picture>
<source srcset="toggle-group-dark.png" media="(prefers-color-scheme: dark)">
<img src="toggle-group.png" alt="toggle-group">
</picture>

`AdwToggleGroup` presents a set of exclusive toggles, represented as
[class@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 [property@ToggleGroup:active] to get that position.

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

`AdwToggle` objects can be retrieved via their index or name, using
[method@ToggleGroup.get_toggle] or [method@ToggleGroup.get_toggle_by_name]
respectively. `AdwToggleGroup` also provides a [iface@Gtk.SelectionModel] of
its toggles via the [property@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 [property@ToggleGroup:homogeneous] property to make the toggles take
the same size, and the [property@ToggleGroup:can-shrink] to control whether
the toggles can ellipsize.

Example of an `AdwToggleGroup` UI definition:

```xml
<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: [class@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-classes.html#flat_1) style class
to remove its background and make it look like a group of buttons.

<picture>
<source srcset="toggle-group-flat-dark.png" media="(prefers-color-scheme: dark)">
<img src="toggle-group-flat.png" alt="toggle-group-flat">
</picture>

It can also use the [`.round`](style-classes.html#round) style class to make
its toggles and the group itself rounded.

<picture>
<source srcset="toggle-group-round-dark.png" media="(prefers-color-scheme: dark)">
<img src="toggle-group-round.png" alt="toggle-group-round">
</picture>

They can also be combined with each other.

<picture>
<source srcset="toggle-group-flat-round-dark.png" media="(prefers-color-scheme: dark)">
<img src="toggle-group-flat-round.png" alt="toggle-group-flat-round">
</picture>

## Accessibility

`AdwToggleGroup` uses the `GTK_ACCESSIBLE_ROLE_RADIO_GROUP` role. Its toggles
use the `GTK_ACCESSIBLE_ROLE_RADIO` role.

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.ToggleGroup.html

  • Konstruktordetails

    • ToggleGroup

      public ToggleGroup(PointerContainer pointer)
    • ToggleGroup

      public ToggleGroup()
      Creates a new `AdwToggleGroup`.
  • Methodendetails

    • getClassHandler

      public static ClassHandler getClassHandler()
    • add

      public void add(@Nonnull Toggle toggle)
      Adds a toggle to @self.
      Parameter:
      toggle - the toggle to add
    • getActive

      public int getActive()
      Gets the index of the active toggle in @self.

      Returns `GTK_INVALID_LIST_POSITION` if no toggle is active.
      Gibt zurück:
      the active toggle index
    • getActiveName

      public Str getActiveName()
      Gets the name of the active toggle in @self.

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

      See [property@Toggle:name].
      Gibt zurück:
      the active toggle name
    • getCanShrink

      public boolean getCanShrink()
      Gets whether the toggles can be smaller than the natural size of their
      contents.
      Gibt zurück:
      whether the toggles can shrink
    • getHomogeneous

      public boolean getHomogeneous()
      Gets whether all toggles take the same size.
      Gibt zurück:
      whether all toggles take the same size
    • getNToggles

      public int getNToggles()
      Gets the number of toggles within @self.
      Gibt zurück:
      the number of toggles
    • getToggle

      public Toggle getToggle(int index)
      Gets the toggle with @index from @self.
      Parameter:
      index - toggle's index
      Gibt zurück:
      the toggle
    • getToggleByName

      public Toggle getToggleByName(@Nonnull Str name)
      Gets the toggle with the name @name from @self.
      Parameter:
      name - toggle name
      Gibt zurück:
      the toggle
    • getToggleByName

      public Toggle getToggleByName(String name)
      Gets the toggle with the name @name from @self.
      Parameter:
      name - toggle name
      Gibt zurück:
      the toggle
    • getToggles

      public SelectionModel getToggles()
      Returns a [iface@Gio.ListModel] that contains the toggles of the group.

      This can be used to keep an up-to-date view. The model also implements
      [iface@Gtk.SelectionModel] and can be used to track and change the active
      toggle.
      Gibt zurück:
      a `GtkSelectionModel` for the group's toggles
    • remove

      public void remove(@Nonnull Toggle toggle)
      Removes @toggle from @self.
      Parameter:
      toggle - a toggle to remove
    • removeAll

      public void removeAll()
      Removes all toggles from @self.
    • setActive

      public void setActive(int active)
      Sets the active toggle for @self.

      If the index is larger than the number of toggles in @self, unsets the
      current active toggle.
      Parameter:
      active - toggle index
    • setActiveName

      public void setActiveName(@Nullable Str name)
      Sets the active toggle for @self.

      The name can be set via [property@Toggle:name].

      If @name is `NULL`, unset the current active toggle instead.
      Parameter:
      name - toggle name
    • setActiveName

      public void setActiveName(String name)
      Sets the active toggle for @self.

      The name can be set via [property@Toggle:name].

      If @name is `NULL`, unset the current active toggle instead.
      Parameter:
      name - toggle name
    • setCanShrink

      public void setCanShrink(boolean 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 [property@Gtk.Button:can-shrink].
      Parameter:
      can_shrink - whether the toggles can shrink
    • setHomogeneous

      public void setHomogeneous(boolean homogeneous)
      Sets whether all toggles take the same size.
      Parameter:
      homogeneous - whether all toggles should take the same size
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Setzt außer Kraft:
      asAccessible in Klasse Widget
      Gibt zurück:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Setzt außer Kraft:
      asBuildable in Klasse Widget
      Gibt zurück:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Setzt außer Kraft:
      asConstraintTarget in Klasse Widget
      Gibt zurück:
      ConstraintTarget
    • asOrientable

      public Orientable asOrientable()
      Implements interface Orientable. Call this to get access to interface functions.
      Gibt zurück:
      Orientable
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()