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