1use crate::{ffi, ColorState, MemoryFormat, Texture};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GdkMemoryTextureBuilder")]
79 pub struct MemoryTextureBuilder(Object<ffi::GdkMemoryTextureBuilder, ffi::GdkMemoryTextureBuilderClass>);
80
81 match fn {
82 type_ => || ffi::gdk_memory_texture_builder_get_type(),
83 }
84}
85
86impl MemoryTextureBuilder {
87 #[doc(alias = "gdk_memory_texture_builder_new")]
93 pub fn new() -> MemoryTextureBuilder {
94 assert_initialized_main_thread!();
95 unsafe { from_glib_full(ffi::gdk_memory_texture_builder_new()) }
96 }
97
98 #[doc(alias = "gdk_memory_texture_builder_build")]
110 pub fn build(&self) -> Texture {
111 unsafe { from_glib_full(ffi::gdk_memory_texture_builder_build(self.to_glib_none().0)) }
112 }
113
114 #[doc(alias = "gdk_memory_texture_builder_get_bytes")]
121 #[doc(alias = "get_bytes")]
122 pub fn bytes(&self) -> Option<glib::Bytes> {
123 unsafe {
124 from_glib_none(ffi::gdk_memory_texture_builder_get_bytes(
125 self.to_glib_none().0,
126 ))
127 }
128 }
129
130 #[doc(alias = "gdk_memory_texture_builder_get_color_state")]
136 #[doc(alias = "get_color_state")]
137 #[doc(alias = "color-state")]
138 pub fn color_state(&self) -> ColorState {
139 unsafe {
140 from_glib_none(ffi::gdk_memory_texture_builder_get_color_state(
141 self.to_glib_none().0,
142 ))
143 }
144 }
145
146 #[doc(alias = "gdk_memory_texture_builder_get_format")]
152 #[doc(alias = "get_format")]
153 pub fn format(&self) -> MemoryFormat {
154 unsafe {
155 from_glib(ffi::gdk_memory_texture_builder_get_format(
156 self.to_glib_none().0,
157 ))
158 }
159 }
160
161 #[doc(alias = "gdk_memory_texture_builder_get_height")]
168 #[doc(alias = "get_height")]
169 pub fn height(&self) -> i32 {
170 unsafe { ffi::gdk_memory_texture_builder_get_height(self.to_glib_none().0) }
171 }
172
173 #[doc(alias = "gdk_memory_texture_builder_get_stride")]
179 #[doc(alias = "get_stride")]
180 pub fn stride(&self) -> usize {
181 unsafe { ffi::gdk_memory_texture_builder_get_stride(self.to_glib_none().0) }
182 }
183
184 #[doc(alias = "gdk_memory_texture_builder_get_update_region")]
191 #[doc(alias = "get_update_region")]
192 #[doc(alias = "update-region")]
193 pub fn update_region(&self) -> Option<cairo::Region> {
194 unsafe {
195 from_glib_none(ffi::gdk_memory_texture_builder_get_update_region(
196 self.to_glib_none().0,
197 ))
198 }
199 }
200
201 #[doc(alias = "gdk_memory_texture_builder_get_update_texture")]
208 #[doc(alias = "get_update_texture")]
209 #[doc(alias = "update-texture")]
210 pub fn update_texture(&self) -> Option<Texture> {
211 unsafe {
212 from_glib_none(ffi::gdk_memory_texture_builder_get_update_texture(
213 self.to_glib_none().0,
214 ))
215 }
216 }
217
218 #[doc(alias = "gdk_memory_texture_builder_get_width")]
225 #[doc(alias = "get_width")]
226 pub fn width(&self) -> i32 {
227 unsafe { ffi::gdk_memory_texture_builder_get_width(self.to_glib_none().0) }
228 }
229
230 #[doc(alias = "gdk_memory_texture_builder_set_bytes")]
236 #[doc(alias = "bytes")]
237 pub fn set_bytes(&self, bytes: Option<&glib::Bytes>) {
238 unsafe {
239 ffi::gdk_memory_texture_builder_set_bytes(
240 self.to_glib_none().0,
241 bytes.to_glib_none().0,
242 );
243 }
244 }
245
246 #[doc(alias = "gdk_memory_texture_builder_set_color_state")]
253 #[doc(alias = "color-state")]
254 pub fn set_color_state(&self, color_state: Option<&ColorState>) {
255 unsafe {
256 ffi::gdk_memory_texture_builder_set_color_state(
257 self.to_glib_none().0,
258 color_state.to_glib_none().0,
259 );
260 }
261 }
262
263 #[doc(alias = "gdk_memory_texture_builder_set_format")]
269 #[doc(alias = "format")]
270 pub fn set_format(&self, format: MemoryFormat) {
271 unsafe {
272 ffi::gdk_memory_texture_builder_set_format(self.to_glib_none().0, format.into_glib());
273 }
274 }
275
276 #[doc(alias = "gdk_memory_texture_builder_set_height")]
282 #[doc(alias = "height")]
283 pub fn set_height(&self, height: i32) {
284 unsafe {
285 ffi::gdk_memory_texture_builder_set_height(self.to_glib_none().0, height);
286 }
287 }
288
289 #[doc(alias = "gdk_memory_texture_builder_set_stride")]
295 #[doc(alias = "stride")]
296 pub fn set_stride(&self, stride: usize) {
297 unsafe {
298 ffi::gdk_memory_texture_builder_set_stride(self.to_glib_none().0, stride);
299 }
300 }
301
302 #[doc(alias = "gdk_memory_texture_builder_set_update_region")]
316 #[doc(alias = "update-region")]
317 pub fn set_update_region(&self, region: Option<&cairo::Region>) {
318 unsafe {
319 ffi::gdk_memory_texture_builder_set_update_region(
320 self.to_glib_none().0,
321 mut_override(region.to_glib_none().0),
322 );
323 }
324 }
325
326 #[doc(alias = "gdk_memory_texture_builder_set_update_texture")]
332 #[doc(alias = "update-texture")]
333 pub fn set_update_texture(&self, texture: Option<&impl IsA<Texture>>) {
334 unsafe {
335 ffi::gdk_memory_texture_builder_set_update_texture(
336 self.to_glib_none().0,
337 texture.map(|p| p.as_ref()).to_glib_none().0,
338 );
339 }
340 }
341
342 #[doc(alias = "gdk_memory_texture_builder_set_width")]
348 #[doc(alias = "width")]
349 pub fn set_width(&self, width: i32) {
350 unsafe {
351 ffi::gdk_memory_texture_builder_set_width(self.to_glib_none().0, width);
352 }
353 }
354
355 #[cfg(feature = "v4_16")]
356 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
357 #[doc(alias = "bytes")]
358 pub fn connect_bytes_notify<F: Fn(&Self) + Send + Sync + 'static>(
359 &self,
360 f: F,
361 ) -> SignalHandlerId {
362 unsafe extern "C" fn notify_bytes_trampoline<
363 F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
364 >(
365 this: *mut ffi::GdkMemoryTextureBuilder,
366 _param_spec: glib::ffi::gpointer,
367 f: glib::ffi::gpointer,
368 ) {
369 let f: &F = &*(f as *const F);
370 f(&from_glib_borrow(this))
371 }
372 unsafe {
373 let f: Box_<F> = Box_::new(f);
374 connect_raw(
375 self.as_ptr() as *mut _,
376 b"notify::bytes\0".as_ptr() as *const _,
377 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
378 notify_bytes_trampoline::<F> as *const (),
379 )),
380 Box_::into_raw(f),
381 )
382 }
383 }
384
385 #[cfg(feature = "v4_16")]
386 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
387 #[doc(alias = "color-state")]
388 pub fn connect_color_state_notify<F: Fn(&Self) + Send + Sync + 'static>(
389 &self,
390 f: F,
391 ) -> SignalHandlerId {
392 unsafe extern "C" fn notify_color_state_trampoline<
393 F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
394 >(
395 this: *mut ffi::GdkMemoryTextureBuilder,
396 _param_spec: glib::ffi::gpointer,
397 f: glib::ffi::gpointer,
398 ) {
399 let f: &F = &*(f as *const F);
400 f(&from_glib_borrow(this))
401 }
402 unsafe {
403 let f: Box_<F> = Box_::new(f);
404 connect_raw(
405 self.as_ptr() as *mut _,
406 b"notify::color-state\0".as_ptr() as *const _,
407 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
408 notify_color_state_trampoline::<F> as *const (),
409 )),
410 Box_::into_raw(f),
411 )
412 }
413 }
414
415 #[cfg(feature = "v4_16")]
416 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
417 #[doc(alias = "format")]
418 pub fn connect_format_notify<F: Fn(&Self) + Send + Sync + 'static>(
419 &self,
420 f: F,
421 ) -> SignalHandlerId {
422 unsafe extern "C" fn notify_format_trampoline<
423 F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
424 >(
425 this: *mut ffi::GdkMemoryTextureBuilder,
426 _param_spec: glib::ffi::gpointer,
427 f: glib::ffi::gpointer,
428 ) {
429 let f: &F = &*(f as *const F);
430 f(&from_glib_borrow(this))
431 }
432 unsafe {
433 let f: Box_<F> = Box_::new(f);
434 connect_raw(
435 self.as_ptr() as *mut _,
436 b"notify::format\0".as_ptr() as *const _,
437 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
438 notify_format_trampoline::<F> as *const (),
439 )),
440 Box_::into_raw(f),
441 )
442 }
443 }
444
445 #[cfg(feature = "v4_16")]
446 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
447 #[doc(alias = "height")]
448 pub fn connect_height_notify<F: Fn(&Self) + Send + Sync + 'static>(
449 &self,
450 f: F,
451 ) -> SignalHandlerId {
452 unsafe extern "C" fn notify_height_trampoline<
453 F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
454 >(
455 this: *mut ffi::GdkMemoryTextureBuilder,
456 _param_spec: glib::ffi::gpointer,
457 f: glib::ffi::gpointer,
458 ) {
459 let f: &F = &*(f as *const F);
460 f(&from_glib_borrow(this))
461 }
462 unsafe {
463 let f: Box_<F> = Box_::new(f);
464 connect_raw(
465 self.as_ptr() as *mut _,
466 b"notify::height\0".as_ptr() as *const _,
467 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
468 notify_height_trampoline::<F> as *const (),
469 )),
470 Box_::into_raw(f),
471 )
472 }
473 }
474
475 #[cfg(feature = "v4_16")]
476 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
477 #[doc(alias = "stride")]
478 pub fn connect_stride_notify<F: Fn(&Self) + Send + Sync + 'static>(
479 &self,
480 f: F,
481 ) -> SignalHandlerId {
482 unsafe extern "C" fn notify_stride_trampoline<
483 F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
484 >(
485 this: *mut ffi::GdkMemoryTextureBuilder,
486 _param_spec: glib::ffi::gpointer,
487 f: glib::ffi::gpointer,
488 ) {
489 let f: &F = &*(f as *const F);
490 f(&from_glib_borrow(this))
491 }
492 unsafe {
493 let f: Box_<F> = Box_::new(f);
494 connect_raw(
495 self.as_ptr() as *mut _,
496 b"notify::stride\0".as_ptr() as *const _,
497 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
498 notify_stride_trampoline::<F> as *const (),
499 )),
500 Box_::into_raw(f),
501 )
502 }
503 }
504
505 #[cfg(feature = "v4_16")]
506 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
507 #[doc(alias = "update-region")]
508 pub fn connect_update_region_notify<F: Fn(&Self) + Send + Sync + 'static>(
509 &self,
510 f: F,
511 ) -> SignalHandlerId {
512 unsafe extern "C" fn notify_update_region_trampoline<
513 F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
514 >(
515 this: *mut ffi::GdkMemoryTextureBuilder,
516 _param_spec: glib::ffi::gpointer,
517 f: glib::ffi::gpointer,
518 ) {
519 let f: &F = &*(f as *const F);
520 f(&from_glib_borrow(this))
521 }
522 unsafe {
523 let f: Box_<F> = Box_::new(f);
524 connect_raw(
525 self.as_ptr() as *mut _,
526 b"notify::update-region\0".as_ptr() as *const _,
527 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
528 notify_update_region_trampoline::<F> as *const (),
529 )),
530 Box_::into_raw(f),
531 )
532 }
533 }
534
535 #[cfg(feature = "v4_16")]
536 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
537 #[doc(alias = "update-texture")]
538 pub fn connect_update_texture_notify<F: Fn(&Self) + Send + Sync + 'static>(
539 &self,
540 f: F,
541 ) -> SignalHandlerId {
542 unsafe extern "C" fn notify_update_texture_trampoline<
543 F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
544 >(
545 this: *mut ffi::GdkMemoryTextureBuilder,
546 _param_spec: glib::ffi::gpointer,
547 f: glib::ffi::gpointer,
548 ) {
549 let f: &F = &*(f as *const F);
550 f(&from_glib_borrow(this))
551 }
552 unsafe {
553 let f: Box_<F> = Box_::new(f);
554 connect_raw(
555 self.as_ptr() as *mut _,
556 b"notify::update-texture\0".as_ptr() as *const _,
557 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
558 notify_update_texture_trampoline::<F> as *const (),
559 )),
560 Box_::into_raw(f),
561 )
562 }
563 }
564
565 #[cfg(feature = "v4_16")]
566 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
567 #[doc(alias = "width")]
568 pub fn connect_width_notify<F: Fn(&Self) + Send + Sync + 'static>(
569 &self,
570 f: F,
571 ) -> SignalHandlerId {
572 unsafe extern "C" fn notify_width_trampoline<
573 F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
574 >(
575 this: *mut ffi::GdkMemoryTextureBuilder,
576 _param_spec: glib::ffi::gpointer,
577 f: glib::ffi::gpointer,
578 ) {
579 let f: &F = &*(f as *const F);
580 f(&from_glib_borrow(this))
581 }
582 unsafe {
583 let f: Box_<F> = Box_::new(f);
584 connect_raw(
585 self.as_ptr() as *mut _,
586 b"notify::width\0".as_ptr() as *const _,
587 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
588 notify_width_trampoline::<F> as *const (),
589 )),
590 Box_::into_raw(f),
591 )
592 }
593 }
594}
595
596#[cfg(feature = "v4_16")]
597#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
598impl Default for MemoryTextureBuilder {
599 fn default() -> Self {
600 Self::new()
601 }
602}
603
604unsafe impl Send for MemoryTextureBuilder {}
605unsafe impl Sync for MemoryTextureBuilder {}