Struct gtk::RadioButton [−][src]
pub struct RadioButton(_);
Expand description
A single radio button performs the same basic function as a CheckButton,
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
RadioButton is one way of giving the user a choice from many options.
Radio button widgets are created with new(), passing None
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, 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 from_widget() with a RadioButton that already
has a group assigned to it. The convenience function
with_label_from_widget() is also provided.
To retrieve the group a RadioButton is assigned to, use
RadioButtonExt::group().
To remove a RadioButton 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 RadioButton will remove
itself and its list item when it is destroyed.
CSS nodes
⚠️ The following code is in plain ⚠️
radiobutton
├── radio
╰── <child>
A GtkRadioButton with indicator (see ToggleButtonExt::set_mode()) has a
main CSS node with name radiobutton and a subnode with name radio.
⚠️ The following code is in plain ⚠️
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.
⚠️ The following code is in C ⚠️
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 signal::ToggleButton::toggled signal, as does the previously
selected button.
Inside the signal::ToggleButton::toggled handler, ToggleButtonExt::is_active()
can be used to determine if the button has been selected or deselected.
Implements
RadioButtonExt, [CheckButtonExt][trait@crate::prelude::CheckButtonExt], ToggleButtonExt, ButtonExt, BinExt, ContainerExt, WidgetExt, glib::ObjectExt, BuildableExt, ActionableExt, WidgetExtManual, BuildableExtManual
Implementations
Creates a new RadioButton, adding it to the same group as
radio_group_member. As with new(), a widget
should be packed into the radio button.
radio_group_member
an existing RadioButton.
Returns
a new radio button.
pub fn with_label_from_widget<P: IsA<RadioButton>>(
radio_group_member: &P,
label: &str
) -> RadioButton
pub fn with_label_from_widget<P: IsA<RadioButton>>(
radio_group_member: &P,
label: &str
) -> RadioButtonCreates a new RadioButton with a text label, adding it to
the same group as radio_group_member.
radio_group_member
widget to get radio group from or None
label
a text string to display next to the radio button.
Returns
a new radio button.
pub fn with_mnemonic_from_widget<P: IsA<RadioButton>>(
radio_group_member: &P,
label: &str
) -> RadioButton
pub fn with_mnemonic_from_widget<P: IsA<RadioButton>>(
radio_group_member: &P,
label: &str
) -> RadioButtonCreates a new RadioButton containing a label. The label
will be created using Label::with_mnemonic(), so underscores
in label indicate the mnemonic for the button.
radio_group_member
widget to get radio group from or None
label
the text of the button, with an underscore in front of the mnemonic character
Returns
a new RadioButton
Creates a new builder-pattern struct instance to construct RadioButton objects.
This method returns an instance of RadioButtonBuilder which can be used to create RadioButton objects.
Creates a new RadioButton. To be of any practical value, a widget should
then be packed into the radio button.
group
an existing
radio button group, or None if you are creating a new group.
Returns
a new radio button
Creates a new RadioButton with a text label.
group
an existing
radio button group, or None if you are creating a new group.
label
the text label to display next to the radio button.
Returns
a new radio button.
Creates a new RadioButton containing a label, adding it to the same
group as group. The label will be created using
Label::with_mnemonic(), so underscores in label indicate the
mnemonic for the button.
group
the radio button
group, or None
label
the text of the button, with an underscore in front of the mnemonic character
Returns
a new RadioButton
Trait Implementations
type Parent = CheckButtonThis method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
Returns the type identifier of Self.
Auto Trait Implementations
impl RefUnwindSafe for RadioButtonimpl !Send for RadioButtonimpl !Sync for RadioButtonimpl Unpin for RadioButtonimpl UnwindSafe for RadioButtonBlanket Implementations
Mutably borrows from an owned value. Read more
Upcasts an object to a superclass or interface T. Read more
Upcasts an object to a reference of its superclass or interface T. Read more
Tries to downcast to a subclass or interface implementor T. Read more
Tries to downcast to a reference of its subclass or interface implementor T. Read more
Tries to cast to an object of type T. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast and upcast will do many checks at compile-time already. Read more
Tries to cast to reference to an object of type T. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast and upcast will do many checks at compile-time already. Read more
Casts to T unconditionally. Read more
Casts to &T unconditionally. Read more
Returns true if the object is an instance of (can be cast to) T.
pub fn set_properties_from_value(
&self,
property_values: &[(&str, Value)]
) -> Result<(), BoolError>pub fn set_property<'a, N, V>(
&self,
property_name: N,
value: V
) -> Result<(), BoolError> where
V: ToValue,
N: Into<&'a str>, pub fn set_property_from_value<'a, N>(
&self,
property_name: N,
value: &Value
) -> Result<(), BoolError> where
N: Into<&'a str>, Safety Read more
Safety Read more
Safety Read more
Safety Read more
pub fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec) + Send + Sync, pub fn connect_notify_local<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec), pub unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: Fn(&T, &ParamSpec), pub fn has_property<'a, N>(&self, property_name: N, type_: Option<Type>) -> bool where
N: Into<&'a str>, pub fn find_property<'a, N>(&self, property_name: N) -> Option<ParamSpec> where
N: Into<&'a str>, pub fn connect<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static,
N: Into<&'a str>, Same as connect but takes a SignalId instead of a signal name.
pub fn connect_local<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value> + 'static,
N: Into<&'a str>, Same as connect_local but takes a SignalId instead of a signal name.
pub unsafe fn connect_unsafe<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value>,
N: Into<&'a str>, Same as connect_unsafe but takes a SignalId instead of a signal name.
Emit signal by signal id.
Emit signal with details by signal id.
Emit signal by it’s name.
pub fn bind_property<'a, O, N, M>(
&'a self,
source_property: N,
target: &'a O,
target_property: M
) -> BindingBuilder<'a> where
O: ObjectType,
N: Into<&'a str>,
M: Into<&'a str>, Same as emit but takes Value for the arguments.
Same as emit_by_name but takes Value for the arguments.
Returns a SendValue clone of self.
impl<'a, T, C> FromValueOptional<'a> for T where
C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError>,
T: FromValue<'a, Checker = C>,