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