gtk/auto/
cell_area_box.rs1use glib::object::Cast;
6use glib::object::IsA;
7use glib::signal::connect_raw;
8use glib::signal::SignalHandlerId;
9use glib::translate::*;
10use glib::StaticType;
11use glib::ToValue;
12use glib_sys;
13use gtk_sys;
14use std::boxed::Box as Box_;
15use std::fmt;
16use std::mem::transmute;
17use Buildable;
18use CellArea;
19use CellLayout;
20use CellRenderer;
21use Orientable;
22
23glib_wrapper! {
24 pub struct CellAreaBox(Object<gtk_sys::GtkCellAreaBox, gtk_sys::GtkCellAreaBoxClass, CellAreaBoxClass>) @extends CellArea, @implements Buildable, CellLayout, Orientable;
25
26 match fn {
27 get_type => || gtk_sys::gtk_cell_area_box_get_type(),
28 }
29}
30
31impl CellAreaBox {
32 pub fn new() -> CellAreaBox {
33 assert_initialized_main_thread!();
34 unsafe { CellArea::from_glib_none(gtk_sys::gtk_cell_area_box_new()).unsafe_cast() }
35 }
36}
37
38impl Default for CellAreaBox {
39 fn default() -> Self {
40 Self::new()
41 }
42}
43
44pub struct CellAreaBoxBuilder {
45 spacing: Option<i32>,
46 focus_cell: Option<CellRenderer>,
47}
48
49impl CellAreaBoxBuilder {
50 pub fn new() -> Self {
51 Self {
52 spacing: None,
53 focus_cell: None,
54 }
55 }
56
57 pub fn build(self) -> CellAreaBox {
58 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
59 if let Some(ref spacing) = self.spacing {
60 properties.push(("spacing", spacing));
61 }
62 if let Some(ref focus_cell) = self.focus_cell {
63 properties.push(("focus-cell", focus_cell));
64 }
65 glib::Object::new(CellAreaBox::static_type(), &properties)
66 .expect("object new")
67 .downcast()
68 .expect("downcast")
69 }
70
71 pub fn spacing(mut self, spacing: i32) -> Self {
72 self.spacing = Some(spacing);
73 self
74 }
75
76 pub fn focus_cell(mut self, focus_cell: &CellRenderer) -> Self {
77 self.focus_cell = Some(focus_cell.clone());
78 self
79 }
80}
81
82pub const NONE_CELL_AREA_BOX: Option<&CellAreaBox> = None;
83
84pub trait CellAreaBoxExt: 'static {
85 fn get_spacing(&self) -> i32;
86
87 fn pack_end<P: IsA<CellRenderer>>(&self, renderer: &P, expand: bool, align: bool, fixed: bool);
88
89 fn pack_start<P: IsA<CellRenderer>>(
90 &self,
91 renderer: &P,
92 expand: bool,
93 align: bool,
94 fixed: bool,
95 );
96
97 fn set_spacing(&self, spacing: i32);
98
99 fn connect_property_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
100}
101
102impl<O: IsA<CellAreaBox>> CellAreaBoxExt for O {
103 fn get_spacing(&self) -> i32 {
104 unsafe { gtk_sys::gtk_cell_area_box_get_spacing(self.as_ref().to_glib_none().0) }
105 }
106
107 fn pack_end<P: IsA<CellRenderer>>(&self, renderer: &P, expand: bool, align: bool, fixed: bool) {
108 unsafe {
109 gtk_sys::gtk_cell_area_box_pack_end(
110 self.as_ref().to_glib_none().0,
111 renderer.as_ref().to_glib_none().0,
112 expand.to_glib(),
113 align.to_glib(),
114 fixed.to_glib(),
115 );
116 }
117 }
118
119 fn pack_start<P: IsA<CellRenderer>>(
120 &self,
121 renderer: &P,
122 expand: bool,
123 align: bool,
124 fixed: bool,
125 ) {
126 unsafe {
127 gtk_sys::gtk_cell_area_box_pack_start(
128 self.as_ref().to_glib_none().0,
129 renderer.as_ref().to_glib_none().0,
130 expand.to_glib(),
131 align.to_glib(),
132 fixed.to_glib(),
133 );
134 }
135 }
136
137 fn set_spacing(&self, spacing: i32) {
138 unsafe {
139 gtk_sys::gtk_cell_area_box_set_spacing(self.as_ref().to_glib_none().0, spacing);
140 }
141 }
142
143 fn connect_property_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
144 unsafe extern "C" fn notify_spacing_trampoline<P, F: Fn(&P) + 'static>(
145 this: *mut gtk_sys::GtkCellAreaBox,
146 _param_spec: glib_sys::gpointer,
147 f: glib_sys::gpointer,
148 ) where
149 P: IsA<CellAreaBox>,
150 {
151 let f: &F = &*(f as *const F);
152 f(&CellAreaBox::from_glib_borrow(this).unsafe_cast())
153 }
154 unsafe {
155 let f: Box_<F> = Box_::new(f);
156 connect_raw(
157 self.as_ptr() as *mut _,
158 b"notify::spacing\0".as_ptr() as *const _,
159 Some(transmute(notify_spacing_trampoline::<Self, F> as usize)),
160 Box_::into_raw(f),
161 )
162 }
163 }
164}
165
166impl fmt::Display for CellAreaBox {
167 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
168 write!(f, "CellAreaBox")
169 }
170}