[go: up one dir, main page]

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