1use gdk;
6use glib;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::object::ObjectExt;
10use glib::signal::connect_raw;
11use glib::signal::SignalHandlerId;
12use glib::translate::*;
13use glib::StaticType;
14use glib::ToValue;
15use glib_sys;
16use gobject_sys;
17use gtk_sys;
18use std::boxed::Box as Box_;
19use std::fmt;
20use std::mem::transmute;
21use Align;
22use Bin;
23use Buildable;
24use Container;
25use ResizeMode;
26use Widget;
27
28glib_wrapper! {
29 pub struct FlowBoxChild(Object<gtk_sys::GtkFlowBoxChild, gtk_sys::GtkFlowBoxChildClass, FlowBoxChildClass>) @extends Bin, Container, Widget, @implements Buildable;
30
31 match fn {
32 get_type => || gtk_sys::gtk_flow_box_child_get_type(),
33 }
34}
35
36impl FlowBoxChild {
37 pub fn new() -> FlowBoxChild {
38 assert_initialized_main_thread!();
39 unsafe { Widget::from_glib_none(gtk_sys::gtk_flow_box_child_new()).unsafe_cast() }
40 }
41}
42
43impl Default for FlowBoxChild {
44 fn default() -> Self {
45 Self::new()
46 }
47}
48
49pub struct FlowBoxChildBuilder {
50 border_width: Option<u32>,
51 child: Option<Widget>,
52 resize_mode: Option<ResizeMode>,
53 app_paintable: Option<bool>,
54 can_default: Option<bool>,
55 can_focus: Option<bool>,
56 events: Option<gdk::EventMask>,
57 expand: Option<bool>,
58 #[cfg(any(feature = "v3_20", feature = "dox"))]
59 focus_on_click: Option<bool>,
60 halign: Option<Align>,
61 has_default: Option<bool>,
62 has_focus: Option<bool>,
63 has_tooltip: Option<bool>,
64 height_request: Option<i32>,
65 hexpand: Option<bool>,
66 hexpand_set: Option<bool>,
67 is_focus: Option<bool>,
68 margin: Option<i32>,
69 margin_bottom: Option<i32>,
70 margin_end: Option<i32>,
71 margin_start: Option<i32>,
72 margin_top: Option<i32>,
73 name: Option<String>,
74 no_show_all: Option<bool>,
75 opacity: Option<f64>,
76 parent: Option<Container>,
77 receives_default: Option<bool>,
78 sensitive: Option<bool>,
79 tooltip_markup: Option<String>,
81 tooltip_text: Option<String>,
82 valign: Option<Align>,
83 vexpand: Option<bool>,
84 vexpand_set: Option<bool>,
85 visible: Option<bool>,
86 width_request: Option<i32>,
87}
88
89impl FlowBoxChildBuilder {
90 pub fn new() -> Self {
91 Self {
92 border_width: None,
93 child: None,
94 resize_mode: None,
95 app_paintable: None,
96 can_default: None,
97 can_focus: None,
98 events: None,
99 expand: None,
100 #[cfg(any(feature = "v3_20", feature = "dox"))]
101 focus_on_click: None,
102 halign: None,
103 has_default: None,
104 has_focus: None,
105 has_tooltip: None,
106 height_request: None,
107 hexpand: None,
108 hexpand_set: None,
109 is_focus: None,
110 margin: None,
111 margin_bottom: None,
112 margin_end: None,
113 margin_start: None,
114 margin_top: None,
115 name: None,
116 no_show_all: None,
117 opacity: None,
118 parent: None,
119 receives_default: None,
120 sensitive: None,
121 tooltip_markup: None,
122 tooltip_text: None,
123 valign: None,
124 vexpand: None,
125 vexpand_set: None,
126 visible: None,
127 width_request: None,
128 }
129 }
130
131 pub fn build(self) -> FlowBoxChild {
132 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
133 if let Some(ref border_width) = self.border_width {
134 properties.push(("border-width", border_width));
135 }
136 if let Some(ref child) = self.child {
137 properties.push(("child", child));
138 }
139 if let Some(ref resize_mode) = self.resize_mode {
140 properties.push(("resize-mode", resize_mode));
141 }
142 if let Some(ref app_paintable) = self.app_paintable {
143 properties.push(("app-paintable", app_paintable));
144 }
145 if let Some(ref can_default) = self.can_default {
146 properties.push(("can-default", can_default));
147 }
148 if let Some(ref can_focus) = self.can_focus {
149 properties.push(("can-focus", can_focus));
150 }
151 if let Some(ref events) = self.events {
152 properties.push(("events", events));
153 }
154 if let Some(ref expand) = self.expand {
155 properties.push(("expand", expand));
156 }
157 #[cfg(any(feature = "v3_20", feature = "dox"))]
158 {
159 if let Some(ref focus_on_click) = self.focus_on_click {
160 properties.push(("focus-on-click", focus_on_click));
161 }
162 }
163 if let Some(ref halign) = self.halign {
164 properties.push(("halign", halign));
165 }
166 if let Some(ref has_default) = self.has_default {
167 properties.push(("has-default", has_default));
168 }
169 if let Some(ref has_focus) = self.has_focus {
170 properties.push(("has-focus", has_focus));
171 }
172 if let Some(ref has_tooltip) = self.has_tooltip {
173 properties.push(("has-tooltip", has_tooltip));
174 }
175 if let Some(ref height_request) = self.height_request {
176 properties.push(("height-request", height_request));
177 }
178 if let Some(ref hexpand) = self.hexpand {
179 properties.push(("hexpand", hexpand));
180 }
181 if let Some(ref hexpand_set) = self.hexpand_set {
182 properties.push(("hexpand-set", hexpand_set));
183 }
184 if let Some(ref is_focus) = self.is_focus {
185 properties.push(("is-focus", is_focus));
186 }
187 if let Some(ref margin) = self.margin {
188 properties.push(("margin", margin));
189 }
190 if let Some(ref margin_bottom) = self.margin_bottom {
191 properties.push(("margin-bottom", margin_bottom));
192 }
193 if let Some(ref margin_end) = self.margin_end {
194 properties.push(("margin-end", margin_end));
195 }
196 if let Some(ref margin_start) = self.margin_start {
197 properties.push(("margin-start", margin_start));
198 }
199 if let Some(ref margin_top) = self.margin_top {
200 properties.push(("margin-top", margin_top));
201 }
202 if let Some(ref name) = self.name {
203 properties.push(("name", name));
204 }
205 if let Some(ref no_show_all) = self.no_show_all {
206 properties.push(("no-show-all", no_show_all));
207 }
208 if let Some(ref opacity) = self.opacity {
209 properties.push(("opacity", opacity));
210 }
211 if let Some(ref parent) = self.parent {
212 properties.push(("parent", parent));
213 }
214 if let Some(ref receives_default) = self.receives_default {
215 properties.push(("receives-default", receives_default));
216 }
217 if let Some(ref sensitive) = self.sensitive {
218 properties.push(("sensitive", sensitive));
219 }
220 if let Some(ref tooltip_markup) = self.tooltip_markup {
221 properties.push(("tooltip-markup", tooltip_markup));
222 }
223 if let Some(ref tooltip_text) = self.tooltip_text {
224 properties.push(("tooltip-text", tooltip_text));
225 }
226 if let Some(ref valign) = self.valign {
227 properties.push(("valign", valign));
228 }
229 if let Some(ref vexpand) = self.vexpand {
230 properties.push(("vexpand", vexpand));
231 }
232 if let Some(ref vexpand_set) = self.vexpand_set {
233 properties.push(("vexpand-set", vexpand_set));
234 }
235 if let Some(ref visible) = self.visible {
236 properties.push(("visible", visible));
237 }
238 if let Some(ref width_request) = self.width_request {
239 properties.push(("width-request", width_request));
240 }
241 glib::Object::new(FlowBoxChild::static_type(), &properties)
242 .expect("object new")
243 .downcast()
244 .expect("downcast")
245 }
246
247 pub fn border_width(mut self, border_width: u32) -> Self {
248 self.border_width = Some(border_width);
249 self
250 }
251
252 pub fn child(mut self, child: &Widget) -> Self {
253 self.child = Some(child.clone());
254 self
255 }
256
257 pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
258 self.resize_mode = Some(resize_mode);
259 self
260 }
261
262 pub fn app_paintable(mut self, app_paintable: bool) -> Self {
263 self.app_paintable = Some(app_paintable);
264 self
265 }
266
267 pub fn can_default(mut self, can_default: bool) -> Self {
268 self.can_default = Some(can_default);
269 self
270 }
271
272 pub fn can_focus(mut self, can_focus: bool) -> Self {
273 self.can_focus = Some(can_focus);
274 self
275 }
276
277 pub fn events(mut self, events: gdk::EventMask) -> Self {
278 self.events = Some(events);
279 self
280 }
281
282 pub fn expand(mut self, expand: bool) -> Self {
283 self.expand = Some(expand);
284 self
285 }
286
287 #[cfg(any(feature = "v3_20", feature = "dox"))]
288 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
289 self.focus_on_click = Some(focus_on_click);
290 self
291 }
292
293 pub fn halign(mut self, halign: Align) -> Self {
294 self.halign = Some(halign);
295 self
296 }
297
298 pub fn has_default(mut self, has_default: bool) -> Self {
299 self.has_default = Some(has_default);
300 self
301 }
302
303 pub fn has_focus(mut self, has_focus: bool) -> Self {
304 self.has_focus = Some(has_focus);
305 self
306 }
307
308 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
309 self.has_tooltip = Some(has_tooltip);
310 self
311 }
312
313 pub fn height_request(mut self, height_request: i32) -> Self {
314 self.height_request = Some(height_request);
315 self
316 }
317
318 pub fn hexpand(mut self, hexpand: bool) -> Self {
319 self.hexpand = Some(hexpand);
320 self
321 }
322
323 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
324 self.hexpand_set = Some(hexpand_set);
325 self
326 }
327
328 pub fn is_focus(mut self, is_focus: bool) -> Self {
329 self.is_focus = Some(is_focus);
330 self
331 }
332
333 pub fn margin(mut self, margin: i32) -> Self {
334 self.margin = Some(margin);
335 self
336 }
337
338 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
339 self.margin_bottom = Some(margin_bottom);
340 self
341 }
342
343 pub fn margin_end(mut self, margin_end: i32) -> Self {
344 self.margin_end = Some(margin_end);
345 self
346 }
347
348 pub fn margin_start(mut self, margin_start: i32) -> Self {
349 self.margin_start = Some(margin_start);
350 self
351 }
352
353 pub fn margin_top(mut self, margin_top: i32) -> Self {
354 self.margin_top = Some(margin_top);
355 self
356 }
357
358 pub fn name(mut self, name: &str) -> Self {
359 self.name = Some(name.to_string());
360 self
361 }
362
363 pub fn no_show_all(mut self, no_show_all: bool) -> Self {
364 self.no_show_all = Some(no_show_all);
365 self
366 }
367
368 pub fn opacity(mut self, opacity: f64) -> Self {
369 self.opacity = Some(opacity);
370 self
371 }
372
373 pub fn parent(mut self, parent: &Container) -> Self {
374 self.parent = Some(parent.clone());
375 self
376 }
377
378 pub fn receives_default(mut self, receives_default: bool) -> Self {
379 self.receives_default = Some(receives_default);
380 self
381 }
382
383 pub fn sensitive(mut self, sensitive: bool) -> Self {
384 self.sensitive = Some(sensitive);
385 self
386 }
387
388 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
389 self.tooltip_markup = Some(tooltip_markup.to_string());
390 self
391 }
392
393 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
394 self.tooltip_text = Some(tooltip_text.to_string());
395 self
396 }
397
398 pub fn valign(mut self, valign: Align) -> Self {
399 self.valign = Some(valign);
400 self
401 }
402
403 pub fn vexpand(mut self, vexpand: bool) -> Self {
404 self.vexpand = Some(vexpand);
405 self
406 }
407
408 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
409 self.vexpand_set = Some(vexpand_set);
410 self
411 }
412
413 pub fn visible(mut self, visible: bool) -> Self {
414 self.visible = Some(visible);
415 self
416 }
417
418 pub fn width_request(mut self, width_request: i32) -> Self {
419 self.width_request = Some(width_request);
420 self
421 }
422}
423
424pub const NONE_FLOW_BOX_CHILD: Option<&FlowBoxChild> = None;
425
426pub trait FlowBoxChildExt: 'static {
427 fn changed(&self);
428
429 fn get_index(&self) -> i32;
430
431 fn is_selected(&self) -> bool;
432
433 fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
434
435 fn emit_activate(&self);
436}
437
438impl<O: IsA<FlowBoxChild>> FlowBoxChildExt for O {
439 fn changed(&self) {
440 unsafe {
441 gtk_sys::gtk_flow_box_child_changed(self.as_ref().to_glib_none().0);
442 }
443 }
444
445 fn get_index(&self) -> i32 {
446 unsafe { gtk_sys::gtk_flow_box_child_get_index(self.as_ref().to_glib_none().0) }
447 }
448
449 fn is_selected(&self) -> bool {
450 unsafe {
451 from_glib(gtk_sys::gtk_flow_box_child_is_selected(
452 self.as_ref().to_glib_none().0,
453 ))
454 }
455 }
456
457 fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
458 unsafe extern "C" fn activate_trampoline<P, F: Fn(&P) + 'static>(
459 this: *mut gtk_sys::GtkFlowBoxChild,
460 f: glib_sys::gpointer,
461 ) where
462 P: IsA<FlowBoxChild>,
463 {
464 let f: &F = &*(f as *const F);
465 f(&FlowBoxChild::from_glib_borrow(this).unsafe_cast())
466 }
467 unsafe {
468 let f: Box_<F> = Box_::new(f);
469 connect_raw(
470 self.as_ptr() as *mut _,
471 b"activate\0".as_ptr() as *const _,
472 Some(transmute(activate_trampoline::<Self, F> as usize)),
473 Box_::into_raw(f),
474 )
475 }
476 }
477
478 fn emit_activate(&self) {
479 let _ = unsafe {
480 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
481 .emit("activate", &[])
482 .unwrap()
483 };
484 }
485}
486
487impl fmt::Display for FlowBoxChild {
488 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
489 write!(f, "FlowBoxChild")
490 }
491}