[go: up one dir, main page]

gtk4/auto/
widget_paintable.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, Widget};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    #[doc(alias = "GtkWidgetPaintable")]
15    pub struct WidgetPaintable(Object<ffi::GtkWidgetPaintable, ffi::GtkWidgetPaintableClass>) @implements gdk::Paintable;
16
17    match fn {
18        type_ => || ffi::gtk_widget_paintable_get_type(),
19    }
20}
21
22impl WidgetPaintable {
23    #[doc(alias = "gtk_widget_paintable_new")]
24    pub fn new(widget: Option<&impl IsA<Widget>>) -> WidgetPaintable {
25        assert_initialized_main_thread!();
26        unsafe {
27            from_glib_full(ffi::gtk_widget_paintable_new(
28                widget.map(|p| p.as_ref()).to_glib_none().0,
29            ))
30        }
31    }
32
33    #[doc(alias = "gtk_widget_paintable_get_widget")]
34    #[doc(alias = "get_widget")]
35    pub fn widget(&self) -> Option<Widget> {
36        unsafe { from_glib_none(ffi::gtk_widget_paintable_get_widget(self.to_glib_none().0)) }
37    }
38
39    #[doc(alias = "gtk_widget_paintable_set_widget")]
40    #[doc(alias = "widget")]
41    pub fn set_widget(&self, widget: Option<&impl IsA<Widget>>) {
42        unsafe {
43            ffi::gtk_widget_paintable_set_widget(
44                self.to_glib_none().0,
45                widget.map(|p| p.as_ref()).to_glib_none().0,
46            );
47        }
48    }
49
50    #[doc(alias = "widget")]
51    pub fn connect_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
52        unsafe extern "C" fn notify_widget_trampoline<F: Fn(&WidgetPaintable) + 'static>(
53            this: *mut ffi::GtkWidgetPaintable,
54            _param_spec: glib::ffi::gpointer,
55            f: glib::ffi::gpointer,
56        ) {
57            let f: &F = &*(f as *const F);
58            f(&from_glib_borrow(this))
59        }
60        unsafe {
61            let f: Box_<F> = Box_::new(f);
62            connect_raw(
63                self.as_ptr() as *mut _,
64                c"notify::widget".as_ptr() as *const _,
65                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
66                    notify_widget_trampoline::<F> as *const (),
67                )),
68                Box_::into_raw(f),
69            )
70        }
71    }
72}