1use crate::ffi;
7#[cfg(feature = "v1_4")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
9use crate::LengthUnit;
10use glib::{
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "AdwClampScrollable")]
19 pub struct ClampScrollable(Object<ffi::AdwClampScrollable, ffi::AdwClampScrollableClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable, gtk::Scrollable;
20
21 match fn {
22 type_ => || ffi::adw_clamp_scrollable_get_type(),
23 }
24}
25
26impl ClampScrollable {
27 #[doc(alias = "adw_clamp_scrollable_new")]
28 pub fn new() -> ClampScrollable {
29 assert_initialized_main_thread!();
30 unsafe { gtk::Widget::from_glib_none(ffi::adw_clamp_scrollable_new()).unsafe_cast() }
31 }
32
33 pub fn builder() -> ClampScrollableBuilder {
38 ClampScrollableBuilder::new()
39 }
40
41 #[doc(alias = "adw_clamp_scrollable_get_child")]
42 #[doc(alias = "get_child")]
43 pub fn child(&self) -> Option<gtk::Widget> {
44 unsafe { from_glib_none(ffi::adw_clamp_scrollable_get_child(self.to_glib_none().0)) }
45 }
46
47 #[doc(alias = "adw_clamp_scrollable_get_maximum_size")]
48 #[doc(alias = "get_maximum_size")]
49 #[doc(alias = "maximum-size")]
50 pub fn maximum_size(&self) -> i32 {
51 unsafe { ffi::adw_clamp_scrollable_get_maximum_size(self.to_glib_none().0) }
52 }
53
54 #[doc(alias = "adw_clamp_scrollable_get_tightening_threshold")]
55 #[doc(alias = "get_tightening_threshold")]
56 #[doc(alias = "tightening-threshold")]
57 pub fn tightening_threshold(&self) -> i32 {
58 unsafe { ffi::adw_clamp_scrollable_get_tightening_threshold(self.to_glib_none().0) }
59 }
60
61 #[cfg(feature = "v1_4")]
62 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
63 #[doc(alias = "adw_clamp_scrollable_get_unit")]
64 #[doc(alias = "get_unit")]
65 pub fn unit(&self) -> LengthUnit {
66 unsafe { from_glib(ffi::adw_clamp_scrollable_get_unit(self.to_glib_none().0)) }
67 }
68
69 #[doc(alias = "adw_clamp_scrollable_set_child")]
70 #[doc(alias = "child")]
71 pub fn set_child(&self, child: Option<&impl IsA<gtk::Widget>>) {
72 unsafe {
73 ffi::adw_clamp_scrollable_set_child(
74 self.to_glib_none().0,
75 child.map(|p| p.as_ref()).to_glib_none().0,
76 );
77 }
78 }
79
80 #[doc(alias = "adw_clamp_scrollable_set_maximum_size")]
81 #[doc(alias = "maximum-size")]
82 pub fn set_maximum_size(&self, maximum_size: i32) {
83 unsafe {
84 ffi::adw_clamp_scrollable_set_maximum_size(self.to_glib_none().0, maximum_size);
85 }
86 }
87
88 #[doc(alias = "adw_clamp_scrollable_set_tightening_threshold")]
89 #[doc(alias = "tightening-threshold")]
90 pub fn set_tightening_threshold(&self, tightening_threshold: i32) {
91 unsafe {
92 ffi::adw_clamp_scrollable_set_tightening_threshold(
93 self.to_glib_none().0,
94 tightening_threshold,
95 );
96 }
97 }
98
99 #[cfg(feature = "v1_4")]
100 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
101 #[doc(alias = "adw_clamp_scrollable_set_unit")]
102 #[doc(alias = "unit")]
103 pub fn set_unit(&self, unit: LengthUnit) {
104 unsafe {
105 ffi::adw_clamp_scrollable_set_unit(self.to_glib_none().0, unit.into_glib());
106 }
107 }
108
109 #[doc(alias = "child")]
110 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
111 unsafe extern "C" fn notify_child_trampoline<F: Fn(&ClampScrollable) + 'static>(
112 this: *mut ffi::AdwClampScrollable,
113 _param_spec: glib::ffi::gpointer,
114 f: glib::ffi::gpointer,
115 ) {
116 let f: &F = &*(f as *const F);
117 f(&from_glib_borrow(this))
118 }
119 unsafe {
120 let f: Box_<F> = Box_::new(f);
121 connect_raw(
122 self.as_ptr() as *mut _,
123 c"notify::child".as_ptr() as *const _,
124 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
125 notify_child_trampoline::<F> as *const (),
126 )),
127 Box_::into_raw(f),
128 )
129 }
130 }
131
132 #[doc(alias = "maximum-size")]
133 pub fn connect_maximum_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
134 unsafe extern "C" fn notify_maximum_size_trampoline<F: Fn(&ClampScrollable) + 'static>(
135 this: *mut ffi::AdwClampScrollable,
136 _param_spec: glib::ffi::gpointer,
137 f: glib::ffi::gpointer,
138 ) {
139 let f: &F = &*(f as *const F);
140 f(&from_glib_borrow(this))
141 }
142 unsafe {
143 let f: Box_<F> = Box_::new(f);
144 connect_raw(
145 self.as_ptr() as *mut _,
146 c"notify::maximum-size".as_ptr() as *const _,
147 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
148 notify_maximum_size_trampoline::<F> as *const (),
149 )),
150 Box_::into_raw(f),
151 )
152 }
153 }
154
155 #[doc(alias = "tightening-threshold")]
156 pub fn connect_tightening_threshold_notify<F: Fn(&Self) + 'static>(
157 &self,
158 f: F,
159 ) -> SignalHandlerId {
160 unsafe extern "C" fn notify_tightening_threshold_trampoline<
161 F: Fn(&ClampScrollable) + 'static,
162 >(
163 this: *mut ffi::AdwClampScrollable,
164 _param_spec: glib::ffi::gpointer,
165 f: glib::ffi::gpointer,
166 ) {
167 let f: &F = &*(f as *const F);
168 f(&from_glib_borrow(this))
169 }
170 unsafe {
171 let f: Box_<F> = Box_::new(f);
172 connect_raw(
173 self.as_ptr() as *mut _,
174 c"notify::tightening-threshold".as_ptr() as *const _,
175 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
176 notify_tightening_threshold_trampoline::<F> as *const (),
177 )),
178 Box_::into_raw(f),
179 )
180 }
181 }
182
183 #[cfg(feature = "v1_4")]
184 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
185 #[doc(alias = "unit")]
186 pub fn connect_unit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
187 unsafe extern "C" fn notify_unit_trampoline<F: Fn(&ClampScrollable) + 'static>(
188 this: *mut ffi::AdwClampScrollable,
189 _param_spec: glib::ffi::gpointer,
190 f: glib::ffi::gpointer,
191 ) {
192 let f: &F = &*(f as *const F);
193 f(&from_glib_borrow(this))
194 }
195 unsafe {
196 let f: Box_<F> = Box_::new(f);
197 connect_raw(
198 self.as_ptr() as *mut _,
199 c"notify::unit".as_ptr() as *const _,
200 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
201 notify_unit_trampoline::<F> as *const (),
202 )),
203 Box_::into_raw(f),
204 )
205 }
206 }
207}
208
209impl Default for ClampScrollable {
210 fn default() -> Self {
211 Self::new()
212 }
213}
214
215#[must_use = "The builder must be built to be used"]
220pub struct ClampScrollableBuilder {
221 builder: glib::object::ObjectBuilder<'static, ClampScrollable>,
222}
223
224impl ClampScrollableBuilder {
225 fn new() -> Self {
226 Self {
227 builder: glib::object::Object::builder(),
228 }
229 }
230
231 pub fn child(self, child: &impl IsA<gtk::Widget>) -> Self {
232 Self {
233 builder: self.builder.property("child", child.clone().upcast()),
234 }
235 }
236
237 pub fn maximum_size(self, maximum_size: i32) -> Self {
238 Self {
239 builder: self.builder.property("maximum-size", maximum_size),
240 }
241 }
242
243 pub fn tightening_threshold(self, tightening_threshold: i32) -> Self {
244 Self {
245 builder: self
246 .builder
247 .property("tightening-threshold", tightening_threshold),
248 }
249 }
250
251 #[cfg(feature = "v1_4")]
252 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
253 pub fn unit(self, unit: LengthUnit) -> Self {
254 Self {
255 builder: self.builder.property("unit", unit),
256 }
257 }
258
259 pub fn can_focus(self, can_focus: bool) -> Self {
260 Self {
261 builder: self.builder.property("can-focus", can_focus),
262 }
263 }
264
265 pub fn can_target(self, can_target: bool) -> Self {
266 Self {
267 builder: self.builder.property("can-target", can_target),
268 }
269 }
270
271 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
272 Self {
273 builder: self.builder.property("css-classes", css_classes.into()),
274 }
275 }
276
277 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
278 Self {
279 builder: self.builder.property("css-name", css_name.into()),
280 }
281 }
282
283 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
284 Self {
285 builder: self.builder.property("cursor", cursor.clone()),
286 }
287 }
288
289 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
290 Self {
291 builder: self.builder.property("focus-on-click", focus_on_click),
292 }
293 }
294
295 pub fn focusable(self, focusable: bool) -> Self {
296 Self {
297 builder: self.builder.property("focusable", focusable),
298 }
299 }
300
301 pub fn halign(self, halign: gtk::Align) -> Self {
302 Self {
303 builder: self.builder.property("halign", halign),
304 }
305 }
306
307 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
308 Self {
309 builder: self.builder.property("has-tooltip", has_tooltip),
310 }
311 }
312
313 pub fn height_request(self, height_request: i32) -> Self {
314 Self {
315 builder: self.builder.property("height-request", height_request),
316 }
317 }
318
319 pub fn hexpand(self, hexpand: bool) -> Self {
320 Self {
321 builder: self.builder.property("hexpand", hexpand),
322 }
323 }
324
325 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
326 Self {
327 builder: self.builder.property("hexpand-set", hexpand_set),
328 }
329 }
330
331 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
332 Self {
333 builder: self
334 .builder
335 .property("layout-manager", layout_manager.clone().upcast()),
336 }
337 }
338
339 #[cfg(feature = "gtk_v4_18")]
340 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
341 pub fn limit_events(self, limit_events: bool) -> Self {
342 Self {
343 builder: self.builder.property("limit-events", limit_events),
344 }
345 }
346
347 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
348 Self {
349 builder: self.builder.property("margin-bottom", margin_bottom),
350 }
351 }
352
353 pub fn margin_end(self, margin_end: i32) -> Self {
354 Self {
355 builder: self.builder.property("margin-end", margin_end),
356 }
357 }
358
359 pub fn margin_start(self, margin_start: i32) -> Self {
360 Self {
361 builder: self.builder.property("margin-start", margin_start),
362 }
363 }
364
365 pub fn margin_top(self, margin_top: i32) -> Self {
366 Self {
367 builder: self.builder.property("margin-top", margin_top),
368 }
369 }
370
371 pub fn name(self, name: impl Into<glib::GString>) -> Self {
372 Self {
373 builder: self.builder.property("name", name.into()),
374 }
375 }
376
377 pub fn opacity(self, opacity: f64) -> Self {
378 Self {
379 builder: self.builder.property("opacity", opacity),
380 }
381 }
382
383 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
384 Self {
385 builder: self.builder.property("overflow", overflow),
386 }
387 }
388
389 pub fn receives_default(self, receives_default: bool) -> Self {
390 Self {
391 builder: self.builder.property("receives-default", receives_default),
392 }
393 }
394
395 pub fn sensitive(self, sensitive: bool) -> Self {
396 Self {
397 builder: self.builder.property("sensitive", sensitive),
398 }
399 }
400
401 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
402 Self {
403 builder: self
404 .builder
405 .property("tooltip-markup", tooltip_markup.into()),
406 }
407 }
408
409 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
410 Self {
411 builder: self.builder.property("tooltip-text", tooltip_text.into()),
412 }
413 }
414
415 pub fn valign(self, valign: gtk::Align) -> Self {
416 Self {
417 builder: self.builder.property("valign", valign),
418 }
419 }
420
421 pub fn vexpand(self, vexpand: bool) -> Self {
422 Self {
423 builder: self.builder.property("vexpand", vexpand),
424 }
425 }
426
427 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
428 Self {
429 builder: self.builder.property("vexpand-set", vexpand_set),
430 }
431 }
432
433 pub fn visible(self, visible: bool) -> Self {
434 Self {
435 builder: self.builder.property("visible", visible),
436 }
437 }
438
439 pub fn width_request(self, width_request: i32) -> Self {
440 Self {
441 builder: self.builder.property("width-request", width_request),
442 }
443 }
444
445 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
446 Self {
447 builder: self.builder.property("accessible-role", accessible_role),
448 }
449 }
450
451 pub fn orientation(self, orientation: gtk::Orientation) -> Self {
452 Self {
453 builder: self.builder.property("orientation", orientation),
454 }
455 }
456
457 pub fn hadjustment(self, hadjustment: &impl IsA<gtk::Adjustment>) -> Self {
458 Self {
459 builder: self
460 .builder
461 .property("hadjustment", hadjustment.clone().upcast()),
462 }
463 }
464
465 pub fn hscroll_policy(self, hscroll_policy: gtk::ScrollablePolicy) -> Self {
466 Self {
467 builder: self.builder.property("hscroll-policy", hscroll_policy),
468 }
469 }
470
471 pub fn vadjustment(self, vadjustment: &impl IsA<gtk::Adjustment>) -> Self {
472 Self {
473 builder: self
474 .builder
475 .property("vadjustment", vadjustment.clone().upcast()),
476 }
477 }
478
479 pub fn vscroll_policy(self, vscroll_policy: gtk::ScrollablePolicy) -> Self {
480 Self {
481 builder: self.builder.property("vscroll-policy", vscroll_policy),
482 }
483 }
484
485 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
488 pub fn build(self) -> ClampScrollable {
489 assert_initialized_main_thread!();
490 self.builder.build()
491 }
492}