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