gtk/
pad_controller.rs

1// Copyright 2013-2018, The Gtk-rs Project Developers.
2// See the COPYRIGHT file at the top-level directory of this distribution.
3// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
4
5use glib::translate::*;
6use glib::IsA;
7use gtk_sys;
8use PadActionEntry;
9use PadController;
10
11pub trait PadControllerExtManual: 'static {
12    fn set_action_entries(&self, entries: &[PadActionEntry]);
13}
14
15impl<O: IsA<PadController>> PadControllerExtManual for O {
16    fn set_action_entries(&self, entries: &[PadActionEntry]) {
17        let n_entries = entries.len() as i32;
18        let entry_strings = entries
19            .iter()
20            .map(|e| {
21                (
22                    e.get_label().to_glib_none(),
23                    e.get_action_name().to_glib_none(),
24                )
25            })
26            .collect::<Vec<(Stash<_, _>, Stash<_, _>)>>();
27        let entries = entries
28            .iter()
29            .zip(entry_strings.iter())
30            .map(|(e, (label, action_name))| gtk_sys::GtkPadActionEntry {
31                type_: e.get_type().to_glib(),
32                index: e.get_index(),
33                mode: e.get_mode(),
34                label: label.0,
35                action_name: action_name.0,
36            })
37            .collect::<Vec<_>>();
38        unsafe {
39            gtk_sys::gtk_pad_controller_set_action_entries(
40                self.as_ref().to_glib_none().0,
41                entries.as_ptr(),
42                n_entries,
43            );
44        }
45    }
46}