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