Skip to main content

gtk4/auto/
adjustment.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// A model for a numeric value.
16    ///
17    /// The [`Adjustment`][crate::Adjustment] has an associated lower and upper bound.
18    /// It also contains step and page increments, and a page size.
19    ///
20    /// Adjustments are used within several GTK widgets, including
21    /// [`SpinButton`][crate::SpinButton], [`Viewport`][crate::Viewport], [`Scrollbar`][crate::Scrollbar]
22    /// and [`Scale`][crate::Scale].
23    ///
24    /// The [`Adjustment`][crate::Adjustment] object does not update the value itself. Instead
25    /// it is left up to the owner of the [`Adjustment`][crate::Adjustment] to control the value.
26    ///
27    /// ## Properties
28    ///
29    ///
30    /// #### `lower`
31    ///  The minimum value of the adjustment.
32    ///
33    /// Readable | Writable
34    ///
35    ///
36    /// #### `page-increment`
37    ///  The page increment of the adjustment.
38    ///
39    /// Readable | Writable
40    ///
41    ///
42    /// #### `page-size`
43    ///  The page size of the adjustment.
44    ///
45    /// Note that the page-size is irrelevant and should be set to zero
46    /// if the adjustment is used for a simple scalar value, e.g. in a
47    /// [`SpinButton`][crate::SpinButton].
48    ///
49    /// Readable | Writable
50    ///
51    ///
52    /// #### `step-increment`
53    ///  The step increment of the adjustment.
54    ///
55    /// Readable | Writable
56    ///
57    ///
58    /// #### `upper`
59    ///  The maximum value of the adjustment.
60    ///
61    /// Note that values will be restricted by `upper - page-size` if the page-size
62    /// property is nonzero.
63    ///
64    /// Readable | Writable
65    ///
66    ///
67    /// #### `value`
68    ///  The value of the adjustment.
69    ///
70    /// Readable | Writable
71    ///
72    /// ## Signals
73    ///
74    ///
75    /// #### `changed`
76    ///  Emitted when one or more of the [`Adjustment`][crate::Adjustment] properties have been
77    /// changed.
78    ///
79    /// Note that the [`value`][struct@crate::Adjustment#value] property is
80    /// covered by the [`value-changed`][struct@crate::Adjustment#value-changed] signal.
81    ///
82    ///
83    ///
84    ///
85    /// #### `value-changed`
86    ///  Emitted when the value has been changed.
87    ///
88    ///
89    ///
90    /// # Implements
91    ///
92    /// [`AdjustmentExt`][trait@crate::prelude::AdjustmentExt], [`trait@glib::ObjectExt`]
93    #[doc(alias = "GtkAdjustment")]
94    pub struct Adjustment(Object<ffi::GtkAdjustment, ffi::GtkAdjustmentClass>);
95
96    match fn {
97        type_ => || ffi::gtk_adjustment_get_type(),
98    }
99}
100
101impl Adjustment {
102    pub const NONE: Option<&'static Adjustment> = None;
103
104    /// Creates a new [`Adjustment`][crate::Adjustment].
105    /// ## `value`
106    /// the initial value
107    /// ## `lower`
108    /// the minimum value
109    /// ## `upper`
110    /// the maximum value
111    /// ## `step_increment`
112    /// the step increment
113    /// ## `page_increment`
114    /// the page increment
115    /// ## `page_size`
116    /// the page size
117    ///
118    /// # Returns
119    ///
120    /// a new [`Adjustment`][crate::Adjustment]
121    #[doc(alias = "gtk_adjustment_new")]
122    pub fn new(
123        value: f64,
124        lower: f64,
125        upper: f64,
126        step_increment: f64,
127        page_increment: f64,
128        page_size: f64,
129    ) -> Adjustment {
130        assert_initialized_main_thread!();
131        unsafe {
132            from_glib_none(ffi::gtk_adjustment_new(
133                value,
134                lower,
135                upper,
136                step_increment,
137                page_increment,
138                page_size,
139            ))
140        }
141    }
142
143    // rustdoc-stripper-ignore-next
144    /// Creates a new builder-pattern struct instance to construct [`Adjustment`] objects.
145    ///
146    /// This method returns an instance of [`AdjustmentBuilder`](crate::builders::AdjustmentBuilder) which can be used to create [`Adjustment`] objects.
147    pub fn builder() -> AdjustmentBuilder {
148        AdjustmentBuilder::new()
149    }
150}
151
152impl Default for Adjustment {
153    fn default() -> Self {
154        glib::object::Object::new::<Self>()
155    }
156}
157
158// rustdoc-stripper-ignore-next
159/// A [builder-pattern] type to construct [`Adjustment`] objects.
160///
161/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
162#[must_use = "The builder must be built to be used"]
163pub struct AdjustmentBuilder {
164    builder: glib::object::ObjectBuilder<'static, Adjustment>,
165}
166
167impl AdjustmentBuilder {
168    fn new() -> Self {
169        Self {
170            builder: glib::object::Object::builder(),
171        }
172    }
173
174    /// The minimum value of the adjustment.
175    pub fn lower(self, lower: f64) -> Self {
176        Self {
177            builder: self.builder.property("lower", lower),
178        }
179    }
180
181    /// The page increment of the adjustment.
182    pub fn page_increment(self, page_increment: f64) -> Self {
183        Self {
184            builder: self.builder.property("page-increment", page_increment),
185        }
186    }
187
188    /// The page size of the adjustment.
189    ///
190    /// Note that the page-size is irrelevant and should be set to zero
191    /// if the adjustment is used for a simple scalar value, e.g. in a
192    /// [`SpinButton`][crate::SpinButton].
193    pub fn page_size(self, page_size: f64) -> Self {
194        Self {
195            builder: self.builder.property("page-size", page_size),
196        }
197    }
198
199    /// The step increment of the adjustment.
200    pub fn step_increment(self, step_increment: f64) -> Self {
201        Self {
202            builder: self.builder.property("step-increment", step_increment),
203        }
204    }
205
206    /// The maximum value of the adjustment.
207    ///
208    /// Note that values will be restricted by `upper - page-size` if the page-size
209    /// property is nonzero.
210    pub fn upper(self, upper: f64) -> Self {
211        Self {
212            builder: self.builder.property("upper", upper),
213        }
214    }
215
216    /// The value of the adjustment.
217    pub fn value(self, value: f64) -> Self {
218        Self {
219            builder: self.builder.property("value", value),
220        }
221    }
222
223    // rustdoc-stripper-ignore-next
224    /// Build the [`Adjustment`].
225    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
226    pub fn build(self) -> Adjustment {
227        assert_initialized_main_thread!();
228        self.builder.build()
229    }
230}
231
232/// Trait containing all [`struct@Adjustment`] methods.
233///
234/// # Implementors
235///
236/// [`Adjustment`][struct@crate::Adjustment]
237pub trait AdjustmentExt: IsA<Adjustment> + 'static {
238    /// Updates the value of the adjustment to ensure that the
239    /// given range is contained in the current page.
240    ///
241    /// The current page goes from `value` to `value` + `page-size`.
242    /// If the range is larger than the page size, then only the
243    /// start of it will be in the current page.
244    ///
245    /// A [`value-changed`][struct@crate::Adjustment#value-changed] signal will be emitted
246    /// if the value is changed.
247    /// ## `lower`
248    /// the lower value
249    /// ## `upper`
250    /// the upper value
251    #[doc(alias = "gtk_adjustment_clamp_page")]
252    fn clamp_page(&self, lower: f64, upper: f64) {
253        unsafe {
254            ffi::gtk_adjustment_clamp_page(self.as_ref().to_glib_none().0, lower, upper);
255        }
256    }
257
258    /// Sets all properties of the adjustment at once.
259    ///
260    /// Use this function to avoid multiple emissions of the
261    /// [`changed`][struct@crate::Adjustment#changed] signal. See
262    /// [`set_lower()`][Self::set_lower()] for an alternative
263    /// way of compressing multiple emissions of
264    /// [`changed`][struct@crate::Adjustment#changed] into one.
265    /// ## `value`
266    /// the new value
267    /// ## `lower`
268    /// the new minimum value
269    /// ## `upper`
270    /// the new maximum value
271    /// ## `step_increment`
272    /// the new step increment
273    /// ## `page_increment`
274    /// the new page increment
275    /// ## `page_size`
276    /// the new page size
277    #[doc(alias = "gtk_adjustment_configure")]
278    fn configure(
279        &self,
280        value: f64,
281        lower: f64,
282        upper: f64,
283        step_increment: f64,
284        page_increment: f64,
285        page_size: f64,
286    ) {
287        unsafe {
288            ffi::gtk_adjustment_configure(
289                self.as_ref().to_glib_none().0,
290                value,
291                lower,
292                upper,
293                step_increment,
294                page_increment,
295                page_size,
296            );
297        }
298    }
299
300    /// Retrieves the minimum value of the adjustment.
301    ///
302    /// # Returns
303    ///
304    /// the minimum value
305    #[doc(alias = "gtk_adjustment_get_lower")]
306    #[doc(alias = "get_lower")]
307    fn lower(&self) -> f64 {
308        unsafe { ffi::gtk_adjustment_get_lower(self.as_ref().to_glib_none().0) }
309    }
310
311    /// Gets the smaller of step increment and page increment.
312    ///
313    /// # Returns
314    ///
315    /// the minimum increment
316    #[doc(alias = "gtk_adjustment_get_minimum_increment")]
317    #[doc(alias = "get_minimum_increment")]
318    fn minimum_increment(&self) -> f64 {
319        unsafe { ffi::gtk_adjustment_get_minimum_increment(self.as_ref().to_glib_none().0) }
320    }
321
322    /// Retrieves the page increment of the adjustment.
323    ///
324    /// # Returns
325    ///
326    /// the page increment
327    #[doc(alias = "gtk_adjustment_get_page_increment")]
328    #[doc(alias = "get_page_increment")]
329    #[doc(alias = "page-increment")]
330    fn page_increment(&self) -> f64 {
331        unsafe { ffi::gtk_adjustment_get_page_increment(self.as_ref().to_glib_none().0) }
332    }
333
334    /// Retrieves the page size of the adjustment.
335    ///
336    /// # Returns
337    ///
338    /// the page size
339    #[doc(alias = "gtk_adjustment_get_page_size")]
340    #[doc(alias = "get_page_size")]
341    #[doc(alias = "page-size")]
342    fn page_size(&self) -> f64 {
343        unsafe { ffi::gtk_adjustment_get_page_size(self.as_ref().to_glib_none().0) }
344    }
345
346    /// Retrieves the step increment of the adjustment.
347    ///
348    /// # Returns
349    ///
350    /// the step increment
351    #[doc(alias = "gtk_adjustment_get_step_increment")]
352    #[doc(alias = "get_step_increment")]
353    #[doc(alias = "step-increment")]
354    fn step_increment(&self) -> f64 {
355        unsafe { ffi::gtk_adjustment_get_step_increment(self.as_ref().to_glib_none().0) }
356    }
357
358    /// Retrieves the maximum value of the adjustment.
359    ///
360    /// # Returns
361    ///
362    /// the maximum value
363    #[doc(alias = "gtk_adjustment_get_upper")]
364    #[doc(alias = "get_upper")]
365    fn upper(&self) -> f64 {
366        unsafe { ffi::gtk_adjustment_get_upper(self.as_ref().to_glib_none().0) }
367    }
368
369    /// Gets the current value of the adjustment.
370    ///
371    /// # Returns
372    ///
373    /// the current value
374    #[doc(alias = "gtk_adjustment_get_value")]
375    #[doc(alias = "get_value")]
376    fn value(&self) -> f64 {
377        unsafe { ffi::gtk_adjustment_get_value(self.as_ref().to_glib_none().0) }
378    }
379
380    /// s possible
381    /// to compress the [`changed`][struct@crate::Adjustment#changed] signals into one
382    /// by calling g_object_freeze_notify() and g_object_thaw_notify()
383    /// around the calls to the individual setters.
384    ///
385    /// Alternatively, using a single g_object_set() for all the properties
386    /// to change, or using [`configure()`][Self::configure()] has the same effect.
387    /// ## `lower`
388    /// the new minimum value
389    #[doc(alias = "gtk_adjustment_set_lower")]
390    #[doc(alias = "lower")]
391    fn set_lower(&self, lower: f64) {
392        unsafe {
393            ffi::gtk_adjustment_set_lower(self.as_ref().to_glib_none().0, lower);
394        }
395    }
396
397    /// Sets the page increment of the adjustment.
398    ///
399    /// See [`set_lower()`][Self::set_lower()] about how to compress
400    /// multiple emissions of the [`changed`][struct@crate::Adjustment#changed]
401    /// signal when setting multiple adjustment properties.
402    /// ## `page_increment`
403    /// the new page increment
404    #[doc(alias = "gtk_adjustment_set_page_increment")]
405    #[doc(alias = "page-increment")]
406    fn set_page_increment(&self, page_increment: f64) {
407        unsafe {
408            ffi::gtk_adjustment_set_page_increment(self.as_ref().to_glib_none().0, page_increment);
409        }
410    }
411
412    /// Sets the page size of the adjustment.
413    ///
414    /// See [`set_lower()`][Self::set_lower()] about how to compress
415    /// multiple emissions of the [`changed`][struct@crate::Adjustment#changed]
416    /// signal when setting multiple adjustment properties.
417    /// ## `page_size`
418    /// the new page size
419    #[doc(alias = "gtk_adjustment_set_page_size")]
420    #[doc(alias = "page-size")]
421    fn set_page_size(&self, page_size: f64) {
422        unsafe {
423            ffi::gtk_adjustment_set_page_size(self.as_ref().to_glib_none().0, page_size);
424        }
425    }
426
427    /// Sets the step increment of the adjustment.
428    ///
429    /// See [`set_lower()`][Self::set_lower()] about how to compress
430    /// multiple emissions of the [`changed`][struct@crate::Adjustment#changed]
431    /// signal when setting multiple adjustment properties.
432    /// ## `step_increment`
433    /// the new step increment
434    #[doc(alias = "gtk_adjustment_set_step_increment")]
435    #[doc(alias = "step-increment")]
436    fn set_step_increment(&self, step_increment: f64) {
437        unsafe {
438            ffi::gtk_adjustment_set_step_increment(self.as_ref().to_glib_none().0, step_increment);
439        }
440    }
441
442    /// Sets the maximum value of the adjustment.
443    ///
444    /// Note that values will be restricted by `upper - page-size`
445    /// if the page-size property is nonzero.
446    ///
447    /// See [`set_lower()`][Self::set_lower()] about how to compress
448    /// multiple emissions of the [`changed`][struct@crate::Adjustment#changed]
449    /// signal when setting multiple adjustment properties.
450    /// ## `upper`
451    /// the new maximum value
452    #[doc(alias = "gtk_adjustment_set_upper")]
453    #[doc(alias = "upper")]
454    fn set_upper(&self, upper: f64) {
455        unsafe {
456            ffi::gtk_adjustment_set_upper(self.as_ref().to_glib_none().0, upper);
457        }
458    }
459
460    /// Sets the [`Adjustment`][crate::Adjustment] value.
461    ///
462    /// The value is clamped to lie between [`lower`][struct@crate::Adjustment#lower]
463    /// and [`upper`][struct@crate::Adjustment#upper].
464    ///
465    /// Note that for adjustments which are used in a [`Scrollbar`][crate::Scrollbar],
466    /// the effective range of allowed values goes from
467    /// [`lower`][struct@crate::Adjustment#lower] to
468    /// [`upper`][struct@crate::Adjustment#upper] - [`page-size`][struct@crate::Adjustment#page-size].
469    /// ## `value`
470    /// the new value
471    #[doc(alias = "gtk_adjustment_set_value")]
472    #[doc(alias = "value")]
473    fn set_value(&self, value: f64) {
474        unsafe {
475            ffi::gtk_adjustment_set_value(self.as_ref().to_glib_none().0, value);
476        }
477    }
478
479    /// Emitted when one or more of the [`Adjustment`][crate::Adjustment] properties have been
480    /// changed.
481    ///
482    /// Note that the [`value`][struct@crate::Adjustment#value] property is
483    /// covered by the [`value-changed`][struct@crate::Adjustment#value-changed] signal.
484    #[doc(alias = "changed")]
485    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
486        unsafe extern "C" fn changed_trampoline<P: IsA<Adjustment>, F: Fn(&P) + 'static>(
487            this: *mut ffi::GtkAdjustment,
488            f: glib::ffi::gpointer,
489        ) {
490            unsafe {
491                let f: &F = &*(f as *const F);
492                f(Adjustment::from_glib_borrow(this).unsafe_cast_ref())
493            }
494        }
495        unsafe {
496            let f: Box_<F> = Box_::new(f);
497            connect_raw(
498                self.as_ptr() as *mut _,
499                c"changed".as_ptr(),
500                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
501                    changed_trampoline::<Self, F> as *const (),
502                )),
503                Box_::into_raw(f),
504            )
505        }
506    }
507
508    /// Emitted when the value has been changed.
509    #[doc(alias = "value-changed")]
510    fn connect_value_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
511        unsafe extern "C" fn value_changed_trampoline<P: IsA<Adjustment>, F: Fn(&P) + 'static>(
512            this: *mut ffi::GtkAdjustment,
513            f: glib::ffi::gpointer,
514        ) {
515            unsafe {
516                let f: &F = &*(f as *const F);
517                f(Adjustment::from_glib_borrow(this).unsafe_cast_ref())
518            }
519        }
520        unsafe {
521            let f: Box_<F> = Box_::new(f);
522            connect_raw(
523                self.as_ptr() as *mut _,
524                c"value-changed".as_ptr(),
525                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
526                    value_changed_trampoline::<Self, F> as *const (),
527                )),
528                Box_::into_raw(f),
529            )
530        }
531    }
532
533    #[doc(alias = "lower")]
534    fn connect_lower_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
535        unsafe extern "C" fn notify_lower_trampoline<P: IsA<Adjustment>, F: Fn(&P) + 'static>(
536            this: *mut ffi::GtkAdjustment,
537            _param_spec: glib::ffi::gpointer,
538            f: glib::ffi::gpointer,
539        ) {
540            unsafe {
541                let f: &F = &*(f as *const F);
542                f(Adjustment::from_glib_borrow(this).unsafe_cast_ref())
543            }
544        }
545        unsafe {
546            let f: Box_<F> = Box_::new(f);
547            connect_raw(
548                self.as_ptr() as *mut _,
549                c"notify::lower".as_ptr(),
550                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
551                    notify_lower_trampoline::<Self, F> as *const (),
552                )),
553                Box_::into_raw(f),
554            )
555        }
556    }
557
558    #[doc(alias = "page-increment")]
559    fn connect_page_increment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
560        unsafe extern "C" fn notify_page_increment_trampoline<
561            P: IsA<Adjustment>,
562            F: Fn(&P) + 'static,
563        >(
564            this: *mut ffi::GtkAdjustment,
565            _param_spec: glib::ffi::gpointer,
566            f: glib::ffi::gpointer,
567        ) {
568            unsafe {
569                let f: &F = &*(f as *const F);
570                f(Adjustment::from_glib_borrow(this).unsafe_cast_ref())
571            }
572        }
573        unsafe {
574            let f: Box_<F> = Box_::new(f);
575            connect_raw(
576                self.as_ptr() as *mut _,
577                c"notify::page-increment".as_ptr(),
578                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
579                    notify_page_increment_trampoline::<Self, F> as *const (),
580                )),
581                Box_::into_raw(f),
582            )
583        }
584    }
585
586    #[doc(alias = "page-size")]
587    fn connect_page_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
588        unsafe extern "C" fn notify_page_size_trampoline<
589            P: IsA<Adjustment>,
590            F: Fn(&P) + 'static,
591        >(
592            this: *mut ffi::GtkAdjustment,
593            _param_spec: glib::ffi::gpointer,
594            f: glib::ffi::gpointer,
595        ) {
596            unsafe {
597                let f: &F = &*(f as *const F);
598                f(Adjustment::from_glib_borrow(this).unsafe_cast_ref())
599            }
600        }
601        unsafe {
602            let f: Box_<F> = Box_::new(f);
603            connect_raw(
604                self.as_ptr() as *mut _,
605                c"notify::page-size".as_ptr(),
606                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
607                    notify_page_size_trampoline::<Self, F> as *const (),
608                )),
609                Box_::into_raw(f),
610            )
611        }
612    }
613
614    #[doc(alias = "step-increment")]
615    fn connect_step_increment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
616        unsafe extern "C" fn notify_step_increment_trampoline<
617            P: IsA<Adjustment>,
618            F: Fn(&P) + 'static,
619        >(
620            this: *mut ffi::GtkAdjustment,
621            _param_spec: glib::ffi::gpointer,
622            f: glib::ffi::gpointer,
623        ) {
624            unsafe {
625                let f: &F = &*(f as *const F);
626                f(Adjustment::from_glib_borrow(this).unsafe_cast_ref())
627            }
628        }
629        unsafe {
630            let f: Box_<F> = Box_::new(f);
631            connect_raw(
632                self.as_ptr() as *mut _,
633                c"notify::step-increment".as_ptr(),
634                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
635                    notify_step_increment_trampoline::<Self, F> as *const (),
636                )),
637                Box_::into_raw(f),
638            )
639        }
640    }
641
642    #[doc(alias = "upper")]
643    fn connect_upper_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
644        unsafe extern "C" fn notify_upper_trampoline<P: IsA<Adjustment>, F: Fn(&P) + 'static>(
645            this: *mut ffi::GtkAdjustment,
646            _param_spec: glib::ffi::gpointer,
647            f: glib::ffi::gpointer,
648        ) {
649            unsafe {
650                let f: &F = &*(f as *const F);
651                f(Adjustment::from_glib_borrow(this).unsafe_cast_ref())
652            }
653        }
654        unsafe {
655            let f: Box_<F> = Box_::new(f);
656            connect_raw(
657                self.as_ptr() as *mut _,
658                c"notify::upper".as_ptr(),
659                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
660                    notify_upper_trampoline::<Self, F> as *const (),
661                )),
662                Box_::into_raw(f),
663            )
664        }
665    }
666
667    #[doc(alias = "value")]
668    fn connect_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
669        unsafe extern "C" fn notify_value_trampoline<P: IsA<Adjustment>, F: Fn(&P) + 'static>(
670            this: *mut ffi::GtkAdjustment,
671            _param_spec: glib::ffi::gpointer,
672            f: glib::ffi::gpointer,
673        ) {
674            unsafe {
675                let f: &F = &*(f as *const F);
676                f(Adjustment::from_glib_borrow(this).unsafe_cast_ref())
677            }
678        }
679        unsafe {
680            let f: Box_<F> = Box_::new(f);
681            connect_raw(
682                self.as_ptr() as *mut _,
683                c"notify::value".as_ptr(),
684                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
685                    notify_value_trampoline::<Self, F> as *const (),
686                )),
687                Box_::into_raw(f),
688            )
689        }
690    }
691}
692
693impl<O: IsA<Adjustment>> AdjustmentExt for O {}