1use crate::{Adjustment, Border, ScrollablePolicy};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14 #[doc(alias = "GtkScrollable")]
15 pub struct Scrollable(Interface<ffi::GtkScrollable, ffi::GtkScrollableInterface>);
16
17 match fn {
18 type_ => || ffi::gtk_scrollable_get_type(),
19 }
20}
21
22impl Scrollable {
23 pub const NONE: Option<&'static Scrollable> = None;
24}
25
26mod sealed {
27 pub trait Sealed {}
28 impl<T: super::IsA<super::Scrollable>> Sealed for T {}
29}
30
31pub trait ScrollableExt: IsA<Scrollable> + sealed::Sealed + 'static {
32 #[doc(alias = "gtk_scrollable_get_border")]
33 #[doc(alias = "get_border")]
34 fn border(&self) -> Option<Border> {
35 unsafe {
36 let mut border = Border::uninitialized();
37 let ret = from_glib(ffi::gtk_scrollable_get_border(
38 self.as_ref().to_glib_none().0,
39 border.to_glib_none_mut().0,
40 ));
41 if ret {
42 Some(border)
43 } else {
44 None
45 }
46 }
47 }
48
49 #[doc(alias = "gtk_scrollable_get_hadjustment")]
50 #[doc(alias = "get_hadjustment")]
51 fn hadjustment(&self) -> Option<Adjustment> {
52 unsafe {
53 from_glib_none(ffi::gtk_scrollable_get_hadjustment(
54 self.as_ref().to_glib_none().0,
55 ))
56 }
57 }
58
59 #[doc(alias = "gtk_scrollable_get_hscroll_policy")]
60 #[doc(alias = "get_hscroll_policy")]
61 fn hscroll_policy(&self) -> ScrollablePolicy {
62 unsafe {
63 from_glib(ffi::gtk_scrollable_get_hscroll_policy(
64 self.as_ref().to_glib_none().0,
65 ))
66 }
67 }
68
69 #[doc(alias = "gtk_scrollable_get_vadjustment")]
70 #[doc(alias = "get_vadjustment")]
71 fn vadjustment(&self) -> Option<Adjustment> {
72 unsafe {
73 from_glib_none(ffi::gtk_scrollable_get_vadjustment(
74 self.as_ref().to_glib_none().0,
75 ))
76 }
77 }
78
79 #[doc(alias = "gtk_scrollable_get_vscroll_policy")]
80 #[doc(alias = "get_vscroll_policy")]
81 fn vscroll_policy(&self) -> ScrollablePolicy {
82 unsafe {
83 from_glib(ffi::gtk_scrollable_get_vscroll_policy(
84 self.as_ref().to_glib_none().0,
85 ))
86 }
87 }
88
89 #[doc(alias = "gtk_scrollable_set_hadjustment")]
90 fn set_hadjustment(&self, hadjustment: Option<&impl IsA<Adjustment>>) {
91 unsafe {
92 ffi::gtk_scrollable_set_hadjustment(
93 self.as_ref().to_glib_none().0,
94 hadjustment.map(|p| p.as_ref()).to_glib_none().0,
95 );
96 }
97 }
98
99 #[doc(alias = "gtk_scrollable_set_hscroll_policy")]
100 fn set_hscroll_policy(&self, policy: ScrollablePolicy) {
101 unsafe {
102 ffi::gtk_scrollable_set_hscroll_policy(
103 self.as_ref().to_glib_none().0,
104 policy.into_glib(),
105 );
106 }
107 }
108
109 #[doc(alias = "gtk_scrollable_set_vadjustment")]
110 fn set_vadjustment(&self, vadjustment: Option<&impl IsA<Adjustment>>) {
111 unsafe {
112 ffi::gtk_scrollable_set_vadjustment(
113 self.as_ref().to_glib_none().0,
114 vadjustment.map(|p| p.as_ref()).to_glib_none().0,
115 );
116 }
117 }
118
119 #[doc(alias = "gtk_scrollable_set_vscroll_policy")]
120 fn set_vscroll_policy(&self, policy: ScrollablePolicy) {
121 unsafe {
122 ffi::gtk_scrollable_set_vscroll_policy(
123 self.as_ref().to_glib_none().0,
124 policy.into_glib(),
125 );
126 }
127 }
128
129 #[doc(alias = "hadjustment")]
130 fn connect_hadjustment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
131 unsafe extern "C" fn notify_hadjustment_trampoline<
132 P: IsA<Scrollable>,
133 F: Fn(&P) + 'static,
134 >(
135 this: *mut ffi::GtkScrollable,
136 _param_spec: glib::ffi::gpointer,
137 f: glib::ffi::gpointer,
138 ) {
139 let f: &F = &*(f as *const F);
140 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
141 }
142 unsafe {
143 let f: Box_<F> = Box_::new(f);
144 connect_raw(
145 self.as_ptr() as *mut _,
146 b"notify::hadjustment\0".as_ptr() as *const _,
147 Some(transmute::<_, unsafe extern "C" fn()>(
148 notify_hadjustment_trampoline::<Self, F> as *const (),
149 )),
150 Box_::into_raw(f),
151 )
152 }
153 }
154
155 #[doc(alias = "hscroll-policy")]
156 fn connect_hscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
157 unsafe extern "C" fn notify_hscroll_policy_trampoline<
158 P: IsA<Scrollable>,
159 F: Fn(&P) + 'static,
160 >(
161 this: *mut ffi::GtkScrollable,
162 _param_spec: glib::ffi::gpointer,
163 f: glib::ffi::gpointer,
164 ) {
165 let f: &F = &*(f as *const F);
166 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
167 }
168 unsafe {
169 let f: Box_<F> = Box_::new(f);
170 connect_raw(
171 self.as_ptr() as *mut _,
172 b"notify::hscroll-policy\0".as_ptr() as *const _,
173 Some(transmute::<_, unsafe extern "C" fn()>(
174 notify_hscroll_policy_trampoline::<Self, F> as *const (),
175 )),
176 Box_::into_raw(f),
177 )
178 }
179 }
180
181 #[doc(alias = "vadjustment")]
182 fn connect_vadjustment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
183 unsafe extern "C" fn notify_vadjustment_trampoline<
184 P: IsA<Scrollable>,
185 F: Fn(&P) + 'static,
186 >(
187 this: *mut ffi::GtkScrollable,
188 _param_spec: glib::ffi::gpointer,
189 f: glib::ffi::gpointer,
190 ) {
191 let f: &F = &*(f as *const F);
192 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
193 }
194 unsafe {
195 let f: Box_<F> = Box_::new(f);
196 connect_raw(
197 self.as_ptr() as *mut _,
198 b"notify::vadjustment\0".as_ptr() as *const _,
199 Some(transmute::<_, unsafe extern "C" fn()>(
200 notify_vadjustment_trampoline::<Self, F> as *const (),
201 )),
202 Box_::into_raw(f),
203 )
204 }
205 }
206
207 #[doc(alias = "vscroll-policy")]
208 fn connect_vscroll_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
209 unsafe extern "C" fn notify_vscroll_policy_trampoline<
210 P: IsA<Scrollable>,
211 F: Fn(&P) + 'static,
212 >(
213 this: *mut ffi::GtkScrollable,
214 _param_spec: glib::ffi::gpointer,
215 f: glib::ffi::gpointer,
216 ) {
217 let f: &F = &*(f as *const F);
218 f(Scrollable::from_glib_borrow(this).unsafe_cast_ref())
219 }
220 unsafe {
221 let f: Box_<F> = Box_::new(f);
222 connect_raw(
223 self.as_ptr() as *mut _,
224 b"notify::vscroll-policy\0".as_ptr() as *const _,
225 Some(transmute::<_, unsafe extern "C" fn()>(
226 notify_vscroll_policy_trampoline::<Self, F> as *const (),
227 )),
228 Box_::into_raw(f),
229 )
230 }
231 }
232}
233
234impl<O: IsA<Scrollable>> ScrollableExt for O {}
235
236impl fmt::Display for Scrollable {
237 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
238 f.write_str("Scrollable")
239 }
240}