use crate::{SpaceLocationFlags, SpaceTypeFlags, ffi};
use glib::{
prelude::*,
signal::{SignalHandlerId, connect_raw},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "GtkSourceSpaceDrawer")]
pub struct SpaceDrawer(Object<ffi::GtkSourceSpaceDrawer, ffi::GtkSourceSpaceDrawerClass>);
match fn {
type_ => || ffi::gtk_source_space_drawer_get_type(),
}
}
impl SpaceDrawer {
#[doc(alias = "gtk_source_space_drawer_new")]
pub fn new() -> SpaceDrawer {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gtk_source_space_drawer_new()) }
}
pub fn builder() -> SpaceDrawerBuilder {
SpaceDrawerBuilder::new()
}
#[doc(alias = "gtk_source_space_drawer_bind_matrix_setting")]
pub fn bind_matrix_setting(
&self,
settings: &impl IsA<gio::Settings>,
key: &str,
flags: gio::SettingsBindFlags,
) {
unsafe {
ffi::gtk_source_space_drawer_bind_matrix_setting(
self.to_glib_none().0,
settings.as_ref().to_glib_none().0,
key.to_glib_none().0,
flags.into_glib(),
);
}
}
#[doc(alias = "gtk_source_space_drawer_get_enable_matrix")]
#[doc(alias = "get_enable_matrix")]
#[doc(alias = "enable-matrix")]
pub fn enables_matrix(&self) -> bool {
unsafe {
from_glib(ffi::gtk_source_space_drawer_get_enable_matrix(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gtk_source_space_drawer_get_matrix")]
#[doc(alias = "get_matrix")]
pub fn matrix(&self) -> glib::Variant {
unsafe {
from_glib_full(ffi::gtk_source_space_drawer_get_matrix(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gtk_source_space_drawer_get_types_for_locations")]
#[doc(alias = "get_types_for_locations")]
pub fn types_for_locations(&self, locations: SpaceLocationFlags) -> SpaceTypeFlags {
unsafe {
from_glib(ffi::gtk_source_space_drawer_get_types_for_locations(
self.to_glib_none().0,
locations.into_glib(),
))
}
}
#[doc(alias = "gtk_source_space_drawer_set_enable_matrix")]
#[doc(alias = "enable-matrix")]
pub fn set_enable_matrix(&self, enable_matrix: bool) {
unsafe {
ffi::gtk_source_space_drawer_set_enable_matrix(
self.to_glib_none().0,
enable_matrix.into_glib(),
);
}
}
#[doc(alias = "gtk_source_space_drawer_set_matrix")]
#[doc(alias = "matrix")]
pub fn set_matrix(&self, matrix: Option<&glib::Variant>) {
unsafe {
ffi::gtk_source_space_drawer_set_matrix(self.to_glib_none().0, matrix.to_glib_none().0);
}
}
#[doc(alias = "gtk_source_space_drawer_set_types_for_locations")]
pub fn set_types_for_locations(&self, locations: SpaceLocationFlags, types: SpaceTypeFlags) {
unsafe {
ffi::gtk_source_space_drawer_set_types_for_locations(
self.to_glib_none().0,
locations.into_glib(),
types.into_glib(),
);
}
}
#[doc(alias = "enable-matrix")]
pub fn connect_enable_matrix_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_enable_matrix_trampoline<F: Fn(&SpaceDrawer) + 'static>(
this: *mut ffi::GtkSourceSpaceDrawer,
_param_spec: glib::ffi::gpointer,
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"notify::enable-matrix".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_enable_matrix_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "matrix")]
pub fn connect_matrix_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_matrix_trampoline<F: Fn(&SpaceDrawer) + 'static>(
this: *mut ffi::GtkSourceSpaceDrawer,
_param_spec: glib::ffi::gpointer,
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"notify::matrix".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_matrix_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl Default for SpaceDrawer {
fn default() -> Self {
Self::new()
}
}
#[must_use = "The builder must be built to be used"]
pub struct SpaceDrawerBuilder {
builder: glib::object::ObjectBuilder<'static, SpaceDrawer>,
}
impl SpaceDrawerBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
pub fn enable_matrix(self, enable_matrix: bool) -> Self {
Self {
builder: self.builder.property("enable-matrix", enable_matrix),
}
}
pub fn matrix(self, matrix: &glib::Variant) -> Self {
Self {
builder: self.builder.property("matrix", matrix.clone()),
}
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> SpaceDrawer {
assert_initialized_main_thread!();
self.builder.build()
}
}