gtk4/auto/button.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
5#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::Accessible;
8use crate::{
9 AccessibleRole, Actionable, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
10 Widget, ffi,
11};
12use glib::{
13 object::ObjectType as _,
14 prelude::*,
15 signal::{SignalHandlerId, connect_raw},
16 translate::*,
17};
18use std::boxed::Box as Box_;
19
20#[cfg(feature = "v4_10")]
21#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
22glib::wrapper! {
23 ///
24 ///
25 /// The [`Button`][crate::Button] widget can hold any valid child widget. That is, it can hold
26 /// almost any other standard [`Widget`][crate::Widget]. The most commonly used child is the
27 /// [`Label`][crate::Label].
28 ///
29 /// # Shortcuts and Gestures
30 ///
31 /// The following signals have default keybindings:
32 ///
33 /// - [`activate`][struct@crate::Button#activate]
34 ///
35 /// # CSS nodes
36 ///
37 /// [`Button`][crate::Button] has a single CSS node with name button. The node will get the
38 /// style classes .image-button or .text-button, if the content is just an
39 /// image or label, respectively. It may also receive the .flat style class.
40 /// When activating a button via the keyboard, the button will temporarily
41 /// gain the .keyboard-activating style class.
42 ///
43 /// Other style classes that are commonly used with [`Button`][crate::Button] include
44 /// .suggested-action and .destructive-action. In special cases, buttons
45 /// can be made round by adding the .circular style class.
46 ///
47 /// Button-like widgets like [`ToggleButton`][crate::ToggleButton], [`MenuButton`][crate::MenuButton],
48 /// [`VolumeButton`][crate::VolumeButton], [`LockButton`][crate::LockButton], [`ColorButton`][crate::ColorButton]
49 /// or [`FontButton`][crate::FontButton] use style classes such as .toggle, .popup, .scale,
50 /// .lock, .color on the button node to differentiate themselves from a plain
51 /// [`Button`][crate::Button].
52 ///
53 /// # Accessibility
54 ///
55 /// [`Button`][crate::Button] uses the [enum@Gtk.AccessibleRole.button] role.
56 ///
57 /// ## Properties
58 ///
59 ///
60 /// #### `can-shrink`
61 /// Whether the size of the button can be made smaller than the natural
62 /// size of its contents.
63 ///
64 /// For text buttons, setting this property will allow ellipsizing the label.
65 ///
66 /// If the contents of a button are an icon or a custom widget, setting this
67 /// property has no effect.
68 ///
69 /// Readable | Writable
70 ///
71 ///
72 /// #### `child`
73 /// The child widget.
74 ///
75 /// Readable | Writable
76 ///
77 ///
78 /// #### `has-frame`
79 /// Whether the button has a frame.
80 ///
81 /// Readable | Writable
82 ///
83 ///
84 /// #### `icon-name`
85 /// The name of the icon used to automatically populate the button.
86 ///
87 /// Readable | Writable
88 ///
89 ///
90 /// #### `label`
91 /// Text of the label inside the button, if the button contains a label widget.
92 ///
93 /// Readable | Writable
94 ///
95 ///
96 /// #### `use-underline`
97 /// If set, an underline in the text indicates that the following character is
98 /// to be used as mnemonic.
99 ///
100 /// Readable | Writable
101 /// <details><summary><h4>Widget</h4></summary>
102 ///
103 ///
104 /// #### `can-focus`
105 /// Whether the widget or any of its descendents can accept
106 /// the input focus.
107 ///
108 /// This property is meant to be set by widget implementations,
109 /// typically in their instance init function.
110 ///
111 /// Readable | Writable
112 ///
113 ///
114 /// #### `can-target`
115 /// Whether the widget can receive pointer events.
116 ///
117 /// Readable | Writable
118 ///
119 ///
120 /// #### `css-classes`
121 /// A list of css classes applied to this widget.
122 ///
123 /// Readable | Writable
124 ///
125 ///
126 /// #### `css-name`
127 /// The name of this widget in the CSS tree.
128 ///
129 /// This property is meant to be set by widget implementations,
130 /// typically in their instance init function.
131 ///
132 /// Readable | Writable | Construct Only
133 ///
134 ///
135 /// #### `cursor`
136 /// The cursor used by @widget.
137 ///
138 /// Readable | Writable
139 ///
140 ///
141 /// #### `focus-on-click`
142 /// Whether the widget should grab focus when it is clicked with the mouse.
143 ///
144 /// This property is only relevant for widgets that can take focus.
145 ///
146 /// Readable | Writable
147 ///
148 ///
149 /// #### `focusable`
150 /// Whether this widget itself will accept the input focus.
151 ///
152 /// Readable | Writable
153 ///
154 ///
155 /// #### `halign`
156 /// How to distribute horizontal space if widget gets extra space.
157 ///
158 /// Readable | Writable
159 ///
160 ///
161 /// #### `has-default`
162 /// Whether the widget is the default widget.
163 ///
164 /// Readable
165 ///
166 ///
167 /// #### `has-focus`
168 /// Whether the widget has the input focus.
169 ///
170 /// Readable
171 ///
172 ///
173 /// #### `has-tooltip`
174 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
175 /// signal on @widget.
176 ///
177 /// A true value indicates that @widget can have a tooltip, in this case
178 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
179 /// determine whether it will provide a tooltip or not.
180 ///
181 /// Readable | Writable
182 ///
183 ///
184 /// #### `height-request`
185 /// Overrides for height request of the widget.
186 ///
187 /// If this is -1, the natural request will be used.
188 ///
189 /// Readable | Writable
190 ///
191 ///
192 /// #### `hexpand`
193 /// Whether to expand horizontally.
194 ///
195 /// Readable | Writable
196 ///
197 ///
198 /// #### `hexpand-set`
199 /// Whether to use the `hexpand` property.
200 ///
201 /// Readable | Writable
202 ///
203 ///
204 /// #### `layout-manager`
205 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
206 /// the preferred size of the widget, and allocate its children.
207 ///
208 /// This property is meant to be set by widget implementations,
209 /// typically in their instance init function.
210 ///
211 /// Readable | Writable
212 ///
213 ///
214 /// #### `limit-events`
215 /// Makes this widget act like a modal dialog, with respect to
216 /// event delivery.
217 ///
218 /// Global event controllers will not handle events with targets
219 /// inside the widget, unless they are set up to ignore propagation
220 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
221 ///
222 /// Readable | Writable
223 ///
224 ///
225 /// #### `margin-bottom`
226 /// Margin on bottom side of widget.
227 ///
228 /// This property adds margin outside of the widget's normal size
229 /// request, the margin will be added in addition to the size from
230 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
231 ///
232 /// Readable | Writable
233 ///
234 ///
235 /// #### `margin-end`
236 /// Margin on end of widget, horizontally.
237 ///
238 /// This property supports left-to-right and right-to-left text
239 /// directions.
240 ///
241 /// This property adds margin outside of the widget's normal size
242 /// request, the margin will be added in addition to the size from
243 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
244 ///
245 /// Readable | Writable
246 ///
247 ///
248 /// #### `margin-start`
249 /// Margin on start of widget, horizontally.
250 ///
251 /// This property supports left-to-right and right-to-left text
252 /// directions.
253 ///
254 /// This property adds margin outside of the widget's normal size
255 /// request, the margin will be added in addition to the size from
256 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
257 ///
258 /// Readable | Writable
259 ///
260 ///
261 /// #### `margin-top`
262 /// Margin on top side of widget.
263 ///
264 /// This property adds margin outside of the widget's normal size
265 /// request, the margin will be added in addition to the size from
266 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
267 ///
268 /// Readable | Writable
269 ///
270 ///
271 /// #### `name`
272 /// The name of the widget.
273 ///
274 /// Readable | Writable
275 ///
276 ///
277 /// #### `opacity`
278 /// The requested opacity of the widget.
279 ///
280 /// Readable | Writable
281 ///
282 ///
283 /// #### `overflow`
284 /// How content outside the widget's content area is treated.
285 ///
286 /// This property is meant to be set by widget implementations,
287 /// typically in their instance init function.
288 ///
289 /// Readable | Writable
290 ///
291 ///
292 /// #### `parent`
293 /// The parent widget of this widget.
294 ///
295 /// Readable
296 ///
297 ///
298 /// #### `receives-default`
299 /// Whether the widget will receive the default action when it is focused.
300 ///
301 /// Readable | Writable
302 ///
303 ///
304 /// #### `root`
305 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
306 ///
307 /// This will be `NULL` if the widget is not contained in a root widget.
308 ///
309 /// Readable
310 ///
311 ///
312 /// #### `scale-factor`
313 /// The scale factor of the widget.
314 ///
315 /// Readable
316 ///
317 ///
318 /// #### `sensitive`
319 /// Whether the widget responds to input.
320 ///
321 /// Readable | Writable
322 ///
323 ///
324 /// #### `tooltip-markup`
325 /// Sets the text of tooltip to be the given string, which is marked up
326 /// with Pango markup.
327 ///
328 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
329 ///
330 /// This is a convenience property which will take care of getting the
331 /// tooltip shown if the given string is not `NULL`:
332 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
333 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
334 /// the default signal handler.
335 ///
336 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
337 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
338 ///
339 /// Readable | Writable
340 ///
341 ///
342 /// #### `tooltip-text`
343 /// Sets the text of tooltip to be the given string.
344 ///
345 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
346 ///
347 /// This is a convenience property which will take care of getting the
348 /// tooltip shown if the given string is not `NULL`:
349 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
350 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
351 /// the default signal handler.
352 ///
353 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
354 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
355 ///
356 /// Readable | Writable
357 ///
358 ///
359 /// #### `valign`
360 /// How to distribute vertical space if widget gets extra space.
361 ///
362 /// Readable | Writable
363 ///
364 ///
365 /// #### `vexpand`
366 /// Whether to expand vertically.
367 ///
368 /// Readable | Writable
369 ///
370 ///
371 /// #### `vexpand-set`
372 /// Whether to use the `vexpand` property.
373 ///
374 /// Readable | Writable
375 ///
376 ///
377 /// #### `visible`
378 /// Whether the widget is visible.
379 ///
380 /// Readable | Writable
381 ///
382 ///
383 /// #### `width-request`
384 /// Overrides for width request of the widget.
385 ///
386 /// If this is -1, the natural request will be used.
387 ///
388 /// Readable | Writable
389 /// </details>
390 /// <details><summary><h4>Accessible</h4></summary>
391 ///
392 ///
393 /// #### `accessible-role`
394 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
395 ///
396 /// The accessible role cannot be changed once set.
397 ///
398 /// Readable | Writable
399 /// </details>
400 /// <details><summary><h4>Actionable</h4></summary>
401 ///
402 ///
403 /// #### `action-name`
404 /// The name of the action with which this widget should be associated.
405 ///
406 /// Readable | Writable
407 ///
408 ///
409 /// #### `action-target`
410 /// The target value of the actionable widget's action.
411 ///
412 /// Readable | Writable
413 /// </details>
414 ///
415 /// ## Signals
416 ///
417 ///
418 /// #### `activate`
419 /// keys.
420 ///
421 /// Action
422 ///
423 ///
424 /// #### `clicked`
425 /// Emitted when the button has been activated (pressed and released).
426 ///
427 /// Action
428 /// <details><summary><h4>Widget</h4></summary>
429 ///
430 ///
431 /// #### `destroy`
432 /// Signals that all holders of a reference to the widget should release
433 /// the reference that they hold.
434 ///
435 /// May result in finalization of the widget if all references are released.
436 ///
437 /// This signal is not suitable for saving widget state.
438 ///
439 ///
440 ///
441 ///
442 /// #### `direction-changed`
443 /// Emitted when the text direction of a widget changes.
444 ///
445 ///
446 ///
447 ///
448 /// #### `hide`
449 /// Emitted when @widget is hidden.
450 ///
451 ///
452 ///
453 ///
454 /// #### `keynav-failed`
455 /// Emitted if keyboard navigation fails.
456 ///
457 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
458 ///
459 ///
460 ///
461 ///
462 /// #### `map`
463 /// Emitted when @widget is going to be mapped.
464 ///
465 /// A widget is mapped when the widget is visible (which is controlled with
466 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
467 /// are also visible.
468 ///
469 /// The `::map` signal can be used to determine whether a widget will be drawn,
470 /// for instance it can resume an animation that was stopped during the
471 /// emission of [`unmap`][struct@crate::Widget#unmap].
472 ///
473 ///
474 ///
475 ///
476 /// #### `mnemonic-activate`
477 /// Emitted when a widget is activated via a mnemonic.
478 ///
479 /// The default handler for this signal activates @widget if @group_cycling
480 /// is false, or just makes @widget grab focus if @group_cycling is true.
481 ///
482 ///
483 ///
484 ///
485 /// #### `move-focus`
486 /// to move backward.
487 ///
488 /// Action
489 ///
490 ///
491 /// #### `query-tooltip`
492 /// s tooltip is about to be shown.
493 ///
494 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
495 /// is true and the hover timeout has expired with the cursor hovering
496 /// above @widget; or emitted when @widget got focus in keyboard mode.
497 ///
498 /// Using the given coordinates, the signal handler should determine
499 /// whether a tooltip should be shown for @widget. If this is the case
500 /// true should be returned, false otherwise. Note that if @keyboard_mode
501 /// is true, the values of @x and @y are undefined and should not be used.
502 ///
503 /// The signal handler is free to manipulate @tooltip with the therefore
504 /// destined function calls.
505 ///
506 ///
507 ///
508 ///
509 /// #### `realize`
510 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
511 ///
512 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
513 /// or the widget has been mapped (that is, it is going to be drawn).
514 ///
515 ///
516 ///
517 ///
518 /// #### `show`
519 /// Emitted when @widget is shown.
520 ///
521 ///
522 ///
523 ///
524 /// #### `state-flags-changed`
525 /// Emitted when the widget state changes.
526 ///
527 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
528 ///
529 ///
530 ///
531 ///
532 /// #### `unmap`
533 /// Emitted when @widget is going to be unmapped.
534 ///
535 /// A widget is unmapped when either it or any of its parents up to the
536 /// toplevel widget have been set as hidden.
537 ///
538 /// As `::unmap` indicates that a widget will not be shown any longer,
539 /// it can be used to, for example, stop an animation on the widget.
540 ///
541 ///
542 ///
543 ///
544 /// #### `unrealize`
545 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
546 ///
547 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
548 /// or the widget has been unmapped (that is, it is going to be hidden).
549 ///
550 ///
551 /// </details>
552 ///
553 /// # Implements
554 ///
555 /// [`ButtonExt`][trait@crate::prelude::ButtonExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`ActionableExt`][trait@crate::prelude::ActionableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual], [`ActionableExtManual`][trait@crate::prelude::ActionableExtManual]
556 #[doc(alias = "GtkButton")]
557 pub struct Button(Object<ffi::GtkButton, ffi::GtkButtonClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Actionable;
558
559 match fn {
560 type_ => || ffi::gtk_button_get_type(),
561 }
562}
563
564#[cfg(not(feature = "v4_10"))]
565glib::wrapper! {
566 #[doc(alias = "GtkButton")]
567 pub struct Button(Object<ffi::GtkButton, ffi::GtkButtonClass>) @extends Widget, @implements Buildable, ConstraintTarget, Actionable;
568
569 match fn {
570 type_ => || ffi::gtk_button_get_type(),
571 }
572}
573
574impl Button {
575 pub const NONE: Option<&'static Button> = None;
576
577 /// Creates a new [`Button`][crate::Button] widget.
578 ///
579 /// To add a child widget to the button, use [`ButtonExt::set_child()`][crate::prelude::ButtonExt::set_child()].
580 ///
581 /// # Returns
582 ///
583 /// The newly created [`Button`][crate::Button] widget.
584 #[doc(alias = "gtk_button_new")]
585 pub fn new() -> Button {
586 assert_initialized_main_thread!();
587 unsafe { Widget::from_glib_none(ffi::gtk_button_new()).unsafe_cast() }
588 }
589
590 /// icon will be
591 /// displayed instead. If the current icon theme is changed, the icon
592 /// will be updated appropriately.
593 /// ## `icon_name`
594 /// an icon name
595 ///
596 /// # Returns
597 ///
598 /// a new [`Button`][crate::Button] displaying the themed icon
599 #[doc(alias = "gtk_button_new_from_icon_name")]
600 #[doc(alias = "new_from_icon_name")]
601 pub fn from_icon_name(icon_name: &str) -> Button {
602 assert_initialized_main_thread!();
603 unsafe {
604 Widget::from_glib_none(ffi::gtk_button_new_from_icon_name(
605 icon_name.to_glib_none().0,
606 ))
607 .unsafe_cast()
608 }
609 }
610
611 /// Creates a [`Button`][crate::Button] widget with a [`Label`][crate::Label] child.
612 /// ## `label`
613 /// The text you want the [`Label`][crate::Label] to hold
614 ///
615 /// # Returns
616 ///
617 /// The newly created [`Button`][crate::Button] widget
618 #[doc(alias = "gtk_button_new_with_label")]
619 #[doc(alias = "new_with_label")]
620 pub fn with_label(label: &str) -> Button {
621 assert_initialized_main_thread!();
622 unsafe {
623 Widget::from_glib_none(ffi::gtk_button_new_with_label(label.to_glib_none().0))
624 .unsafe_cast()
625 }
626 }
627
628 /// and that key
629 /// activates the button.
630 /// ## `label`
631 /// The text of the button, with an underscore in front of the
632 /// mnemonic character
633 ///
634 /// # Returns
635 ///
636 /// a new [`Button`][crate::Button]
637 #[doc(alias = "gtk_button_new_with_mnemonic")]
638 #[doc(alias = "new_with_mnemonic")]
639 pub fn with_mnemonic(label: &str) -> Button {
640 assert_initialized_main_thread!();
641 unsafe {
642 Widget::from_glib_none(ffi::gtk_button_new_with_mnemonic(label.to_glib_none().0))
643 .unsafe_cast()
644 }
645 }
646
647 // rustdoc-stripper-ignore-next
648 /// Creates a new builder-pattern struct instance to construct [`Button`] objects.
649 ///
650 /// This method returns an instance of [`ButtonBuilder`](crate::builders::ButtonBuilder) which can be used to create [`Button`] objects.
651 pub fn builder() -> ButtonBuilder {
652 ButtonBuilder::new()
653 }
654}
655
656impl Default for Button {
657 fn default() -> Self {
658 Self::new()
659 }
660}
661
662// rustdoc-stripper-ignore-next
663/// A [builder-pattern] type to construct [`Button`] objects.
664///
665/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
666#[must_use = "The builder must be built to be used"]
667pub struct ButtonBuilder {
668 builder: glib::object::ObjectBuilder<'static, Button>,
669}
670
671impl ButtonBuilder {
672 fn new() -> Self {
673 Self {
674 builder: glib::object::Object::builder(),
675 }
676 }
677
678 /// Whether the size of the button can be made smaller than the natural
679 /// size of its contents.
680 ///
681 /// For text buttons, setting this property will allow ellipsizing the label.
682 ///
683 /// If the contents of a button are an icon or a custom widget, setting this
684 /// property has no effect.
685 #[cfg(feature = "v4_12")]
686 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
687 pub fn can_shrink(self, can_shrink: bool) -> Self {
688 Self {
689 builder: self.builder.property("can-shrink", can_shrink),
690 }
691 }
692
693 /// The child widget.
694 pub fn child(self, child: &impl IsA<Widget>) -> Self {
695 Self {
696 builder: self.builder.property("child", child.clone().upcast()),
697 }
698 }
699
700 /// Whether the button has a frame.
701 pub fn has_frame(self, has_frame: bool) -> Self {
702 Self {
703 builder: self.builder.property("has-frame", has_frame),
704 }
705 }
706
707 /// The name of the icon used to automatically populate the button.
708 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
709 Self {
710 builder: self.builder.property("icon-name", icon_name.into()),
711 }
712 }
713
714 /// Text of the label inside the button, if the button contains a label widget.
715 pub fn label(self, label: impl Into<glib::GString>) -> Self {
716 Self {
717 builder: self.builder.property("label", label.into()),
718 }
719 }
720
721 /// If set, an underline in the text indicates that the following character is
722 /// to be used as mnemonic.
723 pub fn use_underline(self, use_underline: bool) -> Self {
724 Self {
725 builder: self.builder.property("use-underline", use_underline),
726 }
727 }
728
729 /// Whether the widget or any of its descendents can accept
730 /// the input focus.
731 ///
732 /// This property is meant to be set by widget implementations,
733 /// typically in their instance init function.
734 pub fn can_focus(self, can_focus: bool) -> Self {
735 Self {
736 builder: self.builder.property("can-focus", can_focus),
737 }
738 }
739
740 /// Whether the widget can receive pointer events.
741 pub fn can_target(self, can_target: bool) -> Self {
742 Self {
743 builder: self.builder.property("can-target", can_target),
744 }
745 }
746
747 /// A list of css classes applied to this widget.
748 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
749 Self {
750 builder: self.builder.property("css-classes", css_classes.into()),
751 }
752 }
753
754 /// The name of this widget in the CSS tree.
755 ///
756 /// This property is meant to be set by widget implementations,
757 /// typically in their instance init function.
758 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
759 Self {
760 builder: self.builder.property("css-name", css_name.into()),
761 }
762 }
763
764 /// The cursor used by @widget.
765 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
766 Self {
767 builder: self.builder.property("cursor", cursor.clone()),
768 }
769 }
770
771 /// Whether the widget should grab focus when it is clicked with the mouse.
772 ///
773 /// This property is only relevant for widgets that can take focus.
774 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
775 Self {
776 builder: self.builder.property("focus-on-click", focus_on_click),
777 }
778 }
779
780 /// Whether this widget itself will accept the input focus.
781 pub fn focusable(self, focusable: bool) -> Self {
782 Self {
783 builder: self.builder.property("focusable", focusable),
784 }
785 }
786
787 /// How to distribute horizontal space if widget gets extra space.
788 pub fn halign(self, halign: Align) -> Self {
789 Self {
790 builder: self.builder.property("halign", halign),
791 }
792 }
793
794 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
795 /// signal on @widget.
796 ///
797 /// A true value indicates that @widget can have a tooltip, in this case
798 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
799 /// determine whether it will provide a tooltip or not.
800 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
801 Self {
802 builder: self.builder.property("has-tooltip", has_tooltip),
803 }
804 }
805
806 /// Overrides for height request of the widget.
807 ///
808 /// If this is -1, the natural request will be used.
809 pub fn height_request(self, height_request: i32) -> Self {
810 Self {
811 builder: self.builder.property("height-request", height_request),
812 }
813 }
814
815 /// Whether to expand horizontally.
816 pub fn hexpand(self, hexpand: bool) -> Self {
817 Self {
818 builder: self.builder.property("hexpand", hexpand),
819 }
820 }
821
822 /// Whether to use the `hexpand` property.
823 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
824 Self {
825 builder: self.builder.property("hexpand-set", hexpand_set),
826 }
827 }
828
829 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
830 /// the preferred size of the widget, and allocate its children.
831 ///
832 /// This property is meant to be set by widget implementations,
833 /// typically in their instance init function.
834 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
835 Self {
836 builder: self
837 .builder
838 .property("layout-manager", layout_manager.clone().upcast()),
839 }
840 }
841
842 /// Makes this widget act like a modal dialog, with respect to
843 /// event delivery.
844 ///
845 /// Global event controllers will not handle events with targets
846 /// inside the widget, unless they are set up to ignore propagation
847 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
848 #[cfg(feature = "v4_18")]
849 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
850 pub fn limit_events(self, limit_events: bool) -> Self {
851 Self {
852 builder: self.builder.property("limit-events", limit_events),
853 }
854 }
855
856 /// Margin on bottom side of widget.
857 ///
858 /// This property adds margin outside of the widget's normal size
859 /// request, the margin will be added in addition to the size from
860 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
861 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
862 Self {
863 builder: self.builder.property("margin-bottom", margin_bottom),
864 }
865 }
866
867 /// Margin on end of widget, horizontally.
868 ///
869 /// This property supports left-to-right and right-to-left text
870 /// directions.
871 ///
872 /// This property adds margin outside of the widget's normal size
873 /// request, the margin will be added in addition to the size from
874 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
875 pub fn margin_end(self, margin_end: i32) -> Self {
876 Self {
877 builder: self.builder.property("margin-end", margin_end),
878 }
879 }
880
881 /// Margin on start of widget, horizontally.
882 ///
883 /// This property supports left-to-right and right-to-left text
884 /// directions.
885 ///
886 /// This property adds margin outside of the widget's normal size
887 /// request, the margin will be added in addition to the size from
888 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
889 pub fn margin_start(self, margin_start: i32) -> Self {
890 Self {
891 builder: self.builder.property("margin-start", margin_start),
892 }
893 }
894
895 /// Margin on top side of widget.
896 ///
897 /// This property adds margin outside of the widget's normal size
898 /// request, the margin will be added in addition to the size from
899 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
900 pub fn margin_top(self, margin_top: i32) -> Self {
901 Self {
902 builder: self.builder.property("margin-top", margin_top),
903 }
904 }
905
906 /// The name of the widget.
907 pub fn name(self, name: impl Into<glib::GString>) -> Self {
908 Self {
909 builder: self.builder.property("name", name.into()),
910 }
911 }
912
913 /// The requested opacity of the widget.
914 pub fn opacity(self, opacity: f64) -> Self {
915 Self {
916 builder: self.builder.property("opacity", opacity),
917 }
918 }
919
920 /// How content outside the widget's content area is treated.
921 ///
922 /// This property is meant to be set by widget implementations,
923 /// typically in their instance init function.
924 pub fn overflow(self, overflow: Overflow) -> Self {
925 Self {
926 builder: self.builder.property("overflow", overflow),
927 }
928 }
929
930 /// Whether the widget will receive the default action when it is focused.
931 pub fn receives_default(self, receives_default: bool) -> Self {
932 Self {
933 builder: self.builder.property("receives-default", receives_default),
934 }
935 }
936
937 /// Whether the widget responds to input.
938 pub fn sensitive(self, sensitive: bool) -> Self {
939 Self {
940 builder: self.builder.property("sensitive", sensitive),
941 }
942 }
943
944 /// Sets the text of tooltip to be the given string, which is marked up
945 /// with Pango markup.
946 ///
947 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
948 ///
949 /// This is a convenience property which will take care of getting the
950 /// tooltip shown if the given string is not `NULL`:
951 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
952 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
953 /// the default signal handler.
954 ///
955 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
956 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
957 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
958 Self {
959 builder: self
960 .builder
961 .property("tooltip-markup", tooltip_markup.into()),
962 }
963 }
964
965 /// Sets the text of tooltip to be the given string.
966 ///
967 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
968 ///
969 /// This is a convenience property which will take care of getting the
970 /// tooltip shown if the given string is not `NULL`:
971 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
972 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
973 /// the default signal handler.
974 ///
975 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
976 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
977 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
978 Self {
979 builder: self.builder.property("tooltip-text", tooltip_text.into()),
980 }
981 }
982
983 /// How to distribute vertical space if widget gets extra space.
984 pub fn valign(self, valign: Align) -> Self {
985 Self {
986 builder: self.builder.property("valign", valign),
987 }
988 }
989
990 /// Whether to expand vertically.
991 pub fn vexpand(self, vexpand: bool) -> Self {
992 Self {
993 builder: self.builder.property("vexpand", vexpand),
994 }
995 }
996
997 /// Whether to use the `vexpand` property.
998 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
999 Self {
1000 builder: self.builder.property("vexpand-set", vexpand_set),
1001 }
1002 }
1003
1004 /// Whether the widget is visible.
1005 pub fn visible(self, visible: bool) -> Self {
1006 Self {
1007 builder: self.builder.property("visible", visible),
1008 }
1009 }
1010
1011 /// Overrides for width request of the widget.
1012 ///
1013 /// If this is -1, the natural request will be used.
1014 pub fn width_request(self, width_request: i32) -> Self {
1015 Self {
1016 builder: self.builder.property("width-request", width_request),
1017 }
1018 }
1019
1020 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1021 ///
1022 /// The accessible role cannot be changed once set.
1023 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1024 Self {
1025 builder: self.builder.property("accessible-role", accessible_role),
1026 }
1027 }
1028
1029 /// The name of the action with which this widget should be associated.
1030 pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
1031 Self {
1032 builder: self.builder.property("action-name", action_name.into()),
1033 }
1034 }
1035
1036 /// The target value of the actionable widget's action.
1037 pub fn action_target(self, action_target: &glib::Variant) -> Self {
1038 Self {
1039 builder: self
1040 .builder
1041 .property("action-target", action_target.clone()),
1042 }
1043 }
1044
1045 // rustdoc-stripper-ignore-next
1046 /// Build the [`Button`].
1047 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1048 pub fn build(self) -> Button {
1049 assert_initialized_main_thread!();
1050 self.builder.build()
1051 }
1052}
1053
1054/// Trait containing all [`struct@Button`] methods.
1055///
1056/// # Implementors
1057///
1058/// [`Button`][struct@crate::Button], [`LinkButton`][struct@crate::LinkButton], [`LockButton`][struct@crate::LockButton], [`ToggleButton`][struct@crate::ToggleButton]
1059pub trait ButtonExt: IsA<Button> + 'static {
1060 /// Retrieves whether the button can be smaller than the natural
1061 /// size of its contents.
1062 ///
1063 /// # Returns
1064 ///
1065 /// true if the button can shrink, and false otherwise
1066 #[cfg(feature = "v4_12")]
1067 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1068 #[doc(alias = "gtk_button_get_can_shrink")]
1069 #[doc(alias = "get_can_shrink")]
1070 #[doc(alias = "can-shrink")]
1071 fn can_shrink(&self) -> bool {
1072 unsafe {
1073 from_glib(ffi::gtk_button_get_can_shrink(
1074 self.as_ref().to_glib_none().0,
1075 ))
1076 }
1077 }
1078
1079 /// Gets the child widget of @self.
1080 ///
1081 /// # Returns
1082 ///
1083 /// the child widget of @self
1084 #[doc(alias = "gtk_button_get_child")]
1085 #[doc(alias = "get_child")]
1086 fn child(&self) -> Option<Widget> {
1087 unsafe { from_glib_none(ffi::gtk_button_get_child(self.as_ref().to_glib_none().0)) }
1088 }
1089
1090 /// Returns whether the button has a frame.
1091 ///
1092 /// # Returns
1093 ///
1094 /// [`true`] if the button has a frame
1095 #[doc(alias = "gtk_button_get_has_frame")]
1096 #[doc(alias = "get_has_frame")]
1097 #[doc(alias = "has-frame")]
1098 fn has_frame(&self) -> bool {
1099 unsafe {
1100 from_glib(ffi::gtk_button_get_has_frame(
1101 self.as_ref().to_glib_none().0,
1102 ))
1103 }
1104 }
1105
1106 /// Returns the icon name of the button.
1107 ///
1108 /// If the icon name has not been set with [`set_icon_name()`][Self::set_icon_name()]
1109 /// the return value will be [`None`]. This will be the case if you create
1110 /// an empty button with [`Button::new()`][crate::Button::new()] to use as a container.
1111 ///
1112 /// # Returns
1113 ///
1114 /// The icon name set via [`set_icon_name()`][Self::set_icon_name()]
1115 #[doc(alias = "gtk_button_get_icon_name")]
1116 #[doc(alias = "get_icon_name")]
1117 #[doc(alias = "icon-name")]
1118 fn icon_name(&self) -> Option<glib::GString> {
1119 unsafe {
1120 from_glib_none(ffi::gtk_button_get_icon_name(
1121 self.as_ref().to_glib_none().0,
1122 ))
1123 }
1124 }
1125
1126 /// Fetches the text from the label of the button.
1127 ///
1128 /// If the label text has not been set with [`set_label()`][Self::set_label()]
1129 /// the return value will be [`None`]. This will be the case if you create
1130 /// an empty button with [`Button::new()`][crate::Button::new()] to use as a container.
1131 ///
1132 /// # Returns
1133 ///
1134 /// The text of the label widget. This string is owned
1135 /// by the widget and must not be modified or freed.
1136 #[doc(alias = "gtk_button_get_label")]
1137 #[doc(alias = "get_label")]
1138 fn label(&self) -> Option<glib::GString> {
1139 unsafe { from_glib_none(ffi::gtk_button_get_label(self.as_ref().to_glib_none().0)) }
1140 }
1141
1142 /// gets whether underlines are interpreted as mnemonics.
1143 ///
1144 /// See [`set_use_underline()`][Self::set_use_underline()].
1145 ///
1146 /// # Returns
1147 ///
1148 /// [`true`] if an embedded underline in the button label
1149 /// indicates the mnemonic accelerator keys.
1150 #[doc(alias = "gtk_button_get_use_underline")]
1151 #[doc(alias = "get_use_underline")]
1152 #[doc(alias = "use-underline")]
1153 fn uses_underline(&self) -> bool {
1154 unsafe {
1155 from_glib(ffi::gtk_button_get_use_underline(
1156 self.as_ref().to_glib_none().0,
1157 ))
1158 }
1159 }
1160
1161 /// Sets whether the button size can be smaller than the natural size of
1162 /// its contents.
1163 ///
1164 /// For text buttons, setting @can_shrink to true will ellipsize the label.
1165 ///
1166 /// For icons and custom children, this function has no effect.
1167 /// ## `can_shrink`
1168 /// whether the button can shrink
1169 #[cfg(feature = "v4_12")]
1170 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1171 #[doc(alias = "gtk_button_set_can_shrink")]
1172 #[doc(alias = "can-shrink")]
1173 fn set_can_shrink(&self, can_shrink: bool) {
1174 unsafe {
1175 ffi::gtk_button_set_can_shrink(self.as_ref().to_glib_none().0, can_shrink.into_glib());
1176 }
1177 }
1178
1179 /// Sets the child widget of @self.
1180 ///
1181 /// Note that by using this API, you take full responsibility for setting
1182 /// up the proper accessibility label and description information for @self.
1183 /// Most likely, you'll either set the accessibility label or description
1184 /// for @self explicitly, or you'll set a labelled-by or described-by
1185 /// relations from @child to @self.
1186 /// ## `child`
1187 /// the child widget
1188 #[doc(alias = "gtk_button_set_child")]
1189 #[doc(alias = "child")]
1190 fn set_child(&self, child: Option<&impl IsA<Widget>>) {
1191 unsafe {
1192 ffi::gtk_button_set_child(
1193 self.as_ref().to_glib_none().0,
1194 child.map(|p| p.as_ref()).to_glib_none().0,
1195 );
1196 }
1197 }
1198
1199 /// Sets the style of the button.
1200 ///
1201 /// Buttons can have a flat appearance or have a frame drawn around them.
1202 /// ## `has_frame`
1203 /// whether the button should have a visible frame
1204 #[doc(alias = "gtk_button_set_has_frame")]
1205 #[doc(alias = "has-frame")]
1206 fn set_has_frame(&self, has_frame: bool) {
1207 unsafe {
1208 ffi::gtk_button_set_has_frame(self.as_ref().to_glib_none().0, has_frame.into_glib());
1209 }
1210 }
1211
1212 /// Adds a [`Image`][crate::Image] with the given icon name as a child.
1213 ///
1214 /// If @self already contains a child widget, that child widget will
1215 /// be removed and replaced with the image.
1216 /// ## `icon_name`
1217 /// An icon name
1218 #[doc(alias = "gtk_button_set_icon_name")]
1219 #[doc(alias = "icon-name")]
1220 fn set_icon_name(&self, icon_name: &str) {
1221 unsafe {
1222 ffi::gtk_button_set_icon_name(
1223 self.as_ref().to_glib_none().0,
1224 icon_name.to_glib_none().0,
1225 );
1226 }
1227 }
1228
1229 /// Sets the text of the label of the button to @label.
1230 ///
1231 /// This will also clear any previously set labels.
1232 /// ## `label`
1233 /// a string
1234 #[doc(alias = "gtk_button_set_label")]
1235 #[doc(alias = "label")]
1236 fn set_label(&self, label: &str) {
1237 unsafe {
1238 ffi::gtk_button_set_label(self.as_ref().to_glib_none().0, label.to_glib_none().0);
1239 }
1240 }
1241
1242 /// Sets whether to use underlines as mnemonics.
1243 ///
1244 /// If true, an underline in the text of the button label indicates
1245 /// the next character should be used for the mnemonic accelerator key.
1246 /// ## `use_underline`
1247 /// [`true`] if underlines in the text indicate mnemonics
1248 #[doc(alias = "gtk_button_set_use_underline")]
1249 #[doc(alias = "use-underline")]
1250 fn set_use_underline(&self, use_underline: bool) {
1251 unsafe {
1252 ffi::gtk_button_set_use_underline(
1253 self.as_ref().to_glib_none().0,
1254 use_underline.into_glib(),
1255 );
1256 }
1257 }
1258
1259 /// keys.
1260 #[doc(alias = "activate")]
1261 fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1262 unsafe extern "C" fn activate_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
1263 this: *mut ffi::GtkButton,
1264 f: glib::ffi::gpointer,
1265 ) {
1266 unsafe {
1267 let f: &F = &*(f as *const F);
1268 f(Button::from_glib_borrow(this).unsafe_cast_ref())
1269 }
1270 }
1271 unsafe {
1272 let f: Box_<F> = Box_::new(f);
1273 connect_raw(
1274 self.as_ptr() as *mut _,
1275 c"activate".as_ptr(),
1276 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1277 activate_trampoline::<Self, F> as *const (),
1278 )),
1279 Box_::into_raw(f),
1280 )
1281 }
1282 }
1283
1284 fn emit_activate(&self) {
1285 self.emit_by_name::<()>("activate", &[]);
1286 }
1287
1288 /// Emitted when the button has been activated (pressed and released).
1289 #[doc(alias = "clicked")]
1290 fn connect_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1291 unsafe extern "C" fn clicked_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
1292 this: *mut ffi::GtkButton,
1293 f: glib::ffi::gpointer,
1294 ) {
1295 unsafe {
1296 let f: &F = &*(f as *const F);
1297 f(Button::from_glib_borrow(this).unsafe_cast_ref())
1298 }
1299 }
1300 unsafe {
1301 let f: Box_<F> = Box_::new(f);
1302 connect_raw(
1303 self.as_ptr() as *mut _,
1304 c"clicked".as_ptr(),
1305 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1306 clicked_trampoline::<Self, F> as *const (),
1307 )),
1308 Box_::into_raw(f),
1309 )
1310 }
1311 }
1312
1313 fn emit_clicked(&self) {
1314 self.emit_by_name::<()>("clicked", &[]);
1315 }
1316
1317 #[cfg(feature = "v4_12")]
1318 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
1319 #[doc(alias = "can-shrink")]
1320 fn connect_can_shrink_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1321 unsafe extern "C" fn notify_can_shrink_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
1322 this: *mut ffi::GtkButton,
1323 _param_spec: glib::ffi::gpointer,
1324 f: glib::ffi::gpointer,
1325 ) {
1326 unsafe {
1327 let f: &F = &*(f as *const F);
1328 f(Button::from_glib_borrow(this).unsafe_cast_ref())
1329 }
1330 }
1331 unsafe {
1332 let f: Box_<F> = Box_::new(f);
1333 connect_raw(
1334 self.as_ptr() as *mut _,
1335 c"notify::can-shrink".as_ptr(),
1336 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1337 notify_can_shrink_trampoline::<Self, F> as *const (),
1338 )),
1339 Box_::into_raw(f),
1340 )
1341 }
1342 }
1343
1344 #[doc(alias = "child")]
1345 fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1346 unsafe extern "C" fn notify_child_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
1347 this: *mut ffi::GtkButton,
1348 _param_spec: glib::ffi::gpointer,
1349 f: glib::ffi::gpointer,
1350 ) {
1351 unsafe {
1352 let f: &F = &*(f as *const F);
1353 f(Button::from_glib_borrow(this).unsafe_cast_ref())
1354 }
1355 }
1356 unsafe {
1357 let f: Box_<F> = Box_::new(f);
1358 connect_raw(
1359 self.as_ptr() as *mut _,
1360 c"notify::child".as_ptr(),
1361 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1362 notify_child_trampoline::<Self, F> as *const (),
1363 )),
1364 Box_::into_raw(f),
1365 )
1366 }
1367 }
1368
1369 #[doc(alias = "has-frame")]
1370 fn connect_has_frame_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1371 unsafe extern "C" fn notify_has_frame_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
1372 this: *mut ffi::GtkButton,
1373 _param_spec: glib::ffi::gpointer,
1374 f: glib::ffi::gpointer,
1375 ) {
1376 unsafe {
1377 let f: &F = &*(f as *const F);
1378 f(Button::from_glib_borrow(this).unsafe_cast_ref())
1379 }
1380 }
1381 unsafe {
1382 let f: Box_<F> = Box_::new(f);
1383 connect_raw(
1384 self.as_ptr() as *mut _,
1385 c"notify::has-frame".as_ptr(),
1386 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1387 notify_has_frame_trampoline::<Self, F> as *const (),
1388 )),
1389 Box_::into_raw(f),
1390 )
1391 }
1392 }
1393
1394 #[doc(alias = "icon-name")]
1395 fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1396 unsafe extern "C" fn notify_icon_name_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
1397 this: *mut ffi::GtkButton,
1398 _param_spec: glib::ffi::gpointer,
1399 f: glib::ffi::gpointer,
1400 ) {
1401 unsafe {
1402 let f: &F = &*(f as *const F);
1403 f(Button::from_glib_borrow(this).unsafe_cast_ref())
1404 }
1405 }
1406 unsafe {
1407 let f: Box_<F> = Box_::new(f);
1408 connect_raw(
1409 self.as_ptr() as *mut _,
1410 c"notify::icon-name".as_ptr(),
1411 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1412 notify_icon_name_trampoline::<Self, F> as *const (),
1413 )),
1414 Box_::into_raw(f),
1415 )
1416 }
1417 }
1418
1419 #[doc(alias = "label")]
1420 fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1421 unsafe extern "C" fn notify_label_trampoline<P: IsA<Button>, F: Fn(&P) + 'static>(
1422 this: *mut ffi::GtkButton,
1423 _param_spec: glib::ffi::gpointer,
1424 f: glib::ffi::gpointer,
1425 ) {
1426 unsafe {
1427 let f: &F = &*(f as *const F);
1428 f(Button::from_glib_borrow(this).unsafe_cast_ref())
1429 }
1430 }
1431 unsafe {
1432 let f: Box_<F> = Box_::new(f);
1433 connect_raw(
1434 self.as_ptr() as *mut _,
1435 c"notify::label".as_ptr(),
1436 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1437 notify_label_trampoline::<Self, F> as *const (),
1438 )),
1439 Box_::into_raw(f),
1440 )
1441 }
1442 }
1443
1444 #[doc(alias = "use-underline")]
1445 fn connect_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1446 unsafe extern "C" fn notify_use_underline_trampoline<
1447 P: IsA<Button>,
1448 F: Fn(&P) + 'static,
1449 >(
1450 this: *mut ffi::GtkButton,
1451 _param_spec: glib::ffi::gpointer,
1452 f: glib::ffi::gpointer,
1453 ) {
1454 unsafe {
1455 let f: &F = &*(f as *const F);
1456 f(Button::from_glib_borrow(this).unsafe_cast_ref())
1457 }
1458 }
1459 unsafe {
1460 let f: Box_<F> = Box_::new(f);
1461 connect_raw(
1462 self.as_ptr() as *mut _,
1463 c"notify::use-underline".as_ptr(),
1464 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1465 notify_use_underline_trampoline::<Self, F> as *const (),
1466 )),
1467 Box_::into_raw(f),
1468 )
1469 }
1470 }
1471}
1472
1473impl<O: IsA<Button>> ButtonExt for O {}