gtk/radio_menu_item.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::Widget;
4use crate::{RadioMenuItem, ffi};
5use glib::object::Cast;
6use glib::translate::*;
7use std::ptr;
8
9impl RadioMenuItem {
10 /// Creates a new [`RadioMenuItem`][crate::RadioMenuItem].
11 /// ## `group`
12 /// the group to which the
13 /// radio menu item is to be attached, or [`None`]
14 ///
15 /// # Returns
16 ///
17 /// a new [`RadioMenuItem`][crate::RadioMenuItem]
18 #[doc(alias = "gtk_radio_menu_item_new")]
19 pub fn new() -> Self {
20 assert_initialized_main_thread!();
21 unsafe {
22 Widget::from_glib_none(ffi::gtk_radio_menu_item_new(ptr::null_mut())).unsafe_cast()
23 }
24 }
25
26 /// Creates a new [`RadioMenuItem`][crate::RadioMenuItem] whose child is a simple [`Label`][crate::Label].
27 /// ## `group`
28 ///
29 /// group the radio menu item is inside, or [`None`]
30 /// ## `label`
31 /// the text for the label
32 ///
33 /// # Returns
34 ///
35 /// A new [`RadioMenuItem`][crate::RadioMenuItem]
36 #[doc(alias = "gtk_radio_menu_item_new_with_label")]
37 pub fn with_label(label: &str) -> Self {
38 assert_initialized_main_thread!();
39 unsafe {
40 Widget::from_glib_none(ffi::gtk_radio_menu_item_new_with_label(
41 ptr::null_mut(),
42 label.to_glib_none().0,
43 ))
44 .unsafe_cast()
45 }
46 }
47
48 /// Creates a new [`RadioMenuItem`][crate::RadioMenuItem] containing a label. The label
49 /// will be created using [`Label::with_mnemonic()`][crate::Label::with_mnemonic()], so underscores
50 /// in `label` indicate the mnemonic for the menu item.
51 /// ## `group`
52 ///
53 /// group the radio menu item is inside, 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 [`RadioMenuItem`][crate::RadioMenuItem]
61 #[doc(alias = "gtk_radio_menu_item_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_menu_item_new_with_mnemonic(
66 ptr::null_mut(),
67 label.to_glib_none().0,
68 ))
69 .unsafe_cast()
70 }
71 }
72}
73
74impl Default for RadioMenuItem {
75 fn default() -> Self {
76 Self::new()
77 }
78}