RadioButtonProtocol

public protocol RadioButtonProtocol : CheckButtonProtocol

A single radio button performs the same basic function as a GtkCheckButton, as its position in the object hierarchy reflects. It is only when multiple radio buttons are grouped together that they become a different user interface component in their own right.

Every radio button is a member of some group of radio buttons. When one is selected, all other radio buttons in the same group are deselected. A GtkRadioButton is one way of giving the user a choice from many options.

Radio button widgets are created with gtk_radio_button_new(), passing nil as the argument if this is the first radio button in a group. In subsequent calls, the group you wish to add this button to should be passed as an argument. Optionally, gtk_radio_button_new_with_label() can be used if you want a text label on the radio button.

Alternatively, when adding widgets to an existing group of radio buttons, use gtk_radio_button_new_from_widget() with a GtkRadioButton that already has a group assigned to it. The convenience function gtk_radio_button_new_with_label_from_widget() is also provided.

To retrieve the group a GtkRadioButton is assigned to, use gtk_radio_button_get_group().

To remove a GtkRadioButton from one group and make it part of a new one, use gtk_radio_button_set_group().

The group list does not need to be freed, as each GtkRadioButton will remove itself and its list item when it is destroyed.

CSS nodes

(plain Language Example):

radiobutton
├── radio
╰── <child>

A GtkRadioButton with indicator (see gtk_toggle_button_set_mode()) has a main CSS node with name radiobutton and a subnode with name radio.

(plain Language Example):

button.radio
├── radio
╰── <child>

A GtkRadioButton without indicator changes the name of its main node to button and adds a .radio style class to it. The subnode is invisible in this case.

How to create a group of two radio buttons.

(C Language Example):

void create_radio_buttons (void) {

   GtkWidget *window, *radio1, *radio2, *box, *entry;
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
   gtk_box_set_homogeneous (GTK_BOX (box), TRUE);

   // Create a radio button with a GtkEntry widget
   radio1 = gtk_radio_button_new (NULL);
   entry = gtk_entry_new ();
   gtk_container_add (GTK_CONTAINER (radio1), entry);


   // Create a radio button with a label
   radio2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio1),
                                                         "I’m the second radio button.");

   // Pack them into a box, then show all the widgets
   gtk_box_pack_start (GTK_BOX (box), radio1);
   gtk_box_pack_start (GTK_BOX (box), radio2);
   gtk_container_add (GTK_CONTAINER (window), box);
   gtk_widget_show_all (window);
   return;
}

When an unselected button in the group is clicked the clicked button receives the GtkToggleButton::toggled signal, as does the previously selected button. Inside the GtkToggleButton::toggled handler, gtk_toggle_button_get_active() can be used to determine if the button has been selected or deselected.

The RadioButtonProtocol protocol exposes the methods and properties of an underlying GtkRadioButton instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see RadioButton. Alternatively, use RadioButtonRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying GtkRadioButton instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • radio_button_ptr Default implementation

    Typed pointer to the underlying GtkRadioButton instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GtkRadioButton instance.

    Declaration

    Swift

    var radio_button_ptr: UnsafeMutablePointer<GtkRadioButton>! { get }
  • Required Initialiser for types conforming to RadioButtonProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)

RadioButton Class

  • Bind a RadioButtonPropertyName source property to a given target object.

    Declaration

    Swift

    @discardableResult
    @inlinable
    func bind<Q, T>(property source_property: RadioButtonPropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocol

    Parameters

    source_property

    the source property to bind

    target

    the target object to bind to

    target_property

    the target property to bind to

    flags

    the flags to pass to the Binding

    transform_from

    ValueTransformer to use for forward transformation

    transform_to

    ValueTransformer to use for backwards transformation

    Return Value

    binding reference or nil in case of an error

  • get(property:) Extension method

    Get the value of a RadioButton property

    Declaration

    Swift

    @inlinable
    func get(property: RadioButtonPropertyName) -> GLibObject.Value

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

  • set(property:value:) Extension method

    Set the value of a RadioButton property. Note that this will only have an effect on properties that are writable and not construct-only!

    Declaration

    Swift

    @inlinable
    func set(property: RadioButtonPropertyName, value v: GLibObject.Value)

    Parameters

    property

    the property to get the value for

    Return Value

    the value of the named property

RadioButton signals

  • Connect a Swift signal handler to the given, typed RadioButtonSignalName signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func connect(signal s: RadioButtonSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> Int

    Parameters

    signal

    The signal to connect

    flags

    The connection flags to use

    data

    A pointer to user data to provide to the callback

    destroyData

    A GClosureNotify C function to destroy the data pointed to by userData

    handler

    The Swift signal handler (function or callback) to invoke on the given signal

    Return Value

    The signal handler ID (always greater than 0 for successful connections)

  • Connect a C signal handler to the given, typed RadioButtonSignalName signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func connect(signal s: RadioButtonSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> Int

    Parameters

    signal

    The signal to connect

    flags

    The connection flags to use

    data

    A pointer to user data to provide to the callback

    destroyData

    A GClosureNotify C function to destroy the data pointed to by userData

    signalHandler

    The C function to be called on the given signal

    Return Value

    The signal handler ID (always greater than 0 for successful connections)

  • Emitted when the group of radio buttons that a radio button belongs to changes. This is emitted when a radio button switches from being alone to being part of a group of 2 or more buttons, or vice-versa, and when a button is moved from one group of 2 or more buttons to a different one, but not when the composition of the group that a button belongs to changes.

    Note

    This represents the underlying group-changed signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onGroupChanged(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: RadioButtonRef) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    handler

    The signal handler to call Run the given callback whenever the groupChanged signal is emitted

  • groupChangedSignal Extension method

    Typed group-changed signal for using the connect(signal:) methods

    Declaration

    Swift

    static var groupChangedSignal: RadioButtonSignalName { get }
  • The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

    Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with G_PARAM_EXPLICIT_NOTIFY, then any call to g_object_set_property() results in notify being emitted, even if the new value is the same as the old. If they did pass G_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly call g_object_notify() or g_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.

    This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the g_signal_connect() call, like this:

    (C Language Example):

    g_signal_connect (text_view->buffer, "notify::paste-target-list",
                      G_CALLBACK (gtk_text_view_target_list_notify),
                      text_view)
    

    It is important to note that you must use canonical parameter names as detail strings for the notify signal.

    Note

    This represents the underlying notify::group signal

    Declaration

    Swift

    @discardableResult
    @inlinable
    func onNotifyGroup(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: RadioButtonRef, _ pspec: ParamSpecRef) -> Void) -> Int

    Parameters

    flags

    Flags

    unownedSelf

    Reference to instance of self

    pspec

    the GParamSpec of the property which changed.

    handler

    The signal handler to call Run the given callback whenever the notifyGroup signal is emitted

  • notifyGroupSignal Extension method

    Typed notify::group signal for using the connect(signal:) methods

    Declaration

    Swift

    static var notifyGroupSignal: RadioButtonSignalName { get }

RadioButton Class: RadioButtonProtocol extension (methods and fields)

  • getGroup() Extension method

    Retrieves the group assigned to a radio button.

    Declaration

    Swift

    @inlinable
    func getGroup() -> GLib.SListRef!
  • joinGroup(groupSource:) Extension method

    Joins a GtkRadioButton object to the group of another GtkRadioButton object

    Use this in language bindings instead of the gtk_radio_button_get_group() and gtk_radio_button_set_group() methods

    A common way to set up a group of radio buttons is the following: (C Language Example):

      GtkRadioButton *radio_button;
      GtkRadioButton *last_button;
    
      while (some_condition)
        {
           radio_button = gtk_radio_button_new (NULL);
    
           gtk_radio_button_join_group (radio_button, last_button);
           last_button = radio_button;
        }
    

    Declaration

    Swift

    @inlinable
    func joinGroup(groupSource: RadioButtonRef? = nil)
  • joinGroup(groupSource:) Extension method

    Joins a GtkRadioButton object to the group of another GtkRadioButton object

    Use this in language bindings instead of the gtk_radio_button_get_group() and gtk_radio_button_set_group() methods

    A common way to set up a group of radio buttons is the following: (C Language Example):

      GtkRadioButton *radio_button;
      GtkRadioButton *last_button;
    
      while (some_condition)
        {
           radio_button = gtk_radio_button_new (NULL);
    
           gtk_radio_button_join_group (radio_button, last_button);
           last_button = radio_button;
        }
    

    Declaration

    Swift

    @inlinable
    func joinGroup<RadioButtonT>(groupSource: RadioButtonT?) where RadioButtonT : RadioButtonProtocol
  • set(group:) Extension method

    Sets a GtkRadioButton’s group. It should be noted that this does not change the layout of your interface in any way, so if you are changing the group, it is likely you will need to re-arrange the user interface to reflect these changes.

    Declaration

    Swift

    @inlinable
    func set(group: GLib.SListRef? = nil)
  • set(group:) Extension method

    Sets a GtkRadioButton’s group. It should be noted that this does not change the layout of your interface in any way, so if you are changing the group, it is likely you will need to re-arrange the user interface to reflect these changes.

    Declaration

    Swift

    @inlinable
    func set<SListT>(group: SListT?) where SListT : SListProtocol
  • group Extension method

    Sets a new group for a radio button.

    Declaration

    Swift

    @inlinable
    var group: GLib.SListRef! { get nonmutating set }
  • checkButton Extension method

    Undocumented

    Declaration

    Swift

    @inlinable
    var checkButton: GtkCheckButton { get }