nma4 0.1.2

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

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

glib::wrapper! {
    ///
    ///
    /// ## Properties
    ///
    ///
    /// #### `size`
    ///  Readable
    ///
    ///
    /// #### `text`
    ///  Writeable
    #[doc(alias = "NMABarCode")]
    pub struct BarCode(Object<ffi::NMABarCode, ffi::NMABarCodeClass>);

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

impl BarCode {
    /// ## `text`
    /// set the bar code text
    ///
    /// # Returns
    ///
    /// the bar code instance
    #[cfg(feature = "v1_8_22")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8_22")))]
    #[doc(alias = "nma_bar_code_new")]
    pub fn new(text: &str) -> BarCode {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::nma_bar_code_new(text.to_glib_none().0)) }
    }

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`BarCode`] objects.
    ///
    /// This method returns an instance of [`BarCodeBuilder`](crate::builders::BarCodeBuilder) which can be used to create [`BarCode`] objects.
    pub fn builder() -> BarCodeBuilder {
        BarCodeBuilder::new()
    }

    /// Draws the QR code onto the given context.
    /// ## `cr`
    /// cairo context
    #[cfg(feature = "v1_8_22")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8_22")))]
    #[doc(alias = "nma_bar_code_draw")]
    pub fn draw(&self, cr: &mut cairo::Context) {
        unsafe {
            ffi::nma_bar_code_draw(self.to_glib_none().0, cr.to_raw_none());
        }
    }

    ///
    /// # Returns
    ///
    /// the side of a QR code square.
    #[cfg(feature = "v1_8_22")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8_22")))]
    #[doc(alias = "nma_bar_code_get_size")]
    #[doc(alias = "get_size")]
    pub fn size(&self) -> i32 {
        unsafe { ffi::nma_bar_code_get_size(self.to_glib_none().0) }
    }

    /// Regenerates the QR code for a different text.
    /// ## `text`
    /// new bar code text
    #[cfg(feature = "v1_8_22")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8_22")))]
    #[doc(alias = "nma_bar_code_set_text")]
    #[doc(alias = "text")]
    pub fn set_text(&self, text: &str) {
        unsafe {
            ffi::nma_bar_code_set_text(self.to_glib_none().0, text.to_glib_none().0);
        }
    }

    #[cfg(not(feature = "v1_8_22"))]
    #[cfg_attr(docsrs, doc(cfg(not(feature = "v1_8_22"))))]
    pub fn size(&self) -> i32 {
        ObjectExt::property(self, "size")
    }

    #[cfg(not(feature = "v1_8_22"))]
    #[cfg_attr(docsrs, doc(cfg(not(feature = "v1_8_22"))))]
    pub fn set_text(&self, text: Option<&str>) {
        ObjectExt::set_property(self, "text", text)
    }

    #[doc(alias = "size")]
    pub fn connect_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_size_trampoline<F: Fn(&BarCode) + 'static>(
            this: *mut ffi::NMABarCode,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            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"notify::size".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_size_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "text")]
    pub fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_text_trampoline<F: Fn(&BarCode) + 'static>(
            this: *mut ffi::NMABarCode,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            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"notify::text".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_text_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

#[cfg(feature = "v1_8_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_8_22")))]
impl Default for BarCode {
    fn default() -> Self {
        glib::object::Object::new::<Self>()
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`BarCode`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct BarCodeBuilder {
    builder: glib::object::ObjectBuilder<'static, BarCode>,
}

impl BarCodeBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    pub fn text(self, text: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("text", text.into()),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`BarCode`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> BarCode {
        assert_initialized_main_thread!();
        self.builder.build()
    }
}