gdk4/auto/texture_downloader.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_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 /// Used to download the contents of a [`Texture`][crate::Texture].
13 ///
14 /// It is intended to be created as a short-term object for a single download,
15 /// but can be used for multiple downloads of different textures or with different
16 /// settings.
17 ///
18 /// [`TextureDownloader`][crate::TextureDownloader] can be used to convert data between different formats.
19 /// Create a [`Texture`][crate::Texture] for the existing format and then download it in a
20 /// different format.
21 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
22 pub struct TextureDownloader(Boxed<ffi::GdkTextureDownloader>);
23
24 match fn {
25 copy => |ptr| ffi::gdk_texture_downloader_copy(ptr),
26 free => |ptr| ffi::gdk_texture_downloader_free(ptr),
27 type_ => || ffi::gdk_texture_downloader_get_type(),
28 }
29}
30
31impl TextureDownloader {
32 /// Creates a new texture downloader for @texture.
33 ///
34 /// By default, the downloader will convert the data to
35 /// the default memory format, and to the sRGB color state.
36 /// ## `texture`
37 /// texture to download
38 ///
39 /// # Returns
40 ///
41 /// A new texture downloader
42 #[doc(alias = "gdk_texture_downloader_new")]
43 pub fn new(texture: &impl IsA<Texture>) -> TextureDownloader {
44 skip_assert_initialized!();
45 unsafe {
46 from_glib_full(ffi::gdk_texture_downloader_new(
47 texture.as_ref().to_glib_none().0,
48 ))
49 }
50 }
51
52 /// Downloads the given texture pixels into a `GBytes`. The rowstride will
53 /// be stored in the stride value.
54 ///
55 /// This function will abort if it tries to download a large texture and
56 /// fails to allocate memory. If you think that may happen, you should handle
57 /// memory allocation yourself and use `Gdk::TextureDownloader::download_into()`
58 /// once allocation succeeded.
59 ///
60 /// # Returns
61 ///
62 /// The downloaded pixels
63 ///
64 /// ## `out_stride`
65 /// The stride of the resulting data in bytes
66 #[doc(alias = "gdk_texture_downloader_download_bytes")]
67 pub fn download_bytes(&self) -> (glib::Bytes, usize) {
68 unsafe {
69 let mut out_stride = std::mem::MaybeUninit::uninit();
70 let ret = from_glib_full(ffi::gdk_texture_downloader_download_bytes(
71 self.to_glib_none().0,
72 out_stride.as_mut_ptr(),
73 ));
74 (ret, out_stride.assume_init())
75 }
76 }
77
78 //#[doc(alias = "gdk_texture_downloader_download_into")]
79 //pub fn download_into(&self, data: &[u8], stride: usize) {
80 // unsafe { TODO: call ffi:gdk_texture_downloader_download_into() }
81 //}
82
83 /// Gets the color state that the data will be downloaded in.
84 ///
85 /// # Returns
86 ///
87 /// The color state of the download
88 #[cfg(feature = "v4_16")]
89 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
90 #[doc(alias = "gdk_texture_downloader_get_color_state")]
91 #[doc(alias = "get_color_state")]
92 pub fn color_state(&self) -> ColorState {
93 unsafe {
94 from_glib_full(ffi::gdk_texture_downloader_get_color_state(
95 self.to_glib_none().0,
96 ))
97 }
98 }
99
100 /// Gets the format that the data will be downloaded in.
101 ///
102 /// # Returns
103 ///
104 /// The format of the download
105 #[doc(alias = "gdk_texture_downloader_get_format")]
106 #[doc(alias = "get_format")]
107 pub fn format(&self) -> MemoryFormat {
108 unsafe {
109 from_glib(ffi::gdk_texture_downloader_get_format(
110 self.to_glib_none().0,
111 ))
112 }
113 }
114
115 /// Gets the texture that the downloader will download.
116 ///
117 /// # Returns
118 ///
119 /// The texture to download
120 #[doc(alias = "gdk_texture_downloader_get_texture")]
121 #[doc(alias = "get_texture")]
122 pub fn texture(&self) -> Texture {
123 unsafe {
124 from_glib_none(ffi::gdk_texture_downloader_get_texture(
125 self.to_glib_none().0,
126 ))
127 }
128 }
129
130 /// Sets the color state the downloader will convert the data to.
131 ///
132 /// By default, the sRGB colorstate returned by `get_srgb()`
133 /// is used.
134 /// ## `color_state`
135 /// the color state to use
136 #[cfg(feature = "v4_16")]
137 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
138 #[doc(alias = "gdk_texture_downloader_set_color_state")]
139 pub fn set_color_state(&mut self, color_state: &ColorState) {
140 unsafe {
141 ffi::gdk_texture_downloader_set_color_state(
142 self.to_glib_none_mut().0,
143 color_state.to_glib_none().0,
144 );
145 }
146 }
147
148 /// Sets the format the downloader will download.
149 ///
150 /// By default, GDK_MEMORY_DEFAULT is set.
151 /// ## `format`
152 /// the format to use
153 #[doc(alias = "gdk_texture_downloader_set_format")]
154 pub fn set_format(&mut self, format: MemoryFormat) {
155 unsafe {
156 ffi::gdk_texture_downloader_set_format(self.to_glib_none_mut().0, format.into_glib());
157 }
158 }
159
160 /// Changes the texture the downloader will download.
161 /// ## `texture`
162 /// the new texture to download
163 #[doc(alias = "gdk_texture_downloader_set_texture")]
164 pub fn set_texture(&mut self, texture: &impl IsA<Texture>) {
165 unsafe {
166 ffi::gdk_texture_downloader_set_texture(
167 self.to_glib_none_mut().0,
168 texture.as_ref().to_glib_none().0,
169 );
170 }
171 }
172}