gdk4/auto/
texture_downloader.rs1#[cfg(feature = "v4_16")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
7use crate::ColorState;
8use crate::{ffi, MemoryFormat, Texture};
9use glib::{prelude::*, translate::*};
10
11glib::wrapper! {
12 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
13 pub struct TextureDownloader(Boxed<ffi::GdkTextureDownloader>);
14
15 match fn {
16 copy => |ptr| ffi::gdk_texture_downloader_copy(ptr),
17 free => |ptr| ffi::gdk_texture_downloader_free(ptr),
18 type_ => || ffi::gdk_texture_downloader_get_type(),
19 }
20}
21
22impl TextureDownloader {
23 #[doc(alias = "gdk_texture_downloader_new")]
24 pub fn new(texture: &impl IsA<Texture>) -> TextureDownloader {
25 skip_assert_initialized!();
26 unsafe {
27 from_glib_full(ffi::gdk_texture_downloader_new(
28 texture.as_ref().to_glib_none().0,
29 ))
30 }
31 }
32
33 #[doc(alias = "gdk_texture_downloader_download_bytes")]
34 pub fn download_bytes(&self) -> (glib::Bytes, usize) {
35 unsafe {
36 let mut out_stride = std::mem::MaybeUninit::uninit();
37 let ret = from_glib_full(ffi::gdk_texture_downloader_download_bytes(
38 self.to_glib_none().0,
39 out_stride.as_mut_ptr(),
40 ));
41 (ret, out_stride.assume_init())
42 }
43 }
44
45 #[cfg(feature = "v4_16")]
58 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
59 #[doc(alias = "gdk_texture_downloader_get_color_state")]
60 #[doc(alias = "get_color_state")]
61 pub fn color_state(&self) -> ColorState {
62 unsafe {
63 from_glib_full(ffi::gdk_texture_downloader_get_color_state(
64 self.to_glib_none().0,
65 ))
66 }
67 }
68
69 #[doc(alias = "gdk_texture_downloader_get_format")]
70 #[doc(alias = "get_format")]
71 pub fn format(&self) -> MemoryFormat {
72 unsafe {
73 from_glib(ffi::gdk_texture_downloader_get_format(
74 self.to_glib_none().0,
75 ))
76 }
77 }
78
79 #[doc(alias = "gdk_texture_downloader_get_texture")]
80 #[doc(alias = "get_texture")]
81 pub fn texture(&self) -> Texture {
82 unsafe {
83 from_glib_none(ffi::gdk_texture_downloader_get_texture(
84 self.to_glib_none().0,
85 ))
86 }
87 }
88
89 #[cfg(feature = "v4_16")]
90 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
91 #[doc(alias = "gdk_texture_downloader_set_color_state")]
92 pub fn set_color_state(&mut self, color_state: &ColorState) {
93 unsafe {
94 ffi::gdk_texture_downloader_set_color_state(
95 self.to_glib_none_mut().0,
96 color_state.to_glib_none().0,
97 );
98 }
99 }
100
101 #[doc(alias = "gdk_texture_downloader_set_format")]
102 pub fn set_format(&mut self, format: MemoryFormat) {
103 unsafe {
104 ffi::gdk_texture_downloader_set_format(self.to_glib_none_mut().0, format.into_glib());
105 }
106 }
107
108 #[doc(alias = "gdk_texture_downloader_set_texture")]
109 pub fn set_texture(&mut self, texture: &impl IsA<Texture>) {
110 unsafe {
111 ffi::gdk_texture_downloader_set_texture(
112 self.to_glib_none_mut().0,
113 texture.as_ref().to_glib_none().0,
114 );
115 }
116 }
117}