gtk4/mnemonic_trigger.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::fmt;
4
5use gdk::Key;
6use glib::translate::*;
7
8use crate::{ShortcutTrigger, ffi};
9
10glib::wrapper! {
11 /// ) to be
12 /// pressed together with the mnemonic key.
13 ///
14 /// ## Properties
15 ///
16 ///
17 /// #### `keyval`
18 /// The key value for the trigger.
19 ///
20 /// Readable | Writable | Construct Only
21 ///
22 /// # Implements
23 ///
24 /// [`ShortcutTriggerExt`][trait@crate::prelude::ShortcutTriggerExt], [`trait@glib::ObjectExt`], [`ShortcutTriggerExtManual`][trait@crate::prelude::ShortcutTriggerExtManual]
25 pub struct MnemonicTrigger(Object<ffi::GtkMnemonicTrigger, ffi::GtkMnemonicTriggerClass>) @extends ShortcutTrigger;
26
27 match fn {
28 type_ => || ffi::gtk_mnemonic_trigger_get_type(),
29 }
30}
31
32impl MnemonicTrigger {
33 /// Creates a [`ShortcutTrigger`][crate::ShortcutTrigger] that will trigger whenever the key with
34 /// the given @keyval is pressed and mnemonics have been activated.
35 ///
36 /// Mnemonics are activated by calling code when a key event with the right
37 /// modifiers is detected.
38 /// ## `keyval`
39 /// The keyval to trigger for
40 ///
41 /// # Returns
42 ///
43 /// A new [`ShortcutTrigger`][crate::ShortcutTrigger]
44 #[doc(alias = "gtk_mnemonic_trigger_new")]
45 pub fn new(keyval: Key) -> Self {
46 assert_initialized_main_thread!();
47 unsafe { from_glib_full(ffi::gtk_mnemonic_trigger_new(keyval.into_glib())) }
48 }
49
50 /// Gets the keyval that must be pressed to succeed triggering @self.
51 ///
52 /// # Returns
53 ///
54 /// the keyval
55 #[doc(alias = "gtk_mnemonic_trigger_get_keyval")]
56 #[doc(alias = "get_keyval")]
57 pub fn keyval(&self) -> Key {
58 unsafe { from_glib(ffi::gtk_mnemonic_trigger_get_keyval(self.to_glib_none().0)) }
59 }
60}
61
62impl fmt::Display for MnemonicTrigger {
63 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64 f.write_str("MnemonicTrigger")
65 }
66}