1use crate::{ffi, PaintableFlags, Snapshot};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GdkPaintable")]
16 pub struct Paintable(Interface<ffi::GdkPaintable, ffi::GdkPaintableInterface>);
17
18 match fn {
19 type_ => || ffi::gdk_paintable_get_type(),
20 }
21}
22
23impl Paintable {
24 pub const NONE: Option<&'static Paintable> = None;
25
26 #[doc(alias = "gdk_paintable_new_empty")]
27 pub fn new_empty(intrinsic_width: i32, intrinsic_height: i32) -> Paintable {
28 assert_initialized_main_thread!();
29 unsafe {
30 from_glib_full(ffi::gdk_paintable_new_empty(
31 intrinsic_width,
32 intrinsic_height,
33 ))
34 }
35 }
36}
37
38pub trait PaintableExt: IsA<Paintable> + 'static {
39 #[doc(alias = "gdk_paintable_compute_concrete_size")]
40 fn compute_concrete_size(
41 &self,
42 specified_width: f64,
43 specified_height: f64,
44 default_width: f64,
45 default_height: f64,
46 ) -> (f64, f64) {
47 unsafe {
48 let mut concrete_width = std::mem::MaybeUninit::uninit();
49 let mut concrete_height = std::mem::MaybeUninit::uninit();
50 ffi::gdk_paintable_compute_concrete_size(
51 self.as_ref().to_glib_none().0,
52 specified_width,
53 specified_height,
54 default_width,
55 default_height,
56 concrete_width.as_mut_ptr(),
57 concrete_height.as_mut_ptr(),
58 );
59 (concrete_width.assume_init(), concrete_height.assume_init())
60 }
61 }
62
63 #[doc(alias = "gdk_paintable_get_current_image")]
64 #[doc(alias = "get_current_image")]
65 #[must_use]
66 fn current_image(&self) -> Paintable {
67 unsafe {
68 from_glib_full(ffi::gdk_paintable_get_current_image(
69 self.as_ref().to_glib_none().0,
70 ))
71 }
72 }
73
74 #[doc(alias = "gdk_paintable_get_flags")]
75 #[doc(alias = "get_flags")]
76 fn flags(&self) -> PaintableFlags {
77 unsafe { from_glib(ffi::gdk_paintable_get_flags(self.as_ref().to_glib_none().0)) }
78 }
79
80 #[doc(alias = "gdk_paintable_get_intrinsic_aspect_ratio")]
81 #[doc(alias = "get_intrinsic_aspect_ratio")]
82 fn intrinsic_aspect_ratio(&self) -> f64 {
83 unsafe { ffi::gdk_paintable_get_intrinsic_aspect_ratio(self.as_ref().to_glib_none().0) }
84 }
85
86 #[doc(alias = "gdk_paintable_get_intrinsic_height")]
87 #[doc(alias = "get_intrinsic_height")]
88 fn intrinsic_height(&self) -> i32 {
89 unsafe { ffi::gdk_paintable_get_intrinsic_height(self.as_ref().to_glib_none().0) }
90 }
91
92 #[doc(alias = "gdk_paintable_get_intrinsic_width")]
93 #[doc(alias = "get_intrinsic_width")]
94 fn intrinsic_width(&self) -> i32 {
95 unsafe { ffi::gdk_paintable_get_intrinsic_width(self.as_ref().to_glib_none().0) }
96 }
97
98 #[doc(alias = "gdk_paintable_invalidate_contents")]
99 fn invalidate_contents(&self) {
100 unsafe {
101 ffi::gdk_paintable_invalidate_contents(self.as_ref().to_glib_none().0);
102 }
103 }
104
105 #[doc(alias = "gdk_paintable_invalidate_size")]
106 fn invalidate_size(&self) {
107 unsafe {
108 ffi::gdk_paintable_invalidate_size(self.as_ref().to_glib_none().0);
109 }
110 }
111
112 #[doc(alias = "gdk_paintable_snapshot")]
113 fn snapshot(&self, snapshot: &impl IsA<Snapshot>, width: f64, height: f64) {
114 unsafe {
115 ffi::gdk_paintable_snapshot(
116 self.as_ref().to_glib_none().0,
117 snapshot.as_ref().to_glib_none().0,
118 width,
119 height,
120 );
121 }
122 }
123
124 #[doc(alias = "invalidate-contents")]
125 fn connect_invalidate_contents<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
126 unsafe extern "C" fn invalidate_contents_trampoline<
127 P: IsA<Paintable>,
128 F: Fn(&P) + 'static,
129 >(
130 this: *mut ffi::GdkPaintable,
131 f: glib::ffi::gpointer,
132 ) {
133 let f: &F = &*(f as *const F);
134 f(Paintable::from_glib_borrow(this).unsafe_cast_ref())
135 }
136 unsafe {
137 let f: Box_<F> = Box_::new(f);
138 connect_raw(
139 self.as_ptr() as *mut _,
140 c"invalidate-contents".as_ptr() as *const _,
141 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
142 invalidate_contents_trampoline::<Self, F> as *const (),
143 )),
144 Box_::into_raw(f),
145 )
146 }
147 }
148
149 #[doc(alias = "invalidate-size")]
150 fn connect_invalidate_size<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
151 unsafe extern "C" fn invalidate_size_trampoline<P: IsA<Paintable>, F: Fn(&P) + 'static>(
152 this: *mut ffi::GdkPaintable,
153 f: glib::ffi::gpointer,
154 ) {
155 let f: &F = &*(f as *const F);
156 f(Paintable::from_glib_borrow(this).unsafe_cast_ref())
157 }
158 unsafe {
159 let f: Box_<F> = Box_::new(f);
160 connect_raw(
161 self.as_ptr() as *mut _,
162 c"invalidate-size".as_ptr() as *const _,
163 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
164 invalidate_size_trampoline::<Self, F> as *const (),
165 )),
166 Box_::into_raw(f),
167 )
168 }
169 }
170}
171
172impl<O: IsA<Paintable>> PaintableExt for O {}