1#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::AccessibleRange;
8use crate::{
9 ffi, Accessible, AccessibleRole, Adjustment, Align, Buildable, Button, ConstraintTarget,
10 LayoutManager, Orientable, Orientation, Overflow, Widget,
11};
12use glib::{
13 object::ObjectType as _,
14 prelude::*,
15 signal::{connect_raw, SignalHandlerId},
16 translate::*,
17};
18use std::boxed::Box as Box_;
19
20#[cfg(feature = "v4_10")]
21#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
22glib::wrapper! {
23 #[doc(alias = "GtkScaleButton")]
24 pub struct ScaleButton(Object<ffi::GtkScaleButton, ffi::GtkScaleButtonClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, AccessibleRange, Orientable;
25
26 match fn {
27 type_ => || ffi::gtk_scale_button_get_type(),
28 }
29}
30
31#[cfg(not(any(feature = "v4_10")))]
32glib::wrapper! {
33 #[doc(alias = "GtkScaleButton")]
34 pub struct ScaleButton(Object<ffi::GtkScaleButton, ffi::GtkScaleButtonClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Orientable;
35
36 match fn {
37 type_ => || ffi::gtk_scale_button_get_type(),
38 }
39}
40
41impl ScaleButton {
42 pub const NONE: Option<&'static ScaleButton> = None;
43
44 #[doc(alias = "gtk_scale_button_new")]
45 pub fn new(min: f64, max: f64, step: f64, icons: &[&str]) -> ScaleButton {
46 assert_initialized_main_thread!();
47 unsafe {
48 Widget::from_glib_none(ffi::gtk_scale_button_new(
49 min,
50 max,
51 step,
52 icons.to_glib_none().0,
53 ))
54 .unsafe_cast()
55 }
56 }
57
58 pub fn builder() -> ScaleButtonBuilder {
63 ScaleButtonBuilder::new()
64 }
65}
66
67impl Default for ScaleButton {
68 fn default() -> Self {
69 glib::object::Object::new::<Self>()
70 }
71}
72
73#[must_use = "The builder must be built to be used"]
78pub struct ScaleButtonBuilder {
79 builder: glib::object::ObjectBuilder<'static, ScaleButton>,
80}
81
82impl ScaleButtonBuilder {
83 fn new() -> Self {
84 Self {
85 builder: glib::object::Object::builder(),
86 }
87 }
88
89 pub fn adjustment(self, adjustment: &impl IsA<Adjustment>) -> Self {
90 Self {
91 builder: self
92 .builder
93 .property("adjustment", adjustment.clone().upcast()),
94 }
95 }
96
97 #[cfg(feature = "v4_14")]
98 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
99 pub fn has_frame(self, has_frame: bool) -> Self {
100 Self {
101 builder: self.builder.property("has-frame", has_frame),
102 }
103 }
104
105 pub fn icons(self, icons: impl Into<glib::StrV>) -> Self {
106 Self {
107 builder: self.builder.property("icons", icons.into()),
108 }
109 }
110
111 pub fn value(self, value: f64) -> Self {
112 Self {
113 builder: self.builder.property("value", value),
114 }
115 }
116
117 pub fn can_focus(self, can_focus: bool) -> Self {
118 Self {
119 builder: self.builder.property("can-focus", can_focus),
120 }
121 }
122
123 pub fn can_target(self, can_target: bool) -> Self {
124 Self {
125 builder: self.builder.property("can-target", can_target),
126 }
127 }
128
129 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
130 Self {
131 builder: self.builder.property("css-classes", css_classes.into()),
132 }
133 }
134
135 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
136 Self {
137 builder: self.builder.property("css-name", css_name.into()),
138 }
139 }
140
141 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
142 Self {
143 builder: self.builder.property("cursor", cursor.clone()),
144 }
145 }
146
147 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
148 Self {
149 builder: self.builder.property("focus-on-click", focus_on_click),
150 }
151 }
152
153 pub fn focusable(self, focusable: bool) -> Self {
154 Self {
155 builder: self.builder.property("focusable", focusable),
156 }
157 }
158
159 pub fn halign(self, halign: Align) -> Self {
160 Self {
161 builder: self.builder.property("halign", halign),
162 }
163 }
164
165 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
166 Self {
167 builder: self.builder.property("has-tooltip", has_tooltip),
168 }
169 }
170
171 pub fn height_request(self, height_request: i32) -> Self {
172 Self {
173 builder: self.builder.property("height-request", height_request),
174 }
175 }
176
177 pub fn hexpand(self, hexpand: bool) -> Self {
178 Self {
179 builder: self.builder.property("hexpand", hexpand),
180 }
181 }
182
183 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
184 Self {
185 builder: self.builder.property("hexpand-set", hexpand_set),
186 }
187 }
188
189 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
190 Self {
191 builder: self
192 .builder
193 .property("layout-manager", layout_manager.clone().upcast()),
194 }
195 }
196
197 #[cfg(feature = "v4_18")]
198 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
199 pub fn limit_events(self, limit_events: bool) -> Self {
200 Self {
201 builder: self.builder.property("limit-events", limit_events),
202 }
203 }
204
205 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
206 Self {
207 builder: self.builder.property("margin-bottom", margin_bottom),
208 }
209 }
210
211 pub fn margin_end(self, margin_end: i32) -> Self {
212 Self {
213 builder: self.builder.property("margin-end", margin_end),
214 }
215 }
216
217 pub fn margin_start(self, margin_start: i32) -> Self {
218 Self {
219 builder: self.builder.property("margin-start", margin_start),
220 }
221 }
222
223 pub fn margin_top(self, margin_top: i32) -> Self {
224 Self {
225 builder: self.builder.property("margin-top", margin_top),
226 }
227 }
228
229 pub fn name(self, name: impl Into<glib::GString>) -> Self {
230 Self {
231 builder: self.builder.property("name", name.into()),
232 }
233 }
234
235 pub fn opacity(self, opacity: f64) -> Self {
236 Self {
237 builder: self.builder.property("opacity", opacity),
238 }
239 }
240
241 pub fn overflow(self, overflow: Overflow) -> Self {
242 Self {
243 builder: self.builder.property("overflow", overflow),
244 }
245 }
246
247 pub fn receives_default(self, receives_default: bool) -> Self {
248 Self {
249 builder: self.builder.property("receives-default", receives_default),
250 }
251 }
252
253 pub fn sensitive(self, sensitive: bool) -> Self {
254 Self {
255 builder: self.builder.property("sensitive", sensitive),
256 }
257 }
258
259 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
260 Self {
261 builder: self
262 .builder
263 .property("tooltip-markup", tooltip_markup.into()),
264 }
265 }
266
267 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
268 Self {
269 builder: self.builder.property("tooltip-text", tooltip_text.into()),
270 }
271 }
272
273 pub fn valign(self, valign: Align) -> Self {
274 Self {
275 builder: self.builder.property("valign", valign),
276 }
277 }
278
279 pub fn vexpand(self, vexpand: bool) -> Self {
280 Self {
281 builder: self.builder.property("vexpand", vexpand),
282 }
283 }
284
285 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
286 Self {
287 builder: self.builder.property("vexpand-set", vexpand_set),
288 }
289 }
290
291 pub fn visible(self, visible: bool) -> Self {
292 Self {
293 builder: self.builder.property("visible", visible),
294 }
295 }
296
297 pub fn width_request(self, width_request: i32) -> Self {
298 Self {
299 builder: self.builder.property("width-request", width_request),
300 }
301 }
302
303 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
304 Self {
305 builder: self.builder.property("accessible-role", accessible_role),
306 }
307 }
308
309 pub fn orientation(self, orientation: Orientation) -> Self {
310 Self {
311 builder: self.builder.property("orientation", orientation),
312 }
313 }
314
315 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
318 pub fn build(self) -> ScaleButton {
319 assert_initialized_main_thread!();
320 self.builder.build()
321 }
322}
323
324pub trait ScaleButtonExt: IsA<ScaleButton> + 'static {
325 #[cfg(feature = "v4_10")]
326 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
327 #[doc(alias = "gtk_scale_button_get_active")]
328 #[doc(alias = "get_active")]
329 #[doc(alias = "active")]
330 fn is_active(&self) -> bool {
331 unsafe {
332 from_glib(ffi::gtk_scale_button_get_active(
333 self.as_ref().to_glib_none().0,
334 ))
335 }
336 }
337
338 #[doc(alias = "gtk_scale_button_get_adjustment")]
339 #[doc(alias = "get_adjustment")]
340 fn adjustment(&self) -> Adjustment {
341 unsafe {
342 from_glib_none(ffi::gtk_scale_button_get_adjustment(
343 self.as_ref().to_glib_none().0,
344 ))
345 }
346 }
347
348 #[cfg(feature = "v4_14")]
349 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
350 #[doc(alias = "gtk_scale_button_get_has_frame")]
351 #[doc(alias = "get_has_frame")]
352 #[doc(alias = "has-frame")]
353 fn has_frame(&self) -> bool {
354 unsafe {
355 from_glib(ffi::gtk_scale_button_get_has_frame(
356 self.as_ref().to_glib_none().0,
357 ))
358 }
359 }
360
361 #[doc(alias = "gtk_scale_button_get_minus_button")]
362 #[doc(alias = "get_minus_button")]
363 fn minus_button(&self) -> Button {
364 unsafe {
365 from_glib_none(ffi::gtk_scale_button_get_minus_button(
366 self.as_ref().to_glib_none().0,
367 ))
368 }
369 }
370
371 #[doc(alias = "gtk_scale_button_get_plus_button")]
372 #[doc(alias = "get_plus_button")]
373 fn plus_button(&self) -> Button {
374 unsafe {
375 from_glib_none(ffi::gtk_scale_button_get_plus_button(
376 self.as_ref().to_glib_none().0,
377 ))
378 }
379 }
380
381 #[doc(alias = "gtk_scale_button_get_popup")]
382 #[doc(alias = "get_popup")]
383 fn popup(&self) -> Widget {
384 unsafe {
385 from_glib_none(ffi::gtk_scale_button_get_popup(
386 self.as_ref().to_glib_none().0,
387 ))
388 }
389 }
390
391 #[doc(alias = "gtk_scale_button_get_value")]
392 #[doc(alias = "get_value")]
393 fn value(&self) -> f64 {
394 unsafe { ffi::gtk_scale_button_get_value(self.as_ref().to_glib_none().0) }
395 }
396
397 #[doc(alias = "gtk_scale_button_set_adjustment")]
398 #[doc(alias = "adjustment")]
399 fn set_adjustment(&self, adjustment: &impl IsA<Adjustment>) {
400 unsafe {
401 ffi::gtk_scale_button_set_adjustment(
402 self.as_ref().to_glib_none().0,
403 adjustment.as_ref().to_glib_none().0,
404 );
405 }
406 }
407
408 #[cfg(feature = "v4_14")]
409 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
410 #[doc(alias = "gtk_scale_button_set_has_frame")]
411 #[doc(alias = "has-frame")]
412 fn set_has_frame(&self, has_frame: bool) {
413 unsafe {
414 ffi::gtk_scale_button_set_has_frame(
415 self.as_ref().to_glib_none().0,
416 has_frame.into_glib(),
417 );
418 }
419 }
420
421 #[doc(alias = "gtk_scale_button_set_icons")]
422 #[doc(alias = "icons")]
423 fn set_icons(&self, icons: &[&str]) {
424 unsafe {
425 ffi::gtk_scale_button_set_icons(self.as_ref().to_glib_none().0, icons.to_glib_none().0);
426 }
427 }
428
429 #[doc(alias = "gtk_scale_button_set_value")]
430 #[doc(alias = "value")]
431 fn set_value(&self, value: f64) {
432 unsafe {
433 ffi::gtk_scale_button_set_value(self.as_ref().to_glib_none().0, value);
434 }
435 }
436
437 fn icons(&self) -> Vec<glib::GString> {
438 ObjectExt::property(self.as_ref(), "icons")
439 }
440
441 #[doc(alias = "popdown")]
442 fn connect_popdown<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
443 unsafe extern "C" fn popdown_trampoline<P: IsA<ScaleButton>, F: Fn(&P) + 'static>(
444 this: *mut ffi::GtkScaleButton,
445 f: glib::ffi::gpointer,
446 ) {
447 let f: &F = &*(f as *const F);
448 f(ScaleButton::from_glib_borrow(this).unsafe_cast_ref())
449 }
450 unsafe {
451 let f: Box_<F> = Box_::new(f);
452 connect_raw(
453 self.as_ptr() as *mut _,
454 c"popdown".as_ptr() as *const _,
455 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
456 popdown_trampoline::<Self, F> as *const (),
457 )),
458 Box_::into_raw(f),
459 )
460 }
461 }
462
463 fn emit_popdown(&self) {
464 self.emit_by_name::<()>("popdown", &[]);
465 }
466
467 #[doc(alias = "popup")]
468 fn connect_popup<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
469 unsafe extern "C" fn popup_trampoline<P: IsA<ScaleButton>, F: Fn(&P) + 'static>(
470 this: *mut ffi::GtkScaleButton,
471 f: glib::ffi::gpointer,
472 ) {
473 let f: &F = &*(f as *const F);
474 f(ScaleButton::from_glib_borrow(this).unsafe_cast_ref())
475 }
476 unsafe {
477 let f: Box_<F> = Box_::new(f);
478 connect_raw(
479 self.as_ptr() as *mut _,
480 c"popup".as_ptr() as *const _,
481 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
482 popup_trampoline::<Self, F> as *const (),
483 )),
484 Box_::into_raw(f),
485 )
486 }
487 }
488
489 fn emit_popup(&self) {
490 self.emit_by_name::<()>("popup", &[]);
491 }
492
493 #[doc(alias = "value-changed")]
494 fn connect_value_changed<F: Fn(&Self, f64) + 'static>(&self, f: F) -> SignalHandlerId {
495 unsafe extern "C" fn value_changed_trampoline<
496 P: IsA<ScaleButton>,
497 F: Fn(&P, f64) + 'static,
498 >(
499 this: *mut ffi::GtkScaleButton,
500 value: std::ffi::c_double,
501 f: glib::ffi::gpointer,
502 ) {
503 let f: &F = &*(f as *const F);
504 f(ScaleButton::from_glib_borrow(this).unsafe_cast_ref(), value)
505 }
506 unsafe {
507 let f: Box_<F> = Box_::new(f);
508 connect_raw(
509 self.as_ptr() as *mut _,
510 c"value-changed".as_ptr() as *const _,
511 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
512 value_changed_trampoline::<Self, F> as *const (),
513 )),
514 Box_::into_raw(f),
515 )
516 }
517 }
518
519 #[cfg(feature = "v4_10")]
520 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
521 #[doc(alias = "active")]
522 fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
523 unsafe extern "C" fn notify_active_trampoline<P: IsA<ScaleButton>, F: Fn(&P) + 'static>(
524 this: *mut ffi::GtkScaleButton,
525 _param_spec: glib::ffi::gpointer,
526 f: glib::ffi::gpointer,
527 ) {
528 let f: &F = &*(f as *const F);
529 f(ScaleButton::from_glib_borrow(this).unsafe_cast_ref())
530 }
531 unsafe {
532 let f: Box_<F> = Box_::new(f);
533 connect_raw(
534 self.as_ptr() as *mut _,
535 c"notify::active".as_ptr() as *const _,
536 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
537 notify_active_trampoline::<Self, F> as *const (),
538 )),
539 Box_::into_raw(f),
540 )
541 }
542 }
543
544 #[doc(alias = "adjustment")]
545 fn connect_adjustment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
546 unsafe extern "C" fn notify_adjustment_trampoline<
547 P: IsA<ScaleButton>,
548 F: Fn(&P) + 'static,
549 >(
550 this: *mut ffi::GtkScaleButton,
551 _param_spec: glib::ffi::gpointer,
552 f: glib::ffi::gpointer,
553 ) {
554 let f: &F = &*(f as *const F);
555 f(ScaleButton::from_glib_borrow(this).unsafe_cast_ref())
556 }
557 unsafe {
558 let f: Box_<F> = Box_::new(f);
559 connect_raw(
560 self.as_ptr() as *mut _,
561 c"notify::adjustment".as_ptr() as *const _,
562 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
563 notify_adjustment_trampoline::<Self, F> as *const (),
564 )),
565 Box_::into_raw(f),
566 )
567 }
568 }
569
570 #[cfg(feature = "v4_14")]
571 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
572 #[doc(alias = "has-frame")]
573 fn connect_has_frame_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
574 unsafe extern "C" fn notify_has_frame_trampoline<
575 P: IsA<ScaleButton>,
576 F: Fn(&P) + 'static,
577 >(
578 this: *mut ffi::GtkScaleButton,
579 _param_spec: glib::ffi::gpointer,
580 f: glib::ffi::gpointer,
581 ) {
582 let f: &F = &*(f as *const F);
583 f(ScaleButton::from_glib_borrow(this).unsafe_cast_ref())
584 }
585 unsafe {
586 let f: Box_<F> = Box_::new(f);
587 connect_raw(
588 self.as_ptr() as *mut _,
589 c"notify::has-frame".as_ptr() as *const _,
590 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
591 notify_has_frame_trampoline::<Self, F> as *const (),
592 )),
593 Box_::into_raw(f),
594 )
595 }
596 }
597
598 #[doc(alias = "icons")]
599 fn connect_icons_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
600 unsafe extern "C" fn notify_icons_trampoline<P: IsA<ScaleButton>, F: Fn(&P) + 'static>(
601 this: *mut ffi::GtkScaleButton,
602 _param_spec: glib::ffi::gpointer,
603 f: glib::ffi::gpointer,
604 ) {
605 let f: &F = &*(f as *const F);
606 f(ScaleButton::from_glib_borrow(this).unsafe_cast_ref())
607 }
608 unsafe {
609 let f: Box_<F> = Box_::new(f);
610 connect_raw(
611 self.as_ptr() as *mut _,
612 c"notify::icons".as_ptr() as *const _,
613 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
614 notify_icons_trampoline::<Self, F> as *const (),
615 )),
616 Box_::into_raw(f),
617 )
618 }
619 }
620
621 #[doc(alias = "value")]
622 fn connect_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
623 unsafe extern "C" fn notify_value_trampoline<P: IsA<ScaleButton>, F: Fn(&P) + 'static>(
624 this: *mut ffi::GtkScaleButton,
625 _param_spec: glib::ffi::gpointer,
626 f: glib::ffi::gpointer,
627 ) {
628 let f: &F = &*(f as *const F);
629 f(ScaleButton::from_glib_borrow(this).unsafe_cast_ref())
630 }
631 unsafe {
632 let f: Box_<F> = Box_::new(f);
633 connect_raw(
634 self.as_ptr() as *mut _,
635 c"notify::value".as_ptr() as *const _,
636 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
637 notify_value_trampoline::<Self, F> as *const (),
638 )),
639 Box_::into_raw(f),
640 )
641 }
642 }
643}
644
645impl<O: IsA<ScaleButton>> ScaleButtonExt for O {}