gtk4 0.1.0

Rust bindings of the GTK 4 library
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::Accessible;
use crate::Buildable;
use crate::ConstraintTarget;
use crate::Widget;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
use std::mem;

glib::wrapper! {
    #[doc(alias = "GtkNative")]
    pub struct Native(Interface<ffi::GtkNative, ffi::GtkNativeInterface>) @requires Widget, Accessible, Buildable, ConstraintTarget;

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

impl Native {
    #[doc(alias = "gtk_native_get_for_surface")]
    #[doc(alias = "get_for_surface")]
    pub fn for_surface<P: IsA<gdk::Surface>>(surface: &P) -> Option<Native> {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_none(ffi::gtk_native_get_for_surface(
                surface.as_ref().to_glib_none().0,
            ))
        }
    }
}

pub const NONE_NATIVE: Option<&Native> = None;

pub trait NativeExt: 'static {
    #[doc(alias = "gtk_native_get_renderer")]
    #[doc(alias = "get_renderer")]
    fn renderer(&self) -> Option<gsk::Renderer>;

    #[doc(alias = "gtk_native_get_surface")]
    #[doc(alias = "get_surface")]
    fn surface(&self) -> Option<gdk::Surface>;

    #[doc(alias = "gtk_native_get_surface_transform")]
    #[doc(alias = "get_surface_transform")]
    fn surface_transform(&self) -> (f64, f64);
}

impl<O: IsA<Native>> NativeExt for O {
    fn renderer(&self) -> Option<gsk::Renderer> {
        unsafe { from_glib_none(ffi::gtk_native_get_renderer(self.as_ref().to_glib_none().0)) }
    }

    fn surface(&self) -> Option<gdk::Surface> {
        unsafe { from_glib_none(ffi::gtk_native_get_surface(self.as_ref().to_glib_none().0)) }
    }

    fn surface_transform(&self) -> (f64, f64) {
        unsafe {
            let mut x = mem::MaybeUninit::uninit();
            let mut y = mem::MaybeUninit::uninit();
            ffi::gtk_native_get_surface_transform(
                self.as_ref().to_glib_none().0,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
            );
            let x = x.assume_init();
            let y = y.assume_init();
            (x, y)
        }
    }
}

impl fmt::Display for Native {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Native")
    }
}