gtk/auto/toggle_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 Actionable, Align, Bin, Buildable, Button, Container, PositionType, ReliefStyle, ResizeMode,
7 Widget, ffi,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{SignalHandlerId, connect_raw},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 ///
19 /// static void output_state (GtkToggleButton *source, gpointer user_data) {
20 /// printf ("Active: `d`\n", gtk_toggle_button_get_active (source));
21 /// }
22 ///
23 /// void make_toggles (void) {
24 /// GtkWidget *window, *toggle1, *toggle2;
25 /// GtkWidget *box;
26 /// const char *text;
27 ///
28 /// window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
29 /// box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
30 ///
31 /// text = "Hi, I’m a toggle button.";
32 /// toggle1 = gtk_toggle_button_new_with_label (text);
33 ///
34 /// // Makes this toggle button invisible
35 /// gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle1),
36 /// TRUE);
37 ///
38 /// g_signal_connect (toggle1, "toggled",
39 /// G_CALLBACK (output_state),
40 /// NULL);
41 /// gtk_container_add (GTK_CONTAINER (box), toggle1);
42 ///
43 /// text = "Hi, I’m a toggle button.";
44 /// toggle2 = gtk_toggle_button_new_with_label (text);
45 /// gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle2),
46 /// FALSE);
47 /// g_signal_connect (toggle2, "toggled",
48 /// G_CALLBACK (output_state),
49 /// NULL);
50 /// gtk_container_add (GTK_CONTAINER (box), toggle2);
51 ///
52 /// gtk_container_add (GTK_CONTAINER (window), box);
53 /// gtk_widget_show_all (window);
54 /// }
55 /// ]|
56 ///
57 /// ## Properties
58 ///
59 ///
60 /// #### `active`
61 /// Readable | Writable
62 ///
63 ///
64 /// #### `draw-indicator`
65 /// Readable | Writable
66 ///
67 ///
68 /// #### `inconsistent`
69 /// Readable | Writable
70 /// <details><summary><h4>Button</h4></summary>
71 ///
72 ///
73 /// #### `always-show-image`
74 /// If [`true`], the button will ignore the [`gtk-button-images`][struct@crate::Settings#gtk-button-images]
75 /// setting and always show the image, if available.
76 ///
77 /// Use this property if the button would be useless or hard to use
78 /// without the image.
79 ///
80 /// Readable | Writable | Construct
81 ///
82 ///
83 /// #### `image`
84 /// The child widget to appear next to the button text.
85 ///
86 /// Readable | Writable
87 ///
88 ///
89 /// #### `image-position`
90 /// The position of the image relative to the text inside the button.
91 ///
92 /// Readable | Writable
93 ///
94 ///
95 /// #### `label`
96 /// Readable | Writable | Construct
97 ///
98 ///
99 /// #### `relief`
100 /// Readable | Writable
101 ///
102 ///
103 /// #### `use-stock`
104 /// Readable | Writable | Construct
105 ///
106 ///
107 /// #### `use-underline`
108 /// Readable | Writable | Construct
109 ///
110 ///
111 /// #### `xalign`
112 /// If the child of the button is a [`Misc`][crate::Misc] or `GtkAlignment`, this property
113 /// can be used to control its horizontal alignment. 0.0 is left aligned,
114 /// 1.0 is right aligned.
115 ///
116 /// Readable | Writable
117 ///
118 ///
119 /// #### `yalign`
120 /// If the child of the button is a [`Misc`][crate::Misc] or `GtkAlignment`, this property
121 /// can be used to control its vertical alignment. 0.0 is top aligned,
122 /// 1.0 is bottom aligned.
123 ///
124 /// Readable | Writable
125 /// </details>
126 /// <details><summary><h4>Container</h4></summary>
127 ///
128 ///
129 /// #### `border-width`
130 /// Readable | Writable
131 ///
132 ///
133 /// #### `child`
134 /// Writable
135 ///
136 ///
137 /// #### `resize-mode`
138 /// Readable | Writable
139 /// </details>
140 /// <details><summary><h4>Widget</h4></summary>
141 ///
142 ///
143 /// #### `app-paintable`
144 /// Readable | Writable
145 ///
146 ///
147 /// #### `can-default`
148 /// Readable | Writable
149 ///
150 ///
151 /// #### `can-focus`
152 /// Readable | Writable
153 ///
154 ///
155 /// #### `composite-child`
156 /// Readable
157 ///
158 ///
159 /// #### `double-buffered`
160 /// Whether the widget is double buffered.
161 ///
162 /// Readable | Writable
163 ///
164 ///
165 /// #### `events`
166 /// Readable | Writable
167 ///
168 ///
169 /// #### `expand`
170 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
171 ///
172 /// Readable | Writable
173 ///
174 ///
175 /// #### `focus-on-click`
176 /// Whether the widget should grab focus when it is clicked with the mouse.
177 ///
178 /// This property is only relevant for widgets that can take focus.
179 ///
180 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
181 /// GtkComboBox) implemented this property individually.
182 ///
183 /// Readable | Writable
184 ///
185 ///
186 /// #### `halign`
187 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
188 ///
189 /// Readable | Writable
190 ///
191 ///
192 /// #### `has-default`
193 /// Readable | Writable
194 ///
195 ///
196 /// #### `has-focus`
197 /// Readable | Writable
198 ///
199 ///
200 /// #### `has-tooltip`
201 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
202 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
203 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
204 /// whether it will provide a tooltip or not.
205 ///
206 /// Note that setting this property to [`true`] for the first time will change
207 /// the event masks of the GdkWindows of this widget to include leave-notify
208 /// and motion-notify events. This cannot and will not be undone when the
209 /// property is set to [`false`] again.
210 ///
211 /// Readable | Writable
212 ///
213 ///
214 /// #### `height-request`
215 /// Readable | Writable
216 ///
217 ///
218 /// #### `hexpand`
219 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
220 ///
221 /// Readable | Writable
222 ///
223 ///
224 /// #### `hexpand-set`
225 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
226 ///
227 /// Readable | Writable
228 ///
229 ///
230 /// #### `is-focus`
231 /// Readable | Writable
232 ///
233 ///
234 /// #### `margin`
235 /// Sets all four sides' margin at once. If read, returns max
236 /// margin on any side.
237 ///
238 /// Readable | Writable
239 ///
240 ///
241 /// #### `margin-bottom`
242 /// Margin on bottom side of widget.
243 ///
244 /// This property adds margin outside of the widget's normal size
245 /// request, the margin will be added in addition to the size from
246 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
247 ///
248 /// Readable | Writable
249 ///
250 ///
251 /// #### `margin-end`
252 /// Margin on end of widget, horizontally. This property supports
253 /// left-to-right and right-to-left text directions.
254 ///
255 /// This property adds margin outside of the widget's normal size
256 /// request, the margin will be added in addition to the size from
257 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
258 ///
259 /// Readable | Writable
260 ///
261 ///
262 /// #### `margin-left`
263 /// Margin on left side of widget.
264 ///
265 /// This property adds margin outside of the widget's normal size
266 /// request, the margin will be added in addition to the size from
267 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
268 ///
269 /// Readable | Writable
270 ///
271 ///
272 /// #### `margin-right`
273 /// Margin on right side of widget.
274 ///
275 /// This property adds margin outside of the widget's normal size
276 /// request, the margin will be added in addition to the size from
277 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
278 ///
279 /// Readable | Writable
280 ///
281 ///
282 /// #### `margin-start`
283 /// Margin on start of widget, horizontally. This property supports
284 /// left-to-right and right-to-left text directions.
285 ///
286 /// This property adds margin outside of the widget's normal size
287 /// request, the margin will be added in addition to the size from
288 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
289 ///
290 /// Readable | Writable
291 ///
292 ///
293 /// #### `margin-top`
294 /// Margin on top side of widget.
295 ///
296 /// This property adds margin outside of the widget's normal size
297 /// request, the margin will be added in addition to the size from
298 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
299 ///
300 /// Readable | Writable
301 ///
302 ///
303 /// #### `name`
304 /// Readable | Writable
305 ///
306 ///
307 /// #### `no-show-all`
308 /// Readable | Writable
309 ///
310 ///
311 /// #### `opacity`
312 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
313 /// more details about window opacity.
314 ///
315 /// Before 3.8 this was only available in GtkWindow
316 ///
317 /// Readable | Writable
318 ///
319 ///
320 /// #### `parent`
321 /// Readable | Writable
322 ///
323 ///
324 /// #### `receives-default`
325 /// Readable | Writable
326 ///
327 ///
328 /// #### `scale-factor`
329 /// The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
330 /// more details about widget scaling.
331 ///
332 /// Readable
333 ///
334 ///
335 /// #### `sensitive`
336 /// Readable | Writable
337 ///
338 ///
339 /// #### `style`
340 /// The style of the widget, which contains information about how it will look (colors, etc).
341 ///
342 /// Readable | Writable
343 ///
344 ///
345 /// #### `tooltip-markup`
346 /// Sets the text of tooltip to be the given string, which is marked up
347 /// with the [Pango text markup language][PangoMarkupFormat].
348 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
349 ///
350 /// This is a convenience property which will take care of getting the
351 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
352 /// will automatically be set to [`true`] and there will be taken care of
353 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
354 ///
355 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
356 /// are set, the last one wins.
357 ///
358 /// Readable | Writable
359 ///
360 ///
361 /// #### `tooltip-text`
362 /// Sets the text of tooltip to be the given string.
363 ///
364 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
365 ///
366 /// This is a convenience property which will take care of getting the
367 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
368 /// will automatically be set to [`true`] and there will be taken care of
369 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
370 ///
371 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
372 /// are set, the last one wins.
373 ///
374 /// Readable | Writable
375 ///
376 ///
377 /// #### `valign`
378 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
379 ///
380 /// Readable | Writable
381 ///
382 ///
383 /// #### `vexpand`
384 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
385 ///
386 /// Readable | Writable
387 ///
388 ///
389 /// #### `vexpand-set`
390 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
391 ///
392 /// Readable | Writable
393 ///
394 ///
395 /// #### `visible`
396 /// Readable | Writable
397 ///
398 ///
399 /// #### `width-request`
400 /// Readable | Writable
401 ///
402 ///
403 /// #### `window`
404 /// The widget's window if it is realized, [`None`] otherwise.
405 ///
406 /// Readable
407 /// </details>
408 /// <details><summary><h4>Actionable</h4></summary>
409 ///
410 ///
411 /// #### `action-name`
412 /// Readable | Writable
413 ///
414 ///
415 /// #### `action-target`
416 /// Readable | Writable
417 /// </details>
418 /// <details><summary><h4>Activatable</h4></summary>
419 ///
420 ///
421 /// #### `related-action`
422 /// call `gtk_activatable_do_set_related_action()` when it changes.
423 ///
424 /// Readable | Writable
425 ///
426 ///
427 /// #### `use-action-appearance`
428 /// widget when it changes.
429 ///
430 /// Readable | Writable
431 /// </details>
432 ///
433 /// ## Signals
434 ///
435 ///
436 /// #### `toggled`
437 /// Should be connected if you wish to perform an action whenever the
438 /// [`ToggleButton`][crate::ToggleButton]'s state is changed.
439 ///
440 ///
441 /// <details><summary><h4>Button</h4></summary>
442 ///
443 ///
444 /// #### `activate`
445 /// The ::activate signal on GtkButton is an action signal and
446 /// emitting it causes the button to animate press then release.
447 /// Applications should never connect to this signal, but use the
448 /// [`clicked`][struct@crate::Button#clicked] signal.
449 ///
450 /// Action
451 ///
452 ///
453 /// #### `clicked`
454 /// Emitted when the button has been activated (pressed and released).
455 ///
456 /// Action
457 ///
458 ///
459 /// #### `enter`
460 /// Emitted when the pointer enters the button.
461 ///
462 ///
463 ///
464 ///
465 /// #### `leave`
466 /// Emitted when the pointer leaves the button.
467 ///
468 ///
469 ///
470 ///
471 /// #### `pressed`
472 /// Emitted when the button is pressed.
473 ///
474 ///
475 ///
476 ///
477 /// #### `released`
478 /// Emitted when the button is released.
479 ///
480 ///
481 /// </details>
482 /// <details><summary><h4>Container</h4></summary>
483 ///
484 ///
485 /// #### `add`
486 ///
487 ///
488 ///
489 /// #### `check-resize`
490 ///
491 ///
492 ///
493 /// #### `remove`
494 ///
495 ///
496 ///
497 /// #### `set-focus-child`
498 ///
499 /// </details>
500 /// <details><summary><h4>Widget</h4></summary>
501 ///
502 ///
503 /// #### `accel-closures-changed`
504 ///
505 ///
506 ///
507 /// #### `button-press-event`
508 /// The ::button-press-event signal will be emitted when a button
509 /// (typically from a mouse) is pressed.
510 ///
511 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the
512 /// widget needs to enable the [`gdk::EventMask::BUTTON_PRESS_MASK`][crate::gdk::EventMask::BUTTON_PRESS_MASK] mask.
513 ///
514 /// This signal will be sent to the grab widget if there is one.
515 ///
516 ///
517 ///
518 ///
519 /// #### `button-release-event`
520 /// The ::button-release-event signal will be emitted when a button
521 /// (typically from a mouse) is released.
522 ///
523 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the
524 /// widget needs to enable the [`gdk::EventMask::BUTTON_RELEASE_MASK`][crate::gdk::EventMask::BUTTON_RELEASE_MASK] mask.
525 ///
526 /// This signal will be sent to the grab widget if there is one.
527 ///
528 ///
529 ///
530 ///
531 /// #### `can-activate-accel`
532 /// Determines whether an accelerator that activates the signal
533 /// identified by `signal_id` can currently be activated.
534 /// This signal is present to allow applications and derived
535 /// widgets to override the default [`Widget`][crate::Widget] handling
536 /// for determining whether an accelerator can be activated.
537 ///
538 ///
539 ///
540 ///
541 /// #### `child-notify`
542 /// The ::child-notify signal is emitted for each
543 /// [child property][child-properties] that has
544 /// changed on an object. The signal's detail holds the property name.
545 ///
546 /// Detailed
547 ///
548 ///
549 /// #### `composited-changed`
550 /// The ::composited-changed signal is emitted when the composited
551 /// status of `widgets` screen changes.
552 /// See [`Screen::is_composited()`][crate::gdk::Screen::is_composited()].
553 ///
554 /// Action
555 ///
556 ///
557 /// #### `configure-event`
558 /// The ::configure-event signal will be emitted when the size, position or
559 /// stacking of the `widget`'s window has changed.
560 ///
561 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
562 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
563 /// automatically for all new windows.
564 ///
565 ///
566 ///
567 ///
568 /// #### `damage-event`
569 /// Emitted when a redirected window belonging to `widget` gets drawn into.
570 /// The region/area members of the event shows what area of the redirected
571 /// drawable was drawn into.
572 ///
573 ///
574 ///
575 ///
576 /// #### `delete-event`
577 /// The ::delete-event signal is emitted if a user requests that
578 /// a toplevel window is closed. The default handler for this signal
579 /// destroys the window. Connecting [`WidgetExtManual::hide_on_delete()`][crate::prelude::WidgetExtManual::hide_on_delete()] to
580 /// this signal will cause the window to be hidden instead, so that
581 /// it can later be shown again without reconstructing it.
582 ///
583 ///
584 ///
585 ///
586 /// #### `destroy`
587 /// Signals that all holders of a reference to the widget should release
588 /// the reference that they hold. May result in finalization of the widget
589 /// if all references are released.
590 ///
591 /// This signal is not suitable for saving widget state.
592 ///
593 ///
594 ///
595 ///
596 /// #### `destroy-event`
597 /// The ::destroy-event signal is emitted when a [`gdk::Window`][crate::gdk::Window] is destroyed.
598 /// You rarely get this signal, because most widgets disconnect themselves
599 /// from their window before they destroy it, so no widget owns the
600 /// window at destroy time.
601 ///
602 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
603 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
604 /// automatically for all new windows.
605 ///
606 ///
607 ///
608 ///
609 /// #### `direction-changed`
610 /// The ::direction-changed signal is emitted when the text direction
611 /// of a widget changes.
612 ///
613 ///
614 ///
615 ///
616 /// #### `drag-begin`
617 /// The ::drag-begin signal is emitted on the drag source when a drag is
618 /// started. A typical reason to connect to this signal is to set up a
619 /// custom drag icon with e.g. [`WidgetExt::drag_source_set_icon_pixbuf()`][crate::prelude::WidgetExt::drag_source_set_icon_pixbuf()].
620 ///
621 /// Note that some widgets set up a drag icon in the default handler of
622 /// this signal, so you may have to use `g_signal_connect_after()` to
623 /// override what the default handler did.
624 ///
625 ///
626 ///
627 ///
628 /// #### `drag-data-delete`
629 /// The ::drag-data-delete signal is emitted on the drag source when a drag
630 /// with the action [`gdk::DragAction::MOVE`][crate::gdk::DragAction::MOVE] is successfully completed. The signal
631 /// handler is responsible for deleting the data that has been dropped. What
632 /// "delete" means depends on the context of the drag operation.
633 ///
634 ///
635 ///
636 ///
637 /// #### `drag-data-get`
638 /// The ::drag-data-get signal is emitted on the drag source when the drop
639 /// site requests the data which is dragged. It is the responsibility of
640 /// the signal handler to fill `data` with the data in the format which
641 /// is indicated by `info`. See [`SelectionData::set()`][crate::SelectionData::set()] and
642 /// [`SelectionData::set_text()`][crate::SelectionData::set_text()].
643 ///
644 ///
645 ///
646 ///
647 /// #### `drag-data-received`
648 /// format == 8))
649 /// {
650 /// GdkDragAction action;
651 ///
652 /// // handle data here
653 ///
654 /// action = gdk_drag_context_get_selected_action (context);
655 /// if (action == GDK_ACTION_ASK)
656 /// {
657 /// GtkWidget *dialog;
658 /// gint response;
659 ///
660 /// dialog = gtk_message_dialog_new (NULL,
661 /// GTK_DIALOG_MODAL |
662 /// GTK_DIALOG_DESTROY_WITH_PARENT,
663 /// GTK_MESSAGE_INFO,
664 /// GTK_BUTTONS_YES_NO,
665 /// "Move the data ?\n");
666 /// response = gtk_dialog_run (GTK_DIALOG (dialog));
667 /// gtk_widget_destroy (dialog);
668 ///
669 /// if (response == GTK_RESPONSE_YES)
670 /// action = GDK_ACTION_MOVE;
671 /// else
672 /// action = GDK_ACTION_COPY;
673 /// }
674 ///
675 /// gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
676 /// }
677 /// else
678 /// gtk_drag_finish (context, FALSE, FALSE, time);
679 /// }
680 /// ]|
681 ///
682 ///
683 ///
684 ///
685 /// #### `drag-drop`
686 /// The ::drag-drop signal is emitted on the drop site when the user drops
687 /// the data onto the widget. The signal handler must determine whether
688 /// the cursor position is in a drop zone or not. If it is not in a drop
689 /// zone, it returns [`false`] and no further processing is necessary.
690 /// Otherwise, the handler returns [`true`]. In this case, the handler must
691 /// ensure that `gtk_drag_finish()` is called to let the source know that
692 /// the drop is done. The call to `gtk_drag_finish()` can be done either
693 /// directly or in a [`drag-data-received`][struct@crate::Widget#drag-data-received] handler which gets
694 /// triggered by calling [`WidgetExt::drag_get_data()`][crate::prelude::WidgetExt::drag_get_data()] to receive the data for one
695 /// or more of the supported targets.
696 ///
697 ///
698 ///
699 ///
700 /// #### `drag-end`
701 /// The ::drag-end signal is emitted on the drag source when a drag is
702 /// finished. A typical reason to connect to this signal is to undo
703 /// things done in [`drag-begin`][struct@crate::Widget#drag-begin].
704 ///
705 ///
706 ///
707 ///
708 /// #### `drag-failed`
709 /// The ::drag-failed signal is emitted on the drag source when a drag has
710 /// failed. The signal handler may hook custom code to handle a failed DnD
711 /// operation based on the type of error, it returns [`true`] is the failure has
712 /// been already handled (not showing the default "drag operation failed"
713 /// animation), otherwise it returns [`false`].
714 ///
715 ///
716 ///
717 ///
718 /// #### `drag-leave`
719 /// The ::drag-leave signal is emitted on the drop site when the cursor
720 /// leaves the widget. A typical reason to connect to this signal is to
721 /// undo things done in [`drag-motion`][struct@crate::Widget#drag-motion], e.g. undo highlighting
722 /// with [`WidgetExt::drag_unhighlight()`][crate::prelude::WidgetExt::drag_unhighlight()].
723 ///
724 ///
725 /// Likewise, the [`drag-leave`][struct@crate::Widget#drag-leave] signal is also emitted before the
726 /// ::drag-drop signal, for instance to allow cleaning up of a preview item
727 /// created in the [`drag-motion`][struct@crate::Widget#drag-motion] signal handler.
728 ///
729 ///
730 ///
731 ///
732 /// #### `drag-motion`
733 /// suggested_action,
734 /// time);
735 /// }
736 /// else
737 /// {
738 /// // accept the drop
739 /// }
740 /// }
741 /// ]|
742 ///
743 ///
744 ///
745 ///
746 /// #### `draw`
747 /// This signal is emitted when a widget is supposed to render itself.
748 /// The `widget`'s top left corner must be painted at the origin of
749 /// the passed in context and be sized to the values returned by
750 /// [`WidgetExt::allocated_width()`][crate::prelude::WidgetExt::allocated_width()] and
751 /// [`WidgetExt::allocated_height()`][crate::prelude::WidgetExt::allocated_height()].
752 ///
753 /// Signal handlers connected to this signal can modify the cairo
754 /// context passed as `cr` in any way they like and don't need to
755 /// restore it. The signal emission takes care of calling `cairo_save()`
756 /// before and `cairo_restore()` after invoking the handler.
757 ///
758 /// The signal handler will get a `cr` with a clip region already set to the
759 /// widget's dirty region, i.e. to the area that needs repainting. Complicated
760 /// widgets that want to avoid redrawing themselves completely can get the full
761 /// extents of the clip region with `gdk_cairo_get_clip_rectangle()`, or they can
762 /// get a finer-grained representation of the dirty region with
763 /// `cairo_copy_clip_rectangle_list()`.
764 ///
765 ///
766 ///
767 ///
768 /// #### `enter-notify-event`
769 /// The ::enter-notify-event will be emitted when the pointer enters
770 /// the `widget`'s window.
771 ///
772 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
773 /// to enable the [`gdk::EventMask::ENTER_NOTIFY_MASK`][crate::gdk::EventMask::ENTER_NOTIFY_MASK] mask.
774 ///
775 /// This signal will be sent to the grab widget if there is one.
776 ///
777 ///
778 ///
779 ///
780 /// #### `event`
781 /// The GTK+ main loop will emit three signals for each GDK event delivered
782 /// to a widget: one generic ::event signal, another, more specific,
783 /// signal that matches the type of event delivered (e.g.
784 /// [`key-press-event`][struct@crate::Widget#key-press-event]) and finally a generic
785 /// [`event-after`][struct@crate::Widget#event-after] signal.
786 ///
787 ///
788 ///
789 ///
790 /// #### `event-after`
791 /// After the emission of the [`event`][struct@crate::Widget#event] signal and (optionally)
792 /// the second more specific signal, ::event-after will be emitted
793 /// regardless of the previous two signals handlers return values.
794 ///
795 ///
796 ///
797 ///
798 /// #### `focus`
799 ///
800 ///
801 ///
802 /// #### `focus-in-event`
803 /// The ::focus-in-event signal will be emitted when the keyboard focus
804 /// enters the `widget`'s window.
805 ///
806 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
807 /// to enable the [`gdk::EventMask::FOCUS_CHANGE_MASK`][crate::gdk::EventMask::FOCUS_CHANGE_MASK] mask.
808 ///
809 ///
810 ///
811 ///
812 /// #### `focus-out-event`
813 /// The ::focus-out-event signal will be emitted when the keyboard focus
814 /// leaves the `widget`'s window.
815 ///
816 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
817 /// to enable the [`gdk::EventMask::FOCUS_CHANGE_MASK`][crate::gdk::EventMask::FOCUS_CHANGE_MASK] mask.
818 ///
819 ///
820 ///
821 ///
822 /// #### `grab-broken-event`
823 /// Emitted when a pointer or keyboard grab on a window belonging
824 /// to `widget` gets broken.
825 ///
826 /// On X11, this happens when the grab window becomes unviewable
827 /// (i.e. it or one of its ancestors is unmapped), or if the same
828 /// application grabs the pointer or keyboard again.
829 ///
830 ///
831 ///
832 ///
833 /// #### `grab-focus`
834 /// Action
835 ///
836 ///
837 /// #### `grab-notify`
838 /// The ::grab-notify signal is emitted when a widget becomes
839 /// shadowed by a GTK+ grab (not a pointer or keyboard grab) on
840 /// another widget, or when it becomes unshadowed due to a grab
841 /// being removed.
842 ///
843 /// A widget is shadowed by a [`WidgetExt::grab_add()`][crate::prelude::WidgetExt::grab_add()] when the topmost
844 /// grab widget in the grab stack of its window group is not
845 /// its ancestor.
846 ///
847 ///
848 ///
849 ///
850 /// #### `hide`
851 /// The ::hide signal is emitted when `widget` is hidden, for example with
852 /// [`WidgetExt::hide()`][crate::prelude::WidgetExt::hide()].
853 ///
854 ///
855 ///
856 ///
857 /// #### `hierarchy-changed`
858 /// The ::hierarchy-changed signal is emitted when the
859 /// anchored state of a widget changes. A widget is
860 /// “anchored” when its toplevel
861 /// ancestor is a [`Window`][crate::Window]. This signal is emitted when
862 /// a widget changes from un-anchored to anchored or vice-versa.
863 ///
864 ///
865 ///
866 ///
867 /// #### `key-press-event`
868 /// The ::key-press-event signal is emitted when a key is pressed. The signal
869 /// emission will reoccur at the key-repeat rate when the key is kept pressed.
870 ///
871 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
872 /// to enable the [`gdk::EventMask::KEY_PRESS_MASK`][crate::gdk::EventMask::KEY_PRESS_MASK] mask.
873 ///
874 /// This signal will be sent to the grab widget if there is one.
875 ///
876 ///
877 ///
878 ///
879 /// #### `key-release-event`
880 /// The ::key-release-event signal is emitted when a key is released.
881 ///
882 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
883 /// to enable the [`gdk::EventMask::KEY_RELEASE_MASK`][crate::gdk::EventMask::KEY_RELEASE_MASK] mask.
884 ///
885 /// This signal will be sent to the grab widget if there is one.
886 ///
887 ///
888 ///
889 ///
890 /// #### `keynav-failed`
891 /// Gets emitted if keyboard navigation fails.
892 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
893 ///
894 ///
895 ///
896 ///
897 /// #### `leave-notify-event`
898 /// The ::leave-notify-event will be emitted when the pointer leaves
899 /// the `widget`'s window.
900 ///
901 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
902 /// to enable the [`gdk::EventMask::LEAVE_NOTIFY_MASK`][crate::gdk::EventMask::LEAVE_NOTIFY_MASK] mask.
903 ///
904 /// This signal will be sent to the grab widget if there is one.
905 ///
906 ///
907 ///
908 ///
909 /// #### `map`
910 /// The ::map signal is emitted when `widget` is going to be mapped, that is
911 /// when the widget is visible (which is controlled with
912 /// [`WidgetExt::set_visible()`][crate::prelude::WidgetExt::set_visible()]) and all its parents up to the toplevel widget
913 /// are also visible. Once the map has occurred, [`map-event`][struct@crate::Widget#map-event] will
914 /// be emitted.
915 ///
916 /// The ::map signal can be used to determine whether a widget will be drawn,
917 /// for instance it can resume an animation that was stopped during the
918 /// emission of [`unmap`][struct@crate::Widget#unmap].
919 ///
920 ///
921 ///
922 ///
923 /// #### `map-event`
924 /// The ::map-event signal will be emitted when the `widget`'s window is
925 /// mapped. A window is mapped when it becomes visible on the screen.
926 ///
927 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
928 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
929 /// automatically for all new windows.
930 ///
931 ///
932 ///
933 ///
934 /// #### `mnemonic-activate`
935 /// The default handler for this signal activates `widget` if `group_cycling`
936 /// is [`false`], or just makes `widget` grab focus if `group_cycling` is [`true`].
937 ///
938 ///
939 ///
940 ///
941 /// #### `motion-notify-event`
942 /// The ::motion-notify-event signal is emitted when the pointer moves
943 /// over the widget's [`gdk::Window`][crate::gdk::Window].
944 ///
945 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget
946 /// needs to enable the [`gdk::EventMask::POINTER_MOTION_MASK`][crate::gdk::EventMask::POINTER_MOTION_MASK] mask.
947 ///
948 /// This signal will be sent to the grab widget if there is one.
949 ///
950 ///
951 ///
952 ///
953 /// #### `move-focus`
954 /// Action
955 ///
956 ///
957 /// #### `parent-set`
958 /// The ::parent-set signal is emitted when a new parent
959 /// has been set on a widget.
960 ///
961 ///
962 ///
963 ///
964 /// #### `popup-menu`
965 /// This signal gets emitted whenever a widget should pop up a context
966 /// menu. This usually happens through the standard key binding mechanism;
967 /// by pressing a certain key while a widget is focused, the user can cause
968 /// the widget to pop up a menu. For example, the [`Entry`][crate::Entry] widget creates
969 /// a menu with clipboard commands. See the
970 /// [Popup Menu Migration Checklist][checklist-popup-menu]
971 /// for an example of how to use this signal.
972 ///
973 /// Action
974 ///
975 ///
976 /// #### `property-notify-event`
977 /// The ::property-notify-event signal will be emitted when a property on
978 /// the `widget`'s window has been changed or deleted.
979 ///
980 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
981 /// to enable the [`gdk::EventMask::PROPERTY_CHANGE_MASK`][crate::gdk::EventMask::PROPERTY_CHANGE_MASK] mask.
982 ///
983 ///
984 ///
985 ///
986 /// #### `proximity-in-event`
987 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
988 /// to enable the [`gdk::EventMask::PROXIMITY_IN_MASK`][crate::gdk::EventMask::PROXIMITY_IN_MASK] mask.
989 ///
990 /// This signal will be sent to the grab widget if there is one.
991 ///
992 ///
993 ///
994 ///
995 /// #### `proximity-out-event`
996 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
997 /// to enable the [`gdk::EventMask::PROXIMITY_OUT_MASK`][crate::gdk::EventMask::PROXIMITY_OUT_MASK] mask.
998 ///
999 /// This signal will be sent to the grab widget if there is one.
1000 ///
1001 ///
1002 ///
1003 ///
1004 /// #### `query-tooltip`
1005 /// Emitted when [`has-tooltip`][struct@crate::Widget#has-tooltip] is [`true`] and the hover timeout
1006 /// has expired with the cursor hovering "above" `widget`; or emitted when `widget` got
1007 /// focus in keyboard mode.
1008 ///
1009 /// Using the given coordinates, the signal handler should determine
1010 /// whether a tooltip should be shown for `widget`. If this is the case
1011 /// [`true`] should be returned, [`false`] otherwise. Note that if
1012 /// `keyboard_mode` is [`true`], the values of `x` and `y` are undefined and
1013 /// should not be used.
1014 ///
1015 /// The signal handler is free to manipulate `tooltip` with the therefore
1016 /// destined function calls.
1017 ///
1018 ///
1019 ///
1020 ///
1021 /// #### `realize`
1022 /// The ::realize signal is emitted when `widget` is associated with a
1023 /// [`gdk::Window`][crate::gdk::Window], which means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called or the
1024 /// widget has been mapped (that is, it is going to be drawn).
1025 ///
1026 ///
1027 ///
1028 ///
1029 /// #### `screen-changed`
1030 /// The ::screen-changed signal gets emitted when the
1031 /// screen of a widget has changed.
1032 ///
1033 ///
1034 ///
1035 ///
1036 /// #### `scroll-event`
1037 /// The ::scroll-event signal is emitted when a button in the 4 to 7
1038 /// range is pressed. Wheel mice are usually configured to generate
1039 /// button press events for buttons 4 and 5 when the wheel is turned.
1040 ///
1041 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1042 /// to enable the [`gdk::EventMask::SCROLL_MASK`][crate::gdk::EventMask::SCROLL_MASK] mask.
1043 ///
1044 /// This signal will be sent to the grab widget if there is one.
1045 ///
1046 ///
1047 ///
1048 ///
1049 /// #### `selection-clear-event`
1050 /// The ::selection-clear-event signal will be emitted when the
1051 /// the `widget`'s window has lost ownership of a selection.
1052 ///
1053 ///
1054 ///
1055 ///
1056 /// #### `selection-get`
1057 ///
1058 ///
1059 ///
1060 /// #### `selection-notify-event`
1061 ///
1062 ///
1063 ///
1064 /// #### `selection-received`
1065 ///
1066 ///
1067 ///
1068 /// #### `selection-request-event`
1069 /// The ::selection-request-event signal will be emitted when
1070 /// another client requests ownership of the selection owned by
1071 /// the `widget`'s window.
1072 ///
1073 ///
1074 ///
1075 ///
1076 /// #### `show`
1077 /// The ::show signal is emitted when `widget` is shown, for example with
1078 /// [`WidgetExt::show()`][crate::prelude::WidgetExt::show()].
1079 ///
1080 ///
1081 ///
1082 ///
1083 /// #### `show-help`
1084 /// Action
1085 ///
1086 ///
1087 /// #### `size-allocate`
1088 ///
1089 ///
1090 ///
1091 /// #### `state-changed`
1092 /// The ::state-changed signal is emitted when the widget state changes.
1093 /// See `gtk_widget_get_state()`.
1094 ///
1095 ///
1096 ///
1097 ///
1098 /// #### `state-flags-changed`
1099 /// The ::state-flags-changed signal is emitted when the widget state
1100 /// changes, see [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
1101 ///
1102 ///
1103 ///
1104 ///
1105 /// #### `style-set`
1106 /// The ::style-set signal is emitted when a new style has been set
1107 /// on a widget. Note that style-modifying functions like
1108 /// `gtk_widget_modify_base()` also cause this signal to be emitted.
1109 ///
1110 /// Note that this signal is emitted for changes to the deprecated
1111 /// `GtkStyle`. To track changes to the [`StyleContext`][crate::StyleContext] associated
1112 /// with a widget, use the [`style-updated`][struct@crate::Widget#style-updated] signal.
1113 ///
1114 ///
1115 ///
1116 ///
1117 /// #### `style-updated`
1118 /// The ::style-updated signal is a convenience signal that is emitted when the
1119 /// [`changed`][struct@crate::StyleContext#changed] signal is emitted on the `widget`'s associated
1120 /// [`StyleContext`][crate::StyleContext] as returned by [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()].
1121 ///
1122 /// Note that style-modifying functions like `gtk_widget_override_color()` also
1123 /// cause this signal to be emitted.
1124 ///
1125 ///
1126 ///
1127 ///
1128 /// #### `touch-event`
1129 ///
1130 ///
1131 ///
1132 /// #### `unmap`
1133 /// The ::unmap signal is emitted when `widget` is going to be unmapped, which
1134 /// means that either it or any of its parents up to the toplevel widget have
1135 /// been set as hidden.
1136 ///
1137 /// As ::unmap indicates that a widget will not be shown any longer, it can be
1138 /// used to, for example, stop an animation on the widget.
1139 ///
1140 ///
1141 ///
1142 ///
1143 /// #### `unmap-event`
1144 /// The ::unmap-event signal will be emitted when the `widget`'s window is
1145 /// unmapped. A window is unmapped when it becomes invisible on the screen.
1146 ///
1147 /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1148 /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
1149 /// automatically for all new windows.
1150 ///
1151 ///
1152 ///
1153 ///
1154 /// #### `unrealize`
1155 /// The ::unrealize signal is emitted when the [`gdk::Window`][crate::gdk::Window] associated with
1156 /// `widget` is destroyed, which means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been
1157 /// called or the widget has been unmapped (that is, it is going to be
1158 /// hidden).
1159 ///
1160 ///
1161 ///
1162 ///
1163 /// #### `visibility-notify-event`
1164 /// The ::visibility-notify-event will be emitted when the `widget`'s
1165 /// window is obscured or unobscured.
1166 ///
1167 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1168 /// to enable the [`gdk::EventMask::VISIBILITY_NOTIFY_MASK`][crate::gdk::EventMask::VISIBILITY_NOTIFY_MASK] mask.
1169 ///
1170 ///
1171 ///
1172 ///
1173 /// #### `window-state-event`
1174 /// The ::window-state-event will be emitted when the state of the
1175 /// toplevel window associated to the `widget` changes.
1176 ///
1177 /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget
1178 /// needs to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable
1179 /// this mask automatically for all new windows.
1180 ///
1181 ///
1182 /// </details>
1183 ///
1184 /// # Implements
1185 ///
1186 /// [`ToggleButtonExt`][trait@crate::prelude::ToggleButtonExt], [`ButtonExt`][trait@crate::prelude::ButtonExt], [`BinExt`][trait@crate::prelude::BinExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ActionableExt`][trait@crate::prelude::ActionableExt], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
1187 #[doc(alias = "GtkToggleButton")]
1188 pub struct ToggleButton(Object<ffi::GtkToggleButton, ffi::GtkToggleButtonClass>) @extends Button, Bin, Container, Widget, @implements Buildable, Actionable;
1189
1190 match fn {
1191 type_ => || ffi::gtk_toggle_button_get_type(),
1192 }
1193}
1194
1195impl ToggleButton {
1196 pub const NONE: Option<&'static ToggleButton> = None;
1197
1198 /// Creates a new toggle button. A widget should be packed into the button, as in [`Button::new()`][crate::Button::new()].
1199 ///
1200 /// # Returns
1201 ///
1202 /// a new toggle button.
1203 #[doc(alias = "gtk_toggle_button_new")]
1204 pub fn new() -> ToggleButton {
1205 assert_initialized_main_thread!();
1206 unsafe { Widget::from_glib_none(ffi::gtk_toggle_button_new()).unsafe_cast() }
1207 }
1208
1209 /// Creates a new toggle button with a text label.
1210 /// ## `label`
1211 /// a string containing the message to be placed in the toggle button.
1212 ///
1213 /// # Returns
1214 ///
1215 /// a new toggle button.
1216 #[doc(alias = "gtk_toggle_button_new_with_label")]
1217 #[doc(alias = "new_with_label")]
1218 pub fn with_label(label: &str) -> ToggleButton {
1219 assert_initialized_main_thread!();
1220 unsafe {
1221 Widget::from_glib_none(ffi::gtk_toggle_button_new_with_label(
1222 label.to_glib_none().0,
1223 ))
1224 .unsafe_cast()
1225 }
1226 }
1227
1228 /// Creates a new [`ToggleButton`][crate::ToggleButton] containing a label. The label
1229 /// will be created using [`Label::with_mnemonic()`][crate::Label::with_mnemonic()], so underscores
1230 /// in `label` indicate the mnemonic for the button.
1231 /// ## `label`
1232 /// the text of the button, with an underscore in front of the
1233 /// mnemonic character
1234 ///
1235 /// # Returns
1236 ///
1237 /// a new [`ToggleButton`][crate::ToggleButton]
1238 #[doc(alias = "gtk_toggle_button_new_with_mnemonic")]
1239 #[doc(alias = "new_with_mnemonic")]
1240 pub fn with_mnemonic(label: &str) -> ToggleButton {
1241 assert_initialized_main_thread!();
1242 unsafe {
1243 Widget::from_glib_none(ffi::gtk_toggle_button_new_with_mnemonic(
1244 label.to_glib_none().0,
1245 ))
1246 .unsafe_cast()
1247 }
1248 }
1249
1250 // rustdoc-stripper-ignore-next
1251 /// Creates a new builder-pattern struct instance to construct [`ToggleButton`] objects.
1252 ///
1253 /// This method returns an instance of [`ToggleButtonBuilder`](crate::builders::ToggleButtonBuilder) which can be used to create [`ToggleButton`] objects.
1254 pub fn builder() -> ToggleButtonBuilder {
1255 ToggleButtonBuilder::new()
1256 }
1257}
1258
1259impl Default for ToggleButton {
1260 fn default() -> Self {
1261 Self::new()
1262 }
1263}
1264
1265// rustdoc-stripper-ignore-next
1266/// A [builder-pattern] type to construct [`ToggleButton`] objects.
1267///
1268/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
1269#[must_use = "The builder must be built to be used"]
1270pub struct ToggleButtonBuilder {
1271 builder: glib::object::ObjectBuilder<'static, ToggleButton>,
1272}
1273
1274impl ToggleButtonBuilder {
1275 fn new() -> Self {
1276 Self {
1277 builder: glib::object::Object::builder(),
1278 }
1279 }
1280
1281 pub fn active(self, active: bool) -> Self {
1282 Self {
1283 builder: self.builder.property("active", active),
1284 }
1285 }
1286
1287 pub fn draw_indicator(self, draw_indicator: bool) -> Self {
1288 Self {
1289 builder: self.builder.property("draw-indicator", draw_indicator),
1290 }
1291 }
1292
1293 pub fn inconsistent(self, inconsistent: bool) -> Self {
1294 Self {
1295 builder: self.builder.property("inconsistent", inconsistent),
1296 }
1297 }
1298
1299 /// If [`true`], the button will ignore the [`gtk-button-images`][struct@crate::Settings#gtk-button-images]
1300 /// setting and always show the image, if available.
1301 ///
1302 /// Use this property if the button would be useless or hard to use
1303 /// without the image.
1304 pub fn always_show_image(self, always_show_image: bool) -> Self {
1305 Self {
1306 builder: self
1307 .builder
1308 .property("always-show-image", always_show_image),
1309 }
1310 }
1311
1312 /// The child widget to appear next to the button text.
1313 pub fn image(self, image: &impl IsA<Widget>) -> Self {
1314 Self {
1315 builder: self.builder.property("image", image.clone().upcast()),
1316 }
1317 }
1318
1319 /// The position of the image relative to the text inside the button.
1320 pub fn image_position(self, image_position: PositionType) -> Self {
1321 Self {
1322 builder: self.builder.property("image-position", image_position),
1323 }
1324 }
1325
1326 pub fn label(self, label: impl Into<glib::GString>) -> Self {
1327 Self {
1328 builder: self.builder.property("label", label.into()),
1329 }
1330 }
1331
1332 pub fn relief(self, relief: ReliefStyle) -> Self {
1333 Self {
1334 builder: self.builder.property("relief", relief),
1335 }
1336 }
1337
1338 pub fn use_underline(self, use_underline: bool) -> Self {
1339 Self {
1340 builder: self.builder.property("use-underline", use_underline),
1341 }
1342 }
1343
1344 pub fn border_width(self, border_width: u32) -> Self {
1345 Self {
1346 builder: self.builder.property("border-width", border_width),
1347 }
1348 }
1349
1350 pub fn child(self, child: &impl IsA<Widget>) -> Self {
1351 Self {
1352 builder: self.builder.property("child", child.clone().upcast()),
1353 }
1354 }
1355
1356 pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
1357 Self {
1358 builder: self.builder.property("resize-mode", resize_mode),
1359 }
1360 }
1361
1362 pub fn app_paintable(self, app_paintable: bool) -> Self {
1363 Self {
1364 builder: self.builder.property("app-paintable", app_paintable),
1365 }
1366 }
1367
1368 pub fn can_default(self, can_default: bool) -> Self {
1369 Self {
1370 builder: self.builder.property("can-default", can_default),
1371 }
1372 }
1373
1374 pub fn can_focus(self, can_focus: bool) -> Self {
1375 Self {
1376 builder: self.builder.property("can-focus", can_focus),
1377 }
1378 }
1379
1380 pub fn events(self, events: gdk::EventMask) -> Self {
1381 Self {
1382 builder: self.builder.property("events", events),
1383 }
1384 }
1385
1386 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
1387 pub fn expand(self, expand: bool) -> Self {
1388 Self {
1389 builder: self.builder.property("expand", expand),
1390 }
1391 }
1392
1393 /// Whether the widget should grab focus when it is clicked with the mouse.
1394 ///
1395 /// This property is only relevant for widgets that can take focus.
1396 ///
1397 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
1398 /// GtkComboBox) implemented this property individually.
1399 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
1400 Self {
1401 builder: self.builder.property("focus-on-click", focus_on_click),
1402 }
1403 }
1404
1405 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
1406 pub fn halign(self, halign: Align) -> Self {
1407 Self {
1408 builder: self.builder.property("halign", halign),
1409 }
1410 }
1411
1412 pub fn has_default(self, has_default: bool) -> Self {
1413 Self {
1414 builder: self.builder.property("has-default", has_default),
1415 }
1416 }
1417
1418 pub fn has_focus(self, has_focus: bool) -> Self {
1419 Self {
1420 builder: self.builder.property("has-focus", has_focus),
1421 }
1422 }
1423
1424 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
1425 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
1426 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
1427 /// whether it will provide a tooltip or not.
1428 ///
1429 /// Note that setting this property to [`true`] for the first time will change
1430 /// the event masks of the GdkWindows of this widget to include leave-notify
1431 /// and motion-notify events. This cannot and will not be undone when the
1432 /// property is set to [`false`] again.
1433 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
1434 Self {
1435 builder: self.builder.property("has-tooltip", has_tooltip),
1436 }
1437 }
1438
1439 pub fn height_request(self, height_request: i32) -> Self {
1440 Self {
1441 builder: self.builder.property("height-request", height_request),
1442 }
1443 }
1444
1445 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
1446 pub fn hexpand(self, hexpand: bool) -> Self {
1447 Self {
1448 builder: self.builder.property("hexpand", hexpand),
1449 }
1450 }
1451
1452 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
1453 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1454 Self {
1455 builder: self.builder.property("hexpand-set", hexpand_set),
1456 }
1457 }
1458
1459 pub fn is_focus(self, is_focus: bool) -> Self {
1460 Self {
1461 builder: self.builder.property("is-focus", is_focus),
1462 }
1463 }
1464
1465 /// Sets all four sides' margin at once. If read, returns max
1466 /// margin on any side.
1467 pub fn margin(self, margin: i32) -> Self {
1468 Self {
1469 builder: self.builder.property("margin", margin),
1470 }
1471 }
1472
1473 /// Margin on bottom side of widget.
1474 ///
1475 /// This property adds margin outside of the widget's normal size
1476 /// request, the margin will be added in addition to the size from
1477 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1478 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1479 Self {
1480 builder: self.builder.property("margin-bottom", margin_bottom),
1481 }
1482 }
1483
1484 /// Margin on end of widget, horizontally. This property supports
1485 /// left-to-right and right-to-left text directions.
1486 ///
1487 /// This property adds margin outside of the widget's normal size
1488 /// request, the margin will be added in addition to the size from
1489 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1490 pub fn margin_end(self, margin_end: i32) -> Self {
1491 Self {
1492 builder: self.builder.property("margin-end", margin_end),
1493 }
1494 }
1495
1496 /// Margin on start of widget, horizontally. This property supports
1497 /// left-to-right and right-to-left text directions.
1498 ///
1499 /// This property adds margin outside of the widget's normal size
1500 /// request, the margin will be added in addition to the size from
1501 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1502 pub fn margin_start(self, margin_start: i32) -> Self {
1503 Self {
1504 builder: self.builder.property("margin-start", margin_start),
1505 }
1506 }
1507
1508 /// Margin on top side of widget.
1509 ///
1510 /// This property adds margin outside of the widget's normal size
1511 /// request, the margin will be added in addition to the size from
1512 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1513 pub fn margin_top(self, margin_top: i32) -> Self {
1514 Self {
1515 builder: self.builder.property("margin-top", margin_top),
1516 }
1517 }
1518
1519 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1520 Self {
1521 builder: self.builder.property("name", name.into()),
1522 }
1523 }
1524
1525 pub fn no_show_all(self, no_show_all: bool) -> Self {
1526 Self {
1527 builder: self.builder.property("no-show-all", no_show_all),
1528 }
1529 }
1530
1531 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
1532 /// more details about window opacity.
1533 ///
1534 /// Before 3.8 this was only available in GtkWindow
1535 pub fn opacity(self, opacity: f64) -> Self {
1536 Self {
1537 builder: self.builder.property("opacity", opacity),
1538 }
1539 }
1540
1541 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
1542 Self {
1543 builder: self.builder.property("parent", parent.clone().upcast()),
1544 }
1545 }
1546
1547 pub fn receives_default(self, receives_default: bool) -> Self {
1548 Self {
1549 builder: self.builder.property("receives-default", receives_default),
1550 }
1551 }
1552
1553 pub fn sensitive(self, sensitive: bool) -> Self {
1554 Self {
1555 builder: self.builder.property("sensitive", sensitive),
1556 }
1557 }
1558
1559 /// Sets the text of tooltip to be the given string, which is marked up
1560 /// with the [Pango text markup language][PangoMarkupFormat].
1561 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1562 ///
1563 /// This is a convenience property which will take care of getting the
1564 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
1565 /// will automatically be set to [`true`] and there will be taken care of
1566 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
1567 ///
1568 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
1569 /// are set, the last one wins.
1570 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1571 Self {
1572 builder: self
1573 .builder
1574 .property("tooltip-markup", tooltip_markup.into()),
1575 }
1576 }
1577
1578 /// Sets the text of tooltip to be the given string.
1579 ///
1580 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1581 ///
1582 /// This is a convenience property which will take care of getting the
1583 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
1584 /// will automatically be set to [`true`] and there will be taken care of
1585 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
1586 ///
1587 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
1588 /// are set, the last one wins.
1589 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1590 Self {
1591 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1592 }
1593 }
1594
1595 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
1596 pub fn valign(self, valign: Align) -> Self {
1597 Self {
1598 builder: self.builder.property("valign", valign),
1599 }
1600 }
1601
1602 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
1603 pub fn vexpand(self, vexpand: bool) -> Self {
1604 Self {
1605 builder: self.builder.property("vexpand", vexpand),
1606 }
1607 }
1608
1609 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
1610 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1611 Self {
1612 builder: self.builder.property("vexpand-set", vexpand_set),
1613 }
1614 }
1615
1616 pub fn visible(self, visible: bool) -> Self {
1617 Self {
1618 builder: self.builder.property("visible", visible),
1619 }
1620 }
1621
1622 pub fn width_request(self, width_request: i32) -> Self {
1623 Self {
1624 builder: self.builder.property("width-request", width_request),
1625 }
1626 }
1627
1628 pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
1629 Self {
1630 builder: self.builder.property("action-name", action_name.into()),
1631 }
1632 }
1633
1634 pub fn action_target(self, action_target: &glib::Variant) -> Self {
1635 Self {
1636 builder: self
1637 .builder
1638 .property("action-target", action_target.clone()),
1639 }
1640 }
1641
1642 // rustdoc-stripper-ignore-next
1643 /// Build the [`ToggleButton`].
1644 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1645 pub fn build(self) -> ToggleButton {
1646 assert_initialized_main_thread!();
1647 self.builder.build()
1648 }
1649}
1650
1651/// Trait containing all [`struct@ToggleButton`] methods.
1652///
1653/// # Implementors
1654///
1655/// [`CheckButton`][struct@crate::CheckButton], [`MenuButton`][struct@crate::MenuButton], [`ToggleButton`][struct@crate::ToggleButton]
1656pub trait ToggleButtonExt: IsA<ToggleButton> + 'static {
1657 /// Queries a [`ToggleButton`][crate::ToggleButton] and returns its current state. Returns [`true`] if
1658 /// the toggle button is pressed in and [`false`] if it is raised.
1659 ///
1660 /// # Returns
1661 ///
1662 /// a `gboolean` value.
1663 #[doc(alias = "gtk_toggle_button_get_active")]
1664 #[doc(alias = "get_active")]
1665 #[doc(alias = "active")]
1666 fn is_active(&self) -> bool {
1667 unsafe {
1668 from_glib(ffi::gtk_toggle_button_get_active(
1669 self.as_ref().to_glib_none().0,
1670 ))
1671 }
1672 }
1673
1674 /// Gets the value set by [`set_inconsistent()`][Self::set_inconsistent()].
1675 ///
1676 /// # Returns
1677 ///
1678 /// [`true`] if the button is displayed as inconsistent, [`false`] otherwise
1679 #[doc(alias = "gtk_toggle_button_get_inconsistent")]
1680 #[doc(alias = "get_inconsistent")]
1681 #[doc(alias = "inconsistent")]
1682 fn is_inconsistent(&self) -> bool {
1683 unsafe {
1684 from_glib(ffi::gtk_toggle_button_get_inconsistent(
1685 self.as_ref().to_glib_none().0,
1686 ))
1687 }
1688 }
1689
1690 /// Retrieves whether the button is displayed as a separate indicator
1691 /// and label. See [`set_mode()`][Self::set_mode()].
1692 ///
1693 /// # Returns
1694 ///
1695 /// [`true`] if the togglebutton is drawn as a separate indicator
1696 /// and label.
1697 #[doc(alias = "gtk_toggle_button_get_mode")]
1698 #[doc(alias = "get_mode")]
1699 fn is_mode(&self) -> bool {
1700 unsafe {
1701 from_glib(ffi::gtk_toggle_button_get_mode(
1702 self.as_ref().to_glib_none().0,
1703 ))
1704 }
1705 }
1706
1707 /// Sets the status of the toggle button. Set to [`true`] if you want the
1708 /// GtkToggleButton to be “pressed in”, and [`false`] to raise it.
1709 /// This action causes the [`toggled`][struct@crate::ToggleButton#toggled] signal and the
1710 /// [`clicked`][struct@crate::Button#clicked] signal to be emitted.
1711 /// ## `is_active`
1712 /// [`true`] or [`false`].
1713 #[doc(alias = "gtk_toggle_button_set_active")]
1714 #[doc(alias = "active")]
1715 fn set_active(&self, is_active: bool) {
1716 unsafe {
1717 ffi::gtk_toggle_button_set_active(
1718 self.as_ref().to_glib_none().0,
1719 is_active.into_glib(),
1720 );
1721 }
1722 }
1723
1724 /// If the user has selected a range of elements (such as some text or
1725 /// spreadsheet cells) that are affected by a toggle button, and the
1726 /// current values in that range are inconsistent, you may want to
1727 /// display the toggle in an “in between” state. This function turns on
1728 /// “in between” display. Normally you would turn off the inconsistent
1729 /// state again if the user toggles the toggle button. This has to be
1730 /// done manually, [`set_inconsistent()`][Self::set_inconsistent()] only affects
1731 /// visual appearance, it doesn’t affect the semantics of the button.
1732 /// ## `setting`
1733 /// [`true`] if state is inconsistent
1734 #[doc(alias = "gtk_toggle_button_set_inconsistent")]
1735 #[doc(alias = "inconsistent")]
1736 fn set_inconsistent(&self, setting: bool) {
1737 unsafe {
1738 ffi::gtk_toggle_button_set_inconsistent(
1739 self.as_ref().to_glib_none().0,
1740 setting.into_glib(),
1741 );
1742 }
1743 }
1744
1745 /// Sets whether the button is displayed as a separate indicator and label.
1746 /// You can call this function on a checkbutton or a radiobutton with
1747 /// `draw_indicator` = [`false`] to make the button look like a normal button.
1748 ///
1749 /// This can be used to create linked strip of buttons that work like
1750 /// a [`StackSwitcher`][crate::StackSwitcher].
1751 ///
1752 /// This function only affects instances of classes like [`CheckButton`][crate::CheckButton]
1753 /// and [`RadioButton`][crate::RadioButton] that derive from [`ToggleButton`][crate::ToggleButton],
1754 /// not instances of [`ToggleButton`][crate::ToggleButton] itself.
1755 /// ## `draw_indicator`
1756 /// if [`true`], draw the button as a separate indicator
1757 /// and label; if [`false`], draw the button like a normal button
1758 #[doc(alias = "gtk_toggle_button_set_mode")]
1759 fn set_mode(&self, draw_indicator: bool) {
1760 unsafe {
1761 ffi::gtk_toggle_button_set_mode(
1762 self.as_ref().to_glib_none().0,
1763 draw_indicator.into_glib(),
1764 );
1765 }
1766 }
1767
1768 /// Emits the [`toggled`][struct@crate::ToggleButton#toggled] signal on the
1769 /// [`ToggleButton`][crate::ToggleButton]. There is no good reason for an
1770 /// application ever to call this function.
1771 #[doc(alias = "gtk_toggle_button_toggled")]
1772 fn toggled(&self) {
1773 unsafe {
1774 ffi::gtk_toggle_button_toggled(self.as_ref().to_glib_none().0);
1775 }
1776 }
1777
1778 #[doc(alias = "draw-indicator")]
1779 fn draws_indicator(&self) -> bool {
1780 ObjectExt::property(self.as_ref(), "draw-indicator")
1781 }
1782
1783 #[doc(alias = "draw-indicator")]
1784 fn set_draw_indicator(&self, draw_indicator: bool) {
1785 ObjectExt::set_property(self.as_ref(), "draw-indicator", draw_indicator)
1786 }
1787
1788 /// Should be connected if you wish to perform an action whenever the
1789 /// [`ToggleButton`][crate::ToggleButton]'s state is changed.
1790 #[doc(alias = "toggled")]
1791 fn connect_toggled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1792 unsafe extern "C" fn toggled_trampoline<P: IsA<ToggleButton>, F: Fn(&P) + 'static>(
1793 this: *mut ffi::GtkToggleButton,
1794 f: glib::ffi::gpointer,
1795 ) {
1796 unsafe {
1797 let f: &F = &*(f as *const F);
1798 f(ToggleButton::from_glib_borrow(this).unsafe_cast_ref())
1799 }
1800 }
1801 unsafe {
1802 let f: Box_<F> = Box_::new(f);
1803 connect_raw(
1804 self.as_ptr() as *mut _,
1805 c"toggled".as_ptr(),
1806 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1807 toggled_trampoline::<Self, F> as *const (),
1808 )),
1809 Box_::into_raw(f),
1810 )
1811 }
1812 }
1813
1814 #[doc(alias = "active")]
1815 fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1816 unsafe extern "C" fn notify_active_trampoline<P: IsA<ToggleButton>, F: Fn(&P) + 'static>(
1817 this: *mut ffi::GtkToggleButton,
1818 _param_spec: glib::ffi::gpointer,
1819 f: glib::ffi::gpointer,
1820 ) {
1821 unsafe {
1822 let f: &F = &*(f as *const F);
1823 f(ToggleButton::from_glib_borrow(this).unsafe_cast_ref())
1824 }
1825 }
1826 unsafe {
1827 let f: Box_<F> = Box_::new(f);
1828 connect_raw(
1829 self.as_ptr() as *mut _,
1830 c"notify::active".as_ptr(),
1831 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1832 notify_active_trampoline::<Self, F> as *const (),
1833 )),
1834 Box_::into_raw(f),
1835 )
1836 }
1837 }
1838
1839 #[doc(alias = "draw-indicator")]
1840 fn connect_draw_indicator_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1841 unsafe extern "C" fn notify_draw_indicator_trampoline<
1842 P: IsA<ToggleButton>,
1843 F: Fn(&P) + 'static,
1844 >(
1845 this: *mut ffi::GtkToggleButton,
1846 _param_spec: glib::ffi::gpointer,
1847 f: glib::ffi::gpointer,
1848 ) {
1849 unsafe {
1850 let f: &F = &*(f as *const F);
1851 f(ToggleButton::from_glib_borrow(this).unsafe_cast_ref())
1852 }
1853 }
1854 unsafe {
1855 let f: Box_<F> = Box_::new(f);
1856 connect_raw(
1857 self.as_ptr() as *mut _,
1858 c"notify::draw-indicator".as_ptr(),
1859 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1860 notify_draw_indicator_trampoline::<Self, F> as *const (),
1861 )),
1862 Box_::into_raw(f),
1863 )
1864 }
1865 }
1866
1867 #[doc(alias = "inconsistent")]
1868 fn connect_inconsistent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1869 unsafe extern "C" fn notify_inconsistent_trampoline<
1870 P: IsA<ToggleButton>,
1871 F: Fn(&P) + 'static,
1872 >(
1873 this: *mut ffi::GtkToggleButton,
1874 _param_spec: glib::ffi::gpointer,
1875 f: glib::ffi::gpointer,
1876 ) {
1877 unsafe {
1878 let f: &F = &*(f as *const F);
1879 f(ToggleButton::from_glib_borrow(this).unsafe_cast_ref())
1880 }
1881 }
1882 unsafe {
1883 let f: Box_<F> = Box_::new(f);
1884 connect_raw(
1885 self.as_ptr() as *mut _,
1886 c"notify::inconsistent".as_ptr(),
1887 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1888 notify_inconsistent_trampoline::<Self, F> as *const (),
1889 )),
1890 Box_::into_raw(f),
1891 )
1892 }
1893 }
1894}
1895
1896impl<O: IsA<ToggleButton>> ToggleButtonExt for O {}