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