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