gtk4/auto/pad_controller.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6 EventController, PadActionEntry, PadActionType, PropagationLimit, PropagationPhase, ffi,
7};
8use glib::{prelude::*, translate::*};
9
10glib::wrapper! {
11 ///
12 /// pad_controller = gtk_pad_controller_new (action_group, NULL);
13 /// ```text
14 ///
15 /// The actions belonging to rings/strips/dials will be activated with a parameter
16 /// of type `G_VARIANT_TYPE_DOUBLE` bearing the value of the given axis, it
17 /// is required that those are made stateful and accepting this `GVariantType`.
18 /// For rings the value is the angle of the ring position in degrees with 0
19 /// facing up. For strips the value is the absolute position on the strip, normalized
20 /// to the [0.0, 1.0] range.
21 /// For dials the value is the relative movement of the dial, normalized so that the
22 /// value 120 represents one logical scroll wheel detent in the positive direction.
23 /// Devices that support high-resolution scrolling may send events with fractions of
24 /// 120 to signify a smaller motion.
25 ///
26 /// ## Properties
27 ///
28 ///
29 /// #### `action-group`
30 /// The action group of the controller.
31 ///
32 /// Readable | Writable | Construct Only
33 ///
34 ///
35 /// #### `pad`
36 /// The pad of the controller.
37 ///
38 /// Readable | Writable | Construct Only
39 /// <details><summary><h4>EventController</h4></summary>
40 ///
41 ///
42 /// #### `name`
43 /// The name for this controller, typically used for debugging purposes.
44 ///
45 /// Readable | Writable
46 ///
47 ///
48 /// #### `propagation-limit`
49 /// The limit for which events this controller will handle.
50 ///
51 /// Readable | Writable
52 ///
53 ///
54 /// #### `propagation-phase`
55 /// The propagation phase at which this controller will handle events.
56 ///
57 /// Readable | Writable
58 ///
59 ///
60 /// #### `widget`
61 /// The widget receiving the `GdkEvents` that the controller will handle.
62 ///
63 /// Readable
64 /// </details>
65 ///
66 /// # Implements
67 ///
68 /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`], [`EventControllerExtManual`][trait@crate::prelude::EventControllerExtManual]
69 #[doc(alias = "GtkPadController")]
70 pub struct PadController(Object<ffi::GtkPadController, ffi::GtkPadControllerClass>) @extends EventController;
71
72 match fn {
73 type_ => || ffi::gtk_pad_controller_get_type(),
74 }
75}
76
77impl PadController {
78 /// Creates a new [`PadController`][crate::PadController] that will associate events from @pad to
79 /// actions.
80 ///
81 /// A [`None`] pad may be provided so the controller manages all pad devices
82 /// generically, it is discouraged to mix [`PadController`][crate::PadController] objects with
83 /// [`None`] and non-[`None`] @pad argument on the same toplevel window, as execution
84 /// order is not guaranteed.
85 ///
86 /// The [`PadController`][crate::PadController] is created with no mapped actions. In order to
87 /// map pad events to actions, use [`set_action_entries()`][Self::set_action_entries()]
88 /// or [`set_action()`][Self::set_action()].
89 ///
90 /// Be aware that pad events will only be delivered to [`Window`][crate::Window]s, so adding
91 /// a pad controller to any other type of widget will not have an effect.
92 /// ## `group`
93 /// `GActionGroup` to trigger actions from
94 /// ## `pad`
95 /// A `GDK_SOURCE_TABLET_PAD` device, or [`None`] to handle all pads
96 ///
97 /// # Returns
98 ///
99 /// A newly created [`PadController`][crate::PadController]
100 #[doc(alias = "gtk_pad_controller_new")]
101 pub fn new(group: &impl IsA<gio::ActionGroup>, pad: Option<&gdk::Device>) -> PadController {
102 assert_initialized_main_thread!();
103 unsafe {
104 from_glib_full(ffi::gtk_pad_controller_new(
105 group.as_ref().to_glib_none().0,
106 pad.to_glib_none().0,
107 ))
108 }
109 }
110
111 // rustdoc-stripper-ignore-next
112 /// Creates a new builder-pattern struct instance to construct [`PadController`] objects.
113 ///
114 /// This method returns an instance of [`PadControllerBuilder`](crate::builders::PadControllerBuilder) which can be used to create [`PadController`] objects.
115 pub fn builder() -> PadControllerBuilder {
116 PadControllerBuilder::new()
117 }
118
119 /// Adds an individual action to @self.
120 ///
121 /// This action will only be activated if the given button/ring/strip number
122 /// in @index is interacted while the current mode is @mode. -1 may be used
123 /// for simple cases, so the action is triggered on all modes.
124 ///
125 /// The given @label should be considered user-visible, so internationalization
126 /// rules apply. Some windowing systems may be able to use those for user
127 /// feedback.
128 /// ## `type_`
129 /// the type of pad feature that will trigger this action
130 /// ## `index`
131 /// the 0-indexed button/ring/strip number that will trigger this action
132 /// ## `mode`
133 /// the mode that will trigger this action, or -1 for all modes.
134 /// ## `label`
135 /// Human readable description of this action, this string should
136 /// be deemed user-visible.
137 /// ## `action_name`
138 /// action name that will be activated in the `GActionGroup`
139 #[doc(alias = "gtk_pad_controller_set_action")]
140 pub fn set_action(
141 &self,
142 type_: PadActionType,
143 index: i32,
144 mode: i32,
145 label: &str,
146 action_name: &str,
147 ) {
148 unsafe {
149 ffi::gtk_pad_controller_set_action(
150 self.to_glib_none().0,
151 type_.into_glib(),
152 index,
153 mode,
154 label.to_glib_none().0,
155 action_name.to_glib_none().0,
156 );
157 }
158 }
159
160 /// A convenience function to add a group of action entries on
161 /// @self.
162 ///
163 /// See [`PadActionEntry`][crate::PadActionEntry] and [`set_action()`][Self::set_action()].
164 /// ## `entries`
165 /// the action entries to set on @self
166 #[doc(alias = "gtk_pad_controller_set_action_entries")]
167 pub fn set_action_entries(&self, entries: &[PadActionEntry]) {
168 let n_entries = entries.len() as _;
169 unsafe {
170 ffi::gtk_pad_controller_set_action_entries(
171 self.to_glib_none().0,
172 entries.to_glib_none().0,
173 n_entries,
174 );
175 }
176 }
177
178 /// The action group of the controller.
179 #[doc(alias = "action-group")]
180 pub fn action_group(&self) -> Option<gio::ActionGroup> {
181 ObjectExt::property(self, "action-group")
182 }
183
184 /// The pad of the controller.
185 pub fn pad(&self) -> Option<gdk::Device> {
186 ObjectExt::property(self, "pad")
187 }
188}
189
190impl Default for PadController {
191 fn default() -> Self {
192 glib::object::Object::new::<Self>()
193 }
194}
195
196// rustdoc-stripper-ignore-next
197/// A [builder-pattern] type to construct [`PadController`] objects.
198///
199/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
200#[must_use = "The builder must be built to be used"]
201pub struct PadControllerBuilder {
202 builder: glib::object::ObjectBuilder<'static, PadController>,
203}
204
205impl PadControllerBuilder {
206 fn new() -> Self {
207 Self {
208 builder: glib::object::Object::builder(),
209 }
210 }
211
212 /// The action group of the controller.
213 pub fn action_group(self, action_group: &impl IsA<gio::ActionGroup>) -> Self {
214 Self {
215 builder: self
216 .builder
217 .property("action-group", action_group.clone().upcast()),
218 }
219 }
220
221 /// The pad of the controller.
222 pub fn pad(self, pad: &gdk::Device) -> Self {
223 Self {
224 builder: self.builder.property("pad", pad.clone()),
225 }
226 }
227
228 /// The name for this controller, typically used for debugging purposes.
229 pub fn name(self, name: impl Into<glib::GString>) -> Self {
230 Self {
231 builder: self.builder.property("name", name.into()),
232 }
233 }
234
235 /// The limit for which events this controller will handle.
236 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
237 Self {
238 builder: self
239 .builder
240 .property("propagation-limit", propagation_limit),
241 }
242 }
243
244 /// The propagation phase at which this controller will handle events.
245 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
246 Self {
247 builder: self
248 .builder
249 .property("propagation-phase", propagation_phase),
250 }
251 }
252
253 // rustdoc-stripper-ignore-next
254 /// Build the [`PadController`].
255 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
256 pub fn build(self) -> PadController {
257 assert_initialized_main_thread!();
258 self.builder.build()
259 }
260}