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