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 ffi, EventController, PadActionEntry, PadActionType, PropagationLimit, PropagationPhase,
7};
8use glib::{prelude::*, translate::*};
9
10glib::wrapper! {
11 /// [`PadController`][crate::PadController] is an event controller for the pads found in drawing
12 /// tablets.
13 ///
14 /// Pads are the collection of buttons and tactile sensors often found around
15 /// the stylus-sensitive area.
16 ///
17 /// These buttons and sensors have no implicit meaning, and by default they
18 /// perform no action. [`PadController`][crate::PadController] is provided to map those to
19 /// [`gio::Action`][crate::gio::Action] objects, thus letting the application give them a more
20 /// semantic meaning.
21 ///
22 /// Buttons and sensors are not constrained to triggering a single action,
23 /// some `GDK_SOURCE_TABLET_PAD` devices feature multiple "modes". All these
24 /// input elements have one current mode, which may determine the final action
25 /// being triggered.
26 ///
27 /// Pad devices often divide buttons and sensors into groups. All elements
28 /// in a group share the same current mode, but different groups may have
29 /// different modes. See `Gdk::DevicePad::get_n_groups()` and
30 /// `Gdk::DevicePad::get_group_n_modes()`.
31 ///
32 /// Each of the actions that a given button/strip/ring performs for a given mode
33 /// is defined by a [`PadActionEntry`][crate::PadActionEntry]. It contains an action name that
34 /// will be looked up in the given [`gio::ActionGroup`][crate::gio::ActionGroup] and activated whenever
35 /// the specified input element and mode are triggered.
36 ///
37 /// A simple example of [`PadController`][crate::PadController] usage: Assigning button 1 in all
38 /// modes and pad devices to an "invert-selection" action:
39 ///
40 /// **⚠️ The following code is in c ⚠️**
41 ///
42 /// ```c
43 /// GtkPadActionEntry *pad_actions[] = {
44 /// { GTK_PAD_ACTION_BUTTON, 1, -1, "Invert selection", "pad-actions.invert-selection" },
45 /// …
46 /// };
47 ///
48 /// …
49 /// action_group = g_simple_action_group_new ();
50 /// action = g_simple_action_new ("pad-actions.invert-selection", NULL);
51 /// g_signal_connect (action, "activate", on_invert_selection_activated, NULL);
52 /// g_action_map_add_action (G_ACTION_MAP (action_group), action);
53 /// …
54 /// pad_controller = gtk_pad_controller_new (action_group, NULL);
55 /// ```
56 ///
57 /// The actions belonging to rings/strips will be activated with a parameter
58 /// of type `G_VARIANT_TYPE_DOUBLE` bearing the value of the given axis, it
59 /// is required that those are made stateful and accepting this `GVariantType`.
60 ///
61 /// ## Properties
62 ///
63 ///
64 /// #### `action-group`
65 /// The action group of the controller.
66 ///
67 /// Readable | Writeable | Construct Only
68 ///
69 ///
70 /// #### `pad`
71 /// The pad of the controller.
72 ///
73 /// Readable | Writeable | Construct Only
74 /// <details><summary><h4>EventController</h4></summary>
75 ///
76 ///
77 /// #### `name`
78 /// The name for this controller, typically used for debugging purposes.
79 ///
80 /// Readable | Writeable
81 ///
82 ///
83 /// #### `propagation-limit`
84 /// The limit for which events this controller will handle.
85 ///
86 /// Readable | Writeable
87 ///
88 ///
89 /// #### `propagation-phase`
90 /// The propagation phase at which this controller will handle events.
91 ///
92 /// Readable | Writeable
93 ///
94 ///
95 /// #### `widget`
96 /// The widget receiving the `GdkEvents` that the controller will handle.
97 ///
98 /// Readable
99 /// </details>
100 ///
101 /// # Implements
102 ///
103 /// [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
104 #[doc(alias = "GtkPadController")]
105 pub struct PadController(Object<ffi::GtkPadController, ffi::GtkPadControllerClass>) @extends EventController;
106
107 match fn {
108 type_ => || ffi::gtk_pad_controller_get_type(),
109 }
110}
111
112impl PadController {
113 /// Creates a new [`PadController`][crate::PadController] that will associate events from @pad to
114 /// actions.
115 ///
116 /// A [`None`] pad may be provided so the controller manages all pad devices
117 /// generically, it is discouraged to mix [`PadController`][crate::PadController] objects with
118 /// [`None`] and non-[`None`] @pad argument on the same toplevel window, as execution
119 /// order is not guaranteed.
120 ///
121 /// The [`PadController`][crate::PadController] is created with no mapped actions. In order to
122 /// map pad events to actions, use [`set_action_entries()`][Self::set_action_entries()]
123 /// or [`set_action()`][Self::set_action()].
124 ///
125 /// Be aware that pad events will only be delivered to [`Window`][crate::Window]s, so adding
126 /// a pad controller to any other type of widget will not have an effect.
127 /// ## `group`
128 /// `GActionGroup` to trigger actions from
129 /// ## `pad`
130 /// A `GDK_SOURCE_TABLET_PAD` device, or [`None`] to handle all pads
131 ///
132 /// # Returns
133 ///
134 /// A newly created [`PadController`][crate::PadController]
135 #[doc(alias = "gtk_pad_controller_new")]
136 pub fn new(group: &impl IsA<gio::ActionGroup>, pad: Option<&gdk::Device>) -> PadController {
137 assert_initialized_main_thread!();
138 unsafe {
139 from_glib_full(ffi::gtk_pad_controller_new(
140 group.as_ref().to_glib_none().0,
141 pad.to_glib_none().0,
142 ))
143 }
144 }
145
146 // rustdoc-stripper-ignore-next
147 /// Creates a new builder-pattern struct instance to construct [`PadController`] objects.
148 ///
149 /// This method returns an instance of [`PadControllerBuilder`](crate::builders::PadControllerBuilder) which can be used to create [`PadController`] objects.
150 pub fn builder() -> PadControllerBuilder {
151 PadControllerBuilder::new()
152 }
153
154 /// Adds an individual action to @self.
155 ///
156 /// This action will only be activated if the given button/ring/strip number
157 /// in @index is interacted while the current mode is @mode. -1 may be used
158 /// for simple cases, so the action is triggered on all modes.
159 ///
160 /// The given @label should be considered user-visible, so internationalization
161 /// rules apply. Some windowing systems may be able to use those for user
162 /// feedback.
163 /// ## `type_`
164 /// the type of pad feature that will trigger this action
165 /// ## `index`
166 /// the 0-indexed button/ring/strip number that will trigger this action
167 /// ## `mode`
168 /// the mode that will trigger this action, or -1 for all modes.
169 /// ## `label`
170 /// Human readable description of this action, this string should
171 /// be deemed user-visible.
172 /// ## `action_name`
173 /// action name that will be activated in the `GActionGroup`
174 #[doc(alias = "gtk_pad_controller_set_action")]
175 pub fn set_action(
176 &self,
177 type_: PadActionType,
178 index: i32,
179 mode: i32,
180 label: &str,
181 action_name: &str,
182 ) {
183 unsafe {
184 ffi::gtk_pad_controller_set_action(
185 self.to_glib_none().0,
186 type_.into_glib(),
187 index,
188 mode,
189 label.to_glib_none().0,
190 action_name.to_glib_none().0,
191 );
192 }
193 }
194
195 /// A convenience function to add a group of action entries on
196 /// @self.
197 ///
198 /// See [`PadActionEntry`][crate::PadActionEntry] and [`set_action()`][Self::set_action()].
199 /// ## `entries`
200 /// the action entries to set on @self
201 #[doc(alias = "gtk_pad_controller_set_action_entries")]
202 pub fn set_action_entries(&self, entries: &[PadActionEntry]) {
203 let n_entries = entries.len() as _;
204 unsafe {
205 ffi::gtk_pad_controller_set_action_entries(
206 self.to_glib_none().0,
207 entries.to_glib_none().0,
208 n_entries,
209 );
210 }
211 }
212
213 /// The action group of the controller.
214 #[doc(alias = "action-group")]
215 pub fn action_group(&self) -> Option<gio::ActionGroup> {
216 ObjectExt::property(self, "action-group")
217 }
218
219 /// The pad of the controller.
220 pub fn pad(&self) -> Option<gdk::Device> {
221 ObjectExt::property(self, "pad")
222 }
223}
224
225impl Default for PadController {
226 fn default() -> Self {
227 glib::object::Object::new::<Self>()
228 }
229}
230
231// rustdoc-stripper-ignore-next
232/// A [builder-pattern] type to construct [`PadController`] objects.
233///
234/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
235#[must_use = "The builder must be built to be used"]
236pub struct PadControllerBuilder {
237 builder: glib::object::ObjectBuilder<'static, PadController>,
238}
239
240impl PadControllerBuilder {
241 fn new() -> Self {
242 Self {
243 builder: glib::object::Object::builder(),
244 }
245 }
246
247 /// The action group of the controller.
248 pub fn action_group(self, action_group: &impl IsA<gio::ActionGroup>) -> Self {
249 Self {
250 builder: self
251 .builder
252 .property("action-group", action_group.clone().upcast()),
253 }
254 }
255
256 /// The pad of the controller.
257 pub fn pad(self, pad: &gdk::Device) -> Self {
258 Self {
259 builder: self.builder.property("pad", pad.clone()),
260 }
261 }
262
263 /// The name for this controller, typically used for debugging purposes.
264 pub fn name(self, name: impl Into<glib::GString>) -> Self {
265 Self {
266 builder: self.builder.property("name", name.into()),
267 }
268 }
269
270 /// The limit for which events this controller will handle.
271 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
272 Self {
273 builder: self
274 .builder
275 .property("propagation-limit", propagation_limit),
276 }
277 }
278
279 /// The propagation phase at which this controller will handle events.
280 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
281 Self {
282 builder: self
283 .builder
284 .property("propagation-phase", propagation_phase),
285 }
286 }
287
288 // rustdoc-stripper-ignore-next
289 /// Build the [`PadController`].
290 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
291 pub fn build(self) -> PadController {
292 assert_initialized_main_thread!();
293 self.builder.build()
294 }
295}