Skip to main content

gtk/auto/
scrollbar.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, Buildable, Container, Orientable, Orientation, Range, SensitivityType,
7    Widget,
8};
9use glib::{prelude::*, translate::*};
10use std::fmt;
11
12glib::wrapper! {
13    /// The [`Scrollbar`][crate::Scrollbar] widget is a horizontal or vertical scrollbar,
14    /// depending on the value of the [`orientation`][struct@crate::Orientable#orientation] property.
15    ///
16    /// Its position and movement are controlled by the adjustment that is passed to
17    /// or created by [`new()`][Self::new()]. See [`Adjustment`][crate::Adjustment] for more details. The
18    /// [`value`][struct@crate::Adjustment#value] field sets the position of the thumb and must be between
19    /// [`lower`][struct@crate::Adjustment#lower] and [`upper`][struct@crate::Adjustment#upper] - [`page-size`][struct@crate::Adjustment#page-size]. The
20    /// [`page-size`][struct@crate::Adjustment#page-size] represents the size of the visible scrollable area.
21    /// The fields [`step-increment`][struct@crate::Adjustment#step-increment] and [`page-increment`][struct@crate::Adjustment#page-increment]
22    /// fields are added to or subtracted from the [`value`][struct@crate::Adjustment#value] when the user
23    /// asks to move by a step (using e.g. the cursor arrow keys or, if present, the
24    /// stepper buttons) or by a page (using e.g. the Page Down/Up keys).
25    ///
26    /// # CSS nodes
27    ///
28    ///
29    ///
30    /// **⚠️ The following code is in plain ⚠️**
31    ///
32    /// ```plain
33    /// scrollbar[.fine-tune]
34    /// ╰── contents
35    ///     ├── [button.up]
36    ///     ├── [button.down]
37    ///     ├── trough
38    ///     │   ╰── slider
39    ///     ├── [button.up]
40    ///     ╰── [button.down]
41    /// ```
42    ///
43    /// GtkScrollbar has a main CSS node with name scrollbar and a subnode for its
44    /// contents, with subnodes named trough and slider.
45    ///
46    /// The main node gets the style class .fine-tune added when the scrollbar is
47    /// in 'fine-tuning' mode.
48    ///
49    /// If steppers are enabled, they are represented by up to four additional
50    /// subnodes with name button. These get the style classes .up and .down to
51    /// indicate in which direction they are moving.
52    ///
53    /// Other style classes that may be added to scrollbars inside [`ScrolledWindow`][crate::ScrolledWindow]
54    /// include the positional classes (.left, .right, .top, .bottom) and style
55    /// classes related to overlay scrolling (.overlay-indicator, .dragging, .hovering).
56    ///
57    /// # Implements
58    ///
59    /// [`RangeExt`][trait@crate::prelude::RangeExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`OrientableExt`][trait@crate::prelude::OrientableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
60    #[doc(alias = "GtkScrollbar")]
61    pub struct Scrollbar(Object<ffi::GtkScrollbar, ffi::GtkScrollbarClass>) @extends Range, Widget, @implements Buildable, Orientable;
62
63    match fn {
64        type_ => || ffi::gtk_scrollbar_get_type(),
65    }
66}
67
68impl Scrollbar {
69    pub const NONE: Option<&'static Scrollbar> = None;
70
71    /// Creates a new scrollbar with the given orientation.
72    /// ## `orientation`
73    /// the scrollbar’s orientation.
74    /// ## `adjustment`
75    /// the [`Adjustment`][crate::Adjustment] to use, or [`None`] to create a new adjustment.
76    ///
77    /// # Returns
78    ///
79    /// the new [`Scrollbar`][crate::Scrollbar].
80    #[doc(alias = "gtk_scrollbar_new")]
81    pub fn new(orientation: Orientation, adjustment: Option<&impl IsA<Adjustment>>) -> Scrollbar {
82        assert_initialized_main_thread!();
83        unsafe {
84            Widget::from_glib_none(ffi::gtk_scrollbar_new(
85                orientation.into_glib(),
86                adjustment.map(|p| p.as_ref()).to_glib_none().0,
87            ))
88            .unsafe_cast()
89        }
90    }
91
92    // rustdoc-stripper-ignore-next
93    /// Creates a new builder-pattern struct instance to construct [`Scrollbar`] objects.
94    ///
95    /// This method returns an instance of [`ScrollbarBuilder`](crate::builders::ScrollbarBuilder) which can be used to create [`Scrollbar`] objects.
96    pub fn builder() -> ScrollbarBuilder {
97        ScrollbarBuilder::new()
98    }
99}
100
101impl Default for Scrollbar {
102    fn default() -> Self {
103        glib::object::Object::new::<Self>()
104    }
105}
106
107// rustdoc-stripper-ignore-next
108/// A [builder-pattern] type to construct [`Scrollbar`] objects.
109///
110/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
111#[must_use = "The builder must be built to be used"]
112pub struct ScrollbarBuilder {
113    builder: glib::object::ObjectBuilder<'static, Scrollbar>,
114}
115
116impl ScrollbarBuilder {
117    fn new() -> Self {
118        Self {
119            builder: glib::object::Object::builder(),
120        }
121    }
122
123    pub fn adjustment(self, adjustment: &impl IsA<Adjustment>) -> Self {
124        Self {
125            builder: self
126                .builder
127                .property("adjustment", adjustment.clone().upcast()),
128        }
129    }
130
131    /// The fill level (e.g. prebuffering of a network stream).
132    /// See [`RangeExt::set_fill_level()`][crate::prelude::RangeExt::set_fill_level()].
133    pub fn fill_level(self, fill_level: f64) -> Self {
134        Self {
135            builder: self.builder.property("fill-level", fill_level),
136        }
137    }
138
139    pub fn inverted(self, inverted: bool) -> Self {
140        Self {
141            builder: self.builder.property("inverted", inverted),
142        }
143    }
144
145    pub fn lower_stepper_sensitivity(self, lower_stepper_sensitivity: SensitivityType) -> Self {
146        Self {
147            builder: self
148                .builder
149                .property("lower-stepper-sensitivity", lower_stepper_sensitivity),
150        }
151    }
152
153    /// The restrict-to-fill-level property controls whether slider
154    /// movement is restricted to an upper boundary set by the
155    /// fill level. See [`RangeExt::set_restrict_to_fill_level()`][crate::prelude::RangeExt::set_restrict_to_fill_level()].
156    pub fn restrict_to_fill_level(self, restrict_to_fill_level: bool) -> Self {
157        Self {
158            builder: self
159                .builder
160                .property("restrict-to-fill-level", restrict_to_fill_level),
161        }
162    }
163
164    /// The number of digits to round the value to when
165    /// it changes, or -1. See [`change-value`][struct@crate::Range#change-value].
166    pub fn round_digits(self, round_digits: i32) -> Self {
167        Self {
168            builder: self.builder.property("round-digits", round_digits),
169        }
170    }
171
172    /// The show-fill-level property controls whether fill level indicator
173    /// graphics are displayed on the trough. See
174    /// [`RangeExt::set_show_fill_level()`][crate::prelude::RangeExt::set_show_fill_level()].
175    pub fn show_fill_level(self, show_fill_level: bool) -> Self {
176        Self {
177            builder: self.builder.property("show-fill-level", show_fill_level),
178        }
179    }
180
181    pub fn upper_stepper_sensitivity(self, upper_stepper_sensitivity: SensitivityType) -> Self {
182        Self {
183            builder: self
184                .builder
185                .property("upper-stepper-sensitivity", upper_stepper_sensitivity),
186        }
187    }
188
189    pub fn app_paintable(self, app_paintable: bool) -> Self {
190        Self {
191            builder: self.builder.property("app-paintable", app_paintable),
192        }
193    }
194
195    pub fn can_default(self, can_default: bool) -> Self {
196        Self {
197            builder: self.builder.property("can-default", can_default),
198        }
199    }
200
201    pub fn can_focus(self, can_focus: bool) -> Self {
202        Self {
203            builder: self.builder.property("can-focus", can_focus),
204        }
205    }
206
207    pub fn events(self, events: gdk::EventMask) -> Self {
208        Self {
209            builder: self.builder.property("events", events),
210        }
211    }
212
213    /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
214    pub fn expand(self, expand: bool) -> Self {
215        Self {
216            builder: self.builder.property("expand", expand),
217        }
218    }
219
220    /// Whether the widget should grab focus when it is clicked with the mouse.
221    ///
222    /// This property is only relevant for widgets that can take focus.
223    ///
224    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
225    /// GtkComboBox) implemented this property individually.
226    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
227        Self {
228            builder: self.builder.property("focus-on-click", focus_on_click),
229        }
230    }
231
232    /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
233    pub fn halign(self, halign: Align) -> Self {
234        Self {
235            builder: self.builder.property("halign", halign),
236        }
237    }
238
239    pub fn has_default(self, has_default: bool) -> Self {
240        Self {
241            builder: self.builder.property("has-default", has_default),
242        }
243    }
244
245    pub fn has_focus(self, has_focus: bool) -> Self {
246        Self {
247            builder: self.builder.property("has-focus", has_focus),
248        }
249    }
250
251    /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
252    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
253    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
254    /// whether it will provide a tooltip or not.
255    ///
256    /// Note that setting this property to [`true`] for the first time will change
257    /// the event masks of the GdkWindows of this widget to include leave-notify
258    /// and motion-notify events. This cannot and will not be undone when the
259    /// property is set to [`false`] again.
260    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
261        Self {
262            builder: self.builder.property("has-tooltip", has_tooltip),
263        }
264    }
265
266    pub fn height_request(self, height_request: i32) -> Self {
267        Self {
268            builder: self.builder.property("height-request", height_request),
269        }
270    }
271
272    /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
273    pub fn hexpand(self, hexpand: bool) -> Self {
274        Self {
275            builder: self.builder.property("hexpand", hexpand),
276        }
277    }
278
279    /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
280    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
281        Self {
282            builder: self.builder.property("hexpand-set", hexpand_set),
283        }
284    }
285
286    pub fn is_focus(self, is_focus: bool) -> Self {
287        Self {
288            builder: self.builder.property("is-focus", is_focus),
289        }
290    }
291
292    /// Sets all four sides' margin at once. If read, returns max
293    /// margin on any side.
294    pub fn margin(self, margin: i32) -> Self {
295        Self {
296            builder: self.builder.property("margin", margin),
297        }
298    }
299
300    /// Margin on bottom side of widget.
301    ///
302    /// This property adds margin outside of the widget's normal size
303    /// request, the margin will be added in addition to the size from
304    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
305    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
306        Self {
307            builder: self.builder.property("margin-bottom", margin_bottom),
308        }
309    }
310
311    /// Margin on end of widget, horizontally. This property supports
312    /// left-to-right and right-to-left text directions.
313    ///
314    /// This property adds margin outside of the widget's normal size
315    /// request, the margin will be added in addition to the size from
316    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
317    pub fn margin_end(self, margin_end: i32) -> Self {
318        Self {
319            builder: self.builder.property("margin-end", margin_end),
320        }
321    }
322
323    /// Margin on start of widget, horizontally. This property supports
324    /// left-to-right and right-to-left text directions.
325    ///
326    /// This property adds margin outside of the widget's normal size
327    /// request, the margin will be added in addition to the size from
328    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
329    pub fn margin_start(self, margin_start: i32) -> Self {
330        Self {
331            builder: self.builder.property("margin-start", margin_start),
332        }
333    }
334
335    /// Margin on top side of widget.
336    ///
337    /// This property adds margin outside of the widget's normal size
338    /// request, the margin will be added in addition to the size from
339    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
340    pub fn margin_top(self, margin_top: i32) -> Self {
341        Self {
342            builder: self.builder.property("margin-top", margin_top),
343        }
344    }
345
346    pub fn name(self, name: impl Into<glib::GString>) -> Self {
347        Self {
348            builder: self.builder.property("name", name.into()),
349        }
350    }
351
352    pub fn no_show_all(self, no_show_all: bool) -> Self {
353        Self {
354            builder: self.builder.property("no-show-all", no_show_all),
355        }
356    }
357
358    /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
359    /// more details about window opacity.
360    ///
361    /// Before 3.8 this was only available in GtkWindow
362    pub fn opacity(self, opacity: f64) -> Self {
363        Self {
364            builder: self.builder.property("opacity", opacity),
365        }
366    }
367
368    pub fn parent(self, parent: &impl IsA<Container>) -> Self {
369        Self {
370            builder: self.builder.property("parent", parent.clone().upcast()),
371        }
372    }
373
374    pub fn receives_default(self, receives_default: bool) -> Self {
375        Self {
376            builder: self.builder.property("receives-default", receives_default),
377        }
378    }
379
380    pub fn sensitive(self, sensitive: bool) -> Self {
381        Self {
382            builder: self.builder.property("sensitive", sensitive),
383        }
384    }
385
386    /// Sets the text of tooltip to be the given string, which is marked up
387    /// with the [Pango text markup language][PangoMarkupFormat].
388    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
389    ///
390    /// This is a convenience property which will take care of getting the
391    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
392    /// will automatically be set to [`true`] and there will be taken care of
393    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
394    ///
395    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
396    /// are set, the last one wins.
397    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
398        Self {
399            builder: self
400                .builder
401                .property("tooltip-markup", tooltip_markup.into()),
402        }
403    }
404
405    /// Sets the text of tooltip to be the given string.
406    ///
407    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
408    ///
409    /// This is a convenience property which will take care of getting the
410    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
411    /// will automatically be set to [`true`] and there will be taken care of
412    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
413    ///
414    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
415    /// are set, the last one wins.
416    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
417        Self {
418            builder: self.builder.property("tooltip-text", tooltip_text.into()),
419        }
420    }
421
422    /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
423    pub fn valign(self, valign: Align) -> Self {
424        Self {
425            builder: self.builder.property("valign", valign),
426        }
427    }
428
429    /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
430    pub fn vexpand(self, vexpand: bool) -> Self {
431        Self {
432            builder: self.builder.property("vexpand", vexpand),
433        }
434    }
435
436    /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
437    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
438        Self {
439            builder: self.builder.property("vexpand-set", vexpand_set),
440        }
441    }
442
443    pub fn visible(self, visible: bool) -> Self {
444        Self {
445            builder: self.builder.property("visible", visible),
446        }
447    }
448
449    pub fn width_request(self, width_request: i32) -> Self {
450        Self {
451            builder: self.builder.property("width-request", width_request),
452        }
453    }
454
455    /// The orientation of the orientable.
456    pub fn orientation(self, orientation: Orientation) -> Self {
457        Self {
458            builder: self.builder.property("orientation", orientation),
459        }
460    }
461
462    // rustdoc-stripper-ignore-next
463    /// Build the [`Scrollbar`].
464    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
465    pub fn build(self) -> Scrollbar {
466        self.builder.build()
467    }
468}
469
470impl fmt::Display for Scrollbar {
471    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
472        f.write_str("Scrollbar")
473    }
474}