1use gdk;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::StaticType;
12use glib::ToValue;
13use glib_sys;
14use gtk_sys;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem::transmute;
18use Align;
19use Bin;
20use Buildable;
21use Container;
22use ResizeMode;
23use RevealerTransitionType;
24use Widget;
25
26glib_wrapper! {
27 pub struct Revealer(Object<gtk_sys::GtkRevealer, gtk_sys::GtkRevealerClass, RevealerClass>) @extends Bin, Container, Widget, @implements Buildable;
28
29 match fn {
30 get_type => || gtk_sys::gtk_revealer_get_type(),
31 }
32}
33
34impl Revealer {
35 pub fn new() -> Revealer {
36 assert_initialized_main_thread!();
37 unsafe { Widget::from_glib_none(gtk_sys::gtk_revealer_new()).unsafe_cast() }
38 }
39}
40
41impl Default for Revealer {
42 fn default() -> Self {
43 Self::new()
44 }
45}
46
47pub struct RevealerBuilder {
48 reveal_child: Option<bool>,
49 transition_duration: Option<u32>,
50 transition_type: Option<RevealerTransitionType>,
51 border_width: Option<u32>,
52 child: Option<Widget>,
53 resize_mode: Option<ResizeMode>,
54 app_paintable: Option<bool>,
55 can_default: Option<bool>,
56 can_focus: Option<bool>,
57 events: Option<gdk::EventMask>,
58 expand: Option<bool>,
59 #[cfg(any(feature = "v3_20", feature = "dox"))]
60 focus_on_click: Option<bool>,
61 halign: Option<Align>,
62 has_default: Option<bool>,
63 has_focus: Option<bool>,
64 has_tooltip: Option<bool>,
65 height_request: Option<i32>,
66 hexpand: Option<bool>,
67 hexpand_set: Option<bool>,
68 is_focus: Option<bool>,
69 margin: Option<i32>,
70 margin_bottom: Option<i32>,
71 margin_end: Option<i32>,
72 margin_start: Option<i32>,
73 margin_top: Option<i32>,
74 name: Option<String>,
75 no_show_all: Option<bool>,
76 opacity: Option<f64>,
77 parent: Option<Container>,
78 receives_default: Option<bool>,
79 sensitive: Option<bool>,
80 tooltip_markup: Option<String>,
82 tooltip_text: Option<String>,
83 valign: Option<Align>,
84 vexpand: Option<bool>,
85 vexpand_set: Option<bool>,
86 visible: Option<bool>,
87 width_request: Option<i32>,
88}
89
90impl RevealerBuilder {
91 pub fn new() -> Self {
92 Self {
93 reveal_child: None,
94 transition_duration: None,
95 transition_type: None,
96 border_width: None,
97 child: None,
98 resize_mode: None,
99 app_paintable: None,
100 can_default: None,
101 can_focus: None,
102 events: None,
103 expand: None,
104 #[cfg(any(feature = "v3_20", feature = "dox"))]
105 focus_on_click: None,
106 halign: None,
107 has_default: None,
108 has_focus: None,
109 has_tooltip: None,
110 height_request: None,
111 hexpand: None,
112 hexpand_set: None,
113 is_focus: None,
114 margin: None,
115 margin_bottom: None,
116 margin_end: None,
117 margin_start: None,
118 margin_top: None,
119 name: None,
120 no_show_all: None,
121 opacity: None,
122 parent: None,
123 receives_default: None,
124 sensitive: None,
125 tooltip_markup: None,
126 tooltip_text: None,
127 valign: None,
128 vexpand: None,
129 vexpand_set: None,
130 visible: None,
131 width_request: None,
132 }
133 }
134
135 pub fn build(self) -> Revealer {
136 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
137 if let Some(ref reveal_child) = self.reveal_child {
138 properties.push(("reveal-child", reveal_child));
139 }
140 if let Some(ref transition_duration) = self.transition_duration {
141 properties.push(("transition-duration", transition_duration));
142 }
143 if let Some(ref transition_type) = self.transition_type {
144 properties.push(("transition-type", transition_type));
145 }
146 if let Some(ref border_width) = self.border_width {
147 properties.push(("border-width", border_width));
148 }
149 if let Some(ref child) = self.child {
150 properties.push(("child", child));
151 }
152 if let Some(ref resize_mode) = self.resize_mode {
153 properties.push(("resize-mode", resize_mode));
154 }
155 if let Some(ref app_paintable) = self.app_paintable {
156 properties.push(("app-paintable", app_paintable));
157 }
158 if let Some(ref can_default) = self.can_default {
159 properties.push(("can-default", can_default));
160 }
161 if let Some(ref can_focus) = self.can_focus {
162 properties.push(("can-focus", can_focus));
163 }
164 if let Some(ref events) = self.events {
165 properties.push(("events", events));
166 }
167 if let Some(ref expand) = self.expand {
168 properties.push(("expand", expand));
169 }
170 #[cfg(any(feature = "v3_20", feature = "dox"))]
171 {
172 if let Some(ref focus_on_click) = self.focus_on_click {
173 properties.push(("focus-on-click", focus_on_click));
174 }
175 }
176 if let Some(ref halign) = self.halign {
177 properties.push(("halign", halign));
178 }
179 if let Some(ref has_default) = self.has_default {
180 properties.push(("has-default", has_default));
181 }
182 if let Some(ref has_focus) = self.has_focus {
183 properties.push(("has-focus", has_focus));
184 }
185 if let Some(ref has_tooltip) = self.has_tooltip {
186 properties.push(("has-tooltip", has_tooltip));
187 }
188 if let Some(ref height_request) = self.height_request {
189 properties.push(("height-request", height_request));
190 }
191 if let Some(ref hexpand) = self.hexpand {
192 properties.push(("hexpand", hexpand));
193 }
194 if let Some(ref hexpand_set) = self.hexpand_set {
195 properties.push(("hexpand-set", hexpand_set));
196 }
197 if let Some(ref is_focus) = self.is_focus {
198 properties.push(("is-focus", is_focus));
199 }
200 if let Some(ref margin) = self.margin {
201 properties.push(("margin", margin));
202 }
203 if let Some(ref margin_bottom) = self.margin_bottom {
204 properties.push(("margin-bottom", margin_bottom));
205 }
206 if let Some(ref margin_end) = self.margin_end {
207 properties.push(("margin-end", margin_end));
208 }
209 if let Some(ref margin_start) = self.margin_start {
210 properties.push(("margin-start", margin_start));
211 }
212 if let Some(ref margin_top) = self.margin_top {
213 properties.push(("margin-top", margin_top));
214 }
215 if let Some(ref name) = self.name {
216 properties.push(("name", name));
217 }
218 if let Some(ref no_show_all) = self.no_show_all {
219 properties.push(("no-show-all", no_show_all));
220 }
221 if let Some(ref opacity) = self.opacity {
222 properties.push(("opacity", opacity));
223 }
224 if let Some(ref parent) = self.parent {
225 properties.push(("parent", parent));
226 }
227 if let Some(ref receives_default) = self.receives_default {
228 properties.push(("receives-default", receives_default));
229 }
230 if let Some(ref sensitive) = self.sensitive {
231 properties.push(("sensitive", sensitive));
232 }
233 if let Some(ref tooltip_markup) = self.tooltip_markup {
234 properties.push(("tooltip-markup", tooltip_markup));
235 }
236 if let Some(ref tooltip_text) = self.tooltip_text {
237 properties.push(("tooltip-text", tooltip_text));
238 }
239 if let Some(ref valign) = self.valign {
240 properties.push(("valign", valign));
241 }
242 if let Some(ref vexpand) = self.vexpand {
243 properties.push(("vexpand", vexpand));
244 }
245 if let Some(ref vexpand_set) = self.vexpand_set {
246 properties.push(("vexpand-set", vexpand_set));
247 }
248 if let Some(ref visible) = self.visible {
249 properties.push(("visible", visible));
250 }
251 if let Some(ref width_request) = self.width_request {
252 properties.push(("width-request", width_request));
253 }
254 glib::Object::new(Revealer::static_type(), &properties)
255 .expect("object new")
256 .downcast()
257 .expect("downcast")
258 }
259
260 pub fn reveal_child(mut self, reveal_child: bool) -> Self {
261 self.reveal_child = Some(reveal_child);
262 self
263 }
264
265 pub fn transition_duration(mut self, transition_duration: u32) -> Self {
266 self.transition_duration = Some(transition_duration);
267 self
268 }
269
270 pub fn transition_type(mut self, transition_type: RevealerTransitionType) -> Self {
271 self.transition_type = Some(transition_type);
272 self
273 }
274
275 pub fn border_width(mut self, border_width: u32) -> Self {
276 self.border_width = Some(border_width);
277 self
278 }
279
280 pub fn child(mut self, child: &Widget) -> Self {
281 self.child = Some(child.clone());
282 self
283 }
284
285 pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
286 self.resize_mode = Some(resize_mode);
287 self
288 }
289
290 pub fn app_paintable(mut self, app_paintable: bool) -> Self {
291 self.app_paintable = Some(app_paintable);
292 self
293 }
294
295 pub fn can_default(mut self, can_default: bool) -> Self {
296 self.can_default = Some(can_default);
297 self
298 }
299
300 pub fn can_focus(mut self, can_focus: bool) -> Self {
301 self.can_focus = Some(can_focus);
302 self
303 }
304
305 pub fn events(mut self, events: gdk::EventMask) -> Self {
306 self.events = Some(events);
307 self
308 }
309
310 pub fn expand(mut self, expand: bool) -> Self {
311 self.expand = Some(expand);
312 self
313 }
314
315 #[cfg(any(feature = "v3_20", feature = "dox"))]
316 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
317 self.focus_on_click = Some(focus_on_click);
318 self
319 }
320
321 pub fn halign(mut self, halign: Align) -> Self {
322 self.halign = Some(halign);
323 self
324 }
325
326 pub fn has_default(mut self, has_default: bool) -> Self {
327 self.has_default = Some(has_default);
328 self
329 }
330
331 pub fn has_focus(mut self, has_focus: bool) -> Self {
332 self.has_focus = Some(has_focus);
333 self
334 }
335
336 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
337 self.has_tooltip = Some(has_tooltip);
338 self
339 }
340
341 pub fn height_request(mut self, height_request: i32) -> Self {
342 self.height_request = Some(height_request);
343 self
344 }
345
346 pub fn hexpand(mut self, hexpand: bool) -> Self {
347 self.hexpand = Some(hexpand);
348 self
349 }
350
351 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
352 self.hexpand_set = Some(hexpand_set);
353 self
354 }
355
356 pub fn is_focus(mut self, is_focus: bool) -> Self {
357 self.is_focus = Some(is_focus);
358 self
359 }
360
361 pub fn margin(mut self, margin: i32) -> Self {
362 self.margin = Some(margin);
363 self
364 }
365
366 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
367 self.margin_bottom = Some(margin_bottom);
368 self
369 }
370
371 pub fn margin_end(mut self, margin_end: i32) -> Self {
372 self.margin_end = Some(margin_end);
373 self
374 }
375
376 pub fn margin_start(mut self, margin_start: i32) -> Self {
377 self.margin_start = Some(margin_start);
378 self
379 }
380
381 pub fn margin_top(mut self, margin_top: i32) -> Self {
382 self.margin_top = Some(margin_top);
383 self
384 }
385
386 pub fn name(mut self, name: &str) -> Self {
387 self.name = Some(name.to_string());
388 self
389 }
390
391 pub fn no_show_all(mut self, no_show_all: bool) -> Self {
392 self.no_show_all = Some(no_show_all);
393 self
394 }
395
396 pub fn opacity(mut self, opacity: f64) -> Self {
397 self.opacity = Some(opacity);
398 self
399 }
400
401 pub fn parent(mut self, parent: &Container) -> Self {
402 self.parent = Some(parent.clone());
403 self
404 }
405
406 pub fn receives_default(mut self, receives_default: bool) -> Self {
407 self.receives_default = Some(receives_default);
408 self
409 }
410
411 pub fn sensitive(mut self, sensitive: bool) -> Self {
412 self.sensitive = Some(sensitive);
413 self
414 }
415
416 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
417 self.tooltip_markup = Some(tooltip_markup.to_string());
418 self
419 }
420
421 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
422 self.tooltip_text = Some(tooltip_text.to_string());
423 self
424 }
425
426 pub fn valign(mut self, valign: Align) -> Self {
427 self.valign = Some(valign);
428 self
429 }
430
431 pub fn vexpand(mut self, vexpand: bool) -> Self {
432 self.vexpand = Some(vexpand);
433 self
434 }
435
436 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
437 self.vexpand_set = Some(vexpand_set);
438 self
439 }
440
441 pub fn visible(mut self, visible: bool) -> Self {
442 self.visible = Some(visible);
443 self
444 }
445
446 pub fn width_request(mut self, width_request: i32) -> Self {
447 self.width_request = Some(width_request);
448 self
449 }
450}
451
452pub const NONE_REVEALER: Option<&Revealer> = None;
453
454pub trait RevealerExt: 'static {
455 fn get_child_revealed(&self) -> bool;
456
457 fn get_reveal_child(&self) -> bool;
458
459 fn get_transition_duration(&self) -> u32;
460
461 fn get_transition_type(&self) -> RevealerTransitionType;
462
463 fn set_reveal_child(&self, reveal_child: bool);
464
465 fn set_transition_duration(&self, duration: u32);
466
467 fn set_transition_type(&self, transition: RevealerTransitionType);
468
469 fn connect_property_child_revealed_notify<F: Fn(&Self) + 'static>(
470 &self,
471 f: F,
472 ) -> SignalHandlerId;
473
474 fn connect_property_reveal_child_notify<F: Fn(&Self) + 'static>(&self, f: F)
475 -> SignalHandlerId;
476
477 fn connect_property_transition_duration_notify<F: Fn(&Self) + 'static>(
478 &self,
479 f: F,
480 ) -> SignalHandlerId;
481
482 fn connect_property_transition_type_notify<F: Fn(&Self) + 'static>(
483 &self,
484 f: F,
485 ) -> SignalHandlerId;
486}
487
488impl<O: IsA<Revealer>> RevealerExt for O {
489 fn get_child_revealed(&self) -> bool {
490 unsafe {
491 from_glib(gtk_sys::gtk_revealer_get_child_revealed(
492 self.as_ref().to_glib_none().0,
493 ))
494 }
495 }
496
497 fn get_reveal_child(&self) -> bool {
498 unsafe {
499 from_glib(gtk_sys::gtk_revealer_get_reveal_child(
500 self.as_ref().to_glib_none().0,
501 ))
502 }
503 }
504
505 fn get_transition_duration(&self) -> u32 {
506 unsafe { gtk_sys::gtk_revealer_get_transition_duration(self.as_ref().to_glib_none().0) }
507 }
508
509 fn get_transition_type(&self) -> RevealerTransitionType {
510 unsafe {
511 from_glib(gtk_sys::gtk_revealer_get_transition_type(
512 self.as_ref().to_glib_none().0,
513 ))
514 }
515 }
516
517 fn set_reveal_child(&self, reveal_child: bool) {
518 unsafe {
519 gtk_sys::gtk_revealer_set_reveal_child(
520 self.as_ref().to_glib_none().0,
521 reveal_child.to_glib(),
522 );
523 }
524 }
525
526 fn set_transition_duration(&self, duration: u32) {
527 unsafe {
528 gtk_sys::gtk_revealer_set_transition_duration(self.as_ref().to_glib_none().0, duration);
529 }
530 }
531
532 fn set_transition_type(&self, transition: RevealerTransitionType) {
533 unsafe {
534 gtk_sys::gtk_revealer_set_transition_type(
535 self.as_ref().to_glib_none().0,
536 transition.to_glib(),
537 );
538 }
539 }
540
541 fn connect_property_child_revealed_notify<F: Fn(&Self) + 'static>(
542 &self,
543 f: F,
544 ) -> SignalHandlerId {
545 unsafe extern "C" fn notify_child_revealed_trampoline<P, F: Fn(&P) + 'static>(
546 this: *mut gtk_sys::GtkRevealer,
547 _param_spec: glib_sys::gpointer,
548 f: glib_sys::gpointer,
549 ) where
550 P: IsA<Revealer>,
551 {
552 let f: &F = &*(f as *const F);
553 f(&Revealer::from_glib_borrow(this).unsafe_cast())
554 }
555 unsafe {
556 let f: Box_<F> = Box_::new(f);
557 connect_raw(
558 self.as_ptr() as *mut _,
559 b"notify::child-revealed\0".as_ptr() as *const _,
560 Some(transmute(
561 notify_child_revealed_trampoline::<Self, F> as usize,
562 )),
563 Box_::into_raw(f),
564 )
565 }
566 }
567
568 fn connect_property_reveal_child_notify<F: Fn(&Self) + 'static>(
569 &self,
570 f: F,
571 ) -> SignalHandlerId {
572 unsafe extern "C" fn notify_reveal_child_trampoline<P, F: Fn(&P) + 'static>(
573 this: *mut gtk_sys::GtkRevealer,
574 _param_spec: glib_sys::gpointer,
575 f: glib_sys::gpointer,
576 ) where
577 P: IsA<Revealer>,
578 {
579 let f: &F = &*(f as *const F);
580 f(&Revealer::from_glib_borrow(this).unsafe_cast())
581 }
582 unsafe {
583 let f: Box_<F> = Box_::new(f);
584 connect_raw(
585 self.as_ptr() as *mut _,
586 b"notify::reveal-child\0".as_ptr() as *const _,
587 Some(transmute(
588 notify_reveal_child_trampoline::<Self, F> as usize,
589 )),
590 Box_::into_raw(f),
591 )
592 }
593 }
594
595 fn connect_property_transition_duration_notify<F: Fn(&Self) + 'static>(
596 &self,
597 f: F,
598 ) -> SignalHandlerId {
599 unsafe extern "C" fn notify_transition_duration_trampoline<P, F: Fn(&P) + 'static>(
600 this: *mut gtk_sys::GtkRevealer,
601 _param_spec: glib_sys::gpointer,
602 f: glib_sys::gpointer,
603 ) where
604 P: IsA<Revealer>,
605 {
606 let f: &F = &*(f as *const F);
607 f(&Revealer::from_glib_borrow(this).unsafe_cast())
608 }
609 unsafe {
610 let f: Box_<F> = Box_::new(f);
611 connect_raw(
612 self.as_ptr() as *mut _,
613 b"notify::transition-duration\0".as_ptr() as *const _,
614 Some(transmute(
615 notify_transition_duration_trampoline::<Self, F> as usize,
616 )),
617 Box_::into_raw(f),
618 )
619 }
620 }
621
622 fn connect_property_transition_type_notify<F: Fn(&Self) + 'static>(
623 &self,
624 f: F,
625 ) -> SignalHandlerId {
626 unsafe extern "C" fn notify_transition_type_trampoline<P, F: Fn(&P) + 'static>(
627 this: *mut gtk_sys::GtkRevealer,
628 _param_spec: glib_sys::gpointer,
629 f: glib_sys::gpointer,
630 ) where
631 P: IsA<Revealer>,
632 {
633 let f: &F = &*(f as *const F);
634 f(&Revealer::from_glib_borrow(this).unsafe_cast())
635 }
636 unsafe {
637 let f: Box_<F> = Box_::new(f);
638 connect_raw(
639 self.as_ptr() as *mut _,
640 b"notify::transition-type\0".as_ptr() as *const _,
641 Some(transmute(
642 notify_transition_type_trampoline::<Self, F> as usize,
643 )),
644 Box_::into_raw(f),
645 )
646 }
647 }
648}
649
650impl fmt::Display for Revealer {
651 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
652 write!(f, "Revealer")
653 }
654}