Skip to main content

gtk4/auto/
scale.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, AccessibleRange};
8use crate::{
9    AccessibleRole, Adjustment, Align, Buildable, ConstraintTarget, LayoutManager, Orientable,
10    Orientation, Overflow, PositionType, Range, Widget, ffi,
11};
12use glib::{
13    prelude::*,
14    signal::{SignalHandlerId, connect_raw},
15    translate::*,
16};
17use std::boxed::Box as Box_;
18
19#[cfg(feature = "v4_10")]
20#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
21glib::wrapper! {
22    ///  slider
23    /// ```text
24    ///
25    /// [`Scale`][crate::Scale] has a main CSS node with name scale and a subnode for its contents,
26    /// with subnodes named trough and slider.
27    ///
28    /// The main node gets the style class .fine-tune added when the scale is in
29    /// 'fine-tuning' mode.
30    ///
31    /// If the scale has an origin (see [`ScaleExt::set_has_origin()`][crate::prelude::ScaleExt::set_has_origin()]), there is
32    /// a subnode with name highlight below the trough node that is used for rendering
33    /// the highlighted part of the trough.
34    ///
35    /// If the scale is showing a fill level (see [`RangeExt::set_show_fill_level()`][crate::prelude::RangeExt::set_show_fill_level()]),
36    /// there is a subnode with name fill below the trough node that is used for
37    /// rendering the filled in part of the trough.
38    ///
39    /// If marks are present, there is a marks subnode before or after the trough
40    /// node, below which each mark gets a node with name mark. The marks nodes get
41    /// either the .top or .bottom style class.
42    ///
43    /// The mark node has a subnode named indicator. If the mark has text, it also
44    /// has a subnode named label. When the mark is either above or left of the
45    /// scale, the label subnode is the first when present. Otherwise, the indicator
46    /// subnode is the first.
47    ///
48    /// The main CSS node gets the 'marks-before' and/or 'marks-after' style classes
49    /// added depending on what marks are present.
50    ///
51    /// If the scale is displaying the value (see [`draw-value`][struct@crate::Scale#draw-value]),
52    /// there is subnode with name value. This node will get the .top or .bottom style
53    /// classes similar to the marks node.
54    ///
55    /// # Accessibility
56    ///
57    /// [`Scale`][crate::Scale] uses the [enum@Gtk.AccessibleRole.slider] role.
58    ///
59    /// ## Properties
60    ///
61    ///
62    /// #### `digits`
63    ///  The number of decimal places that are displayed in the value.
64    ///
65    /// Readable | Writable
66    ///
67    ///
68    /// #### `draw-value`
69    ///  Whether the current value is displayed as a string next to the slider.
70    ///
71    /// Readable | Writable
72    ///
73    ///
74    /// #### `has-origin`
75    ///  Whether the scale has an origin.
76    ///
77    /// Readable | Writable
78    ///
79    ///
80    /// #### `value-pos`
81    ///  The position in which the current value is displayed.
82    ///
83    /// Readable | Writable
84    /// <details><summary><h4>Range</h4></summary>
85    ///
86    ///
87    /// #### `adjustment`
88    ///  The adjustment that is controlled by the range.
89    ///
90    /// Readable | Writable | Construct
91    ///
92    ///
93    /// #### `fill-level`
94    ///  The fill level (e.g. prebuffering of a network stream).
95    ///
96    /// Readable | Writable
97    ///
98    ///
99    /// #### `inverted`
100    ///  If [`true`], the direction in which the slider moves is inverted.
101    ///
102    /// Readable | Writable
103    ///
104    ///
105    /// #### `restrict-to-fill-level`
106    ///  Controls whether slider movement is restricted to an
107    /// upper boundary set by the fill level.
108    ///
109    /// Readable | Writable
110    ///
111    ///
112    /// #### `round-digits`
113    ///  The number of digits to round the value to when
114    /// it changes.
115    ///
116    /// See [`change-value`][struct@crate::Range#change-value].
117    ///
118    /// Readable | Writable
119    ///
120    ///
121    /// #### `show-fill-level`
122    ///  Controls whether fill level indicator graphics are displayed
123    /// on the trough.
124    ///
125    /// Readable | Writable
126    /// </details>
127    /// <details><summary><h4>Widget</h4></summary>
128    ///
129    ///
130    /// #### `can-focus`
131    ///  Whether the widget or any of its descendents can accept
132    /// the input focus.
133    ///
134    /// This property is meant to be set by widget implementations,
135    /// typically in their instance init function.
136    ///
137    /// Readable | Writable
138    ///
139    ///
140    /// #### `can-target`
141    ///  Whether the widget can receive pointer events.
142    ///
143    /// Readable | Writable
144    ///
145    ///
146    /// #### `css-classes`
147    ///  A list of css classes applied to this widget.
148    ///
149    /// Readable | Writable
150    ///
151    ///
152    /// #### `css-name`
153    ///  The name of this widget in the CSS tree.
154    ///
155    /// This property is meant to be set by widget implementations,
156    /// typically in their instance init function.
157    ///
158    /// Readable | Writable | Construct Only
159    ///
160    ///
161    /// #### `cursor`
162    ///  The cursor used by @widget.
163    ///
164    /// Readable | Writable
165    ///
166    ///
167    /// #### `focus-on-click`
168    ///  Whether the widget should grab focus when it is clicked with the mouse.
169    ///
170    /// This property is only relevant for widgets that can take focus.
171    ///
172    /// Readable | Writable
173    ///
174    ///
175    /// #### `focusable`
176    ///  Whether this widget itself will accept the input focus.
177    ///
178    /// Readable | Writable
179    ///
180    ///
181    /// #### `halign`
182    ///  How to distribute horizontal space if widget gets extra space.
183    ///
184    /// Readable | Writable
185    ///
186    ///
187    /// #### `has-default`
188    ///  Whether the widget is the default widget.
189    ///
190    /// Readable
191    ///
192    ///
193    /// #### `has-focus`
194    ///  Whether the widget has the input focus.
195    ///
196    /// Readable
197    ///
198    ///
199    /// #### `has-tooltip`
200    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
201    /// signal on @widget.
202    ///
203    /// A true value indicates that @widget can have a tooltip, in this case
204    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
205    /// determine whether it will provide a tooltip or not.
206    ///
207    /// Readable | Writable
208    ///
209    ///
210    /// #### `height-request`
211    ///  Overrides for height request of the widget.
212    ///
213    /// If this is -1, the natural request will be used.
214    ///
215    /// Readable | Writable
216    ///
217    ///
218    /// #### `hexpand`
219    ///  Whether to expand horizontally.
220    ///
221    /// Readable | Writable
222    ///
223    ///
224    /// #### `hexpand-set`
225    ///  Whether to use the `hexpand` property.
226    ///
227    /// Readable | Writable
228    ///
229    ///
230    /// #### `layout-manager`
231    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
232    /// the preferred size of the widget, and allocate its children.
233    ///
234    /// This property is meant to be set by widget implementations,
235    /// typically in their instance init function.
236    ///
237    /// Readable | Writable
238    ///
239    ///
240    /// #### `limit-events`
241    ///  Makes this widget act like a modal dialog, with respect to
242    /// event delivery.
243    ///
244    /// Global event controllers will not handle events with targets
245    /// inside the widget, unless they are set up to ignore propagation
246    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
247    ///
248    /// Readable | Writable
249    ///
250    ///
251    /// #### `margin-bottom`
252    ///  Margin on bottom side of widget.
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-end`
262    ///  Margin on end of widget, horizontally.
263    ///
264    /// This property supports left-to-right and right-to-left text
265    /// directions.
266    ///
267    /// This property adds margin outside of the widget's normal size
268    /// request, the margin will be added in addition to the size from
269    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
270    ///
271    /// Readable | Writable
272    ///
273    ///
274    /// #### `margin-start`
275    ///  Margin on start of widget, horizontally.
276    ///
277    /// This property supports left-to-right and right-to-left text
278    /// directions.
279    ///
280    /// This property adds margin outside of the widget's normal size
281    /// request, the margin will be added in addition to the size from
282    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
283    ///
284    /// Readable | Writable
285    ///
286    ///
287    /// #### `margin-top`
288    ///  Margin on top side of widget.
289    ///
290    /// This property adds margin outside of the widget's normal size
291    /// request, the margin will be added in addition to the size from
292    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
293    ///
294    /// Readable | Writable
295    ///
296    ///
297    /// #### `name`
298    ///  The name of the widget.
299    ///
300    /// Readable | Writable
301    ///
302    ///
303    /// #### `opacity`
304    ///  The requested opacity of the widget.
305    ///
306    /// Readable | Writable
307    ///
308    ///
309    /// #### `overflow`
310    ///  How content outside the widget's content area is treated.
311    ///
312    /// This property is meant to be set by widget implementations,
313    /// typically in their instance init function.
314    ///
315    /// Readable | Writable
316    ///
317    ///
318    /// #### `parent`
319    ///  The parent widget of this widget.
320    ///
321    /// Readable
322    ///
323    ///
324    /// #### `receives-default`
325    ///  Whether the widget will receive the default action when it is focused.
326    ///
327    /// Readable | Writable
328    ///
329    ///
330    /// #### `root`
331    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
332    ///
333    /// This will be `NULL` if the widget is not contained in a root widget.
334    ///
335    /// Readable
336    ///
337    ///
338    /// #### `scale-factor`
339    ///  The scale factor of the widget.
340    ///
341    /// Readable
342    ///
343    ///
344    /// #### `sensitive`
345    ///  Whether the widget responds to input.
346    ///
347    /// Readable | Writable
348    ///
349    ///
350    /// #### `tooltip-markup`
351    ///  Sets the text of tooltip to be the given string, which is marked up
352    /// with Pango markup.
353    ///
354    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
355    ///
356    /// This is a convenience property which will take care of getting the
357    /// tooltip shown if the given string is not `NULL`:
358    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
359    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
360    /// the default signal handler.
361    ///
362    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
363    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
364    ///
365    /// Readable | Writable
366    ///
367    ///
368    /// #### `tooltip-text`
369    ///  Sets the text of tooltip to be the given string.
370    ///
371    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
372    ///
373    /// This is a convenience property which will take care of getting the
374    /// tooltip shown if the given string is not `NULL`:
375    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
376    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
377    /// the default signal handler.
378    ///
379    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
380    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
381    ///
382    /// Readable | Writable
383    ///
384    ///
385    /// #### `valign`
386    ///  How to distribute vertical space if widget gets extra space.
387    ///
388    /// Readable | Writable
389    ///
390    ///
391    /// #### `vexpand`
392    ///  Whether to expand vertically.
393    ///
394    /// Readable | Writable
395    ///
396    ///
397    /// #### `vexpand-set`
398    ///  Whether to use the `vexpand` property.
399    ///
400    /// Readable | Writable
401    ///
402    ///
403    /// #### `visible`
404    ///  Whether the widget is visible.
405    ///
406    /// Readable | Writable
407    ///
408    ///
409    /// #### `width-request`
410    ///  Overrides for width request of the widget.
411    ///
412    /// If this is -1, the natural request will be used.
413    ///
414    /// Readable | Writable
415    /// </details>
416    /// <details><summary><h4>Accessible</h4></summary>
417    ///
418    ///
419    /// #### `accessible-role`
420    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
421    ///
422    /// The accessible role cannot be changed once set.
423    ///
424    /// Readable | Writable
425    /// </details>
426    /// <details><summary><h4>Orientable</h4></summary>
427    ///
428    ///
429    /// #### `orientation`
430    ///  The orientation of the orientable.
431    ///
432    /// Readable | Writable
433    /// </details>
434    ///
435    /// # Implements
436    ///
437    /// [`ScaleExt`][trait@crate::prelude::ScaleExt], [`RangeExt`][trait@crate::prelude::RangeExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`AccessibleRangeExt`][trait@crate::prelude::AccessibleRangeExt], [`OrientableExt`][trait@crate::prelude::OrientableExt], [`ScaleExtManual`][trait@crate::prelude::ScaleExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
438    #[doc(alias = "GtkScale")]
439    pub struct Scale(Object<ffi::GtkScale, ffi::GtkScaleClass>) @extends Range, Widget, @implements Accessible, Buildable, ConstraintTarget, AccessibleRange, Orientable;
440
441    match fn {
442        type_ => || ffi::gtk_scale_get_type(),
443    }
444}
445
446#[cfg(not(feature = "v4_10"))]
447glib::wrapper! {
448    #[doc(alias = "GtkScale")]
449    pub struct Scale(Object<ffi::GtkScale, ffi::GtkScaleClass>) @extends Range, Widget, @implements Buildable, ConstraintTarget, Orientable;
450
451    match fn {
452        type_ => || ffi::gtk_scale_get_type(),
453    }
454}
455
456impl Scale {
457    pub const NONE: Option<&'static Scale> = None;
458
459    /// Creates a new [`Scale`][crate::Scale].
460    /// ## `orientation`
461    /// s orientation.
462    /// ## `adjustment`
463    /// the [`Adjustment`][crate::Adjustment] which sets
464    ///   the range of the scale, or [`None`] to create a new adjustment.
465    ///
466    /// # Returns
467    ///
468    /// a new [`Scale`][crate::Scale]
469    #[doc(alias = "gtk_scale_new")]
470    pub fn new(orientation: Orientation, adjustment: Option<&impl IsA<Adjustment>>) -> Scale {
471        assert_initialized_main_thread!();
472        unsafe {
473            Widget::from_glib_none(ffi::gtk_scale_new(
474                orientation.into_glib(),
475                adjustment.map(|p| p.as_ref()).to_glib_none().0,
476            ))
477            .unsafe_cast()
478        }
479    }
480
481    /// s the distance
482    /// the slider moves when using the arrow keys to adjust the scale
483    /// value.
484    ///
485    /// Note that the way in which the precision is derived works best if
486    /// @step is a power of ten. If the resulting precision is not suitable
487    /// for your needs, use [`ScaleExt::set_digits()`][crate::prelude::ScaleExt::set_digits()] to correct it.
488    /// ## `orientation`
489    /// s orientation.
490    /// ## `min`
491    /// minimum value
492    /// ## `max`
493    /// maximum value
494    /// ## `step`
495    /// step increment (tick size) used with keyboard shortcuts
496    ///
497    /// # Returns
498    ///
499    /// a new [`Scale`][crate::Scale]
500    #[doc(alias = "gtk_scale_new_with_range")]
501    #[doc(alias = "new_with_range")]
502    pub fn with_range(orientation: Orientation, min: f64, max: f64, step: f64) -> Scale {
503        assert_initialized_main_thread!();
504        unsafe {
505            Widget::from_glib_none(ffi::gtk_scale_new_with_range(
506                orientation.into_glib(),
507                min,
508                max,
509                step,
510            ))
511            .unsafe_cast()
512        }
513    }
514
515    // rustdoc-stripper-ignore-next
516    /// Creates a new builder-pattern struct instance to construct [`Scale`] objects.
517    ///
518    /// This method returns an instance of [`ScaleBuilder`](crate::builders::ScaleBuilder) which can be used to create [`Scale`] objects.
519    pub fn builder() -> ScaleBuilder {
520        ScaleBuilder::new()
521    }
522}
523
524impl Default for Scale {
525    fn default() -> Self {
526        glib::object::Object::new::<Self>()
527    }
528}
529
530// rustdoc-stripper-ignore-next
531/// A [builder-pattern] type to construct [`Scale`] objects.
532///
533/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
534#[must_use = "The builder must be built to be used"]
535pub struct ScaleBuilder {
536    builder: glib::object::ObjectBuilder<'static, Scale>,
537}
538
539impl ScaleBuilder {
540    fn new() -> Self {
541        Self {
542            builder: glib::object::Object::builder(),
543        }
544    }
545
546    /// The number of decimal places that are displayed in the value.
547    pub fn digits(self, digits: i32) -> Self {
548        Self {
549            builder: self.builder.property("digits", digits),
550        }
551    }
552
553    /// Whether the current value is displayed as a string next to the slider.
554    pub fn draw_value(self, draw_value: bool) -> Self {
555        Self {
556            builder: self.builder.property("draw-value", draw_value),
557        }
558    }
559
560    /// Whether the scale has an origin.
561    pub fn has_origin(self, has_origin: bool) -> Self {
562        Self {
563            builder: self.builder.property("has-origin", has_origin),
564        }
565    }
566
567    /// The position in which the current value is displayed.
568    pub fn value_pos(self, value_pos: PositionType) -> Self {
569        Self {
570            builder: self.builder.property("value-pos", value_pos),
571        }
572    }
573
574    /// The adjustment that is controlled by the range.
575    pub fn adjustment(self, adjustment: &impl IsA<Adjustment>) -> Self {
576        Self {
577            builder: self
578                .builder
579                .property("adjustment", adjustment.clone().upcast()),
580        }
581    }
582
583    /// The fill level (e.g. prebuffering of a network stream).
584    pub fn fill_level(self, fill_level: f64) -> Self {
585        Self {
586            builder: self.builder.property("fill-level", fill_level),
587        }
588    }
589
590    /// If [`true`], the direction in which the slider moves is inverted.
591    pub fn inverted(self, inverted: bool) -> Self {
592        Self {
593            builder: self.builder.property("inverted", inverted),
594        }
595    }
596
597    /// Controls whether slider movement is restricted to an
598    /// upper boundary set by the fill level.
599    pub fn restrict_to_fill_level(self, restrict_to_fill_level: bool) -> Self {
600        Self {
601            builder: self
602                .builder
603                .property("restrict-to-fill-level", restrict_to_fill_level),
604        }
605    }
606
607    /// The number of digits to round the value to when
608    /// it changes.
609    ///
610    /// See [`change-value`][struct@crate::Range#change-value].
611    pub fn round_digits(self, round_digits: i32) -> Self {
612        Self {
613            builder: self.builder.property("round-digits", round_digits),
614        }
615    }
616
617    /// Controls whether fill level indicator graphics are displayed
618    /// on the trough.
619    pub fn show_fill_level(self, show_fill_level: bool) -> Self {
620        Self {
621            builder: self.builder.property("show-fill-level", show_fill_level),
622        }
623    }
624
625    /// Whether the widget or any of its descendents can accept
626    /// the input focus.
627    ///
628    /// This property is meant to be set by widget implementations,
629    /// typically in their instance init function.
630    pub fn can_focus(self, can_focus: bool) -> Self {
631        Self {
632            builder: self.builder.property("can-focus", can_focus),
633        }
634    }
635
636    /// Whether the widget can receive pointer events.
637    pub fn can_target(self, can_target: bool) -> Self {
638        Self {
639            builder: self.builder.property("can-target", can_target),
640        }
641    }
642
643    /// A list of css classes applied to this widget.
644    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
645        Self {
646            builder: self.builder.property("css-classes", css_classes.into()),
647        }
648    }
649
650    /// The name of this widget in the CSS tree.
651    ///
652    /// This property is meant to be set by widget implementations,
653    /// typically in their instance init function.
654    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
655        Self {
656            builder: self.builder.property("css-name", css_name.into()),
657        }
658    }
659
660    /// The cursor used by @widget.
661    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
662        Self {
663            builder: self.builder.property("cursor", cursor.clone()),
664        }
665    }
666
667    /// Whether the widget should grab focus when it is clicked with the mouse.
668    ///
669    /// This property is only relevant for widgets that can take focus.
670    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
671        Self {
672            builder: self.builder.property("focus-on-click", focus_on_click),
673        }
674    }
675
676    /// Whether this widget itself will accept the input focus.
677    pub fn focusable(self, focusable: bool) -> Self {
678        Self {
679            builder: self.builder.property("focusable", focusable),
680        }
681    }
682
683    /// How to distribute horizontal space if widget gets extra space.
684    pub fn halign(self, halign: Align) -> Self {
685        Self {
686            builder: self.builder.property("halign", halign),
687        }
688    }
689
690    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
691    /// signal on @widget.
692    ///
693    /// A true value indicates that @widget can have a tooltip, in this case
694    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
695    /// determine whether it will provide a tooltip or not.
696    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
697        Self {
698            builder: self.builder.property("has-tooltip", has_tooltip),
699        }
700    }
701
702    /// Overrides for height request of the widget.
703    ///
704    /// If this is -1, the natural request will be used.
705    pub fn height_request(self, height_request: i32) -> Self {
706        Self {
707            builder: self.builder.property("height-request", height_request),
708        }
709    }
710
711    /// Whether to expand horizontally.
712    pub fn hexpand(self, hexpand: bool) -> Self {
713        Self {
714            builder: self.builder.property("hexpand", hexpand),
715        }
716    }
717
718    /// Whether to use the `hexpand` property.
719    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
720        Self {
721            builder: self.builder.property("hexpand-set", hexpand_set),
722        }
723    }
724
725    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
726    /// the preferred size of the widget, and allocate its children.
727    ///
728    /// This property is meant to be set by widget implementations,
729    /// typically in their instance init function.
730    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
731        Self {
732            builder: self
733                .builder
734                .property("layout-manager", layout_manager.clone().upcast()),
735        }
736    }
737
738    /// Makes this widget act like a modal dialog, with respect to
739    /// event delivery.
740    ///
741    /// Global event controllers will not handle events with targets
742    /// inside the widget, unless they are set up to ignore propagation
743    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
744    #[cfg(feature = "v4_18")]
745    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
746    pub fn limit_events(self, limit_events: bool) -> Self {
747        Self {
748            builder: self.builder.property("limit-events", limit_events),
749        }
750    }
751
752    /// Margin on bottom side of widget.
753    ///
754    /// This property adds margin outside of the widget's normal size
755    /// request, the margin will be added in addition to the size from
756    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
757    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
758        Self {
759            builder: self.builder.property("margin-bottom", margin_bottom),
760        }
761    }
762
763    /// Margin on end of widget, horizontally.
764    ///
765    /// This property supports left-to-right and right-to-left text
766    /// directions.
767    ///
768    /// This property adds margin outside of the widget's normal size
769    /// request, the margin will be added in addition to the size from
770    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
771    pub fn margin_end(self, margin_end: i32) -> Self {
772        Self {
773            builder: self.builder.property("margin-end", margin_end),
774        }
775    }
776
777    /// Margin on start of widget, horizontally.
778    ///
779    /// This property supports left-to-right and right-to-left text
780    /// directions.
781    ///
782    /// This property adds margin outside of the widget's normal size
783    /// request, the margin will be added in addition to the size from
784    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
785    pub fn margin_start(self, margin_start: i32) -> Self {
786        Self {
787            builder: self.builder.property("margin-start", margin_start),
788        }
789    }
790
791    /// Margin on top side of widget.
792    ///
793    /// This property adds margin outside of the widget's normal size
794    /// request, the margin will be added in addition to the size from
795    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
796    pub fn margin_top(self, margin_top: i32) -> Self {
797        Self {
798            builder: self.builder.property("margin-top", margin_top),
799        }
800    }
801
802    /// The name of the widget.
803    pub fn name(self, name: impl Into<glib::GString>) -> Self {
804        Self {
805            builder: self.builder.property("name", name.into()),
806        }
807    }
808
809    /// The requested opacity of the widget.
810    pub fn opacity(self, opacity: f64) -> Self {
811        Self {
812            builder: self.builder.property("opacity", opacity),
813        }
814    }
815
816    /// How content outside the widget's content area is treated.
817    ///
818    /// This property is meant to be set by widget implementations,
819    /// typically in their instance init function.
820    pub fn overflow(self, overflow: Overflow) -> Self {
821        Self {
822            builder: self.builder.property("overflow", overflow),
823        }
824    }
825
826    /// Whether the widget will receive the default action when it is focused.
827    pub fn receives_default(self, receives_default: bool) -> Self {
828        Self {
829            builder: self.builder.property("receives-default", receives_default),
830        }
831    }
832
833    /// Whether the widget responds to input.
834    pub fn sensitive(self, sensitive: bool) -> Self {
835        Self {
836            builder: self.builder.property("sensitive", sensitive),
837        }
838    }
839
840    /// Sets the text of tooltip to be the given string, which is marked up
841    /// with Pango markup.
842    ///
843    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
844    ///
845    /// This is a convenience property which will take care of getting the
846    /// tooltip shown if the given string is not `NULL`:
847    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
848    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
849    /// the default signal handler.
850    ///
851    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
852    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
853    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
854        Self {
855            builder: self
856                .builder
857                .property("tooltip-markup", tooltip_markup.into()),
858        }
859    }
860
861    /// Sets the text of tooltip to be the given string.
862    ///
863    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
864    ///
865    /// This is a convenience property which will take care of getting the
866    /// tooltip shown if the given string is not `NULL`:
867    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
868    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
869    /// the default signal handler.
870    ///
871    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
872    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
873    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
874        Self {
875            builder: self.builder.property("tooltip-text", tooltip_text.into()),
876        }
877    }
878
879    /// How to distribute vertical space if widget gets extra space.
880    pub fn valign(self, valign: Align) -> Self {
881        Self {
882            builder: self.builder.property("valign", valign),
883        }
884    }
885
886    /// Whether to expand vertically.
887    pub fn vexpand(self, vexpand: bool) -> Self {
888        Self {
889            builder: self.builder.property("vexpand", vexpand),
890        }
891    }
892
893    /// Whether to use the `vexpand` property.
894    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
895        Self {
896            builder: self.builder.property("vexpand-set", vexpand_set),
897        }
898    }
899
900    /// Whether the widget is visible.
901    pub fn visible(self, visible: bool) -> Self {
902        Self {
903            builder: self.builder.property("visible", visible),
904        }
905    }
906
907    /// Overrides for width request of the widget.
908    ///
909    /// If this is -1, the natural request will be used.
910    pub fn width_request(self, width_request: i32) -> Self {
911        Self {
912            builder: self.builder.property("width-request", width_request),
913        }
914    }
915
916    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
917    ///
918    /// The accessible role cannot be changed once set.
919    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
920        Self {
921            builder: self.builder.property("accessible-role", accessible_role),
922        }
923    }
924
925    /// The orientation of the orientable.
926    pub fn orientation(self, orientation: Orientation) -> Self {
927        Self {
928            builder: self.builder.property("orientation", orientation),
929        }
930    }
931
932    // rustdoc-stripper-ignore-next
933    /// Build the [`Scale`].
934    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
935    pub fn build(self) -> Scale {
936        assert_initialized_main_thread!();
937        self.builder.build()
938    }
939}
940
941/// Trait containing all [`struct@Scale`] methods.
942///
943/// # Implementors
944///
945/// [`Scale`][struct@crate::Scale]
946pub trait ScaleExt: IsA<Scale> + 'static {
947    /// Adds a mark at @value.
948    ///
949    /// A mark is indicated visually by drawing a tick mark next to the scale,
950    /// and GTK makes it easy for the user to position the scale exactly at the
951    /// marks value.
952    ///
953    /// If @markup is not [`None`], text is shown next to the tick mark.
954    ///
955    /// To remove marks from a scale, use [`clear_marks()`][Self::clear_marks()].
956    /// ## `value`
957    ///  adjustment
958    /// ## `position`
959    /// where to draw the mark. For a horizontal scale, [`PositionType::Top`][crate::PositionType::Top]
960    ///   and [`PositionType::Left`][crate::PositionType::Left] are drawn above the scale, anything else below.
961    ///   For a vertical scale, [`PositionType::Left`][crate::PositionType::Left] and [`PositionType::Top`][crate::PositionType::Top] are drawn to
962    ///   the left of the scale, anything else to the right.
963    /// ## `markup`
964    /// Text to be shown at the mark, using Pango markup
965    #[doc(alias = "gtk_scale_add_mark")]
966    fn add_mark(&self, value: f64, position: PositionType, markup: Option<&str>) {
967        unsafe {
968            ffi::gtk_scale_add_mark(
969                self.as_ref().to_glib_none().0,
970                value,
971                position.into_glib(),
972                markup.to_glib_none().0,
973            );
974        }
975    }
976
977    /// Removes any marks that have been added.
978    #[doc(alias = "gtk_scale_clear_marks")]
979    fn clear_marks(&self) {
980        unsafe {
981            ffi::gtk_scale_clear_marks(self.as_ref().to_glib_none().0);
982        }
983    }
984
985    /// Gets the number of decimal places that are displayed in the value.
986    ///
987    /// # Returns
988    ///
989    /// the number of decimal places that are displayed
990    #[doc(alias = "gtk_scale_get_digits")]
991    #[doc(alias = "get_digits")]
992    fn digits(&self) -> i32 {
993        unsafe { ffi::gtk_scale_get_digits(self.as_ref().to_glib_none().0) }
994    }
995
996    /// Returns whether the current value is displayed as a string
997    /// next to the slider.
998    ///
999    /// # Returns
1000    ///
1001    /// whether the current value is displayed as a string
1002    #[doc(alias = "gtk_scale_get_draw_value")]
1003    #[doc(alias = "get_draw_value")]
1004    #[doc(alias = "draw-value")]
1005    fn draws_value(&self) -> bool {
1006        unsafe {
1007            from_glib(ffi::gtk_scale_get_draw_value(
1008                self.as_ref().to_glib_none().0,
1009            ))
1010        }
1011    }
1012
1013    /// Returns whether the scale has an origin.
1014    ///
1015    /// # Returns
1016    ///
1017    /// [`true`] if the scale has an origin.
1018    #[doc(alias = "gtk_scale_get_has_origin")]
1019    #[doc(alias = "get_has_origin")]
1020    #[doc(alias = "has-origin")]
1021    fn has_origin(&self) -> bool {
1022        unsafe {
1023            from_glib(ffi::gtk_scale_get_has_origin(
1024                self.as_ref().to_glib_none().0,
1025            ))
1026        }
1027    }
1028
1029    /// Gets the [`pango::Layout`][crate::pango::Layout] used to display the scale.
1030    ///
1031    /// The returned object is owned by the scale so does not need
1032    /// to be freed by the caller.
1033    ///
1034    /// # Returns
1035    ///
1036    /// the [`pango::Layout`][crate::pango::Layout]
1037    ///   for this scale, or [`None`] if the [`draw-value`][struct@crate::Scale#draw-value]
1038    ///   property is [`false`].
1039    #[doc(alias = "gtk_scale_get_layout")]
1040    #[doc(alias = "get_layout")]
1041    fn layout(&self) -> Option<pango::Layout> {
1042        unsafe { from_glib_none(ffi::gtk_scale_get_layout(self.as_ref().to_glib_none().0)) }
1043    }
1044
1045    /// Obtains the coordinates where the scale will draw the
1046    /// [`pango::Layout`][crate::pango::Layout] representing the text in the scale.
1047    ///
1048    /// Remember when using the [`pango::Layout`][crate::pango::Layout] function you need to
1049    /// convert to and from pixels using `PANGO_PIXELS()` or `PANGO_SCALE`.
1050    ///
1051    /// If the [`draw-value`][struct@crate::Scale#draw-value] property is [`false`], the return
1052    /// values are undefined.
1053    ///
1054    /// # Returns
1055    ///
1056    ///
1057    /// ## `x`
1058    /// location to store X offset of layout
1059    ///
1060    /// ## `y`
1061    /// location to store Y offset of layout
1062    #[doc(alias = "gtk_scale_get_layout_offsets")]
1063    #[doc(alias = "get_layout_offsets")]
1064    fn layout_offsets(&self) -> (i32, i32) {
1065        unsafe {
1066            let mut x = std::mem::MaybeUninit::uninit();
1067            let mut y = std::mem::MaybeUninit::uninit();
1068            ffi::gtk_scale_get_layout_offsets(
1069                self.as_ref().to_glib_none().0,
1070                x.as_mut_ptr(),
1071                y.as_mut_ptr(),
1072            );
1073            (x.assume_init(), y.assume_init())
1074        }
1075    }
1076
1077    /// Gets the position in which the current value is displayed.
1078    ///
1079    /// # Returns
1080    ///
1081    /// the position in which the current value is displayed
1082    #[doc(alias = "gtk_scale_get_value_pos")]
1083    #[doc(alias = "get_value_pos")]
1084    #[doc(alias = "value-pos")]
1085    fn value_pos(&self) -> PositionType {
1086        unsafe { from_glib(ffi::gtk_scale_get_value_pos(self.as_ref().to_glib_none().0)) }
1087    }
1088
1089    /// Sets the number of decimal places that are displayed in the value.
1090    ///
1091    /// Also causes the value of the adjustment to be rounded to this number
1092    /// of digits, so the retrieved value matches the displayed one, if
1093    /// [`draw-value`][struct@crate::Scale#draw-value] is [`true`] when the value changes. If
1094    /// you want to enforce rounding the value when [`draw-value`][struct@crate::Scale#draw-value]
1095    /// is [`false`], you can set [`round-digits`][struct@crate::Range#round-digits] instead.
1096    ///
1097    /// Note that rounding to a small number of digits can interfere with
1098    /// the smooth autoscrolling that is built into [`Scale`][crate::Scale]. As an alternative,
1099    /// you can use [`set_format_value_func()`][Self::set_format_value_func()] to format the displayed
1100    /// value yourself.
1101    /// ## `digits`
1102    /// the number of decimal places to display,
1103    ///   e.g. use 1 to display 1.0, 2 to display 1.00, etc
1104    #[doc(alias = "gtk_scale_set_digits")]
1105    #[doc(alias = "digits")]
1106    fn set_digits(&self, digits: i32) {
1107        unsafe {
1108            ffi::gtk_scale_set_digits(self.as_ref().to_glib_none().0, digits);
1109        }
1110    }
1111
1112    /// Specifies whether the current value is displayed as a string next
1113    /// to the slider.
1114    /// ## `draw_value`
1115    /// [`true`] to draw the value
1116    #[doc(alias = "gtk_scale_set_draw_value")]
1117    #[doc(alias = "draw-value")]
1118    fn set_draw_value(&self, draw_value: bool) {
1119        unsafe {
1120            ffi::gtk_scale_set_draw_value(self.as_ref().to_glib_none().0, draw_value.into_glib());
1121        }
1122    }
1123
1124    /// @func allows you to change how the scale value is displayed.
1125    ///
1126    /// The given function will return an allocated string representing
1127    /// @value. That string will then be used to display the scale's value.
1128    ///
1129    /// If #NULL is passed as @func, the value will be displayed on
1130    /// its own, rounded according to the value of the
1131    /// [`digits`][struct@crate::Scale#digits] property.
1132    /// ## `func`
1133    /// function
1134    ///   that formats the value
1135    /// ## `destroy_notify`
1136    /// destroy function for @user_data
1137    #[doc(alias = "gtk_scale_set_format_value_func")]
1138    fn set_format_value_func<P: Fn(&Scale, f64) -> String + 'static>(&self, func: P) {
1139        let func_data: Box_<P> = Box_::new(func);
1140        unsafe extern "C" fn func_func<P: Fn(&Scale, f64) -> String + 'static>(
1141            scale: *mut ffi::GtkScale,
1142            value: std::ffi::c_double,
1143            user_data: glib::ffi::gpointer,
1144        ) -> *mut std::ffi::c_char {
1145            unsafe {
1146                let scale = from_glib_borrow(scale);
1147                let callback = &*(user_data as *mut P);
1148                (*callback)(&scale, value).to_glib_full()
1149            }
1150        }
1151        let func = Some(func_func::<P> as _);
1152        unsafe extern "C" fn destroy_notify_func<P: Fn(&Scale, f64) -> String + 'static>(
1153            data: glib::ffi::gpointer,
1154        ) {
1155            unsafe {
1156                let _callback = Box_::from_raw(data as *mut P);
1157            }
1158        }
1159        let destroy_call3 = Some(destroy_notify_func::<P> as _);
1160        let super_callback0: Box_<P> = func_data;
1161        unsafe {
1162            ffi::gtk_scale_set_format_value_func(
1163                self.as_ref().to_glib_none().0,
1164                func,
1165                Box_::into_raw(super_callback0) as *mut _,
1166                destroy_call3,
1167            );
1168        }
1169    }
1170
1171    /// Sets whether the scale has an origin.
1172    ///
1173    /// If [`has-origin`][struct@crate::Scale#has-origin] is set to [`true`] (the default),
1174    /// the scale will highlight the part of the trough between the origin
1175    /// (bottom or left side) and the current value.
1176    /// ## `has_origin`
1177    /// [`true`] if the scale has an origin
1178    #[doc(alias = "gtk_scale_set_has_origin")]
1179    #[doc(alias = "has-origin")]
1180    fn set_has_origin(&self, has_origin: bool) {
1181        unsafe {
1182            ffi::gtk_scale_set_has_origin(self.as_ref().to_glib_none().0, has_origin.into_glib());
1183        }
1184    }
1185
1186    /// Sets the position in which the current value is displayed.
1187    /// ## `pos`
1188    /// the position in which the current value is displayed
1189    #[doc(alias = "gtk_scale_set_value_pos")]
1190    #[doc(alias = "value-pos")]
1191    fn set_value_pos(&self, pos: PositionType) {
1192        unsafe {
1193            ffi::gtk_scale_set_value_pos(self.as_ref().to_glib_none().0, pos.into_glib());
1194        }
1195    }
1196
1197    #[doc(alias = "digits")]
1198    fn connect_digits_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1199        unsafe extern "C" fn notify_digits_trampoline<P: IsA<Scale>, F: Fn(&P) + 'static>(
1200            this: *mut ffi::GtkScale,
1201            _param_spec: glib::ffi::gpointer,
1202            f: glib::ffi::gpointer,
1203        ) {
1204            unsafe {
1205                let f: &F = &*(f as *const F);
1206                f(Scale::from_glib_borrow(this).unsafe_cast_ref())
1207            }
1208        }
1209        unsafe {
1210            let f: Box_<F> = Box_::new(f);
1211            connect_raw(
1212                self.as_ptr() as *mut _,
1213                c"notify::digits".as_ptr(),
1214                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1215                    notify_digits_trampoline::<Self, F> as *const (),
1216                )),
1217                Box_::into_raw(f),
1218            )
1219        }
1220    }
1221
1222    #[doc(alias = "draw-value")]
1223    fn connect_draw_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1224        unsafe extern "C" fn notify_draw_value_trampoline<P: IsA<Scale>, F: Fn(&P) + 'static>(
1225            this: *mut ffi::GtkScale,
1226            _param_spec: glib::ffi::gpointer,
1227            f: glib::ffi::gpointer,
1228        ) {
1229            unsafe {
1230                let f: &F = &*(f as *const F);
1231                f(Scale::from_glib_borrow(this).unsafe_cast_ref())
1232            }
1233        }
1234        unsafe {
1235            let f: Box_<F> = Box_::new(f);
1236            connect_raw(
1237                self.as_ptr() as *mut _,
1238                c"notify::draw-value".as_ptr(),
1239                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1240                    notify_draw_value_trampoline::<Self, F> as *const (),
1241                )),
1242                Box_::into_raw(f),
1243            )
1244        }
1245    }
1246
1247    #[doc(alias = "has-origin")]
1248    fn connect_has_origin_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1249        unsafe extern "C" fn notify_has_origin_trampoline<P: IsA<Scale>, F: Fn(&P) + 'static>(
1250            this: *mut ffi::GtkScale,
1251            _param_spec: glib::ffi::gpointer,
1252            f: glib::ffi::gpointer,
1253        ) {
1254            unsafe {
1255                let f: &F = &*(f as *const F);
1256                f(Scale::from_glib_borrow(this).unsafe_cast_ref())
1257            }
1258        }
1259        unsafe {
1260            let f: Box_<F> = Box_::new(f);
1261            connect_raw(
1262                self.as_ptr() as *mut _,
1263                c"notify::has-origin".as_ptr(),
1264                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1265                    notify_has_origin_trampoline::<Self, F> as *const (),
1266                )),
1267                Box_::into_raw(f),
1268            )
1269        }
1270    }
1271
1272    #[doc(alias = "value-pos")]
1273    fn connect_value_pos_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1274        unsafe extern "C" fn notify_value_pos_trampoline<P: IsA<Scale>, F: Fn(&P) + 'static>(
1275            this: *mut ffi::GtkScale,
1276            _param_spec: glib::ffi::gpointer,
1277            f: glib::ffi::gpointer,
1278        ) {
1279            unsafe {
1280                let f: &F = &*(f as *const F);
1281                f(Scale::from_glib_borrow(this).unsafe_cast_ref())
1282            }
1283        }
1284        unsafe {
1285            let f: Box_<F> = Box_::new(f);
1286            connect_raw(
1287                self.as_ptr() as *mut _,
1288                c"notify::value-pos".as_ptr(),
1289                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1290                    notify_value_pos_trampoline::<Self, F> as *const (),
1291                )),
1292                Box_::into_raw(f),
1293            )
1294        }
1295    }
1296}
1297
1298impl<O: IsA<Scale>> ScaleExt for O {}