Skip to main content

gtk/
pad_controller.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::PadActionEntry;
4use crate::PadController;
5use glib::translate::*;
6
7impl PadController {
8    /// This is a convenience function to add a group of action entries on
9    /// `self`. See [`PadActionEntry`][crate::PadActionEntry] and [`set_action()`][Self::set_action()].
10    /// ## `entries`
11    /// the action entries to set on `self`
12    #[doc(alias = "gtk_pad_controller_set_action_entries")]
13    pub fn set_action_entries(&self, entries: &[PadActionEntry]) {
14        let n_entries = entries.len() as i32;
15        let entry_strings = entries
16            .iter()
17            .map(|e| (e.label().to_glib_none(), e.action_name().to_glib_none()))
18            .collect::<Vec<(Stash<_, _>, Stash<_, _>)>>();
19        let entries = entries
20            .iter()
21            .zip(entry_strings.iter())
22            .map(|(e, (label, action_name))| ffi::GtkPadActionEntry {
23                type_: e.type_().into_glib(),
24                index: e.index(),
25                mode: e.mode(),
26                label: label.0,
27                action_name: action_name.0,
28            })
29            .collect::<Vec<_>>();
30        unsafe {
31            ffi::gtk_pad_controller_set_action_entries(
32                self.to_glib_none().0,
33                entries.as_ptr(),
34                n_entries,
35            );
36        }
37    }
38}