gtk/auto/shortcut_label.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::{Box, Buildable, Container, Orientable, Widget};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14 /// [`ShortcutLabel`][crate::ShortcutLabel] is a widget that represents a single keyboard shortcut or gesture
15 /// in the user interface.
16 ///
17 /// ## Properties
18 ///
19 ///
20 /// #### `accelerator`
21 /// The accelerator that `self_` displays. See [`accelerator`][struct@crate::ShortcutsShortcut#accelerator]
22 /// for the accepted syntax.
23 ///
24 /// Readable | Writeable
25 ///
26 ///
27 /// #### `disabled-text`
28 /// The text that is displayed when no accelerator is set.
29 ///
30 /// Readable | Writeable
31 /// <details><summary><h4>Box</h4></summary>
32 ///
33 ///
34 /// #### `baseline-position`
35 /// Readable | Writeable
36 ///
37 ///
38 /// #### `homogeneous`
39 /// Readable | Writeable
40 ///
41 ///
42 /// #### `spacing`
43 /// Readable | Writeable
44 /// </details>
45 /// <details><summary><h4>Container</h4></summary>
46 ///
47 ///
48 /// #### `border-width`
49 /// Readable | Writeable
50 ///
51 ///
52 /// #### `child`
53 /// Writeable
54 ///
55 ///
56 /// #### `resize-mode`
57 /// Readable | Writeable
58 /// </details>
59 /// <details><summary><h4>Widget</h4></summary>
60 ///
61 ///
62 /// #### `app-paintable`
63 /// Readable | Writeable
64 ///
65 ///
66 /// #### `can-default`
67 /// Readable | Writeable
68 ///
69 ///
70 /// #### `can-focus`
71 /// Readable | Writeable
72 ///
73 ///
74 /// #### `composite-child`
75 /// Readable
76 ///
77 ///
78 /// #### `double-buffered`
79 /// Whether the widget is double buffered.
80 ///
81 /// Readable | Writeable
82 ///
83 ///
84 /// #### `events`
85 /// Readable | Writeable
86 ///
87 ///
88 /// #### `expand`
89 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
90 ///
91 /// Readable | Writeable
92 ///
93 ///
94 /// #### `focus-on-click`
95 /// Whether the widget should grab focus when it is clicked with the mouse.
96 ///
97 /// This property is only relevant for widgets that can take focus.
98 ///
99 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
100 /// GtkComboBox) implemented this property individually.
101 ///
102 /// Readable | Writeable
103 ///
104 ///
105 /// #### `halign`
106 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
107 ///
108 /// Readable | Writeable
109 ///
110 ///
111 /// #### `has-default`
112 /// Readable | Writeable
113 ///
114 ///
115 /// #### `has-focus`
116 /// Readable | Writeable
117 ///
118 ///
119 /// #### `has-tooltip`
120 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
121 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
122 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
123 /// whether it will provide a tooltip or not.
124 ///
125 /// Note that setting this property to [`true`] for the first time will change
126 /// the event masks of the GdkWindows of this widget to include leave-notify
127 /// and motion-notify events. This cannot and will not be undone when the
128 /// property is set to [`false`] again.
129 ///
130 /// Readable | Writeable
131 ///
132 ///
133 /// #### `height-request`
134 /// Readable | Writeable
135 ///
136 ///
137 /// #### `hexpand`
138 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
139 ///
140 /// Readable | Writeable
141 ///
142 ///
143 /// #### `hexpand-set`
144 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
145 ///
146 /// Readable | Writeable
147 ///
148 ///
149 /// #### `is-focus`
150 /// Readable | Writeable
151 ///
152 ///
153 /// #### `margin`
154 /// Sets all four sides' margin at once. If read, returns max
155 /// margin on any side.
156 ///
157 /// Readable | Writeable
158 ///
159 ///
160 /// #### `margin-bottom`
161 /// Margin on bottom side of widget.
162 ///
163 /// This property adds margin outside of the widget's normal size
164 /// request, the margin will be added in addition to the size from
165 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
166 ///
167 /// Readable | Writeable
168 ///
169 ///
170 /// #### `margin-end`
171 /// Margin on end of widget, horizontally. This property supports
172 /// left-to-right and right-to-left text directions.
173 ///
174 /// This property adds margin outside of the widget's normal size
175 /// request, the margin will be added in addition to the size from
176 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
177 ///
178 /// Readable | Writeable
179 ///
180 ///
181 /// #### `margin-left`
182 /// Margin on left side of widget.
183 ///
184 /// This property adds margin outside of the widget's normal size
185 /// request, the margin will be added in addition to the size from
186 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
187 ///
188 /// Readable | Writeable
189 ///
190 ///
191 /// #### `margin-right`
192 /// Margin on right side of widget.
193 ///
194 /// This property adds margin outside of the widget's normal size
195 /// request, the margin will be added in addition to the size from
196 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
197 ///
198 /// Readable | Writeable
199 ///
200 ///
201 /// #### `margin-start`
202 /// Margin on start of widget, horizontally. This property supports
203 /// left-to-right and right-to-left text directions.
204 ///
205 /// This property adds margin outside of the widget's normal size
206 /// request, the margin will be added in addition to the size from
207 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
208 ///
209 /// Readable | Writeable
210 ///
211 ///
212 /// #### `margin-top`
213 /// Margin on top side of widget.
214 ///
215 /// This property adds margin outside of the widget's normal size
216 /// request, the margin will be added in addition to the size from
217 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
218 ///
219 /// Readable | Writeable
220 ///
221 ///
222 /// #### `name`
223 /// Readable | Writeable
224 ///
225 ///
226 /// #### `no-show-all`
227 /// Readable | Writeable
228 ///
229 ///
230 /// #### `opacity`
231 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
232 /// more details about window opacity.
233 ///
234 /// Before 3.8 this was only available in GtkWindow
235 ///
236 /// Readable | Writeable
237 ///
238 ///
239 /// #### `parent`
240 /// Readable | Writeable
241 ///
242 ///
243 /// #### `receives-default`
244 /// Readable | Writeable
245 ///
246 ///
247 /// #### `scale-factor`
248 /// The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
249 /// more details about widget scaling.
250 ///
251 /// Readable
252 ///
253 ///
254 /// #### `sensitive`
255 /// Readable | Writeable
256 ///
257 ///
258 /// #### `style`
259 /// The style of the widget, which contains information about how it will look (colors, etc).
260 ///
261 /// Readable | Writeable
262 ///
263 ///
264 /// #### `tooltip-markup`
265 /// Sets the text of tooltip to be the given string, which is marked up
266 /// with the [Pango text markup language][PangoMarkupFormat].
267 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
268 ///
269 /// This is a convenience property which will take care of getting the
270 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
271 /// will automatically be set to [`true`] and there will be taken care of
272 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
273 ///
274 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
275 /// are set, the last one wins.
276 ///
277 /// Readable | Writeable
278 ///
279 ///
280 /// #### `tooltip-text`
281 /// Sets the text of tooltip to be the given string.
282 ///
283 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
284 ///
285 /// This is a convenience property which will take care of getting the
286 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
287 /// will automatically be set to [`true`] and there will be taken care of
288 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
289 ///
290 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
291 /// are set, the last one wins.
292 ///
293 /// Readable | Writeable
294 ///
295 ///
296 /// #### `valign`
297 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
298 ///
299 /// Readable | Writeable
300 ///
301 ///
302 /// #### `vexpand`
303 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
304 ///
305 /// Readable | Writeable
306 ///
307 ///
308 /// #### `vexpand-set`
309 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
310 ///
311 /// Readable | Writeable
312 ///
313 ///
314 /// #### `visible`
315 /// Readable | Writeable
316 ///
317 ///
318 /// #### `width-request`
319 /// Readable | Writeable
320 ///
321 ///
322 /// #### `window`
323 /// The widget's window if it is realized, [`None`] otherwise.
324 ///
325 /// Readable
326 /// </details>
327 /// <details><summary><h4>Orientable</h4></summary>
328 ///
329 ///
330 /// #### `orientation`
331 /// The orientation of the orientable.
332 ///
333 /// Readable | Writeable
334 /// </details>
335 ///
336 /// # Implements
337 ///
338 /// [`BoxExt`][trait@crate::prelude::BoxExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`OrientableExt`][trait@crate::prelude::OrientableExt], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
339 #[doc(alias = "GtkShortcutLabel")]
340 pub struct ShortcutLabel(Object<ffi::GtkShortcutLabel, ffi::GtkShortcutLabelClass>) @extends Box, Container, Widget, @implements Buildable, Orientable;
341
342 match fn {
343 type_ => || ffi::gtk_shortcut_label_get_type(),
344 }
345}
346
347impl ShortcutLabel {
348 /// Creates a new [`ShortcutLabel`][crate::ShortcutLabel] with `accelerator` set.
349 /// ## `accelerator`
350 /// the initial accelerator
351 ///
352 /// # Returns
353 ///
354 /// a newly-allocated [`ShortcutLabel`][crate::ShortcutLabel]
355 #[doc(alias = "gtk_shortcut_label_new")]
356 pub fn new(accelerator: &str) -> ShortcutLabel {
357 assert_initialized_main_thread!();
358 unsafe {
359 Widget::from_glib_none(ffi::gtk_shortcut_label_new(accelerator.to_glib_none().0))
360 .unsafe_cast()
361 }
362 }
363
364 /// Retrieves the current accelerator of `self`.
365 ///
366 /// # Returns
367 ///
368 /// the current accelerator.
369 #[doc(alias = "gtk_shortcut_label_get_accelerator")]
370 #[doc(alias = "get_accelerator")]
371 pub fn accelerator(&self) -> Option<glib::GString> {
372 unsafe {
373 from_glib_none(ffi::gtk_shortcut_label_get_accelerator(
374 self.to_glib_none().0,
375 ))
376 }
377 }
378
379 /// Retrieves the text that is displayed when no accelerator is set.
380 ///
381 /// # Returns
382 ///
383 /// the current text displayed when no
384 /// accelerator is set.
385 #[doc(alias = "gtk_shortcut_label_get_disabled_text")]
386 #[doc(alias = "get_disabled_text")]
387 pub fn disabled_text(&self) -> Option<glib::GString> {
388 unsafe {
389 from_glib_none(ffi::gtk_shortcut_label_get_disabled_text(
390 self.to_glib_none().0,
391 ))
392 }
393 }
394
395 /// Sets the accelerator to be displayed by `self`.
396 /// ## `accelerator`
397 /// the new accelerator
398 #[doc(alias = "gtk_shortcut_label_set_accelerator")]
399 pub fn set_accelerator(&self, accelerator: &str) {
400 unsafe {
401 ffi::gtk_shortcut_label_set_accelerator(
402 self.to_glib_none().0,
403 accelerator.to_glib_none().0,
404 );
405 }
406 }
407
408 /// Sets the text to be displayed by `self` when no accelerator is set.
409 /// ## `disabled_text`
410 /// the text to be displayed when no accelerator is set
411 #[doc(alias = "gtk_shortcut_label_set_disabled_text")]
412 pub fn set_disabled_text(&self, disabled_text: &str) {
413 unsafe {
414 ffi::gtk_shortcut_label_set_disabled_text(
415 self.to_glib_none().0,
416 disabled_text.to_glib_none().0,
417 );
418 }
419 }
420
421 #[doc(alias = "accelerator")]
422 pub fn connect_accelerator_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
423 unsafe extern "C" fn notify_accelerator_trampoline<F: Fn(&ShortcutLabel) + 'static>(
424 this: *mut ffi::GtkShortcutLabel,
425 _param_spec: glib::ffi::gpointer,
426 f: glib::ffi::gpointer,
427 ) {
428 let f: &F = &*(f as *const F);
429 f(&from_glib_borrow(this))
430 }
431 unsafe {
432 let f: Box_<F> = Box_::new(f);
433 connect_raw(
434 self.as_ptr() as *mut _,
435 b"notify::accelerator\0".as_ptr() as *const _,
436 Some(transmute::<_, unsafe extern "C" fn()>(
437 notify_accelerator_trampoline::<F> as *const (),
438 )),
439 Box_::into_raw(f),
440 )
441 }
442 }
443
444 #[doc(alias = "disabled-text")]
445 pub fn connect_disabled_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
446 unsafe extern "C" fn notify_disabled_text_trampoline<F: Fn(&ShortcutLabel) + 'static>(
447 this: *mut ffi::GtkShortcutLabel,
448 _param_spec: glib::ffi::gpointer,
449 f: glib::ffi::gpointer,
450 ) {
451 let f: &F = &*(f as *const F);
452 f(&from_glib_borrow(this))
453 }
454 unsafe {
455 let f: Box_<F> = Box_::new(f);
456 connect_raw(
457 self.as_ptr() as *mut _,
458 b"notify::disabled-text\0".as_ptr() as *const _,
459 Some(transmute::<_, unsafe extern "C" fn()>(
460 notify_disabled_text_trampoline::<F> as *const (),
461 )),
462 Box_::into_raw(f),
463 )
464 }
465 }
466}
467
468impl fmt::Display for ShortcutLabel {
469 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
470 f.write_str("ShortcutLabel")
471 }
472}