gtk4/auto/
pad_controller.rs1use crate::{
6 ffi, EventController, PadActionEntry, PadActionType, PropagationLimit, PropagationPhase,
7};
8use glib::{prelude::*, translate::*};
9
10glib::wrapper! {
11 #[doc(alias = "GtkPadController")]
12 pub struct PadController(Object<ffi::GtkPadController, ffi::GtkPadControllerClass>) @extends EventController;
13
14 match fn {
15 type_ => || ffi::gtk_pad_controller_get_type(),
16 }
17}
18
19impl PadController {
20 #[doc(alias = "gtk_pad_controller_new")]
21 pub fn new(group: &impl IsA<gio::ActionGroup>, pad: Option<&gdk::Device>) -> PadController {
22 assert_initialized_main_thread!();
23 unsafe {
24 from_glib_full(ffi::gtk_pad_controller_new(
25 group.as_ref().to_glib_none().0,
26 pad.to_glib_none().0,
27 ))
28 }
29 }
30
31 pub fn builder() -> PadControllerBuilder {
36 PadControllerBuilder::new()
37 }
38
39 #[doc(alias = "gtk_pad_controller_set_action")]
40 pub fn set_action(
41 &self,
42 type_: PadActionType,
43 index: i32,
44 mode: i32,
45 label: &str,
46 action_name: &str,
47 ) {
48 unsafe {
49 ffi::gtk_pad_controller_set_action(
50 self.to_glib_none().0,
51 type_.into_glib(),
52 index,
53 mode,
54 label.to_glib_none().0,
55 action_name.to_glib_none().0,
56 );
57 }
58 }
59
60 #[doc(alias = "gtk_pad_controller_set_action_entries")]
61 pub fn set_action_entries(&self, entries: &[PadActionEntry]) {
62 let n_entries = entries.len() as _;
63 unsafe {
64 ffi::gtk_pad_controller_set_action_entries(
65 self.to_glib_none().0,
66 entries.to_glib_none().0,
67 n_entries,
68 );
69 }
70 }
71
72 #[doc(alias = "action-group")]
73 pub fn action_group(&self) -> Option<gio::ActionGroup> {
74 ObjectExt::property(self, "action-group")
75 }
76
77 pub fn pad(&self) -> Option<gdk::Device> {
78 ObjectExt::property(self, "pad")
79 }
80}
81
82impl Default for PadController {
83 fn default() -> Self {
84 glib::object::Object::new::<Self>()
85 }
86}
87
88#[must_use = "The builder must be built to be used"]
93pub struct PadControllerBuilder {
94 builder: glib::object::ObjectBuilder<'static, PadController>,
95}
96
97impl PadControllerBuilder {
98 fn new() -> Self {
99 Self {
100 builder: glib::object::Object::builder(),
101 }
102 }
103
104 pub fn action_group(self, action_group: &impl IsA<gio::ActionGroup>) -> Self {
105 Self {
106 builder: self
107 .builder
108 .property("action-group", action_group.clone().upcast()),
109 }
110 }
111
112 pub fn pad(self, pad: &gdk::Device) -> Self {
113 Self {
114 builder: self.builder.property("pad", pad.clone()),
115 }
116 }
117
118 pub fn name(self, name: impl Into<glib::GString>) -> Self {
119 Self {
120 builder: self.builder.property("name", name.into()),
121 }
122 }
123
124 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
125 Self {
126 builder: self
127 .builder
128 .property("propagation-limit", propagation_limit),
129 }
130 }
131
132 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
133 Self {
134 builder: self
135 .builder
136 .property("propagation-phase", propagation_phase),
137 }
138 }
139
140 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
143 pub fn build(self) -> PadController {
144 assert_initialized_main_thread!();
145 self.builder.build()
146 }
147}