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