sourceview5 0.11.0

Rust bindings for GtkSourceView 5
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{AnnotationProvider, ffi};
use glib::{
    object::ObjectType as _,
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "GtkSourceAnnotations")]
    pub struct Annotations(Object<ffi::GtkSourceAnnotations, ffi::GtkSourceAnnotationsClass>);

    match fn {
        type_ => || ffi::gtk_source_annotations_get_type(),
    }
}

impl Annotations {
    #[doc(alias = "gtk_source_annotations_add_provider")]
    pub fn add_provider(&self, provider: &impl IsA<AnnotationProvider>) {
        unsafe {
            ffi::gtk_source_annotations_add_provider(
                self.to_glib_none().0,
                provider.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "gtk_source_annotations_remove_provider")]
    pub fn remove_provider(&self, provider: &impl IsA<AnnotationProvider>) -> bool {
        unsafe {
            from_glib(ffi::gtk_source_annotations_remove_provider(
                self.to_glib_none().0,
                provider.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "changed")]
    pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn changed_trampoline<F: Fn(&Annotations) + 'static>(
            this: *mut ffi::GtkSourceAnnotations,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"changed".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    changed_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}