use crate::ffi;
use glib::{
prelude::*,
signal::{SignalHandlerId, connect_raw},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "NMABarCode")]
pub struct BarCode(Object<ffi::NMABarCode, ffi::NMABarCodeClass>);
match fn {
type_ => || ffi::nma_bar_code_get_type(),
}
}
impl BarCode {
#[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)) }
}
pub fn builder() -> BarCodeBuilder {
BarCodeBuilder::new()
}
#[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());
}
}
#[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) }
}
#[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>()
}
}
#[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()),
}
}
#[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()
}
}