1use crate::Widget;
4use crate::{Fixed, ffi};
5use glib::object::IsA;
6use glib::translate::*;
7
8fn has_widget<O: IsA<Fixed>, T: IsA<Widget>>(c: &O, item: &T) -> bool {
11 skip_assert_initialized!();
12 unsafe {
13 let glist = ffi::gtk_container_get_children(c.to_glib_none().0 as *mut _);
14 let found = !glib::ffi::g_list_find(glist, item.to_glib_none().0 as _).is_null();
15 glib::ffi::g_list_free(glist);
16 found
17 }
18}
19
20pub trait FixedExtManual: IsA<Fixed> + 'static {
21 #[doc(alias = "get_child_x")]
22 fn child_x<T: IsA<Widget>>(&self, item: &T) -> i32 {
23 assert!(
24 has_widget(self, item),
25 "this item isn't in the Fixed's widget list"
26 );
27 let mut value = glib::Value::from(&0);
28 unsafe {
29 ffi::gtk_container_child_get_property(
30 self.to_glib_none().0 as *mut _,
31 item.as_ref().to_glib_none().0,
32 "x".to_glib_none().0,
33 value.to_glib_none_mut().0,
34 );
35 }
36 value
37 .get()
38 .expect("Return Value for `FixedExtManual::get_child_x`")
39 }
40
41 fn set_child_x<T: IsA<Widget>>(&self, item: &T, x: i32) {
42 assert!(
43 has_widget(self, item),
44 "this item isn't in the Fixed's widget list"
45 );
46 unsafe {
47 ffi::gtk_container_child_set_property(
48 self.to_glib_none().0 as *mut _,
49 item.as_ref().to_glib_none().0,
50 "x".to_glib_none().0,
51 glib::Value::from(&x).to_glib_none().0,
52 );
53 }
54 }
55
56 #[doc(alias = "get_child_y")]
57 fn child_y<T: IsA<Widget>>(&self, item: &T) -> i32 {
58 assert!(
59 has_widget(self, item),
60 "this item isn't in the Fixed's widget list"
61 );
62 let mut value = glib::Value::from(&0);
63 unsafe {
64 ffi::gtk_container_child_get_property(
65 self.to_glib_none().0 as *mut _,
66 item.as_ref().to_glib_none().0,
67 "y".to_glib_none().0,
68 value.to_glib_none_mut().0,
69 );
70 }
71 value
72 .get()
73 .expect("Return Value for `FixedExtManual::get_child_y`")
74 }
75
76 fn set_child_y<T: IsA<Widget>>(&self, item: &T, y: i32) {
77 assert!(
78 has_widget(self, item),
79 "this item isn't in the Fixed's widget list"
80 );
81 unsafe {
82 ffi::gtk_container_child_set_property(
83 self.to_glib_none().0 as *mut _,
84 item.as_ref().to_glib_none().0,
85 "y".to_glib_none().0,
86 glib::Value::from(&y).to_glib_none().0,
87 );
88 }
89 }
90}
91
92impl<O: IsA<Fixed>> FixedExtManual for O {}