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