gtk4/auto/
icon_paintable.rs1#![allow(deprecated)]
5
6use crate::ffi;
7#[cfg(feature = "v4_6")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
9use crate::SymbolicPaintable;
10use glib::{
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17#[cfg(feature = "v4_6")]
18#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
19glib::wrapper! {
20 #[doc(alias = "GtkIconPaintable")]
57 pub struct IconPaintable(Object<ffi::GtkIconPaintable, ffi::GtkIconPaintableClass>) @implements gdk::Paintable, SymbolicPaintable;
58
59 match fn {
60 type_ => || ffi::gtk_icon_paintable_get_type(),
61 }
62}
63
64#[cfg(not(any(feature = "v4_6")))]
65glib::wrapper! {
66 #[doc(alias = "GtkIconPaintable")]
67 pub struct IconPaintable(Object<ffi::GtkIconPaintable, ffi::GtkIconPaintableClass>) @implements gdk::Paintable;
68
69 match fn {
70 type_ => || ffi::gtk_icon_paintable_get_type(),
71 }
72}
73
74impl IconPaintable {
75 #[doc(alias = "gtk_icon_paintable_new_for_file")]
90 #[doc(alias = "new_for_file")]
91 pub fn for_file(file: &impl IsA<gio::File>, size: i32, scale: i32) -> IconPaintable {
92 assert_initialized_main_thread!();
93 unsafe {
94 from_glib_full(ffi::gtk_icon_paintable_new_for_file(
95 file.as_ref().to_glib_none().0,
96 size,
97 scale,
98 ))
99 }
100 }
101
102 #[doc(alias = "gtk_icon_paintable_get_file")]
110 #[doc(alias = "get_file")]
111 pub fn file(&self) -> Option<gio::File> {
112 unsafe { from_glib_full(ffi::gtk_icon_paintable_get_file(self.to_glib_none().0)) }
113 }
114
115 #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
133 #[allow(deprecated)]
134 #[doc(alias = "gtk_icon_paintable_get_icon_name")]
135 #[doc(alias = "get_icon_name")]
136 #[doc(alias = "icon-name")]
137 pub fn icon_name(&self) -> Option<std::path::PathBuf> {
138 unsafe { from_glib_none(ffi::gtk_icon_paintable_get_icon_name(self.to_glib_none().0)) }
139 }
140
141 #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
153 #[allow(deprecated)]
154 #[doc(alias = "gtk_icon_paintable_is_symbolic")]
155 #[doc(alias = "is-symbolic")]
156 pub fn is_symbolic(&self) -> bool {
157 unsafe { from_glib(ffi::gtk_icon_paintable_is_symbolic(self.to_glib_none().0)) }
158 }
159
160 #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
165 #[doc(alias = "is-symbolic")]
166 pub fn set_is_symbolic(&self, is_symbolic: bool) {
167 ObjectExt::set_property(self, "is-symbolic", is_symbolic)
168 }
169
170 pub fn scale(&self) -> i32 {
171 ObjectExt::property(self, "scale")
172 }
173
174 pub fn set_scale(&self, scale: i32) {
175 ObjectExt::set_property(self, "scale", scale)
176 }
177
178 pub fn size(&self) -> i32 {
179 ObjectExt::property(self, "size")
180 }
181
182 pub fn set_size(&self, size: i32) {
183 ObjectExt::set_property(self, "size", size)
184 }
185
186 #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
187 #[doc(alias = "is-symbolic")]
188 pub fn connect_is_symbolic_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
189 unsafe extern "C" fn notify_is_symbolic_trampoline<F: Fn(&IconPaintable) + 'static>(
190 this: *mut ffi::GtkIconPaintable,
191 _param_spec: glib::ffi::gpointer,
192 f: glib::ffi::gpointer,
193 ) {
194 let f: &F = &*(f as *const F);
195 f(&from_glib_borrow(this))
196 }
197 unsafe {
198 let f: Box_<F> = Box_::new(f);
199 connect_raw(
200 self.as_ptr() as *mut _,
201 c"notify::is-symbolic".as_ptr() as *const _,
202 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
203 notify_is_symbolic_trampoline::<F> as *const (),
204 )),
205 Box_::into_raw(f),
206 )
207 }
208 }
209
210 #[doc(alias = "scale")]
211 pub fn connect_scale_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
212 unsafe extern "C" fn notify_scale_trampoline<F: Fn(&IconPaintable) + 'static>(
213 this: *mut ffi::GtkIconPaintable,
214 _param_spec: glib::ffi::gpointer,
215 f: glib::ffi::gpointer,
216 ) {
217 let f: &F = &*(f as *const F);
218 f(&from_glib_borrow(this))
219 }
220 unsafe {
221 let f: Box_<F> = Box_::new(f);
222 connect_raw(
223 self.as_ptr() as *mut _,
224 c"notify::scale".as_ptr() as *const _,
225 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
226 notify_scale_trampoline::<F> as *const (),
227 )),
228 Box_::into_raw(f),
229 )
230 }
231 }
232
233 #[doc(alias = "size")]
234 pub fn connect_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
235 unsafe extern "C" fn notify_size_trampoline<F: Fn(&IconPaintable) + 'static>(
236 this: *mut ffi::GtkIconPaintable,
237 _param_spec: glib::ffi::gpointer,
238 f: glib::ffi::gpointer,
239 ) {
240 let f: &F = &*(f as *const F);
241 f(&from_glib_borrow(this))
242 }
243 unsafe {
244 let f: Box_<F> = Box_::new(f);
245 connect_raw(
246 self.as_ptr() as *mut _,
247 c"notify::size".as_ptr() as *const _,
248 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
249 notify_size_trampoline::<F> as *const (),
250 )),
251 Box_::into_raw(f),
252 )
253 }
254 }
255}