Skip to main content

gtk/auto/
viewport.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    Adjustment, Align, Bin, Buildable, Container, ResizeMode, Scrollable, ScrollablePolicy,
7    ShadowType, Widget,
8};
9use glib::{
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::{boxed::Box as Box_, fmt, mem::transmute};
15
16glib::wrapper! {
17    /// The [`Viewport`][crate::Viewport] widget acts as an adaptor class, implementing
18    /// scrollability for child widgets that lack their own scrolling
19    /// capabilities. Use GtkViewport to scroll child widgets such as
20    /// [`Grid`][crate::Grid], [`Box`][crate::Box], and so on.
21    ///
22    /// If a widget has native scrolling abilities, such as [`TextView`][crate::TextView],
23    /// [`TreeView`][crate::TreeView] or [`IconView`][crate::IconView], it can be added to a [`ScrolledWindow`][crate::ScrolledWindow]
24    /// with [`ContainerExt::add()`][crate::prelude::ContainerExt::add()]. If a widget does not, you must first add the
25    /// widget to a [`Viewport`][crate::Viewport], then add the viewport to the scrolled window.
26    /// [`ContainerExt::add()`][crate::prelude::ContainerExt::add()] does this automatically if a child that does not
27    /// implement [`Scrollable`][crate::Scrollable] is added to a [`ScrolledWindow`][crate::ScrolledWindow], so you can
28    /// ignore the presence of the viewport.
29    ///
30    /// The GtkViewport will start scrolling content only if allocated less
31    /// than the child widget’s minimum size in a given orientation.
32    ///
33    /// # CSS nodes
34    ///
35    /// GtkViewport has a single CSS node with name viewport.
36    ///
37    /// ## Properties
38    ///
39    ///
40    /// #### `shadow-type`
41    ///  Readable | Writeable
42    /// <details><summary><h4>Container</h4></summary>
43    ///
44    ///
45    /// #### `border-width`
46    ///  Readable | Writeable
47    ///
48    ///
49    /// #### `child`
50    ///  Writeable
51    ///
52    ///
53    /// #### `resize-mode`
54    ///  Readable | Writeable
55    /// </details>
56    /// <details><summary><h4>Widget</h4></summary>
57    ///
58    ///
59    /// #### `app-paintable`
60    ///  Readable | Writeable
61    ///
62    ///
63    /// #### `can-default`
64    ///  Readable | Writeable
65    ///
66    ///
67    /// #### `can-focus`
68    ///  Readable | Writeable
69    ///
70    ///
71    /// #### `composite-child`
72    ///  Readable
73    ///
74    ///
75    /// #### `double-buffered`
76    ///  Whether the widget is double buffered.
77    ///
78    /// Readable | Writeable
79    ///
80    ///
81    /// #### `events`
82    ///  Readable | Writeable
83    ///
84    ///
85    /// #### `expand`
86    ///  Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
87    ///
88    /// Readable | Writeable
89    ///
90    ///
91    /// #### `focus-on-click`
92    ///  Whether the widget should grab focus when it is clicked with the mouse.
93    ///
94    /// This property is only relevant for widgets that can take focus.
95    ///
96    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
97    /// GtkComboBox) implemented this property individually.
98    ///
99    /// Readable | Writeable
100    ///
101    ///
102    /// #### `halign`
103    ///  How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
104    ///
105    /// Readable | Writeable
106    ///
107    ///
108    /// #### `has-default`
109    ///  Readable | Writeable
110    ///
111    ///
112    /// #### `has-focus`
113    ///  Readable | Writeable
114    ///
115    ///
116    /// #### `has-tooltip`
117    ///  Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
118    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
119    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
120    /// whether it will provide a tooltip or not.
121    ///
122    /// Note that setting this property to [`true`] for the first time will change
123    /// the event masks of the GdkWindows of this widget to include leave-notify
124    /// and motion-notify events. This cannot and will not be undone when the
125    /// property is set to [`false`] again.
126    ///
127    /// Readable | Writeable
128    ///
129    ///
130    /// #### `height-request`
131    ///  Readable | Writeable
132    ///
133    ///
134    /// #### `hexpand`
135    ///  Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
136    ///
137    /// Readable | Writeable
138    ///
139    ///
140    /// #### `hexpand-set`
141    ///  Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
142    ///
143    /// Readable | Writeable
144    ///
145    ///
146    /// #### `is-focus`
147    ///  Readable | Writeable
148    ///
149    ///
150    /// #### `margin`
151    ///  Sets all four sides' margin at once. If read, returns max
152    /// margin on any side.
153    ///
154    /// Readable | Writeable
155    ///
156    ///
157    /// #### `margin-bottom`
158    ///  Margin on bottom side of widget.
159    ///
160    /// This property adds margin outside of the widget's normal size
161    /// request, the margin will be added in addition to the size from
162    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
163    ///
164    /// Readable | Writeable
165    ///
166    ///
167    /// #### `margin-end`
168    ///  Margin on end of widget, horizontally. This property supports
169    /// left-to-right and right-to-left text directions.
170    ///
171    /// This property adds margin outside of the widget's normal size
172    /// request, the margin will be added in addition to the size from
173    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
174    ///
175    /// Readable | Writeable
176    ///
177    ///
178    /// #### `margin-left`
179    ///  Margin on left side of widget.
180    ///
181    /// This property adds margin outside of the widget's normal size
182    /// request, the margin will be added in addition to the size from
183    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
184    ///
185    /// Readable | Writeable
186    ///
187    ///
188    /// #### `margin-right`
189    ///  Margin on right side of widget.
190    ///
191    /// This property adds margin outside of the widget's normal size
192    /// request, the margin will be added in addition to the size from
193    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
194    ///
195    /// Readable | Writeable
196    ///
197    ///
198    /// #### `margin-start`
199    ///  Margin on start of widget, horizontally. This property supports
200    /// left-to-right and right-to-left text directions.
201    ///
202    /// This property adds margin outside of the widget's normal size
203    /// request, the margin will be added in addition to the size from
204    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
205    ///
206    /// Readable | Writeable
207    ///
208    ///
209    /// #### `margin-top`
210    ///  Margin on top side of widget.
211    ///
212    /// This property adds margin outside of the widget's normal size
213    /// request, the margin will be added in addition to the size from
214    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
215    ///
216    /// Readable | Writeable
217    ///
218    ///
219    /// #### `name`
220    ///  Readable | Writeable
221    ///
222    ///
223    /// #### `no-show-all`
224    ///  Readable | Writeable
225    ///
226    ///
227    /// #### `opacity`
228    ///  The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
229    /// more details about window opacity.
230    ///
231    /// Before 3.8 this was only available in GtkWindow
232    ///
233    /// Readable | Writeable
234    ///
235    ///
236    /// #### `parent`
237    ///  Readable | Writeable
238    ///
239    ///
240    /// #### `receives-default`
241    ///  Readable | Writeable
242    ///
243    ///
244    /// #### `scale-factor`
245    ///  The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
246    /// more details about widget scaling.
247    ///
248    /// Readable
249    ///
250    ///
251    /// #### `sensitive`
252    ///  Readable | Writeable
253    ///
254    ///
255    /// #### `style`
256    ///  The style of the widget, which contains information about how it will look (colors, etc).
257    ///
258    /// Readable | Writeable
259    ///
260    ///
261    /// #### `tooltip-markup`
262    ///  Sets the text of tooltip to be the given string, which is marked up
263    /// with the [Pango text markup language][PangoMarkupFormat].
264    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
265    ///
266    /// This is a convenience property which will take care of getting the
267    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
268    /// will automatically be set to [`true`] and there will be taken care of
269    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
270    ///
271    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
272    /// are set, the last one wins.
273    ///
274    /// Readable | Writeable
275    ///
276    ///
277    /// #### `tooltip-text`
278    ///  Sets the text of tooltip to be the given string.
279    ///
280    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
281    ///
282    /// This is a convenience property which will take care of getting the
283    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
284    /// will automatically be set to [`true`] and there will be taken care of
285    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
286    ///
287    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
288    /// are set, the last one wins.
289    ///
290    /// Readable | Writeable
291    ///
292    ///
293    /// #### `valign`
294    ///  How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
295    ///
296    /// Readable | Writeable
297    ///
298    ///
299    /// #### `vexpand`
300    ///  Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
301    ///
302    /// Readable | Writeable
303    ///
304    ///
305    /// #### `vexpand-set`
306    ///  Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
307    ///
308    /// Readable | Writeable
309    ///
310    ///
311    /// #### `visible`
312    ///  Readable | Writeable
313    ///
314    ///
315    /// #### `width-request`
316    ///  Readable | Writeable
317    ///
318    ///
319    /// #### `window`
320    ///  The widget's window if it is realized, [`None`] otherwise.
321    ///
322    /// Readable
323    /// </details>
324    /// <details><summary><h4>Scrollable</h4></summary>
325    ///
326    ///
327    /// #### `hadjustment`
328    ///  Horizontal [`Adjustment`][crate::Adjustment] of the scrollable widget. This adjustment is
329    /// shared between the scrollable widget and its parent.
330    ///
331    /// Readable | Writeable | Construct
332    ///
333    ///
334    /// #### `hscroll-policy`
335    ///  Determines whether horizontal scrolling should start once the scrollable
336    /// widget is allocated less than its minimum width or less than its natural width.
337    ///
338    /// Readable | Writeable
339    ///
340    ///
341    /// #### `vadjustment`
342    ///  Verical [`Adjustment`][crate::Adjustment] of the scrollable widget. This adjustment is shared
343    /// between the scrollable widget and its parent.
344    ///
345    /// Readable | Writeable | Construct
346    ///
347    ///
348    /// #### `vscroll-policy`
349    ///  Determines whether vertical scrolling should start once the scrollable
350    /// widget is allocated less than its minimum height or less than its natural height.
351    ///
352    /// Readable | Writeable
353    /// </details>
354    ///
355    /// # Implements
356    ///
357    /// [`ViewportExt`][trait@crate::prelude::ViewportExt], [`BinExt`][trait@crate::prelude::BinExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ScrollableExt`][trait@crate::prelude::ScrollableExt], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
358    #[doc(alias = "GtkViewport")]
359    pub struct Viewport(Object<ffi::GtkViewport, ffi::GtkViewportClass>) @extends Bin, Container, Widget, @implements Buildable, Scrollable;
360
361    match fn {
362        type_ => || ffi::gtk_viewport_get_type(),
363    }
364}
365
366impl Viewport {
367    pub const NONE: Option<&'static Viewport> = None;
368
369    /// Creates a new [`Viewport`][crate::Viewport] with the given adjustments, or with default
370    /// adjustments if none are given.
371    /// ## `hadjustment`
372    /// horizontal adjustment
373    /// ## `vadjustment`
374    /// vertical adjustment
375    ///
376    /// # Returns
377    ///
378    /// a new [`Viewport`][crate::Viewport]
379    #[doc(alias = "gtk_viewport_new")]
380    pub fn new(
381        hadjustment: Option<&impl IsA<Adjustment>>,
382        vadjustment: Option<&impl IsA<Adjustment>>,
383    ) -> Viewport {
384        assert_initialized_main_thread!();
385        unsafe {
386            Widget::from_glib_none(ffi::gtk_viewport_new(
387                hadjustment.map(|p| p.as_ref()).to_glib_none().0,
388                vadjustment.map(|p| p.as_ref()).to_glib_none().0,
389            ))
390            .unsafe_cast()
391        }
392    }
393
394    // rustdoc-stripper-ignore-next
395    /// Creates a new builder-pattern struct instance to construct [`Viewport`] objects.
396    ///
397    /// This method returns an instance of [`ViewportBuilder`](crate::builders::ViewportBuilder) which can be used to create [`Viewport`] objects.
398    pub fn builder() -> ViewportBuilder {
399        ViewportBuilder::new()
400    }
401}
402
403impl Default for Viewport {
404    fn default() -> Self {
405        glib::object::Object::new::<Self>()
406    }
407}
408
409// rustdoc-stripper-ignore-next
410/// A [builder-pattern] type to construct [`Viewport`] objects.
411///
412/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
413#[must_use = "The builder must be built to be used"]
414pub struct ViewportBuilder {
415    builder: glib::object::ObjectBuilder<'static, Viewport>,
416}
417
418impl ViewportBuilder {
419    fn new() -> Self {
420        Self {
421            builder: glib::object::Object::builder(),
422        }
423    }
424
425    pub fn shadow_type(self, shadow_type: ShadowType) -> Self {
426        Self {
427            builder: self.builder.property("shadow-type", shadow_type),
428        }
429    }
430
431    pub fn border_width(self, border_width: u32) -> Self {
432        Self {
433            builder: self.builder.property("border-width", border_width),
434        }
435    }
436
437    pub fn child(self, child: &impl IsA<Widget>) -> Self {
438        Self {
439            builder: self.builder.property("child", child.clone().upcast()),
440        }
441    }
442
443    pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
444        Self {
445            builder: self.builder.property("resize-mode", resize_mode),
446        }
447    }
448
449    pub fn app_paintable(self, app_paintable: bool) -> Self {
450        Self {
451            builder: self.builder.property("app-paintable", app_paintable),
452        }
453    }
454
455    pub fn can_default(self, can_default: bool) -> Self {
456        Self {
457            builder: self.builder.property("can-default", can_default),
458        }
459    }
460
461    pub fn can_focus(self, can_focus: bool) -> Self {
462        Self {
463            builder: self.builder.property("can-focus", can_focus),
464        }
465    }
466
467    pub fn events(self, events: gdk::EventMask) -> Self {
468        Self {
469            builder: self.builder.property("events", events),
470        }
471    }
472
473    /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
474    pub fn expand(self, expand: bool) -> Self {
475        Self {
476            builder: self.builder.property("expand", expand),
477        }
478    }
479
480    /// Whether the widget should grab focus when it is clicked with the mouse.
481    ///
482    /// This property is only relevant for widgets that can take focus.
483    ///
484    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
485    /// GtkComboBox) implemented this property individually.
486    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
487        Self {
488            builder: self.builder.property("focus-on-click", focus_on_click),
489        }
490    }
491
492    /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
493    pub fn halign(self, halign: Align) -> Self {
494        Self {
495            builder: self.builder.property("halign", halign),
496        }
497    }
498
499    pub fn has_default(self, has_default: bool) -> Self {
500        Self {
501            builder: self.builder.property("has-default", has_default),
502        }
503    }
504
505    pub fn has_focus(self, has_focus: bool) -> Self {
506        Self {
507            builder: self.builder.property("has-focus", has_focus),
508        }
509    }
510
511    /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
512    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
513    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
514    /// whether it will provide a tooltip or not.
515    ///
516    /// Note that setting this property to [`true`] for the first time will change
517    /// the event masks of the GdkWindows of this widget to include leave-notify
518    /// and motion-notify events. This cannot and will not be undone when the
519    /// property is set to [`false`] again.
520    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
521        Self {
522            builder: self.builder.property("has-tooltip", has_tooltip),
523        }
524    }
525
526    pub fn height_request(self, height_request: i32) -> Self {
527        Self {
528            builder: self.builder.property("height-request", height_request),
529        }
530    }
531
532    /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
533    pub fn hexpand(self, hexpand: bool) -> Self {
534        Self {
535            builder: self.builder.property("hexpand", hexpand),
536        }
537    }
538
539    /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
540    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
541        Self {
542            builder: self.builder.property("hexpand-set", hexpand_set),
543        }
544    }
545
546    pub fn is_focus(self, is_focus: bool) -> Self {
547        Self {
548            builder: self.builder.property("is-focus", is_focus),
549        }
550    }
551
552    /// Sets all four sides' margin at once. If read, returns max
553    /// margin on any side.
554    pub fn margin(self, margin: i32) -> Self {
555        Self {
556            builder: self.builder.property("margin", margin),
557        }
558    }
559
560    /// Margin on bottom side of widget.
561    ///
562    /// This property adds margin outside of the widget's normal size
563    /// request, the margin will be added in addition to the size from
564    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
565    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
566        Self {
567            builder: self.builder.property("margin-bottom", margin_bottom),
568        }
569    }
570
571    /// Margin on end of widget, horizontally. This property supports
572    /// left-to-right and right-to-left text directions.
573    ///
574    /// This property adds margin outside of the widget's normal size
575    /// request, the margin will be added in addition to the size from
576    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
577    pub fn margin_end(self, margin_end: i32) -> Self {
578        Self {
579            builder: self.builder.property("margin-end", margin_end),
580        }
581    }
582
583    /// Margin on start of widget, horizontally. This property supports
584    /// left-to-right and right-to-left text directions.
585    ///
586    /// This property adds margin outside of the widget's normal size
587    /// request, the margin will be added in addition to the size from
588    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
589    pub fn margin_start(self, margin_start: i32) -> Self {
590        Self {
591            builder: self.builder.property("margin-start", margin_start),
592        }
593    }
594
595    /// Margin on top side of widget.
596    ///
597    /// This property adds margin outside of the widget's normal size
598    /// request, the margin will be added in addition to the size from
599    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
600    pub fn margin_top(self, margin_top: i32) -> Self {
601        Self {
602            builder: self.builder.property("margin-top", margin_top),
603        }
604    }
605
606    pub fn name(self, name: impl Into<glib::GString>) -> Self {
607        Self {
608            builder: self.builder.property("name", name.into()),
609        }
610    }
611
612    pub fn no_show_all(self, no_show_all: bool) -> Self {
613        Self {
614            builder: self.builder.property("no-show-all", no_show_all),
615        }
616    }
617
618    /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
619    /// more details about window opacity.
620    ///
621    /// Before 3.8 this was only available in GtkWindow
622    pub fn opacity(self, opacity: f64) -> Self {
623        Self {
624            builder: self.builder.property("opacity", opacity),
625        }
626    }
627
628    pub fn parent(self, parent: &impl IsA<Container>) -> Self {
629        Self {
630            builder: self.builder.property("parent", parent.clone().upcast()),
631        }
632    }
633
634    pub fn receives_default(self, receives_default: bool) -> Self {
635        Self {
636            builder: self.builder.property("receives-default", receives_default),
637        }
638    }
639
640    pub fn sensitive(self, sensitive: bool) -> Self {
641        Self {
642            builder: self.builder.property("sensitive", sensitive),
643        }
644    }
645
646    /// Sets the text of tooltip to be the given string, which is marked up
647    /// with the [Pango text markup language][PangoMarkupFormat].
648    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
649    ///
650    /// This is a convenience property which will take care of getting the
651    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
652    /// will automatically be set to [`true`] and there will be taken care of
653    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
654    ///
655    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
656    /// are set, the last one wins.
657    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
658        Self {
659            builder: self
660                .builder
661                .property("tooltip-markup", tooltip_markup.into()),
662        }
663    }
664
665    /// Sets the text of tooltip to be the given string.
666    ///
667    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
668    ///
669    /// This is a convenience property which will take care of getting the
670    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
671    /// will automatically be set to [`true`] and there will be taken care of
672    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
673    ///
674    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
675    /// are set, the last one wins.
676    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
677        Self {
678            builder: self.builder.property("tooltip-text", tooltip_text.into()),
679        }
680    }
681
682    /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
683    pub fn valign(self, valign: Align) -> Self {
684        Self {
685            builder: self.builder.property("valign", valign),
686        }
687    }
688
689    /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
690    pub fn vexpand(self, vexpand: bool) -> Self {
691        Self {
692            builder: self.builder.property("vexpand", vexpand),
693        }
694    }
695
696    /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
697    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
698        Self {
699            builder: self.builder.property("vexpand-set", vexpand_set),
700        }
701    }
702
703    pub fn visible(self, visible: bool) -> Self {
704        Self {
705            builder: self.builder.property("visible", visible),
706        }
707    }
708
709    pub fn width_request(self, width_request: i32) -> Self {
710        Self {
711            builder: self.builder.property("width-request", width_request),
712        }
713    }
714
715    /// Horizontal [`Adjustment`][crate::Adjustment] of the scrollable widget. This adjustment is
716    /// shared between the scrollable widget and its parent.
717    pub fn hadjustment(self, hadjustment: &impl IsA<Adjustment>) -> Self {
718        Self {
719            builder: self
720                .builder
721                .property("hadjustment", hadjustment.clone().upcast()),
722        }
723    }
724
725    /// Determines whether horizontal scrolling should start once the scrollable
726    /// widget is allocated less than its minimum width or less than its natural width.
727    pub fn hscroll_policy(self, hscroll_policy: ScrollablePolicy) -> Self {
728        Self {
729            builder: self.builder.property("hscroll-policy", hscroll_policy),
730        }
731    }
732
733    /// Verical [`Adjustment`][crate::Adjustment] of the scrollable widget. This adjustment is shared
734    /// between the scrollable widget and its parent.
735    pub fn vadjustment(self, vadjustment: &impl IsA<Adjustment>) -> Self {
736        Self {
737            builder: self
738                .builder
739                .property("vadjustment", vadjustment.clone().upcast()),
740        }
741    }
742
743    /// Determines whether vertical scrolling should start once the scrollable
744    /// widget is allocated less than its minimum height or less than its natural height.
745    pub fn vscroll_policy(self, vscroll_policy: ScrollablePolicy) -> Self {
746        Self {
747            builder: self.builder.property("vscroll-policy", vscroll_policy),
748        }
749    }
750
751    // rustdoc-stripper-ignore-next
752    /// Build the [`Viewport`].
753    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
754    pub fn build(self) -> Viewport {
755        self.builder.build()
756    }
757}
758
759mod sealed {
760    pub trait Sealed {}
761    impl<T: super::IsA<super::Viewport>> Sealed for T {}
762}
763
764/// Trait containing all [`struct@Viewport`] methods.
765///
766/// # Implementors
767///
768/// [`Viewport`][struct@crate::Viewport]
769pub trait ViewportExt: IsA<Viewport> + sealed::Sealed + 'static {
770    /// Gets the bin window of the [`Viewport`][crate::Viewport].
771    ///
772    /// # Returns
773    ///
774    /// a [`gdk::Window`][crate::gdk::Window]
775    #[doc(alias = "gtk_viewport_get_bin_window")]
776    #[doc(alias = "get_bin_window")]
777    fn bin_window(&self) -> Option<gdk::Window> {
778        unsafe {
779            from_glib_none(ffi::gtk_viewport_get_bin_window(
780                self.as_ref().to_glib_none().0,
781            ))
782        }
783    }
784
785    /// Gets the shadow type of the [`Viewport`][crate::Viewport]. See
786    /// [`set_shadow_type()`][Self::set_shadow_type()].
787    ///
788    /// # Returns
789    ///
790    /// the shadow type
791    #[doc(alias = "gtk_viewport_get_shadow_type")]
792    #[doc(alias = "get_shadow_type")]
793    fn shadow_type(&self) -> ShadowType {
794        unsafe {
795            from_glib(ffi::gtk_viewport_get_shadow_type(
796                self.as_ref().to_glib_none().0,
797            ))
798        }
799    }
800
801    /// Gets the view window of the [`Viewport`][crate::Viewport].
802    ///
803    /// # Returns
804    ///
805    /// a [`gdk::Window`][crate::gdk::Window]
806    #[doc(alias = "gtk_viewport_get_view_window")]
807    #[doc(alias = "get_view_window")]
808    fn view_window(&self) -> Option<gdk::Window> {
809        unsafe {
810            from_glib_none(ffi::gtk_viewport_get_view_window(
811                self.as_ref().to_glib_none().0,
812            ))
813        }
814    }
815
816    /// Sets the shadow type of the viewport.
817    /// ## `type_`
818    /// the new shadow type.
819    #[doc(alias = "gtk_viewport_set_shadow_type")]
820    fn set_shadow_type(&self, type_: ShadowType) {
821        unsafe {
822            ffi::gtk_viewport_set_shadow_type(self.as_ref().to_glib_none().0, type_.into_glib());
823        }
824    }
825
826    #[doc(alias = "shadow-type")]
827    fn connect_shadow_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
828        unsafe extern "C" fn notify_shadow_type_trampoline<
829            P: IsA<Viewport>,
830            F: Fn(&P) + 'static,
831        >(
832            this: *mut ffi::GtkViewport,
833            _param_spec: glib::ffi::gpointer,
834            f: glib::ffi::gpointer,
835        ) {
836            let f: &F = &*(f as *const F);
837            f(Viewport::from_glib_borrow(this).unsafe_cast_ref())
838        }
839        unsafe {
840            let f: Box_<F> = Box_::new(f);
841            connect_raw(
842                self.as_ptr() as *mut _,
843                b"notify::shadow-type\0".as_ptr() as *const _,
844                Some(transmute::<_, unsafe extern "C" fn()>(
845                    notify_shadow_type_trampoline::<Self, F> as *const (),
846                )),
847                Box_::into_raw(f),
848            )
849        }
850    }
851}
852
853impl<O: IsA<Viewport>> ViewportExt for O {}
854
855impl fmt::Display for Viewport {
856    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
857        f.write_str("Viewport")
858    }
859}