gdk4/
memory_texture_builder.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::{ffi, ColorState, MemoryFormat, MemoryTextureBuilder, Texture};
4use glib::{prelude::*, translate::*};
5
6impl MemoryTextureBuilder {
7    /// Sets the data to be shown but the texture.
8    ///
9    /// The bytes must be set before calling [`build()`][Self::build()].
10    /// ## `bytes`
11    /// The bytes the texture shows or [`None`] to unset
12    #[doc(alias = "gdk_memory_texture_builder_set_bytes")]
13    #[doc(alias = "bytes")]
14    pub fn set_bytes(self, bytes: Option<&glib::Bytes>) -> Self {
15        unsafe {
16            ffi::gdk_memory_texture_builder_set_bytes(
17                self.to_glib_none().0,
18                bytes.to_glib_none().0,
19            );
20        }
21
22        self
23    }
24
25    /// Sets the colorstate describing the data.
26    ///
27    /// By default, the sRGB colorstate is used. If you don't know
28    /// what colorstates are, this is probably the right thing.
29    /// ## `color_state`
30    /// The colorstate describing the data
31    #[doc(alias = "gdk_memory_texture_builder_set_color_state")]
32    #[doc(alias = "color-state")]
33    pub fn set_color_state(self, color_state: &ColorState) -> Self {
34        unsafe {
35            ffi::gdk_memory_texture_builder_set_color_state(
36                self.to_glib_none().0,
37                color_state.to_glib_none().0,
38            );
39        }
40
41        self
42    }
43
44    /// Sets the format of the bytes.
45    ///
46    /// The default is `GDK_MEMORY_R8G8B8A8_PREMULTIPLIED`.
47    /// ## `format`
48    /// The texture's format
49    #[doc(alias = "gdk_memory_texture_builder_set_format")]
50    #[doc(alias = "format")]
51    pub fn set_format(self, format: MemoryFormat) -> Self {
52        unsafe {
53            ffi::gdk_memory_texture_builder_set_format(self.to_glib_none().0, format.into_glib());
54        }
55
56        self
57    }
58
59    /// Sets the height of the texture.
60    ///
61    /// The height must be set before calling [`build()`][Self::build()]
62    /// and conform to size requirements of the provided format.
63    /// ## `height`
64    /// The texture's height or 0 to unset
65    #[doc(alias = "gdk_memory_texture_builder_set_height")]
66    #[doc(alias = "height")]
67    pub fn set_height(self, height: i32) -> Self {
68        unsafe {
69            ffi::gdk_memory_texture_builder_set_height(self.to_glib_none().0, height);
70        }
71
72        self
73    }
74
75    /// Sets the offset of the texture for @plane.
76    /// ## `plane`
77    /// a plane
78    /// ## `offset`
79    /// the texture's offset for @plane
80    #[cfg(feature = "v4_20")]
81    #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
82    #[doc(alias = "gdk_memory_texture_builder_set_offset")]
83    pub fn set_offset(self, plane: u32, offset: usize) -> Self {
84        unsafe {
85            ffi::gdk_memory_texture_builder_set_offset(self.to_glib_none().0, plane, offset);
86        }
87
88        self
89    }
90
91    /// Sets the rowstride of the bytes used.
92    ///
93    /// The rowstride must be set before calling [`build()`][Self::build()].
94    /// ## `stride`
95    /// the stride or 0 to unset
96    #[doc(alias = "gdk_memory_texture_builder_set_stride")]
97    #[doc(alias = "stride")]
98    pub fn set_stride(self, stride: usize) -> Self {
99        unsafe {
100            ffi::gdk_memory_texture_builder_set_stride(self.to_glib_none().0, stride);
101        }
102
103        self
104    }
105
106    /// Sets the stride of the texture for @plane.
107    /// ## `plane`
108    /// a plane
109    /// ## `stride`
110    /// the texture's stride for @plane
111    #[cfg(feature = "v4_20")]
112    #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
113    #[doc(alias = "gdk_memory_texture_builder_set_stride_for_plane")]
114    pub fn set_stride_for_plane(self, plane: u32, stride: usize) -> Self {
115        unsafe {
116            ffi::gdk_memory_texture_builder_set_stride_for_plane(
117                self.to_glib_none().0,
118                plane,
119                stride,
120            );
121        }
122
123        self
124    }
125
126    /// Sets the region to be updated by this texture.
127    ///
128    /// Together with [`update-texture`][struct@crate::MemoryTextureBuilder#update-texture],
129    /// this describes an update of a previous texture.
130    ///
131    /// When rendering animations of large textures, it is possible that
132    /// consecutive textures are only updating contents in parts of the texture.
133    /// It is then possible to describe this update via these two properties,
134    /// so that GTK can avoid rerendering parts that did not change.
135    ///
136    /// An example would be a screen recording where only the mouse pointer moves.
137    /// ## `region`
138    /// the region to update
139    #[doc(alias = "gdk_memory_texture_builder_set_update_region")]
140    #[doc(alias = "update-region")]
141    pub fn set_update_region(self, region: Option<&cairo::Region>) -> Self {
142        unsafe {
143            ffi::gdk_memory_texture_builder_set_update_region(
144                self.to_glib_none().0,
145                mut_override(region.to_glib_none().0),
146            );
147        }
148
149        self
150    }
151
152    /// Sets the texture to be updated by this texture.
153    ///
154    /// See [`set_update_region()`][Self::set_update_region()] for an explanation.
155    /// ## `texture`
156    /// the texture to update
157    #[doc(alias = "gdk_memory_texture_builder_set_update_texture")]
158    #[doc(alias = "update-texture")]
159    pub fn set_update_texture(self, texture: Option<&impl IsA<Texture>>) -> Self {
160        unsafe {
161            ffi::gdk_memory_texture_builder_set_update_texture(
162                self.to_glib_none().0,
163                texture.map(|p| p.as_ref()).to_glib_none().0,
164            );
165        }
166
167        self
168    }
169
170    /// Sets the width of the texture.
171    ///
172    /// The width must be set before calling [`build()`][Self::build()]
173    /// and conform to size requirements of the provided format.
174    /// ## `width`
175    /// The texture's width or 0 to unset
176    #[doc(alias = "gdk_memory_texture_builder_set_width")]
177    #[doc(alias = "width")]
178    pub fn set_width(self, width: i32) -> Self {
179        unsafe {
180            ffi::gdk_memory_texture_builder_set_width(self.to_glib_none().0, width);
181        }
182
183        self
184    }
185}