gtk4/auto/link_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, Button, ConstraintTarget,
7 LayoutManager, 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 /// A button with a hyperlink.
19 ///
20 /// <picture>
21 /// <source srcset="link-button-dark.png" media="(prefers-color-scheme: dark)">
22 /// <img alt="An example GtkLinkButton" src="link-button.png">
23 /// </picture>
24 ///
25 /// It is useful to show quick links to resources.
26 ///
27 /// A link button is created by calling either [`new()`][Self::new()] or
28 /// [`with_label()`][Self::with_label()]. If using the former, the URI you
29 /// pass to the constructor is used as a label for the widget.
30 ///
31 /// The URI bound to a [`LinkButton`][crate::LinkButton] can be set specifically using
32 /// [`set_uri()`][Self::set_uri()].
33 ///
34 /// By default, [`LinkButton`][crate::LinkButton] calls [`FileLauncher::launch()`][crate::FileLauncher::launch()] when the button
35 /// is clicked. This behaviour can be overridden by connecting to the
36 /// [`activate-link`][struct@crate::LinkButton#activate-link] signal and returning [`true`] from
37 /// the signal handler.
38 ///
39 /// # Shortcuts and Gestures
40 ///
41 /// [`LinkButton`][crate::LinkButton] supports the following keyboard shortcuts:
42 ///
43 /// - <kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Menu</kbd> opens the context menu.
44 ///
45 /// # Actions
46 ///
47 /// [`LinkButton`][crate::LinkButton] defines a set of built-in actions:
48 ///
49 /// - `clipboard.copy` copies the url to the clipboard.
50 /// - `menu.popup` opens the context menu.
51 ///
52 /// # CSS nodes
53 ///
54 /// [`LinkButton`][crate::LinkButton] has a single CSS node with name button. To differentiate
55 /// it from a plain [`Button`][crate::Button], it gets the .link style class.
56 ///
57 /// # Accessibility
58 ///
59 /// [`LinkButton`][crate::LinkButton] uses the [enum@Gtk.AccessibleRole.link] role.
60 ///
61 /// ## Properties
62 ///
63 ///
64 /// #### `uri`
65 /// The URI bound to this button.
66 ///
67 /// Readable | Writeable
68 ///
69 ///
70 /// #### `visited`
71 /// The 'visited' state of this button.
72 ///
73 /// A visited link is drawn in a different color.
74 ///
75 /// Readable | Writeable
76 /// <details><summary><h4>Button</h4></summary>
77 ///
78 ///
79 /// #### `can-shrink`
80 /// Whether the size of the button can be made smaller than the natural
81 /// size of its contents.
82 ///
83 /// For text buttons, setting this property will allow ellipsizing the label.
84 ///
85 /// If the contents of a button are an icon or a custom widget, setting this
86 /// property has no effect.
87 ///
88 /// Readable | Writeable
89 ///
90 ///
91 /// #### `child`
92 /// The child widget.
93 ///
94 /// Readable | Writeable
95 ///
96 ///
97 /// #### `has-frame`
98 /// Whether the button has a frame.
99 ///
100 /// Readable | Writeable
101 ///
102 ///
103 /// #### `icon-name`
104 /// The name of the icon used to automatically populate the button.
105 ///
106 /// Readable | Writeable
107 ///
108 ///
109 /// #### `label`
110 /// Text of the label inside the button, if the button contains a label widget.
111 ///
112 /// Readable | Writeable
113 ///
114 ///
115 /// #### `use-underline`
116 /// If set, an underline in the text indicates that the following character is
117 /// to be used as mnemonic.
118 ///
119 /// Readable | Writeable
120 /// </details>
121 /// <details><summary><h4>Widget</h4></summary>
122 ///
123 ///
124 /// #### `can-focus`
125 /// Whether the widget or any of its descendents can accept
126 /// the input focus.
127 ///
128 /// This property is meant to be set by widget implementations,
129 /// typically in their instance init function.
130 ///
131 /// Readable | Writeable
132 ///
133 ///
134 /// #### `can-target`
135 /// Whether the widget can receive pointer events.
136 ///
137 /// Readable | Writeable
138 ///
139 ///
140 /// #### `css-classes`
141 /// A list of css classes applied to this widget.
142 ///
143 /// Readable | Writeable
144 ///
145 ///
146 /// #### `css-name`
147 /// The name of this widget in the CSS tree.
148 ///
149 /// This property is meant to be set by widget implementations,
150 /// typically in their instance init function.
151 ///
152 /// Readable | Writeable | Construct Only
153 ///
154 ///
155 /// #### `cursor`
156 /// The cursor used by @widget.
157 ///
158 /// Readable | Writeable
159 ///
160 ///
161 /// #### `focus-on-click`
162 /// Whether the widget should grab focus when it is clicked with the mouse.
163 ///
164 /// This property is only relevant for widgets that can take focus.
165 ///
166 /// Readable | Writeable
167 ///
168 ///
169 /// #### `focusable`
170 /// Whether this widget itself will accept the input focus.
171 ///
172 /// Readable | Writeable
173 ///
174 ///
175 /// #### `halign`
176 /// How to distribute horizontal space if widget gets extra space.
177 ///
178 /// Readable | Writeable
179 ///
180 ///
181 /// #### `has-default`
182 /// Whether the widget is the default widget.
183 ///
184 /// Readable
185 ///
186 ///
187 /// #### `has-focus`
188 /// Whether the widget has the input focus.
189 ///
190 /// Readable
191 ///
192 ///
193 /// #### `has-tooltip`
194 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
195 /// signal on @widget.
196 ///
197 /// A true value indicates that @widget can have a tooltip, in this case
198 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
199 /// determine whether it will provide a tooltip or not.
200 ///
201 /// Readable | Writeable
202 ///
203 ///
204 /// #### `height-request`
205 /// Overrides for height request of the widget.
206 ///
207 /// If this is -1, the natural request will be used.
208 ///
209 /// Readable | Writeable
210 ///
211 ///
212 /// #### `hexpand`
213 /// Whether to expand horizontally.
214 ///
215 /// Readable | Writeable
216 ///
217 ///
218 /// #### `hexpand-set`
219 /// Whether to use the `hexpand` property.
220 ///
221 /// Readable | Writeable
222 ///
223 ///
224 /// #### `layout-manager`
225 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
226 /// the preferred size of the widget, and allocate its children.
227 ///
228 /// This property is meant to be set by widget implementations,
229 /// typically in their instance init function.
230 ///
231 /// Readable | Writeable
232 ///
233 ///
234 /// #### `limit-events`
235 /// Makes this widget act like a modal dialog, with respect to
236 /// event delivery.
237 ///
238 /// Global event controllers will not handle events with targets
239 /// inside the widget, unless they are set up to ignore propagation
240 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
241 ///
242 /// Readable | Writeable
243 ///
244 ///
245 /// #### `margin-bottom`
246 /// Margin on bottom side of widget.
247 ///
248 /// This property adds margin outside of the widget's normal size
249 /// request, the margin will be added in addition to the size from
250 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
251 ///
252 /// Readable | Writeable
253 ///
254 ///
255 /// #### `margin-end`
256 /// Margin on end of widget, horizontally.
257 ///
258 /// This property supports left-to-right and right-to-left text
259 /// directions.
260 ///
261 /// This property adds margin outside of the widget's normal size
262 /// request, the margin will be added in addition to the size from
263 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
264 ///
265 /// Readable | Writeable
266 ///
267 ///
268 /// #### `margin-start`
269 /// Margin on start of widget, horizontally.
270 ///
271 /// This property supports left-to-right and right-to-left text
272 /// directions.
273 ///
274 /// This property adds margin outside of the widget's normal size
275 /// request, the margin will be added in addition to the size from
276 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
277 ///
278 /// Readable | Writeable
279 ///
280 ///
281 /// #### `margin-top`
282 /// Margin on top side of widget.
283 ///
284 /// This property adds margin outside of the widget's normal size
285 /// request, the margin will be added in addition to the size from
286 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
287 ///
288 /// Readable | Writeable
289 ///
290 ///
291 /// #### `name`
292 /// The name of the widget.
293 ///
294 /// Readable | Writeable
295 ///
296 ///
297 /// #### `opacity`
298 /// The requested opacity of the widget.
299 ///
300 /// Readable | Writeable
301 ///
302 ///
303 /// #### `overflow`
304 /// How content outside the widget's content area is treated.
305 ///
306 /// This property is meant to be set by widget implementations,
307 /// typically in their instance init function.
308 ///
309 /// Readable | Writeable
310 ///
311 ///
312 /// #### `parent`
313 /// The parent widget of this widget.
314 ///
315 /// Readable
316 ///
317 ///
318 /// #### `receives-default`
319 /// Whether the widget will receive the default action when it is focused.
320 ///
321 /// Readable | Writeable
322 ///
323 ///
324 /// #### `root`
325 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
326 ///
327 /// This will be `NULL` if the widget is not contained in a root widget.
328 ///
329 /// Readable
330 ///
331 ///
332 /// #### `scale-factor`
333 /// The scale factor of the widget.
334 ///
335 /// Readable
336 ///
337 ///
338 /// #### `sensitive`
339 /// Whether the widget responds to input.
340 ///
341 /// Readable | Writeable
342 ///
343 ///
344 /// #### `tooltip-markup`
345 /// Sets the text of tooltip to be the given string, which is marked up
346 /// with Pango markup.
347 ///
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 `NULL`:
352 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
353 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
354 /// the default signal handler.
355 ///
356 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
357 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
358 ///
359 /// Readable | Writeable
360 ///
361 ///
362 /// #### `tooltip-text`
363 /// Sets the text of tooltip to be the given string.
364 ///
365 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
366 ///
367 /// This is a convenience property which will take care of getting the
368 /// tooltip shown if the given string is not `NULL`:
369 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
370 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
371 /// the default signal handler.
372 ///
373 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
374 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
375 ///
376 /// Readable | Writeable
377 ///
378 ///
379 /// #### `valign`
380 /// How to distribute vertical space if widget gets extra space.
381 ///
382 /// Readable | Writeable
383 ///
384 ///
385 /// #### `vexpand`
386 /// Whether to expand vertically.
387 ///
388 /// Readable | Writeable
389 ///
390 ///
391 /// #### `vexpand-set`
392 /// Whether to use the `vexpand` property.
393 ///
394 /// Readable | Writeable
395 ///
396 ///
397 /// #### `visible`
398 /// Whether the widget is visible.
399 ///
400 /// Readable | Writeable
401 ///
402 ///
403 /// #### `width-request`
404 /// Overrides for width request of the widget.
405 ///
406 /// If this is -1, the natural request will be used.
407 ///
408 /// Readable | Writeable
409 /// </details>
410 /// <details><summary><h4>Accessible</h4></summary>
411 ///
412 ///
413 /// #### `accessible-role`
414 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
415 ///
416 /// The accessible role cannot be changed once set.
417 ///
418 /// Readable | Writeable
419 /// </details>
420 /// <details><summary><h4>Actionable</h4></summary>
421 ///
422 ///
423 /// #### `action-name`
424 /// The name of the action with which this widget should be associated.
425 ///
426 /// Readable | Writeable
427 ///
428 ///
429 /// #### `action-target`
430 /// The target value of the actionable widget's action.
431 ///
432 /// Readable | Writeable
433 /// </details>
434 ///
435 /// ## Signals
436 ///
437 ///
438 /// #### `activate-link`
439 /// Emitted each time the [`LinkButton`][crate::LinkButton] is clicked.
440 ///
441 /// The default handler will call [`FileLauncher::launch()`][crate::FileLauncher::launch()] with the URI
442 /// stored inside the [`uri`][struct@crate::LinkButton#uri] property.
443 ///
444 /// To override the default behavior, you can connect to the
445 /// ::activate-link signal and stop the propagation of the signal
446 /// by returning [`true`] from your handler.
447 ///
448 ///
449 /// <details><summary><h4>Button</h4></summary>
450 ///
451 ///
452 /// #### `activate`
453 /// Emitted to animate press then release.
454 ///
455 /// This is an action signal. Applications should never connect
456 /// to this signal, but use the [`clicked`][struct@crate::Button#clicked] signal.
457 ///
458 /// The default bindings for this signal are all forms of the
459 /// <kbd>␣</kbd> and <kbd>Enter</kbd> keys.
460 ///
461 /// Action
462 ///
463 ///
464 /// #### `clicked`
465 /// Emitted when the button has been activated (pressed and released).
466 ///
467 /// Action
468 /// </details>
469 /// <details><summary><h4>Widget</h4></summary>
470 ///
471 ///
472 /// #### `destroy`
473 /// Signals that all holders of a reference to the widget should release
474 /// the reference that they hold.
475 ///
476 /// May result in finalization of the widget if all references are released.
477 ///
478 /// This signal is not suitable for saving widget state.
479 ///
480 ///
481 ///
482 ///
483 /// #### `direction-changed`
484 /// Emitted when the text direction of a widget changes.
485 ///
486 ///
487 ///
488 ///
489 /// #### `hide`
490 /// Emitted when @widget is hidden.
491 ///
492 ///
493 ///
494 ///
495 /// #### `keynav-failed`
496 /// Emitted if keyboard navigation fails.
497 ///
498 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
499 ///
500 ///
501 ///
502 ///
503 /// #### `map`
504 /// Emitted when @widget is going to be mapped.
505 ///
506 /// A widget is mapped when the widget is visible (which is controlled with
507 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
508 /// are also visible.
509 ///
510 /// The `::map` signal can be used to determine whether a widget will be drawn,
511 /// for instance it can resume an animation that was stopped during the
512 /// emission of [`unmap`][struct@crate::Widget#unmap].
513 ///
514 ///
515 ///
516 ///
517 /// #### `mnemonic-activate`
518 /// Emitted when a widget is activated via a mnemonic.
519 ///
520 /// The default handler for this signal activates @widget if @group_cycling
521 /// is false, or just makes @widget grab focus if @group_cycling is true.
522 ///
523 ///
524 ///
525 ///
526 /// #### `move-focus`
527 /// Emitted when the focus is moved.
528 ///
529 /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
530 ///
531 /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
532 /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
533 ///
534 /// Action
535 ///
536 ///
537 /// #### `query-tooltip`
538 /// Emitted when the widget’s tooltip is about to be shown.
539 ///
540 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
541 /// is true and the hover timeout has expired with the cursor hovering
542 /// above @widget; or emitted when @widget got focus in keyboard mode.
543 ///
544 /// Using the given coordinates, the signal handler should determine
545 /// whether a tooltip should be shown for @widget. If this is the case
546 /// true should be returned, false otherwise. Note that if @keyboard_mode
547 /// is true, the values of @x and @y are undefined and should not be used.
548 ///
549 /// The signal handler is free to manipulate @tooltip with the therefore
550 /// destined function calls.
551 ///
552 ///
553 ///
554 ///
555 /// #### `realize`
556 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
557 ///
558 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
559 /// or the widget has been mapped (that is, it is going to be drawn).
560 ///
561 ///
562 ///
563 ///
564 /// #### `show`
565 /// Emitted when @widget is shown.
566 ///
567 ///
568 ///
569 ///
570 /// #### `state-flags-changed`
571 /// Emitted when the widget state changes.
572 ///
573 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
574 ///
575 ///
576 ///
577 ///
578 /// #### `unmap`
579 /// Emitted when @widget is going to be unmapped.
580 ///
581 /// A widget is unmapped when either it or any of its parents up to the
582 /// toplevel widget have been set as hidden.
583 ///
584 /// As `::unmap` indicates that a widget will not be shown any longer,
585 /// it can be used to, for example, stop an animation on the widget.
586 ///
587 ///
588 ///
589 ///
590 /// #### `unrealize`
591 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
592 ///
593 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
594 /// or the widget has been unmapped (that is, it is going to be hidden).
595 ///
596 ///
597 /// </details>
598 ///
599 /// # Implements
600 ///
601 /// [`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]
602 #[doc(alias = "GtkLinkButton")]
603 pub struct LinkButton(Object<ffi::GtkLinkButton>) @extends Button, Widget, @implements Accessible, Buildable, ConstraintTarget, Actionable;
604
605 match fn {
606 type_ => || ffi::gtk_link_button_get_type(),
607 }
608}
609
610impl LinkButton {
611 /// Creates a new [`LinkButton`][crate::LinkButton] with the URI as its text.
612 /// ## `uri`
613 /// a valid URI
614 ///
615 /// # Returns
616 ///
617 /// a new link button widget.
618 #[doc(alias = "gtk_link_button_new")]
619 pub fn new(uri: &str) -> LinkButton {
620 assert_initialized_main_thread!();
621 unsafe {
622 Widget::from_glib_none(ffi::gtk_link_button_new(uri.to_glib_none().0)).unsafe_cast()
623 }
624 }
625
626 /// Creates a new [`LinkButton`][crate::LinkButton] containing a label.
627 /// ## `uri`
628 /// a valid URI
629 /// ## `label`
630 /// the text of the button
631 ///
632 /// # Returns
633 ///
634 /// a new link button widget.
635 #[doc(alias = "gtk_link_button_new_with_label")]
636 #[doc(alias = "new_with_label")]
637 pub fn with_label(uri: &str, label: &str) -> LinkButton {
638 assert_initialized_main_thread!();
639 unsafe {
640 Widget::from_glib_none(ffi::gtk_link_button_new_with_label(
641 uri.to_glib_none().0,
642 label.to_glib_none().0,
643 ))
644 .unsafe_cast()
645 }
646 }
647
648 // rustdoc-stripper-ignore-next
649 /// Creates a new builder-pattern struct instance to construct [`LinkButton`] objects.
650 ///
651 /// This method returns an instance of [`LinkButtonBuilder`](crate::builders::LinkButtonBuilder) which can be used to create [`LinkButton`] objects.
652 pub fn builder() -> LinkButtonBuilder {
653 LinkButtonBuilder::new()
654 }
655
656 /// Retrieves the URI of the [`LinkButton`][crate::LinkButton].
657 ///
658 /// # Returns
659 ///
660 /// a valid URI. The returned string is owned by the link button
661 /// and should not be modified or freed.
662 #[doc(alias = "gtk_link_button_get_uri")]
663 #[doc(alias = "get_uri")]
664 pub fn uri(&self) -> glib::GString {
665 unsafe { from_glib_none(ffi::gtk_link_button_get_uri(self.to_glib_none().0)) }
666 }
667
668 /// Retrieves the “visited” state of the [`LinkButton`][crate::LinkButton].
669 ///
670 /// The button becomes visited when it is clicked. If the URI
671 /// is changed on the button, the “visited” state is unset again.
672 ///
673 /// The state may also be changed using [`set_visited()`][Self::set_visited()].
674 ///
675 /// # Returns
676 ///
677 /// [`true`] if the link has been visited, [`false`] otherwise
678 #[doc(alias = "gtk_link_button_get_visited")]
679 #[doc(alias = "get_visited")]
680 #[doc(alias = "visited")]
681 pub fn is_visited(&self) -> bool {
682 unsafe { from_glib(ffi::gtk_link_button_get_visited(self.to_glib_none().0)) }
683 }
684
685 /// Sets @uri as the URI where the [`LinkButton`][crate::LinkButton] points.
686 ///
687 /// As a side-effect this unsets the “visited” state of the button.
688 /// ## `uri`
689 /// a valid URI
690 #[doc(alias = "gtk_link_button_set_uri")]
691 #[doc(alias = "uri")]
692 pub fn set_uri(&self, uri: &str) {
693 unsafe {
694 ffi::gtk_link_button_set_uri(self.to_glib_none().0, uri.to_glib_none().0);
695 }
696 }
697
698 /// Sets the “visited” state of the [`LinkButton`][crate::LinkButton].
699 ///
700 /// See [`is_visited()`][Self::is_visited()] for more details.
701 /// ## `visited`
702 /// the new “visited” state
703 #[doc(alias = "gtk_link_button_set_visited")]
704 #[doc(alias = "visited")]
705 pub fn set_visited(&self, visited: bool) {
706 unsafe {
707 ffi::gtk_link_button_set_visited(self.to_glib_none().0, visited.into_glib());
708 }
709 }
710
711 /// Emitted each time the [`LinkButton`][crate::LinkButton] is clicked.
712 ///
713 /// The default handler will call [`FileLauncher::launch()`][crate::FileLauncher::launch()] with the URI
714 /// stored inside the [`uri`][struct@crate::LinkButton#uri] property.
715 ///
716 /// To override the default behavior, you can connect to the
717 /// ::activate-link signal and stop the propagation of the signal
718 /// by returning [`true`] from your handler.
719 ///
720 /// # Returns
721 ///
722 /// [`true`] if the signal has been handled
723 #[doc(alias = "activate-link")]
724 pub fn connect_activate_link<F: Fn(&Self) -> glib::Propagation + 'static>(
725 &self,
726 f: F,
727 ) -> SignalHandlerId {
728 unsafe extern "C" fn activate_link_trampoline<
729 F: Fn(&LinkButton) -> glib::Propagation + 'static,
730 >(
731 this: *mut ffi::GtkLinkButton,
732 f: glib::ffi::gpointer,
733 ) -> glib::ffi::gboolean {
734 let f: &F = &*(f as *const F);
735 f(&from_glib_borrow(this)).into_glib()
736 }
737 unsafe {
738 let f: Box_<F> = Box_::new(f);
739 connect_raw(
740 self.as_ptr() as *mut _,
741 c"activate-link".as_ptr() as *const _,
742 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
743 activate_link_trampoline::<F> as *const (),
744 )),
745 Box_::into_raw(f),
746 )
747 }
748 }
749
750 #[doc(alias = "uri")]
751 pub fn connect_uri_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
752 unsafe extern "C" fn notify_uri_trampoline<F: Fn(&LinkButton) + 'static>(
753 this: *mut ffi::GtkLinkButton,
754 _param_spec: glib::ffi::gpointer,
755 f: glib::ffi::gpointer,
756 ) {
757 let f: &F = &*(f as *const F);
758 f(&from_glib_borrow(this))
759 }
760 unsafe {
761 let f: Box_<F> = Box_::new(f);
762 connect_raw(
763 self.as_ptr() as *mut _,
764 c"notify::uri".as_ptr() as *const _,
765 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
766 notify_uri_trampoline::<F> as *const (),
767 )),
768 Box_::into_raw(f),
769 )
770 }
771 }
772
773 #[doc(alias = "visited")]
774 pub fn connect_visited_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
775 unsafe extern "C" fn notify_visited_trampoline<F: Fn(&LinkButton) + 'static>(
776 this: *mut ffi::GtkLinkButton,
777 _param_spec: glib::ffi::gpointer,
778 f: glib::ffi::gpointer,
779 ) {
780 let f: &F = &*(f as *const F);
781 f(&from_glib_borrow(this))
782 }
783 unsafe {
784 let f: Box_<F> = Box_::new(f);
785 connect_raw(
786 self.as_ptr() as *mut _,
787 c"notify::visited".as_ptr() as *const _,
788 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
789 notify_visited_trampoline::<F> as *const (),
790 )),
791 Box_::into_raw(f),
792 )
793 }
794 }
795}
796
797impl Default for LinkButton {
798 fn default() -> Self {
799 glib::object::Object::new::<Self>()
800 }
801}
802
803// rustdoc-stripper-ignore-next
804/// A [builder-pattern] type to construct [`LinkButton`] objects.
805///
806/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
807#[must_use = "The builder must be built to be used"]
808pub struct LinkButtonBuilder {
809 builder: glib::object::ObjectBuilder<'static, LinkButton>,
810}
811
812impl LinkButtonBuilder {
813 fn new() -> Self {
814 Self {
815 builder: glib::object::Object::builder(),
816 }
817 }
818
819 /// The URI bound to this button.
820 pub fn uri(self, uri: impl Into<glib::GString>) -> Self {
821 Self {
822 builder: self.builder.property("uri", uri.into()),
823 }
824 }
825
826 /// The 'visited' state of this button.
827 ///
828 /// A visited link is drawn in a different color.
829 pub fn visited(self, visited: bool) -> Self {
830 Self {
831 builder: self.builder.property("visited", visited),
832 }
833 }
834
835 /// Whether the size of the button can be made smaller than the natural
836 /// size of its contents.
837 ///
838 /// For text buttons, setting this property will allow ellipsizing the label.
839 ///
840 /// If the contents of a button are an icon or a custom widget, setting this
841 /// property has no effect.
842 #[cfg(feature = "v4_12")]
843 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
844 pub fn can_shrink(self, can_shrink: bool) -> Self {
845 Self {
846 builder: self.builder.property("can-shrink", can_shrink),
847 }
848 }
849
850 /// The child widget.
851 pub fn child(self, child: &impl IsA<Widget>) -> Self {
852 Self {
853 builder: self.builder.property("child", child.clone().upcast()),
854 }
855 }
856
857 /// Whether the button has a frame.
858 pub fn has_frame(self, has_frame: bool) -> Self {
859 Self {
860 builder: self.builder.property("has-frame", has_frame),
861 }
862 }
863
864 /// The name of the icon used to automatically populate the button.
865 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
866 Self {
867 builder: self.builder.property("icon-name", icon_name.into()),
868 }
869 }
870
871 /// Text of the label inside the button, if the button contains a label widget.
872 pub fn label(self, label: impl Into<glib::GString>) -> Self {
873 Self {
874 builder: self.builder.property("label", label.into()),
875 }
876 }
877
878 /// If set, an underline in the text indicates that the following character is
879 /// to be used as mnemonic.
880 pub fn use_underline(self, use_underline: bool) -> Self {
881 Self {
882 builder: self.builder.property("use-underline", use_underline),
883 }
884 }
885
886 /// Whether the widget or any of its descendents can accept
887 /// the input focus.
888 ///
889 /// This property is meant to be set by widget implementations,
890 /// typically in their instance init function.
891 pub fn can_focus(self, can_focus: bool) -> Self {
892 Self {
893 builder: self.builder.property("can-focus", can_focus),
894 }
895 }
896
897 /// Whether the widget can receive pointer events.
898 pub fn can_target(self, can_target: bool) -> Self {
899 Self {
900 builder: self.builder.property("can-target", can_target),
901 }
902 }
903
904 /// A list of css classes applied to this widget.
905 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
906 Self {
907 builder: self.builder.property("css-classes", css_classes.into()),
908 }
909 }
910
911 /// The name of this widget in the CSS tree.
912 ///
913 /// This property is meant to be set by widget implementations,
914 /// typically in their instance init function.
915 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
916 Self {
917 builder: self.builder.property("css-name", css_name.into()),
918 }
919 }
920
921 /// The cursor used by @widget.
922 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
923 Self {
924 builder: self.builder.property("cursor", cursor.clone()),
925 }
926 }
927
928 /// Whether the widget should grab focus when it is clicked with the mouse.
929 ///
930 /// This property is only relevant for widgets that can take focus.
931 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
932 Self {
933 builder: self.builder.property("focus-on-click", focus_on_click),
934 }
935 }
936
937 /// Whether this widget itself will accept the input focus.
938 pub fn focusable(self, focusable: bool) -> Self {
939 Self {
940 builder: self.builder.property("focusable", focusable),
941 }
942 }
943
944 /// How to distribute horizontal space if widget gets extra space.
945 pub fn halign(self, halign: Align) -> Self {
946 Self {
947 builder: self.builder.property("halign", halign),
948 }
949 }
950
951 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
952 /// signal on @widget.
953 ///
954 /// A true value indicates that @widget can have a tooltip, in this case
955 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
956 /// determine whether it will provide a tooltip or not.
957 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
958 Self {
959 builder: self.builder.property("has-tooltip", has_tooltip),
960 }
961 }
962
963 /// Overrides for height request of the widget.
964 ///
965 /// If this is -1, the natural request will be used.
966 pub fn height_request(self, height_request: i32) -> Self {
967 Self {
968 builder: self.builder.property("height-request", height_request),
969 }
970 }
971
972 /// Whether to expand horizontally.
973 pub fn hexpand(self, hexpand: bool) -> Self {
974 Self {
975 builder: self.builder.property("hexpand", hexpand),
976 }
977 }
978
979 /// Whether to use the `hexpand` property.
980 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
981 Self {
982 builder: self.builder.property("hexpand-set", hexpand_set),
983 }
984 }
985
986 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
987 /// the preferred size of the widget, and allocate its children.
988 ///
989 /// This property is meant to be set by widget implementations,
990 /// typically in their instance init function.
991 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
992 Self {
993 builder: self
994 .builder
995 .property("layout-manager", layout_manager.clone().upcast()),
996 }
997 }
998
999 /// Makes this widget act like a modal dialog, with respect to
1000 /// event delivery.
1001 ///
1002 /// Global event controllers will not handle events with targets
1003 /// inside the widget, unless they are set up to ignore propagation
1004 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1005 #[cfg(feature = "v4_18")]
1006 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1007 pub fn limit_events(self, limit_events: bool) -> Self {
1008 Self {
1009 builder: self.builder.property("limit-events", limit_events),
1010 }
1011 }
1012
1013 /// Margin on bottom side of widget.
1014 ///
1015 /// This property adds margin outside of the widget's normal size
1016 /// request, the margin will be added in addition to the size from
1017 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1018 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1019 Self {
1020 builder: self.builder.property("margin-bottom", margin_bottom),
1021 }
1022 }
1023
1024 /// Margin on end of widget, horizontally.
1025 ///
1026 /// This property supports left-to-right and right-to-left text
1027 /// directions.
1028 ///
1029 /// This property adds margin outside of the widget's normal size
1030 /// request, the margin will be added in addition to the size from
1031 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1032 pub fn margin_end(self, margin_end: i32) -> Self {
1033 Self {
1034 builder: self.builder.property("margin-end", margin_end),
1035 }
1036 }
1037
1038 /// Margin on start of widget, horizontally.
1039 ///
1040 /// This property supports left-to-right and right-to-left text
1041 /// directions.
1042 ///
1043 /// This property adds margin outside of the widget's normal size
1044 /// request, the margin will be added in addition to the size from
1045 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1046 pub fn margin_start(self, margin_start: i32) -> Self {
1047 Self {
1048 builder: self.builder.property("margin-start", margin_start),
1049 }
1050 }
1051
1052 /// Margin on top side of widget.
1053 ///
1054 /// This property adds margin outside of the widget's normal size
1055 /// request, the margin will be added in addition to the size from
1056 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1057 pub fn margin_top(self, margin_top: i32) -> Self {
1058 Self {
1059 builder: self.builder.property("margin-top", margin_top),
1060 }
1061 }
1062
1063 /// The name of the widget.
1064 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1065 Self {
1066 builder: self.builder.property("name", name.into()),
1067 }
1068 }
1069
1070 /// The requested opacity of the widget.
1071 pub fn opacity(self, opacity: f64) -> Self {
1072 Self {
1073 builder: self.builder.property("opacity", opacity),
1074 }
1075 }
1076
1077 /// How content outside the widget's content area is treated.
1078 ///
1079 /// This property is meant to be set by widget implementations,
1080 /// typically in their instance init function.
1081 pub fn overflow(self, overflow: Overflow) -> Self {
1082 Self {
1083 builder: self.builder.property("overflow", overflow),
1084 }
1085 }
1086
1087 /// Whether the widget will receive the default action when it is focused.
1088 pub fn receives_default(self, receives_default: bool) -> Self {
1089 Self {
1090 builder: self.builder.property("receives-default", receives_default),
1091 }
1092 }
1093
1094 /// Whether the widget responds to input.
1095 pub fn sensitive(self, sensitive: bool) -> Self {
1096 Self {
1097 builder: self.builder.property("sensitive", sensitive),
1098 }
1099 }
1100
1101 /// Sets the text of tooltip to be the given string, which is marked up
1102 /// with Pango markup.
1103 ///
1104 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1105 ///
1106 /// This is a convenience property which will take care of getting the
1107 /// tooltip shown if the given string is not `NULL`:
1108 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1109 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1110 /// the default signal handler.
1111 ///
1112 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1113 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1114 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1115 Self {
1116 builder: self
1117 .builder
1118 .property("tooltip-markup", tooltip_markup.into()),
1119 }
1120 }
1121
1122 /// Sets the text of tooltip to be the given string.
1123 ///
1124 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1125 ///
1126 /// This is a convenience property which will take care of getting the
1127 /// tooltip shown if the given string is not `NULL`:
1128 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1129 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1130 /// the default signal handler.
1131 ///
1132 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1133 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1134 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1135 Self {
1136 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1137 }
1138 }
1139
1140 /// How to distribute vertical space if widget gets extra space.
1141 pub fn valign(self, valign: Align) -> Self {
1142 Self {
1143 builder: self.builder.property("valign", valign),
1144 }
1145 }
1146
1147 /// Whether to expand vertically.
1148 pub fn vexpand(self, vexpand: bool) -> Self {
1149 Self {
1150 builder: self.builder.property("vexpand", vexpand),
1151 }
1152 }
1153
1154 /// Whether to use the `vexpand` property.
1155 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1156 Self {
1157 builder: self.builder.property("vexpand-set", vexpand_set),
1158 }
1159 }
1160
1161 /// Whether the widget is visible.
1162 pub fn visible(self, visible: bool) -> Self {
1163 Self {
1164 builder: self.builder.property("visible", visible),
1165 }
1166 }
1167
1168 /// Overrides for width request of the widget.
1169 ///
1170 /// If this is -1, the natural request will be used.
1171 pub fn width_request(self, width_request: i32) -> Self {
1172 Self {
1173 builder: self.builder.property("width-request", width_request),
1174 }
1175 }
1176
1177 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1178 ///
1179 /// The accessible role cannot be changed once set.
1180 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1181 Self {
1182 builder: self.builder.property("accessible-role", accessible_role),
1183 }
1184 }
1185
1186 /// The name of the action with which this widget should be associated.
1187 pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
1188 Self {
1189 builder: self.builder.property("action-name", action_name.into()),
1190 }
1191 }
1192
1193 /// The target value of the actionable widget's action.
1194 pub fn action_target(self, action_target: &glib::Variant) -> Self {
1195 Self {
1196 builder: self
1197 .builder
1198 .property("action-target", action_target.clone()),
1199 }
1200 }
1201
1202 // rustdoc-stripper-ignore-next
1203 /// Build the [`LinkButton`].
1204 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1205 pub fn build(self) -> LinkButton {
1206 assert_initialized_main_thread!();
1207 self.builder.build()
1208 }
1209}