[go: up one dir, main page]

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::AccessibleRange;
8use crate::{
9    ffi, Accessible, AccessibleRole, Adjustment, Align, Buildable, ConstraintTarget, LayoutManager,
10    Orientable, Orientation, Overflow, PositionType, Range, Widget,
11};
12use glib::{
13    prelude::*,
14    signal::{connect_raw, SignalHandlerId},
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    #[doc(alias = "GtkScale")]
23    pub struct Scale(Object<ffi::GtkScale, ffi::GtkScaleClass>) @extends Range, Widget, @implements Accessible, Buildable, ConstraintTarget, AccessibleRange, Orientable;
24
25    match fn {
26        type_ => || ffi::gtk_scale_get_type(),
27    }
28}
29
30#[cfg(not(any(feature = "v4_10")))]
31glib::wrapper! {
32    #[doc(alias = "GtkScale")]
33    pub struct Scale(Object<ffi::GtkScale, ffi::GtkScaleClass>) @extends Range, Widget, @implements Accessible, Buildable, ConstraintTarget, Orientable;
34
35    match fn {
36        type_ => || ffi::gtk_scale_get_type(),
37    }
38}
39
40impl Scale {
41    pub const NONE: Option<&'static Scale> = None;
42
43    #[doc(alias = "gtk_scale_new")]
44    pub fn new(orientation: Orientation, adjustment: Option<&impl IsA<Adjustment>>) -> Scale {
45        assert_initialized_main_thread!();
46        unsafe {
47            Widget::from_glib_none(ffi::gtk_scale_new(
48                orientation.into_glib(),
49                adjustment.map(|p| p.as_ref()).to_glib_none().0,
50            ))
51            .unsafe_cast()
52        }
53    }
54
55    #[doc(alias = "gtk_scale_new_with_range")]
56    #[doc(alias = "new_with_range")]
57    pub fn with_range(orientation: Orientation, min: f64, max: f64, step: f64) -> Scale {
58        assert_initialized_main_thread!();
59        unsafe {
60            Widget::from_glib_none(ffi::gtk_scale_new_with_range(
61                orientation.into_glib(),
62                min,
63                max,
64                step,
65            ))
66            .unsafe_cast()
67        }
68    }
69
70    // rustdoc-stripper-ignore-next
71    /// Creates a new builder-pattern struct instance to construct [`Scale`] objects.
72    ///
73    /// This method returns an instance of [`ScaleBuilder`](crate::builders::ScaleBuilder) which can be used to create [`Scale`] objects.
74    pub fn builder() -> ScaleBuilder {
75        ScaleBuilder::new()
76    }
77}
78
79impl Default for Scale {
80    fn default() -> Self {
81        glib::object::Object::new::<Self>()
82    }
83}
84
85// rustdoc-stripper-ignore-next
86/// A [builder-pattern] type to construct [`Scale`] objects.
87///
88/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
89#[must_use = "The builder must be built to be used"]
90pub struct ScaleBuilder {
91    builder: glib::object::ObjectBuilder<'static, Scale>,
92}
93
94impl ScaleBuilder {
95    fn new() -> Self {
96        Self {
97            builder: glib::object::Object::builder(),
98        }
99    }
100
101    pub fn digits(self, digits: i32) -> Self {
102        Self {
103            builder: self.builder.property("digits", digits),
104        }
105    }
106
107    pub fn draw_value(self, draw_value: bool) -> Self {
108        Self {
109            builder: self.builder.property("draw-value", draw_value),
110        }
111    }
112
113    pub fn has_origin(self, has_origin: bool) -> Self {
114        Self {
115            builder: self.builder.property("has-origin", has_origin),
116        }
117    }
118
119    pub fn value_pos(self, value_pos: PositionType) -> Self {
120        Self {
121            builder: self.builder.property("value-pos", value_pos),
122        }
123    }
124
125    pub fn adjustment(self, adjustment: &impl IsA<Adjustment>) -> Self {
126        Self {
127            builder: self
128                .builder
129                .property("adjustment", adjustment.clone().upcast()),
130        }
131    }
132
133    pub fn fill_level(self, fill_level: f64) -> Self {
134        Self {
135            builder: self.builder.property("fill-level", fill_level),
136        }
137    }
138
139    pub fn inverted(self, inverted: bool) -> Self {
140        Self {
141            builder: self.builder.property("inverted", inverted),
142        }
143    }
144
145    pub fn restrict_to_fill_level(self, restrict_to_fill_level: bool) -> Self {
146        Self {
147            builder: self
148                .builder
149                .property("restrict-to-fill-level", restrict_to_fill_level),
150        }
151    }
152
153    pub fn round_digits(self, round_digits: i32) -> Self {
154        Self {
155            builder: self.builder.property("round-digits", round_digits),
156        }
157    }
158
159    pub fn show_fill_level(self, show_fill_level: bool) -> Self {
160        Self {
161            builder: self.builder.property("show-fill-level", show_fill_level),
162        }
163    }
164
165    pub fn can_focus(self, can_focus: bool) -> Self {
166        Self {
167            builder: self.builder.property("can-focus", can_focus),
168        }
169    }
170
171    pub fn can_target(self, can_target: bool) -> Self {
172        Self {
173            builder: self.builder.property("can-target", can_target),
174        }
175    }
176
177    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
178        Self {
179            builder: self.builder.property("css-classes", css_classes.into()),
180        }
181    }
182
183    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
184        Self {
185            builder: self.builder.property("css-name", css_name.into()),
186        }
187    }
188
189    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
190        Self {
191            builder: self.builder.property("cursor", cursor.clone()),
192        }
193    }
194
195    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
196        Self {
197            builder: self.builder.property("focus-on-click", focus_on_click),
198        }
199    }
200
201    pub fn focusable(self, focusable: bool) -> Self {
202        Self {
203            builder: self.builder.property("focusable", focusable),
204        }
205    }
206
207    pub fn halign(self, halign: Align) -> Self {
208        Self {
209            builder: self.builder.property("halign", halign),
210        }
211    }
212
213    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
214        Self {
215            builder: self.builder.property("has-tooltip", has_tooltip),
216        }
217    }
218
219    pub fn height_request(self, height_request: i32) -> Self {
220        Self {
221            builder: self.builder.property("height-request", height_request),
222        }
223    }
224
225    pub fn hexpand(self, hexpand: bool) -> Self {
226        Self {
227            builder: self.builder.property("hexpand", hexpand),
228        }
229    }
230
231    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
232        Self {
233            builder: self.builder.property("hexpand-set", hexpand_set),
234        }
235    }
236
237    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
238        Self {
239            builder: self
240                .builder
241                .property("layout-manager", layout_manager.clone().upcast()),
242        }
243    }
244
245    #[cfg(feature = "v4_18")]
246    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
247    pub fn limit_events(self, limit_events: bool) -> Self {
248        Self {
249            builder: self.builder.property("limit-events", limit_events),
250        }
251    }
252
253    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
254        Self {
255            builder: self.builder.property("margin-bottom", margin_bottom),
256        }
257    }
258
259    pub fn margin_end(self, margin_end: i32) -> Self {
260        Self {
261            builder: self.builder.property("margin-end", margin_end),
262        }
263    }
264
265    pub fn margin_start(self, margin_start: i32) -> Self {
266        Self {
267            builder: self.builder.property("margin-start", margin_start),
268        }
269    }
270
271    pub fn margin_top(self, margin_top: i32) -> Self {
272        Self {
273            builder: self.builder.property("margin-top", margin_top),
274        }
275    }
276
277    pub fn name(self, name: impl Into<glib::GString>) -> Self {
278        Self {
279            builder: self.builder.property("name", name.into()),
280        }
281    }
282
283    pub fn opacity(self, opacity: f64) -> Self {
284        Self {
285            builder: self.builder.property("opacity", opacity),
286        }
287    }
288
289    pub fn overflow(self, overflow: Overflow) -> Self {
290        Self {
291            builder: self.builder.property("overflow", overflow),
292        }
293    }
294
295    pub fn receives_default(self, receives_default: bool) -> Self {
296        Self {
297            builder: self.builder.property("receives-default", receives_default),
298        }
299    }
300
301    pub fn sensitive(self, sensitive: bool) -> Self {
302        Self {
303            builder: self.builder.property("sensitive", sensitive),
304        }
305    }
306
307    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
308        Self {
309            builder: self
310                .builder
311                .property("tooltip-markup", tooltip_markup.into()),
312        }
313    }
314
315    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
316        Self {
317            builder: self.builder.property("tooltip-text", tooltip_text.into()),
318        }
319    }
320
321    pub fn valign(self, valign: Align) -> Self {
322        Self {
323            builder: self.builder.property("valign", valign),
324        }
325    }
326
327    pub fn vexpand(self, vexpand: bool) -> Self {
328        Self {
329            builder: self.builder.property("vexpand", vexpand),
330        }
331    }
332
333    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
334        Self {
335            builder: self.builder.property("vexpand-set", vexpand_set),
336        }
337    }
338
339    pub fn visible(self, visible: bool) -> Self {
340        Self {
341            builder: self.builder.property("visible", visible),
342        }
343    }
344
345    pub fn width_request(self, width_request: i32) -> Self {
346        Self {
347            builder: self.builder.property("width-request", width_request),
348        }
349    }
350
351    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
352        Self {
353            builder: self.builder.property("accessible-role", accessible_role),
354        }
355    }
356
357    pub fn orientation(self, orientation: Orientation) -> Self {
358        Self {
359            builder: self.builder.property("orientation", orientation),
360        }
361    }
362
363    // rustdoc-stripper-ignore-next
364    /// Build the [`Scale`].
365    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
366    pub fn build(self) -> Scale {
367        assert_initialized_main_thread!();
368        self.builder.build()
369    }
370}
371
372pub trait ScaleExt: IsA<Scale> + 'static {
373    #[doc(alias = "gtk_scale_add_mark")]
374    fn add_mark(&self, value: f64, position: PositionType, markup: Option<&str>) {
375        unsafe {
376            ffi::gtk_scale_add_mark(
377                self.as_ref().to_glib_none().0,
378                value,
379                position.into_glib(),
380                markup.to_glib_none().0,
381            );
382        }
383    }
384
385    #[doc(alias = "gtk_scale_clear_marks")]
386    fn clear_marks(&self) {
387        unsafe {
388            ffi::gtk_scale_clear_marks(self.as_ref().to_glib_none().0);
389        }
390    }
391
392    #[doc(alias = "gtk_scale_get_digits")]
393    #[doc(alias = "get_digits")]
394    fn digits(&self) -> i32 {
395        unsafe { ffi::gtk_scale_get_digits(self.as_ref().to_glib_none().0) }
396    }
397
398    #[doc(alias = "gtk_scale_get_draw_value")]
399    #[doc(alias = "get_draw_value")]
400    #[doc(alias = "draw-value")]
401    fn draws_value(&self) -> bool {
402        unsafe {
403            from_glib(ffi::gtk_scale_get_draw_value(
404                self.as_ref().to_glib_none().0,
405            ))
406        }
407    }
408
409    #[doc(alias = "gtk_scale_get_has_origin")]
410    #[doc(alias = "get_has_origin")]
411    #[doc(alias = "has-origin")]
412    fn has_origin(&self) -> bool {
413        unsafe {
414            from_glib(ffi::gtk_scale_get_has_origin(
415                self.as_ref().to_glib_none().0,
416            ))
417        }
418    }
419
420    #[doc(alias = "gtk_scale_get_layout")]
421    #[doc(alias = "get_layout")]
422    fn layout(&self) -> Option<pango::Layout> {
423        unsafe { from_glib_none(ffi::gtk_scale_get_layout(self.as_ref().to_glib_none().0)) }
424    }
425
426    #[doc(alias = "gtk_scale_get_layout_offsets")]
427    #[doc(alias = "get_layout_offsets")]
428    fn layout_offsets(&self) -> (i32, i32) {
429        unsafe {
430            let mut x = std::mem::MaybeUninit::uninit();
431            let mut y = std::mem::MaybeUninit::uninit();
432            ffi::gtk_scale_get_layout_offsets(
433                self.as_ref().to_glib_none().0,
434                x.as_mut_ptr(),
435                y.as_mut_ptr(),
436            );
437            (x.assume_init(), y.assume_init())
438        }
439    }
440
441    #[doc(alias = "gtk_scale_get_value_pos")]
442    #[doc(alias = "get_value_pos")]
443    #[doc(alias = "value-pos")]
444    fn value_pos(&self) -> PositionType {
445        unsafe { from_glib(ffi::gtk_scale_get_value_pos(self.as_ref().to_glib_none().0)) }
446    }
447
448    #[doc(alias = "gtk_scale_set_digits")]
449    #[doc(alias = "digits")]
450    fn set_digits(&self, digits: i32) {
451        unsafe {
452            ffi::gtk_scale_set_digits(self.as_ref().to_glib_none().0, digits);
453        }
454    }
455
456    #[doc(alias = "gtk_scale_set_draw_value")]
457    #[doc(alias = "draw-value")]
458    fn set_draw_value(&self, draw_value: bool) {
459        unsafe {
460            ffi::gtk_scale_set_draw_value(self.as_ref().to_glib_none().0, draw_value.into_glib());
461        }
462    }
463
464    #[doc(alias = "gtk_scale_set_format_value_func")]
465    fn set_format_value_func<P: Fn(&Scale, f64) -> String + 'static>(&self, func: P) {
466        let func_data: Box_<P> = Box_::new(func);
467        unsafe extern "C" fn func_func<P: Fn(&Scale, f64) -> String + 'static>(
468            scale: *mut ffi::GtkScale,
469            value: std::ffi::c_double,
470            user_data: glib::ffi::gpointer,
471        ) -> *mut std::ffi::c_char {
472            let scale = from_glib_borrow(scale);
473            let callback = &*(user_data as *mut P);
474            (*callback)(&scale, value).to_glib_full()
475        }
476        let func = Some(func_func::<P> as _);
477        unsafe extern "C" fn destroy_notify_func<P: Fn(&Scale, f64) -> String + 'static>(
478            data: glib::ffi::gpointer,
479        ) {
480            let _callback = Box_::from_raw(data as *mut P);
481        }
482        let destroy_call3 = Some(destroy_notify_func::<P> as _);
483        let super_callback0: Box_<P> = func_data;
484        unsafe {
485            ffi::gtk_scale_set_format_value_func(
486                self.as_ref().to_glib_none().0,
487                func,
488                Box_::into_raw(super_callback0) as *mut _,
489                destroy_call3,
490            );
491        }
492    }
493
494    #[doc(alias = "gtk_scale_set_has_origin")]
495    #[doc(alias = "has-origin")]
496    fn set_has_origin(&self, has_origin: bool) {
497        unsafe {
498            ffi::gtk_scale_set_has_origin(self.as_ref().to_glib_none().0, has_origin.into_glib());
499        }
500    }
501
502    #[doc(alias = "gtk_scale_set_value_pos")]
503    #[doc(alias = "value-pos")]
504    fn set_value_pos(&self, pos: PositionType) {
505        unsafe {
506            ffi::gtk_scale_set_value_pos(self.as_ref().to_glib_none().0, pos.into_glib());
507        }
508    }
509
510    #[doc(alias = "digits")]
511    fn connect_digits_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
512        unsafe extern "C" fn notify_digits_trampoline<P: IsA<Scale>, F: Fn(&P) + 'static>(
513            this: *mut ffi::GtkScale,
514            _param_spec: glib::ffi::gpointer,
515            f: glib::ffi::gpointer,
516        ) {
517            let f: &F = &*(f as *const F);
518            f(Scale::from_glib_borrow(this).unsafe_cast_ref())
519        }
520        unsafe {
521            let f: Box_<F> = Box_::new(f);
522            connect_raw(
523                self.as_ptr() as *mut _,
524                c"notify::digits".as_ptr() as *const _,
525                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
526                    notify_digits_trampoline::<Self, F> as *const (),
527                )),
528                Box_::into_raw(f),
529            )
530        }
531    }
532
533    #[doc(alias = "draw-value")]
534    fn connect_draw_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
535        unsafe extern "C" fn notify_draw_value_trampoline<P: IsA<Scale>, F: Fn(&P) + 'static>(
536            this: *mut ffi::GtkScale,
537            _param_spec: glib::ffi::gpointer,
538            f: glib::ffi::gpointer,
539        ) {
540            let f: &F = &*(f as *const F);
541            f(Scale::from_glib_borrow(this).unsafe_cast_ref())
542        }
543        unsafe {
544            let f: Box_<F> = Box_::new(f);
545            connect_raw(
546                self.as_ptr() as *mut _,
547                c"notify::draw-value".as_ptr() as *const _,
548                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
549                    notify_draw_value_trampoline::<Self, F> as *const (),
550                )),
551                Box_::into_raw(f),
552            )
553        }
554    }
555
556    #[doc(alias = "has-origin")]
557    fn connect_has_origin_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
558        unsafe extern "C" fn notify_has_origin_trampoline<P: IsA<Scale>, F: Fn(&P) + 'static>(
559            this: *mut ffi::GtkScale,
560            _param_spec: glib::ffi::gpointer,
561            f: glib::ffi::gpointer,
562        ) {
563            let f: &F = &*(f as *const F);
564            f(Scale::from_glib_borrow(this).unsafe_cast_ref())
565        }
566        unsafe {
567            let f: Box_<F> = Box_::new(f);
568            connect_raw(
569                self.as_ptr() as *mut _,
570                c"notify::has-origin".as_ptr() as *const _,
571                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
572                    notify_has_origin_trampoline::<Self, F> as *const (),
573                )),
574                Box_::into_raw(f),
575            )
576        }
577    }
578
579    #[doc(alias = "value-pos")]
580    fn connect_value_pos_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
581        unsafe extern "C" fn notify_value_pos_trampoline<P: IsA<Scale>, F: Fn(&P) + 'static>(
582            this: *mut ffi::GtkScale,
583            _param_spec: glib::ffi::gpointer,
584            f: glib::ffi::gpointer,
585        ) {
586            let f: &F = &*(f as *const F);
587            f(Scale::from_glib_borrow(this).unsafe_cast_ref())
588        }
589        unsafe {
590            let f: Box_<F> = Box_::new(f);
591            connect_raw(
592                self.as_ptr() as *mut _,
593                c"notify::value-pos".as_ptr() as *const _,
594                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
595                    notify_value_pos_trampoline::<Self, F> as *const (),
596                )),
597                Box_::into_raw(f),
598            )
599        }
600    }
601}
602
603impl<O: IsA<Scale>> ScaleExt for O {}