// 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::{MemoryFormat, Texture, ffi};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    #[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 {
    #[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,
            ))
        }
    }

    #[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())
        }
    }

    //#[cfg(feature = "v4_20")]
    //#[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
    //#[doc(alias = "gdk_texture_downloader_download_bytes_with_planes")]
    //pub fn download_bytes_with_planes(&self, out_offsets: /*Unimplemented*/FixedArray TypeId { ns_id: 0, id: 18 }; 4, out_strides: /*Unimplemented*/FixedArray TypeId { ns_id: 0, id: 18 }; 4) -> glib::Bytes {
    //    unsafe { TODO: call ffi:gdk_texture_downloader_download_bytes_with_planes() }
    //}

    //#[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() }
    //}

    #[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,
            ))
        }
    }

    #[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,
            ))
        }
    }

    #[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,
            ))
        }
    }

    #[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,
            );
        }
    }

    #[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());
        }
    }

    #[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,
            );
        }
    }
}
