Skip to main content

gtk/
radio_button.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::Widget;
4use crate::{RadioButton, ffi};
5use glib::object::Cast;
6use glib::translate::*;
7use std::ptr;
8
9impl RadioButton {
10    /// Creates a new [`RadioButton`][crate::RadioButton]. To be of any practical value, a widget should
11    /// then be packed into the radio button.
12    /// ## `group`
13    /// an existing
14    ///  radio button group, or [`None`] if you are creating a new group.
15    ///
16    /// # Returns
17    ///
18    /// a new radio button
19    #[doc(alias = "gtk_radio_button_new")]
20    pub fn new() -> Self {
21        assert_initialized_main_thread!();
22        unsafe { Widget::from_glib_none(ffi::gtk_radio_button_new(ptr::null_mut())).unsafe_cast() }
23    }
24
25    /// Creates a new [`RadioButton`][crate::RadioButton] with a text label.
26    /// ## `group`
27    /// an existing
28    ///  radio button group, or [`None`] if you are creating a new group.
29    /// ## `label`
30    /// the text label to display next to the radio button.
31    ///
32    /// # Returns
33    ///
34    /// a new radio button.
35    #[doc(alias = "gtk_radio_button_new_with_label")]
36    pub fn with_label(label: &str) -> Self {
37        assert_initialized_main_thread!();
38        unsafe {
39            Widget::from_glib_none(ffi::gtk_radio_button_new_with_label(
40                ptr::null_mut(),
41                label.to_glib_none().0,
42            ))
43            .unsafe_cast()
44        }
45    }
46
47    /// Creates a new [`RadioButton`][crate::RadioButton] containing a label, adding it to the same
48    /// group as `group`. The label will be created using
49    /// [`Label::with_mnemonic()`][crate::Label::with_mnemonic()], so underscores in `label` indicate the
50    /// mnemonic for the button.
51    /// ## `group`
52    /// the radio button
53    ///  group, or [`None`]
54    /// ## `label`
55    /// the text of the button, with an underscore in front of the
56    ///  mnemonic character
57    ///
58    /// # Returns
59    ///
60    /// a new [`RadioButton`][crate::RadioButton]
61    #[doc(alias = "gtk_radio_button_new_with_mnemonic")]
62    pub fn with_mnemonic(label: &str) -> Self {
63        assert_initialized_main_thread!();
64        unsafe {
65            Widget::from_glib_none(ffi::gtk_radio_button_new_with_mnemonic(
66                ptr::null_mut(),
67                label.to_glib_none().0,
68            ))
69            .unsafe_cast()
70        }
71    }
72}
73
74impl Default for RadioButton {
75    fn default() -> Self {
76        Self::new()
77    }
78}