[go: up one dir, main page]

gtk4/auto/
picture.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#![allow(deprecated)]
5
6#[cfg(feature = "v4_8")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
8use crate::ContentFit;
9use crate::{
10    ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
11    Widget,
12};
13use glib::{
14    prelude::*,
15    signal::{connect_raw, SignalHandlerId},
16    translate::*,
17};
18use std::boxed::Box as Box_;
19
20glib::wrapper! {
21    #[doc(alias = "GtkPicture")]
22    pub struct Picture(Object<ffi::GtkPicture, ffi::GtkPictureClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
23
24    match fn {
25        type_ => || ffi::gtk_picture_get_type(),
26    }
27}
28
29impl Picture {
30    #[doc(alias = "gtk_picture_new")]
31    pub fn new() -> Picture {
32        assert_initialized_main_thread!();
33        unsafe { Widget::from_glib_none(ffi::gtk_picture_new()).unsafe_cast() }
34    }
35
36    #[doc(alias = "gtk_picture_new_for_file")]
37    #[doc(alias = "new_for_file")]
38    pub fn for_file(file: &impl IsA<gio::File>) -> Picture {
39        assert_initialized_main_thread!();
40        unsafe {
41            Widget::from_glib_none(ffi::gtk_picture_new_for_file(
42                file.as_ref().to_glib_none().0,
43            ))
44            .unsafe_cast()
45        }
46    }
47
48    #[doc(alias = "gtk_picture_new_for_filename")]
49    #[doc(alias = "new_for_filename")]
50    pub fn for_filename(filename: impl AsRef<std::path::Path>) -> Picture {
51        assert_initialized_main_thread!();
52        unsafe {
53            Widget::from_glib_none(ffi::gtk_picture_new_for_filename(
54                filename.as_ref().to_glib_none().0,
55            ))
56            .unsafe_cast()
57        }
58    }
59
60    #[doc(alias = "gtk_picture_new_for_paintable")]
61    #[doc(alias = "new_for_paintable")]
62    pub fn for_paintable(paintable: &impl IsA<gdk::Paintable>) -> Picture {
63        assert_initialized_main_thread!();
64        unsafe {
65            Widget::from_glib_none(ffi::gtk_picture_new_for_paintable(
66                paintable.as_ref().to_glib_none().0,
67            ))
68            .unsafe_cast()
69        }
70    }
71
72    #[cfg_attr(feature = "v4_12", deprecated = "Since 4.12")]
73    #[allow(deprecated)]
74    #[doc(alias = "gtk_picture_new_for_pixbuf")]
75    #[doc(alias = "new_for_pixbuf")]
76    pub fn for_pixbuf(pixbuf: &gdk_pixbuf::Pixbuf) -> Picture {
77        assert_initialized_main_thread!();
78        unsafe {
79            Widget::from_glib_none(ffi::gtk_picture_new_for_pixbuf(pixbuf.to_glib_none().0))
80                .unsafe_cast()
81        }
82    }
83
84    #[doc(alias = "gtk_picture_new_for_resource")]
85    #[doc(alias = "new_for_resource")]
86    pub fn for_resource(resource_path: &str) -> Picture {
87        assert_initialized_main_thread!();
88        unsafe {
89            Widget::from_glib_none(ffi::gtk_picture_new_for_resource(
90                resource_path.to_glib_none().0,
91            ))
92            .unsafe_cast()
93        }
94    }
95
96    // rustdoc-stripper-ignore-next
97    /// Creates a new builder-pattern struct instance to construct [`Picture`] objects.
98    ///
99    /// This method returns an instance of [`PictureBuilder`](crate::builders::PictureBuilder) which can be used to create [`Picture`] objects.
100    pub fn builder() -> PictureBuilder {
101        PictureBuilder::new()
102    }
103
104    #[doc(alias = "gtk_picture_get_alternative_text")]
105    #[doc(alias = "get_alternative_text")]
106    #[doc(alias = "alternative-text")]
107    pub fn alternative_text(&self) -> Option<glib::GString> {
108        unsafe { from_glib_none(ffi::gtk_picture_get_alternative_text(self.to_glib_none().0)) }
109    }
110
111    #[doc(alias = "gtk_picture_get_can_shrink")]
112    #[doc(alias = "get_can_shrink")]
113    #[doc(alias = "can-shrink")]
114    pub fn can_shrink(&self) -> bool {
115        unsafe { from_glib(ffi::gtk_picture_get_can_shrink(self.to_glib_none().0)) }
116    }
117
118    #[cfg(feature = "v4_8")]
119    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
120    #[doc(alias = "gtk_picture_get_content_fit")]
121    #[doc(alias = "get_content_fit")]
122    #[doc(alias = "content-fit")]
123    pub fn content_fit(&self) -> ContentFit {
124        unsafe { from_glib(ffi::gtk_picture_get_content_fit(self.to_glib_none().0)) }
125    }
126
127    #[doc(alias = "gtk_picture_get_file")]
128    #[doc(alias = "get_file")]
129    pub fn file(&self) -> Option<gio::File> {
130        unsafe { from_glib_none(ffi::gtk_picture_get_file(self.to_glib_none().0)) }
131    }
132
133    #[cfg_attr(feature = "v4_8", deprecated = "Since 4.8")]
134    #[allow(deprecated)]
135    #[doc(alias = "gtk_picture_get_keep_aspect_ratio")]
136    #[doc(alias = "get_keep_aspect_ratio")]
137    #[doc(alias = "keep-aspect-ratio")]
138    pub fn is_keep_aspect_ratio(&self) -> bool {
139        unsafe {
140            from_glib(ffi::gtk_picture_get_keep_aspect_ratio(
141                self.to_glib_none().0,
142            ))
143        }
144    }
145
146    #[doc(alias = "gtk_picture_get_paintable")]
147    #[doc(alias = "get_paintable")]
148    pub fn paintable(&self) -> Option<gdk::Paintable> {
149        unsafe { from_glib_none(ffi::gtk_picture_get_paintable(self.to_glib_none().0)) }
150    }
151
152    #[doc(alias = "gtk_picture_set_alternative_text")]
153    #[doc(alias = "alternative-text")]
154    pub fn set_alternative_text(&self, alternative_text: Option<&str>) {
155        unsafe {
156            ffi::gtk_picture_set_alternative_text(
157                self.to_glib_none().0,
158                alternative_text.to_glib_none().0,
159            );
160        }
161    }
162
163    #[doc(alias = "gtk_picture_set_can_shrink")]
164    #[doc(alias = "can-shrink")]
165    pub fn set_can_shrink(&self, can_shrink: bool) {
166        unsafe {
167            ffi::gtk_picture_set_can_shrink(self.to_glib_none().0, can_shrink.into_glib());
168        }
169    }
170
171    #[cfg(feature = "v4_8")]
172    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
173    #[doc(alias = "gtk_picture_set_content_fit")]
174    #[doc(alias = "content-fit")]
175    pub fn set_content_fit(&self, content_fit: ContentFit) {
176        unsafe {
177            ffi::gtk_picture_set_content_fit(self.to_glib_none().0, content_fit.into_glib());
178        }
179    }
180
181    #[doc(alias = "gtk_picture_set_file")]
182    #[doc(alias = "file")]
183    pub fn set_file(&self, file: Option<&impl IsA<gio::File>>) {
184        unsafe {
185            ffi::gtk_picture_set_file(
186                self.to_glib_none().0,
187                file.map(|p| p.as_ref()).to_glib_none().0,
188            );
189        }
190    }
191
192    #[doc(alias = "gtk_picture_set_filename")]
193    pub fn set_filename(&self, filename: Option<impl AsRef<std::path::Path>>) {
194        unsafe {
195            ffi::gtk_picture_set_filename(
196                self.to_glib_none().0,
197                filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
198            );
199        }
200    }
201
202    #[cfg_attr(feature = "v4_8", deprecated = "Since 4.8")]
203    #[allow(deprecated)]
204    #[doc(alias = "gtk_picture_set_keep_aspect_ratio")]
205    #[doc(alias = "keep-aspect-ratio")]
206    pub fn set_keep_aspect_ratio(&self, keep_aspect_ratio: bool) {
207        unsafe {
208            ffi::gtk_picture_set_keep_aspect_ratio(
209                self.to_glib_none().0,
210                keep_aspect_ratio.into_glib(),
211            );
212        }
213    }
214
215    #[doc(alias = "gtk_picture_set_paintable")]
216    #[doc(alias = "paintable")]
217    pub fn set_paintable(&self, paintable: Option<&impl IsA<gdk::Paintable>>) {
218        unsafe {
219            ffi::gtk_picture_set_paintable(
220                self.to_glib_none().0,
221                paintable.map(|p| p.as_ref()).to_glib_none().0,
222            );
223        }
224    }
225
226    #[cfg_attr(feature = "v4_12", deprecated = "Since 4.12")]
227    #[allow(deprecated)]
228    #[doc(alias = "gtk_picture_set_pixbuf")]
229    pub fn set_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
230        unsafe {
231            ffi::gtk_picture_set_pixbuf(self.to_glib_none().0, pixbuf.to_glib_none().0);
232        }
233    }
234
235    #[doc(alias = "gtk_picture_set_resource")]
236    pub fn set_resource(&self, resource_path: Option<&str>) {
237        unsafe {
238            ffi::gtk_picture_set_resource(self.to_glib_none().0, resource_path.to_glib_none().0);
239        }
240    }
241
242    #[doc(alias = "alternative-text")]
243    pub fn connect_alternative_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
244        unsafe extern "C" fn notify_alternative_text_trampoline<F: Fn(&Picture) + 'static>(
245            this: *mut ffi::GtkPicture,
246            _param_spec: glib::ffi::gpointer,
247            f: glib::ffi::gpointer,
248        ) {
249            let f: &F = &*(f as *const F);
250            f(&from_glib_borrow(this))
251        }
252        unsafe {
253            let f: Box_<F> = Box_::new(f);
254            connect_raw(
255                self.as_ptr() as *mut _,
256                c"notify::alternative-text".as_ptr() as *const _,
257                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
258                    notify_alternative_text_trampoline::<F> as *const (),
259                )),
260                Box_::into_raw(f),
261            )
262        }
263    }
264
265    #[doc(alias = "can-shrink")]
266    pub fn connect_can_shrink_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
267        unsafe extern "C" fn notify_can_shrink_trampoline<F: Fn(&Picture) + 'static>(
268            this: *mut ffi::GtkPicture,
269            _param_spec: glib::ffi::gpointer,
270            f: glib::ffi::gpointer,
271        ) {
272            let f: &F = &*(f as *const F);
273            f(&from_glib_borrow(this))
274        }
275        unsafe {
276            let f: Box_<F> = Box_::new(f);
277            connect_raw(
278                self.as_ptr() as *mut _,
279                c"notify::can-shrink".as_ptr() as *const _,
280                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
281                    notify_can_shrink_trampoline::<F> as *const (),
282                )),
283                Box_::into_raw(f),
284            )
285        }
286    }
287
288    #[cfg(feature = "v4_8")]
289    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
290    #[doc(alias = "content-fit")]
291    pub fn connect_content_fit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
292        unsafe extern "C" fn notify_content_fit_trampoline<F: Fn(&Picture) + 'static>(
293            this: *mut ffi::GtkPicture,
294            _param_spec: glib::ffi::gpointer,
295            f: glib::ffi::gpointer,
296        ) {
297            let f: &F = &*(f as *const F);
298            f(&from_glib_borrow(this))
299        }
300        unsafe {
301            let f: Box_<F> = Box_::new(f);
302            connect_raw(
303                self.as_ptr() as *mut _,
304                c"notify::content-fit".as_ptr() as *const _,
305                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
306                    notify_content_fit_trampoline::<F> as *const (),
307                )),
308                Box_::into_raw(f),
309            )
310        }
311    }
312
313    #[doc(alias = "file")]
314    pub fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
315        unsafe extern "C" fn notify_file_trampoline<F: Fn(&Picture) + 'static>(
316            this: *mut ffi::GtkPicture,
317            _param_spec: glib::ffi::gpointer,
318            f: glib::ffi::gpointer,
319        ) {
320            let f: &F = &*(f as *const F);
321            f(&from_glib_borrow(this))
322        }
323        unsafe {
324            let f: Box_<F> = Box_::new(f);
325            connect_raw(
326                self.as_ptr() as *mut _,
327                c"notify::file".as_ptr() as *const _,
328                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
329                    notify_file_trampoline::<F> as *const (),
330                )),
331                Box_::into_raw(f),
332            )
333        }
334    }
335
336    #[cfg_attr(feature = "v4_8", deprecated = "Since 4.8")]
337    #[doc(alias = "keep-aspect-ratio")]
338    pub fn connect_keep_aspect_ratio_notify<F: Fn(&Self) + 'static>(
339        &self,
340        f: F,
341    ) -> SignalHandlerId {
342        unsafe extern "C" fn notify_keep_aspect_ratio_trampoline<F: Fn(&Picture) + 'static>(
343            this: *mut ffi::GtkPicture,
344            _param_spec: glib::ffi::gpointer,
345            f: glib::ffi::gpointer,
346        ) {
347            let f: &F = &*(f as *const F);
348            f(&from_glib_borrow(this))
349        }
350        unsafe {
351            let f: Box_<F> = Box_::new(f);
352            connect_raw(
353                self.as_ptr() as *mut _,
354                c"notify::keep-aspect-ratio".as_ptr() as *const _,
355                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
356                    notify_keep_aspect_ratio_trampoline::<F> as *const (),
357                )),
358                Box_::into_raw(f),
359            )
360        }
361    }
362
363    #[doc(alias = "paintable")]
364    pub fn connect_paintable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
365        unsafe extern "C" fn notify_paintable_trampoline<F: Fn(&Picture) + 'static>(
366            this: *mut ffi::GtkPicture,
367            _param_spec: glib::ffi::gpointer,
368            f: glib::ffi::gpointer,
369        ) {
370            let f: &F = &*(f as *const F);
371            f(&from_glib_borrow(this))
372        }
373        unsafe {
374            let f: Box_<F> = Box_::new(f);
375            connect_raw(
376                self.as_ptr() as *mut _,
377                c"notify::paintable".as_ptr() as *const _,
378                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
379                    notify_paintable_trampoline::<F> as *const (),
380                )),
381                Box_::into_raw(f),
382            )
383        }
384    }
385}
386
387impl Default for Picture {
388    fn default() -> Self {
389        Self::new()
390    }
391}
392
393// rustdoc-stripper-ignore-next
394/// A [builder-pattern] type to construct [`Picture`] objects.
395///
396/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
397#[must_use = "The builder must be built to be used"]
398pub struct PictureBuilder {
399    builder: glib::object::ObjectBuilder<'static, Picture>,
400}
401
402impl PictureBuilder {
403    fn new() -> Self {
404        Self {
405            builder: glib::object::Object::builder(),
406        }
407    }
408
409    pub fn alternative_text(self, alternative_text: impl Into<glib::GString>) -> Self {
410        Self {
411            builder: self
412                .builder
413                .property("alternative-text", alternative_text.into()),
414        }
415    }
416
417    pub fn can_shrink(self, can_shrink: bool) -> Self {
418        Self {
419            builder: self.builder.property("can-shrink", can_shrink),
420        }
421    }
422
423    #[cfg(feature = "v4_8")]
424    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
425    pub fn content_fit(self, content_fit: ContentFit) -> Self {
426        Self {
427            builder: self.builder.property("content-fit", content_fit),
428        }
429    }
430
431    pub fn file(self, file: &impl IsA<gio::File>) -> Self {
432        Self {
433            builder: self.builder.property("file", file.clone().upcast()),
434        }
435    }
436
437    #[cfg_attr(feature = "v4_8", deprecated = "Since 4.8")]
438    pub fn keep_aspect_ratio(self, keep_aspect_ratio: bool) -> Self {
439        Self {
440            builder: self
441                .builder
442                .property("keep-aspect-ratio", keep_aspect_ratio),
443        }
444    }
445
446    pub fn paintable(self, paintable: &impl IsA<gdk::Paintable>) -> Self {
447        Self {
448            builder: self
449                .builder
450                .property("paintable", paintable.clone().upcast()),
451        }
452    }
453
454    pub fn can_focus(self, can_focus: bool) -> Self {
455        Self {
456            builder: self.builder.property("can-focus", can_focus),
457        }
458    }
459
460    pub fn can_target(self, can_target: bool) -> Self {
461        Self {
462            builder: self.builder.property("can-target", can_target),
463        }
464    }
465
466    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
467        Self {
468            builder: self.builder.property("css-classes", css_classes.into()),
469        }
470    }
471
472    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
473        Self {
474            builder: self.builder.property("css-name", css_name.into()),
475        }
476    }
477
478    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
479        Self {
480            builder: self.builder.property("cursor", cursor.clone()),
481        }
482    }
483
484    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
485        Self {
486            builder: self.builder.property("focus-on-click", focus_on_click),
487        }
488    }
489
490    pub fn focusable(self, focusable: bool) -> Self {
491        Self {
492            builder: self.builder.property("focusable", focusable),
493        }
494    }
495
496    pub fn halign(self, halign: Align) -> Self {
497        Self {
498            builder: self.builder.property("halign", halign),
499        }
500    }
501
502    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
503        Self {
504            builder: self.builder.property("has-tooltip", has_tooltip),
505        }
506    }
507
508    pub fn height_request(self, height_request: i32) -> Self {
509        Self {
510            builder: self.builder.property("height-request", height_request),
511        }
512    }
513
514    pub fn hexpand(self, hexpand: bool) -> Self {
515        Self {
516            builder: self.builder.property("hexpand", hexpand),
517        }
518    }
519
520    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
521        Self {
522            builder: self.builder.property("hexpand-set", hexpand_set),
523        }
524    }
525
526    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
527        Self {
528            builder: self
529                .builder
530                .property("layout-manager", layout_manager.clone().upcast()),
531        }
532    }
533
534    #[cfg(feature = "v4_18")]
535    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
536    pub fn limit_events(self, limit_events: bool) -> Self {
537        Self {
538            builder: self.builder.property("limit-events", limit_events),
539        }
540    }
541
542    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
543        Self {
544            builder: self.builder.property("margin-bottom", margin_bottom),
545        }
546    }
547
548    pub fn margin_end(self, margin_end: i32) -> Self {
549        Self {
550            builder: self.builder.property("margin-end", margin_end),
551        }
552    }
553
554    pub fn margin_start(self, margin_start: i32) -> Self {
555        Self {
556            builder: self.builder.property("margin-start", margin_start),
557        }
558    }
559
560    pub fn margin_top(self, margin_top: i32) -> Self {
561        Self {
562            builder: self.builder.property("margin-top", margin_top),
563        }
564    }
565
566    pub fn name(self, name: impl Into<glib::GString>) -> Self {
567        Self {
568            builder: self.builder.property("name", name.into()),
569        }
570    }
571
572    pub fn opacity(self, opacity: f64) -> Self {
573        Self {
574            builder: self.builder.property("opacity", opacity),
575        }
576    }
577
578    pub fn overflow(self, overflow: Overflow) -> Self {
579        Self {
580            builder: self.builder.property("overflow", overflow),
581        }
582    }
583
584    pub fn receives_default(self, receives_default: bool) -> Self {
585        Self {
586            builder: self.builder.property("receives-default", receives_default),
587        }
588    }
589
590    pub fn sensitive(self, sensitive: bool) -> Self {
591        Self {
592            builder: self.builder.property("sensitive", sensitive),
593        }
594    }
595
596    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
597        Self {
598            builder: self
599                .builder
600                .property("tooltip-markup", tooltip_markup.into()),
601        }
602    }
603
604    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
605        Self {
606            builder: self.builder.property("tooltip-text", tooltip_text.into()),
607        }
608    }
609
610    pub fn valign(self, valign: Align) -> Self {
611        Self {
612            builder: self.builder.property("valign", valign),
613        }
614    }
615
616    pub fn vexpand(self, vexpand: bool) -> Self {
617        Self {
618            builder: self.builder.property("vexpand", vexpand),
619        }
620    }
621
622    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
623        Self {
624            builder: self.builder.property("vexpand-set", vexpand_set),
625        }
626    }
627
628    pub fn visible(self, visible: bool) -> Self {
629        Self {
630            builder: self.builder.property("visible", visible),
631        }
632    }
633
634    pub fn width_request(self, width_request: i32) -> Self {
635        Self {
636            builder: self.builder.property("width-request", width_request),
637        }
638    }
639
640    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
641        Self {
642            builder: self.builder.property("accessible-role", accessible_role),
643        }
644    }
645
646    // rustdoc-stripper-ignore-next
647    /// Build the [`Picture`].
648    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
649    pub fn build(self) -> Picture {
650        assert_initialized_main_thread!();
651        self.builder.build()
652    }
653}