use crate::{Actor, GridPosition, LayoutManager, Orientation};
use glib::{
object as gobject,
object::{Cast, IsA},
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
use std::{fmt, mem::transmute};
glib_wrapper! {
pub struct GridLayout(Object<ffi::ClutterGridLayout, ffi::ClutterGridLayoutClass, GridLayoutClass>) @extends LayoutManager, gobject::InitiallyUnowned;
match fn {
get_type => || ffi::clutter_grid_layout_get_type(),
}
}
impl GridLayout {
pub fn new() -> GridLayout {
unsafe { LayoutManager::from_glib_none(ffi::clutter_grid_layout_new()).unsafe_cast() }
}
}
impl Default for GridLayout {
fn default() -> Self {
Self::new()
}
}
pub trait GridLayoutExt: 'static {
fn attach<P: IsA<Actor>>(&self, child: &P, left: i32, top: i32, width: i32, height: i32);
fn attach_next_to<P: IsA<Actor>, Q: IsA<Actor>>(
&self,
child: &P,
sibling: Option<&Q>,
side: GridPosition,
width: i32,
height: i32,
);
fn get_child_at(&self, left: i32, top: i32) -> Option<Actor>;
fn get_column_homogeneous(&self) -> bool;
fn get_column_spacing(&self) -> u32;
fn get_orientation(&self) -> Orientation;
fn get_row_homogeneous(&self) -> bool;
fn get_row_spacing(&self) -> u32;
fn insert_column(&self, position: i32);
fn insert_next_to<P: IsA<Actor>>(&self, sibling: &P, side: GridPosition);
fn insert_row(&self, position: i32);
fn set_column_homogeneous(&self, homogeneous: bool);
fn set_column_spacing(&self, spacing: u32);
fn set_orientation(&self, orientation: Orientation);
fn set_row_homogeneous(&self, homogeneous: bool);
fn set_row_spacing(&self, spacing: u32);
fn connect_property_column_homogeneous_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_column_spacing_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_row_homogeneous_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<GridLayout>> GridLayoutExt for O {
fn attach<P: IsA<Actor>>(&self, child: &P, left: i32, top: i32, width: i32, height: i32) {
unsafe {
ffi::clutter_grid_layout_attach(
self.as_ref().to_glib_none().0,
child.as_ref().to_glib_none().0,
left,
top,
width,
height,
);
}
}
fn attach_next_to<P: IsA<Actor>, Q: IsA<Actor>>(
&self,
child: &P,
sibling: Option<&Q>,
side: GridPosition,
width: i32,
height: i32,
) {
unsafe {
ffi::clutter_grid_layout_attach_next_to(
self.as_ref().to_glib_none().0,
child.as_ref().to_glib_none().0,
sibling.map(|p| p.as_ref()).to_glib_none().0,
side.to_glib(),
width,
height,
);
}
}
fn get_child_at(&self, left: i32, top: i32) -> Option<Actor> {
unsafe {
from_glib_none(ffi::clutter_grid_layout_get_child_at(
self.as_ref().to_glib_none().0,
left,
top,
))
}
}
fn get_column_homogeneous(&self) -> bool {
unsafe {
from_glib(ffi::clutter_grid_layout_get_column_homogeneous(
self.as_ref().to_glib_none().0,
))
}
}
fn get_column_spacing(&self) -> u32 {
unsafe { ffi::clutter_grid_layout_get_column_spacing(self.as_ref().to_glib_none().0) }
}
fn get_orientation(&self) -> Orientation {
unsafe {
from_glib(ffi::clutter_grid_layout_get_orientation(
self.as_ref().to_glib_none().0,
))
}
}
fn get_row_homogeneous(&self) -> bool {
unsafe {
from_glib(ffi::clutter_grid_layout_get_row_homogeneous(
self.as_ref().to_glib_none().0,
))
}
}
fn get_row_spacing(&self) -> u32 {
unsafe { ffi::clutter_grid_layout_get_row_spacing(self.as_ref().to_glib_none().0) }
}
fn insert_column(&self, position: i32) {
unsafe {
ffi::clutter_grid_layout_insert_column(self.as_ref().to_glib_none().0, position);
}
}
fn insert_next_to<P: IsA<Actor>>(&self, sibling: &P, side: GridPosition) {
unsafe {
ffi::clutter_grid_layout_insert_next_to(
self.as_ref().to_glib_none().0,
sibling.as_ref().to_glib_none().0,
side.to_glib(),
);
}
}
fn insert_row(&self, position: i32) {
unsafe {
ffi::clutter_grid_layout_insert_row(self.as_ref().to_glib_none().0, position);
}
}
fn set_column_homogeneous(&self, homogeneous: bool) {
unsafe {
ffi::clutter_grid_layout_set_column_homogeneous(
self.as_ref().to_glib_none().0,
homogeneous.to_glib(),
);
}
}
fn set_column_spacing(&self, spacing: u32) {
unsafe {
ffi::clutter_grid_layout_set_column_spacing(self.as_ref().to_glib_none().0, spacing);
}
}
fn set_orientation(&self, orientation: Orientation) {
unsafe {
ffi::clutter_grid_layout_set_orientation(
self.as_ref().to_glib_none().0,
orientation.to_glib(),
);
}
}
fn set_row_homogeneous(&self, homogeneous: bool) {
unsafe {
ffi::clutter_grid_layout_set_row_homogeneous(
self.as_ref().to_glib_none().0,
homogeneous.to_glib(),
);
}
}
fn set_row_spacing(&self, spacing: u32) {
unsafe {
ffi::clutter_grid_layout_set_row_spacing(self.as_ref().to_glib_none().0, spacing);
}
}
fn connect_property_column_homogeneous_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_column_homogeneous_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterGridLayout,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<GridLayout>,
{
let f: &F = &*(f as *const F);
f(&GridLayout::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::column-homogeneous\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_column_homogeneous_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_column_spacing_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_column_spacing_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterGridLayout,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<GridLayout>,
{
let f: &F = &*(f as *const F);
f(&GridLayout::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::column-spacing\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_column_spacing_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_orientation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_orientation_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterGridLayout,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<GridLayout>,
{
let f: &F = &*(f as *const F);
f(&GridLayout::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::orientation\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_orientation_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_row_homogeneous_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_row_homogeneous_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterGridLayout,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<GridLayout>,
{
let f: &F = &*(f as *const F);
f(&GridLayout::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::row-homogeneous\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_row_homogeneous_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_row_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_row_spacing_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterGridLayout,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<GridLayout>,
{
let f: &F = &*(f as *const F);
f(&GridLayout::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::row-spacing\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_row_spacing_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for GridLayout {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "GridLayout")
}
}