Class ToggleGroup

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Orientable, Proxy

@Generated("org.javagi.JavaGI") public final class ToggleGroup extends Widget implements Accessible, Buildable, ConstraintTarget, Orientable

A group of exclusive toggles.

toggle-group

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 getToggle(int) or getToggleByName(String) respectively. AdwToggleGroup also provides a SelectionModel 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.

toggle-group-flat

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

toggle-group-round

They can also be combined with each other.

toggle-group-flat-round

Accessibility

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

Since:
1.7
  • Constructor Details

    • ToggleGroup

      public ToggleGroup(MemorySegment address)
      Create a ToggleGroup instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • ToggleGroup

      public ToggleGroup()
      Create a new ToggleGroup.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the ToggleGroup class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected ToggleGroup asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Widget
      Returns:
      the instance as if it were its parent type
    • add

      public void add(Toggle toggle)
      Adds a toggle to self.
      Parameters:
      toggle - the toggle to add
      Since:
      1.7
    • getActive

      public int getActive()

      Gets the index of the active toggle in self.

      Returns Gtk.INVALID_LIST_POSITION if no toggle is active.

      Returns:
      the active toggle index
      Since:
      1.7
    • getActiveName

      public @Nullable String getActiveName()

      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.

      Returns:
      the active toggle name
      Since:
      1.7
    • getCanShrink

      public boolean getCanShrink()
      Gets whether the toggles can be smaller than the natural size of their contents.
      Returns:
      whether the toggles can shrink
      Since:
      1.7
    • getHomogeneous

      public boolean getHomogeneous()
      Gets whether all toggles take the same size.
      Returns:
      whether all toggles take the same size
      Since:
      1.7
    • getNToggles

      public int getNToggles()
      Gets the number of toggles within self.
      Returns:
      the number of toggles
      Since:
      1.7
    • getToggle

      public @Nullable Toggle getToggle(int index)
      Gets the toggle with index from self.
      Parameters:
      index - toggle's index
      Returns:
      the toggle
      Since:
      1.7
    • getToggleByName

      public @Nullable Toggle getToggleByName(String name)
      Gets the toggle with the name name from self.
      Parameters:
      name - toggle name
      Returns:
      the toggle
      Since:
      1.7
    • getToggles

      public SelectionModel getToggles()

      Returns a ListModel that contains the toggles of the group.

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

      Returns:
      a GtkSelectionModel for the group's toggles
    • remove

      public void remove(Toggle toggle)
      Removes toggle from self.
      Parameters:
      toggle - a toggle to remove
      Since:
      1.7
    • removeAll

      public void removeAll()
      Removes all toggles from self.
      Since:
      1.7
    • 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.

      Parameters:
      active - toggle index
      Since:
      1.7
    • setActiveName

      public void setActiveName(@Nullable String 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.

      Parameters:
      name - toggle name
      Since:
      1.7
    • setCanShrink

      public void setCanShrink(boolean canShrink)

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

      If canShrink is TRUE, the toggle labels will ellipsize.

      See Gtk.Button:can-shrink.

      Parameters:
      canShrink - whether the toggles can shrink
      Since:
      1.7
    • setHomogeneous

      public void setHomogeneous(boolean homogeneous)
      Sets whether all toggles take the same size.
      Parameters:
      homogeneous - whether all toggles should take the same size
      Since:
      1.7
    • builder

      public static ToggleGroup.Builder<? extends ToggleGroup.Builder> builder()
      A ToggleGroup.Builder object constructs a ToggleGroup with the specified properties. Use the various set...() methods to set properties, and finish construction with ToggleGroup.Builder.build().
      Returns:
      the builder object