gtk/auto/
color_button.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6    Actionable, Align, Bin, Buildable, Button, ColorChooser, Container, PositionType, ReliefStyle,
7    ResizeMode, Widget,
8};
9use glib::{
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::{boxed::Box as Box_, fmt, mem::transmute};
15
16glib::wrapper! {
17    #[doc(alias = "GtkColorButton")]
18    pub struct ColorButton(Object<ffi::GtkColorButton, ffi::GtkColorButtonClass>) @extends Button, Bin, Container, Widget, @implements Buildable, Actionable, ColorChooser;
19
20    match fn {
21        type_ => || ffi::gtk_color_button_get_type(),
22    }
23}
24
25impl ColorButton {
26    pub const NONE: Option<&'static ColorButton> = None;
27
28    #[doc(alias = "gtk_color_button_new")]
29    pub fn new() -> ColorButton {
30        assert_initialized_main_thread!();
31        unsafe { Widget::from_glib_none(ffi::gtk_color_button_new()).unsafe_cast() }
32    }
33
34    #[doc(alias = "gtk_color_button_new_with_rgba")]
35    #[doc(alias = "new_with_rgba")]
36    pub fn with_rgba(rgba: &gdk::RGBA) -> ColorButton {
37        assert_initialized_main_thread!();
38        unsafe {
39            Widget::from_glib_none(ffi::gtk_color_button_new_with_rgba(rgba.to_glib_none().0))
40                .unsafe_cast()
41        }
42    }
43
44    // rustdoc-stripper-ignore-next
45    /// Creates a new builder-pattern struct instance to construct [`ColorButton`] objects.
46    ///
47    /// This method returns an instance of [`ColorButtonBuilder`](crate::builders::ColorButtonBuilder) which can be used to create [`ColorButton`] objects.
48    pub fn builder() -> ColorButtonBuilder {
49        ColorButtonBuilder::new()
50    }
51}
52
53impl Default for ColorButton {
54    fn default() -> Self {
55        Self::new()
56    }
57}
58
59// rustdoc-stripper-ignore-next
60/// A [builder-pattern] type to construct [`ColorButton`] objects.
61///
62/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
63#[must_use = "The builder must be built to be used"]
64pub struct ColorButtonBuilder {
65    builder: glib::object::ObjectBuilder<'static, ColorButton>,
66}
67
68impl ColorButtonBuilder {
69    fn new() -> Self {
70        Self {
71            builder: glib::object::Object::builder(),
72        }
73    }
74
75    pub fn alpha(self, alpha: u32) -> Self {
76        Self {
77            builder: self.builder.property("alpha", alpha),
78        }
79    }
80
81    pub fn rgba(self, rgba: &gdk::RGBA) -> Self {
82        Self {
83            builder: self.builder.property("rgba", rgba),
84        }
85    }
86
87    pub fn show_editor(self, show_editor: bool) -> Self {
88        Self {
89            builder: self.builder.property("show-editor", show_editor),
90        }
91    }
92
93    pub fn title(self, title: impl Into<glib::GString>) -> Self {
94        Self {
95            builder: self.builder.property("title", title.into()),
96        }
97    }
98
99    pub fn use_alpha(self, use_alpha: bool) -> Self {
100        Self {
101            builder: self.builder.property("use-alpha", use_alpha),
102        }
103    }
104
105    pub fn always_show_image(self, always_show_image: bool) -> Self {
106        Self {
107            builder: self
108                .builder
109                .property("always-show-image", always_show_image),
110        }
111    }
112
113    pub fn image(self, image: &impl IsA<Widget>) -> Self {
114        Self {
115            builder: self.builder.property("image", image.clone().upcast()),
116        }
117    }
118
119    pub fn image_position(self, image_position: PositionType) -> Self {
120        Self {
121            builder: self.builder.property("image-position", image_position),
122        }
123    }
124
125    pub fn label(self, label: impl Into<glib::GString>) -> Self {
126        Self {
127            builder: self.builder.property("label", label.into()),
128        }
129    }
130
131    pub fn relief(self, relief: ReliefStyle) -> Self {
132        Self {
133            builder: self.builder.property("relief", relief),
134        }
135    }
136
137    pub fn use_underline(self, use_underline: bool) -> Self {
138        Self {
139            builder: self.builder.property("use-underline", use_underline),
140        }
141    }
142
143    pub fn border_width(self, border_width: u32) -> Self {
144        Self {
145            builder: self.builder.property("border-width", border_width),
146        }
147    }
148
149    pub fn child(self, child: &impl IsA<Widget>) -> Self {
150        Self {
151            builder: self.builder.property("child", child.clone().upcast()),
152        }
153    }
154
155    pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
156        Self {
157            builder: self.builder.property("resize-mode", resize_mode),
158        }
159    }
160
161    pub fn app_paintable(self, app_paintable: bool) -> Self {
162        Self {
163            builder: self.builder.property("app-paintable", app_paintable),
164        }
165    }
166
167    pub fn can_default(self, can_default: bool) -> Self {
168        Self {
169            builder: self.builder.property("can-default", can_default),
170        }
171    }
172
173    pub fn can_focus(self, can_focus: bool) -> Self {
174        Self {
175            builder: self.builder.property("can-focus", can_focus),
176        }
177    }
178
179    pub fn events(self, events: gdk::EventMask) -> Self {
180        Self {
181            builder: self.builder.property("events", events),
182        }
183    }
184
185    pub fn expand(self, expand: bool) -> Self {
186        Self {
187            builder: self.builder.property("expand", expand),
188        }
189    }
190
191    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
192        Self {
193            builder: self.builder.property("focus-on-click", focus_on_click),
194        }
195    }
196
197    pub fn halign(self, halign: Align) -> Self {
198        Self {
199            builder: self.builder.property("halign", halign),
200        }
201    }
202
203    pub fn has_default(self, has_default: bool) -> Self {
204        Self {
205            builder: self.builder.property("has-default", has_default),
206        }
207    }
208
209    pub fn has_focus(self, has_focus: bool) -> Self {
210        Self {
211            builder: self.builder.property("has-focus", has_focus),
212        }
213    }
214
215    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
216        Self {
217            builder: self.builder.property("has-tooltip", has_tooltip),
218        }
219    }
220
221    pub fn height_request(self, height_request: i32) -> Self {
222        Self {
223            builder: self.builder.property("height-request", height_request),
224        }
225    }
226
227    pub fn hexpand(self, hexpand: bool) -> Self {
228        Self {
229            builder: self.builder.property("hexpand", hexpand),
230        }
231    }
232
233    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
234        Self {
235            builder: self.builder.property("hexpand-set", hexpand_set),
236        }
237    }
238
239    pub fn is_focus(self, is_focus: bool) -> Self {
240        Self {
241            builder: self.builder.property("is-focus", is_focus),
242        }
243    }
244
245    pub fn margin(self, margin: i32) -> Self {
246        Self {
247            builder: self.builder.property("margin", margin),
248        }
249    }
250
251    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
252        Self {
253            builder: self.builder.property("margin-bottom", margin_bottom),
254        }
255    }
256
257    pub fn margin_end(self, margin_end: i32) -> Self {
258        Self {
259            builder: self.builder.property("margin-end", margin_end),
260        }
261    }
262
263    pub fn margin_start(self, margin_start: i32) -> Self {
264        Self {
265            builder: self.builder.property("margin-start", margin_start),
266        }
267    }
268
269    pub fn margin_top(self, margin_top: i32) -> Self {
270        Self {
271            builder: self.builder.property("margin-top", margin_top),
272        }
273    }
274
275    pub fn name(self, name: impl Into<glib::GString>) -> Self {
276        Self {
277            builder: self.builder.property("name", name.into()),
278        }
279    }
280
281    pub fn no_show_all(self, no_show_all: bool) -> Self {
282        Self {
283            builder: self.builder.property("no-show-all", no_show_all),
284        }
285    }
286
287    pub fn opacity(self, opacity: f64) -> Self {
288        Self {
289            builder: self.builder.property("opacity", opacity),
290        }
291    }
292
293    pub fn parent(self, parent: &impl IsA<Container>) -> Self {
294        Self {
295            builder: self.builder.property("parent", parent.clone().upcast()),
296        }
297    }
298
299    pub fn receives_default(self, receives_default: bool) -> Self {
300        Self {
301            builder: self.builder.property("receives-default", receives_default),
302        }
303    }
304
305    pub fn sensitive(self, sensitive: bool) -> Self {
306        Self {
307            builder: self.builder.property("sensitive", sensitive),
308        }
309    }
310
311    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
312        Self {
313            builder: self
314                .builder
315                .property("tooltip-markup", tooltip_markup.into()),
316        }
317    }
318
319    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
320        Self {
321            builder: self.builder.property("tooltip-text", tooltip_text.into()),
322        }
323    }
324
325    pub fn valign(self, valign: Align) -> Self {
326        Self {
327            builder: self.builder.property("valign", valign),
328        }
329    }
330
331    pub fn vexpand(self, vexpand: bool) -> Self {
332        Self {
333            builder: self.builder.property("vexpand", vexpand),
334        }
335    }
336
337    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
338        Self {
339            builder: self.builder.property("vexpand-set", vexpand_set),
340        }
341    }
342
343    pub fn visible(self, visible: bool) -> Self {
344        Self {
345            builder: self.builder.property("visible", visible),
346        }
347    }
348
349    pub fn width_request(self, width_request: i32) -> Self {
350        Self {
351            builder: self.builder.property("width-request", width_request),
352        }
353    }
354
355    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
356        Self {
357            builder: self.builder.property("action-name", action_name.into()),
358        }
359    }
360
361    pub fn action_target(self, action_target: &glib::Variant) -> Self {
362        Self {
363            builder: self
364                .builder
365                .property("action-target", action_target.clone()),
366        }
367    }
368
369    // rustdoc-stripper-ignore-next
370    /// Build the [`ColorButton`].
371    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
372    pub fn build(self) -> ColorButton {
373        self.builder.build()
374    }
375}
376
377mod sealed {
378    pub trait Sealed {}
379    impl<T: super::IsA<super::ColorButton>> Sealed for T {}
380}
381
382pub trait ColorButtonExt: IsA<ColorButton> + sealed::Sealed + 'static {
383    #[doc(alias = "gtk_color_button_get_title")]
384    #[doc(alias = "get_title")]
385    fn title(&self) -> Option<glib::GString> {
386        unsafe {
387            from_glib_none(ffi::gtk_color_button_get_title(
388                self.as_ref().to_glib_none().0,
389            ))
390        }
391    }
392
393    #[doc(alias = "gtk_color_button_set_title")]
394    fn set_title(&self, title: &str) {
395        unsafe {
396            ffi::gtk_color_button_set_title(self.as_ref().to_glib_none().0, title.to_glib_none().0);
397        }
398    }
399
400    fn alpha(&self) -> u32 {
401        ObjectExt::property(self.as_ref(), "alpha")
402    }
403
404    fn set_alpha(&self, alpha: u32) {
405        ObjectExt::set_property(self.as_ref(), "alpha", alpha)
406    }
407
408    #[doc(alias = "show-editor")]
409    fn shows_editor(&self) -> bool {
410        ObjectExt::property(self.as_ref(), "show-editor")
411    }
412
413    #[doc(alias = "show-editor")]
414    fn set_show_editor(&self, show_editor: bool) {
415        ObjectExt::set_property(self.as_ref(), "show-editor", show_editor)
416    }
417
418    #[doc(alias = "color-set")]
419    fn connect_color_set<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
420        unsafe extern "C" fn color_set_trampoline<P: IsA<ColorButton>, F: Fn(&P) + 'static>(
421            this: *mut ffi::GtkColorButton,
422            f: glib::ffi::gpointer,
423        ) {
424            let f: &F = &*(f as *const F);
425            f(ColorButton::from_glib_borrow(this).unsafe_cast_ref())
426        }
427        unsafe {
428            let f: Box_<F> = Box_::new(f);
429            connect_raw(
430                self.as_ptr() as *mut _,
431                b"color-set\0".as_ptr() as *const _,
432                Some(transmute::<_, unsafe extern "C" fn()>(
433                    color_set_trampoline::<Self, F> as *const (),
434                )),
435                Box_::into_raw(f),
436            )
437        }
438    }
439
440    #[doc(alias = "alpha")]
441    fn connect_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
442        unsafe extern "C" fn notify_alpha_trampoline<P: IsA<ColorButton>, F: Fn(&P) + 'static>(
443            this: *mut ffi::GtkColorButton,
444            _param_spec: glib::ffi::gpointer,
445            f: glib::ffi::gpointer,
446        ) {
447            let f: &F = &*(f as *const F);
448            f(ColorButton::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                b"notify::alpha\0".as_ptr() as *const _,
455                Some(transmute::<_, unsafe extern "C" fn()>(
456                    notify_alpha_trampoline::<Self, F> as *const (),
457                )),
458                Box_::into_raw(f),
459            )
460        }
461    }
462
463    #[doc(alias = "show-editor")]
464    fn connect_show_editor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
465        unsafe extern "C" fn notify_show_editor_trampoline<
466            P: IsA<ColorButton>,
467            F: Fn(&P) + 'static,
468        >(
469            this: *mut ffi::GtkColorButton,
470            _param_spec: glib::ffi::gpointer,
471            f: glib::ffi::gpointer,
472        ) {
473            let f: &F = &*(f as *const F);
474            f(ColorButton::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                b"notify::show-editor\0".as_ptr() as *const _,
481                Some(transmute::<_, unsafe extern "C" fn()>(
482                    notify_show_editor_trampoline::<Self, F> as *const (),
483                )),
484                Box_::into_raw(f),
485            )
486        }
487    }
488
489    #[doc(alias = "title")]
490    fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
491        unsafe extern "C" fn notify_title_trampoline<P: IsA<ColorButton>, F: Fn(&P) + 'static>(
492            this: *mut ffi::GtkColorButton,
493            _param_spec: glib::ffi::gpointer,
494            f: glib::ffi::gpointer,
495        ) {
496            let f: &F = &*(f as *const F);
497            f(ColorButton::from_glib_borrow(this).unsafe_cast_ref())
498        }
499        unsafe {
500            let f: Box_<F> = Box_::new(f);
501            connect_raw(
502                self.as_ptr() as *mut _,
503                b"notify::title\0".as_ptr() as *const _,
504                Some(transmute::<_, unsafe extern "C" fn()>(
505                    notify_title_trampoline::<Self, F> as *const (),
506                )),
507                Box_::into_raw(f),
508            )
509        }
510    }
511}
512
513impl<O: IsA<ColorButton>> ColorButtonExt for O {}
514
515impl fmt::Display for ColorButton {
516    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
517        f.write_str("ColorButton")
518    }
519}