gdk4/auto/memory_texture_builder.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
5use crate::{ffi, ColorState, MemoryFormat, Texture};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// Constructs [`Texture`][crate::Texture] objects from system memory provided
10 /// via [`glib::Bytes`][crate::glib::Bytes].
11 ///
12 /// The operation is quite simple: Create a texture builder, set all the necessary
13 /// properties - keep in mind that the properties [`bytes`][struct@crate::MemoryTextureBuilder#bytes],
14 /// [`stride`][struct@crate::MemoryTextureBuilder#stride], [`width`][struct@crate::MemoryTextureBuilder#width],
15 /// and [`height`][struct@crate::MemoryTextureBuilder#height] are mandatory - and then call
16 /// [`build()`][Self::build()] to create the new texture.
17 ///
18 /// [`MemoryTextureBuilder`][crate::MemoryTextureBuilder] can be used for quick one-shot construction of
19 /// textures as well as kept around and reused to construct multiple textures.
20 ///
21 /// ## Properties
22 ///
23 ///
24 /// #### `bytes`
25 /// The bytes holding the data.
26 ///
27 /// Readable | Writeable
28 ///
29 ///
30 /// #### `color-state`
31 /// The colorstate describing the data.
32 ///
33 /// Readable | Writeable
34 ///
35 ///
36 /// #### `format`
37 /// The format of the data.
38 ///
39 /// Readable | Writeable
40 ///
41 ///
42 /// #### `height`
43 /// The height of the texture.
44 ///
45 /// Readable | Writeable
46 ///
47 ///
48 /// #### `stride`
49 /// The rowstride of the texture.
50 ///
51 /// The rowstride is the number of bytes between the first pixel
52 /// in a row of image data, and the first pixel in the next row.
53 ///
54 /// Readable | Writeable
55 ///
56 ///
57 /// #### `update-region`
58 /// The update region for [`update-texture`][struct@crate::MemoryTextureBuilder#update-texture].
59 ///
60 /// Readable | Writeable
61 ///
62 ///
63 /// #### `update-texture`
64 /// The texture [`update-region`][struct@crate::MemoryTextureBuilder#update-region] is an update for.
65 ///
66 /// Readable | Writeable
67 ///
68 ///
69 /// #### `width`
70 /// The width of the texture.
71 ///
72 /// Readable | Writeable
73 #[doc(alias = "GdkMemoryTextureBuilder")]
74 pub struct MemoryTextureBuilder(Object<ffi::GdkMemoryTextureBuilder, ffi::GdkMemoryTextureBuilderClass>);
75
76 match fn {
77 type_ => || ffi::gdk_memory_texture_builder_get_type(),
78 }
79}
80
81impl MemoryTextureBuilder {
82 /// Creates a new texture builder.
83 ///
84 /// # Returns
85 ///
86 /// the new `GdkTextureBuilder`
87 #[doc(alias = "gdk_memory_texture_builder_new")]
88 pub fn new() -> MemoryTextureBuilder {
89 assert_initialized_main_thread!();
90 unsafe { from_glib_full(ffi::gdk_memory_texture_builder_new()) }
91 }
92
93 /// Builds a new [`Texture`][crate::Texture] with the values set up in the builder.
94 ///
95 /// Note that it is a programming error to call this function if any mandatory
96 /// property has not been set.
97 ///
98 /// It is possible to call this function multiple times to create multiple textures,
99 /// possibly with changing properties in between.
100 ///
101 /// # Returns
102 ///
103 /// a newly built [`Texture`][crate::Texture]
104 #[doc(alias = "gdk_memory_texture_builder_build")]
105 pub fn build(&self) -> Texture {
106 unsafe { from_glib_full(ffi::gdk_memory_texture_builder_build(self.to_glib_none().0)) }
107 }
108
109 /// Gets the bytes previously set via gdk_memory_texture_builder_set_bytes()
110 /// or [`None`] if none was set.
111 ///
112 /// # Returns
113 ///
114 /// The bytes
115 #[doc(alias = "gdk_memory_texture_builder_get_bytes")]
116 #[doc(alias = "get_bytes")]
117 pub fn bytes(&self) -> Option<glib::Bytes> {
118 unsafe {
119 from_glib_none(ffi::gdk_memory_texture_builder_get_bytes(
120 self.to_glib_none().0,
121 ))
122 }
123 }
124
125 /// Gets the colorstate previously set via gdk_memory_texture_builder_set_color_state().
126 ///
127 /// # Returns
128 ///
129 /// The colorstate
130 #[doc(alias = "gdk_memory_texture_builder_get_color_state")]
131 #[doc(alias = "get_color_state")]
132 #[doc(alias = "color-state")]
133 pub fn color_state(&self) -> ColorState {
134 unsafe {
135 from_glib_none(ffi::gdk_memory_texture_builder_get_color_state(
136 self.to_glib_none().0,
137 ))
138 }
139 }
140
141 /// Gets the format previously set via gdk_memory_texture_builder_set_format().
142 ///
143 /// # Returns
144 ///
145 /// The format
146 #[doc(alias = "gdk_memory_texture_builder_get_format")]
147 #[doc(alias = "get_format")]
148 pub fn format(&self) -> MemoryFormat {
149 unsafe {
150 from_glib(ffi::gdk_memory_texture_builder_get_format(
151 self.to_glib_none().0,
152 ))
153 }
154 }
155
156 /// Gets the height previously set via gdk_memory_texture_builder_set_height()
157 /// or 0 if the height wasn't set.
158 ///
159 /// # Returns
160 ///
161 /// The height
162 #[doc(alias = "gdk_memory_texture_builder_get_height")]
163 #[doc(alias = "get_height")]
164 pub fn height(&self) -> i32 {
165 unsafe { ffi::gdk_memory_texture_builder_get_height(self.to_glib_none().0) }
166 }
167
168 /// Gets the offset previously set via gdk_memory_texture_builder_set_offset().
169 /// ## `plane`
170 /// a plane
171 ///
172 /// # Returns
173 ///
174 /// The offset associated to a @plane
175 #[cfg(feature = "v4_20")]
176 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
177 #[doc(alias = "gdk_memory_texture_builder_get_offset")]
178 #[doc(alias = "get_offset")]
179 pub fn offset(&self, plane: u32) -> usize {
180 unsafe { ffi::gdk_memory_texture_builder_get_offset(self.to_glib_none().0, plane) }
181 }
182
183 /// Gets the stride previously set via gdk_memory_texture_builder_set_stride().
184 ///
185 /// # Returns
186 ///
187 /// the stride
188 #[doc(alias = "gdk_memory_texture_builder_get_stride")]
189 #[doc(alias = "get_stride")]
190 pub fn stride(&self) -> usize {
191 unsafe { ffi::gdk_memory_texture_builder_get_stride(self.to_glib_none().0) }
192 }
193
194 /// Gets the stride previously set via gdk_memory_texture_builder_set_stride_for_plane().
195 /// ## `plane`
196 /// a plane
197 ///
198 /// # Returns
199 ///
200 /// The stride associated to a @plane
201 #[cfg(feature = "v4_20")]
202 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
203 #[doc(alias = "gdk_memory_texture_builder_get_stride_for_plane")]
204 #[doc(alias = "get_stride_for_plane")]
205 pub fn stride_for_plane(&self, plane: u32) -> usize {
206 unsafe {
207 ffi::gdk_memory_texture_builder_get_stride_for_plane(self.to_glib_none().0, plane)
208 }
209 }
210
211 /// Gets the region previously set via gdk_memory_texture_builder_set_update_region()
212 /// or [`None`] if none was set.
213 ///
214 /// # Returns
215 ///
216 /// The update region
217 #[doc(alias = "gdk_memory_texture_builder_get_update_region")]
218 #[doc(alias = "get_update_region")]
219 #[doc(alias = "update-region")]
220 pub fn update_region(&self) -> Option<cairo::Region> {
221 unsafe {
222 from_glib_none(ffi::gdk_memory_texture_builder_get_update_region(
223 self.to_glib_none().0,
224 ))
225 }
226 }
227
228 /// Gets the texture previously set via gdk_memory_texture_builder_set_update_texture()
229 /// or [`None`] if none was set.
230 ///
231 /// # Returns
232 ///
233 /// The update texture
234 #[doc(alias = "gdk_memory_texture_builder_get_update_texture")]
235 #[doc(alias = "get_update_texture")]
236 #[doc(alias = "update-texture")]
237 pub fn update_texture(&self) -> Option<Texture> {
238 unsafe {
239 from_glib_none(ffi::gdk_memory_texture_builder_get_update_texture(
240 self.to_glib_none().0,
241 ))
242 }
243 }
244
245 /// Gets the width previously set via gdk_memory_texture_builder_set_width()
246 /// or 0 if the width wasn't set.
247 ///
248 /// # Returns
249 ///
250 /// The width
251 #[doc(alias = "gdk_memory_texture_builder_get_width")]
252 #[doc(alias = "get_width")]
253 pub fn width(&self) -> i32 {
254 unsafe { ffi::gdk_memory_texture_builder_get_width(self.to_glib_none().0) }
255 }
256}
257
258#[cfg(feature = "v4_16")]
259#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
260impl Default for MemoryTextureBuilder {
261 fn default() -> Self {
262 Self::new()
263 }
264}
265
266unsafe impl Send for MemoryTextureBuilder {}
267unsafe impl Sync for MemoryTextureBuilder {}