Skip to main content

gtk4/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#![allow(deprecated)]
5
6#[cfg(feature = "v4_10")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
8use crate::Accessible;
9use crate::{
10    AccessibleRole, Align, Buildable, ColorChooser, ConstraintTarget, LayoutManager, Overflow,
11    Widget, ffi,
12};
13use glib::{
14    object::ObjectType as _,
15    prelude::*,
16    signal::{SignalHandlerId, connect_raw},
17    translate::*,
18};
19use std::boxed::Box as Box_;
20
21#[cfg(feature = "v4_10")]
22#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
23glib::wrapper! {
24    /// Use [`ColorDialogButton`][crate::ColorDialogButton] instead
25    ///  [content]
26    /// ```text
27    ///
28    /// [`ColorButton`][crate::ColorButton] has a single CSS node with name colorbutton which
29    /// contains a button node. To differentiate it from a plain [`Button`][crate::Button],
30    /// it gets the .color style class.
31    ///
32    /// ## Properties
33    ///
34    ///
35    /// #### `modal`
36    ///  Whether the color chooser dialog should be modal.
37    ///
38    /// Readable | Writable
39    ///
40    ///
41    /// #### `show-editor`
42    ///  Whether the color chooser should open in editor mode.
43    ///
44    /// This property should be used in cases where the palette
45    /// in the editor would be redundant, such as when the color
46    /// button is already part of a palette.
47    ///
48    /// Readable | Writable
49    ///
50    ///
51    /// #### `title`
52    ///  The title of the color chooser dialog
53    ///
54    /// Readable | Writable
55    /// <details><summary><h4>Widget</h4></summary>
56    ///
57    ///
58    /// #### `can-focus`
59    ///  Whether the widget or any of its descendents can accept
60    /// the input focus.
61    ///
62    /// This property is meant to be set by widget implementations,
63    /// typically in their instance init function.
64    ///
65    /// Readable | Writable
66    ///
67    ///
68    /// #### `can-target`
69    ///  Whether the widget can receive pointer events.
70    ///
71    /// Readable | Writable
72    ///
73    ///
74    /// #### `css-classes`
75    ///  A list of css classes applied to this widget.
76    ///
77    /// Readable | Writable
78    ///
79    ///
80    /// #### `css-name`
81    ///  The name of this widget in the CSS tree.
82    ///
83    /// This property is meant to be set by widget implementations,
84    /// typically in their instance init function.
85    ///
86    /// Readable | Writable | Construct Only
87    ///
88    ///
89    /// #### `cursor`
90    ///  The cursor used by @widget.
91    ///
92    /// Readable | Writable
93    ///
94    ///
95    /// #### `focus-on-click`
96    ///  Whether the widget should grab focus when it is clicked with the mouse.
97    ///
98    /// This property is only relevant for widgets that can take focus.
99    ///
100    /// Readable | Writable
101    ///
102    ///
103    /// #### `focusable`
104    ///  Whether this widget itself will accept the input focus.
105    ///
106    /// Readable | Writable
107    ///
108    ///
109    /// #### `halign`
110    ///  How to distribute horizontal space if widget gets extra space.
111    ///
112    /// Readable | Writable
113    ///
114    ///
115    /// #### `has-default`
116    ///  Whether the widget is the default widget.
117    ///
118    /// Readable
119    ///
120    ///
121    /// #### `has-focus`
122    ///  Whether the widget has the input focus.
123    ///
124    /// Readable
125    ///
126    ///
127    /// #### `has-tooltip`
128    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
129    /// signal on @widget.
130    ///
131    /// A true value indicates that @widget can have a tooltip, in this case
132    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
133    /// determine whether it will provide a tooltip or not.
134    ///
135    /// Readable | Writable
136    ///
137    ///
138    /// #### `height-request`
139    ///  Overrides for height request of the widget.
140    ///
141    /// If this is -1, the natural request will be used.
142    ///
143    /// Readable | Writable
144    ///
145    ///
146    /// #### `hexpand`
147    ///  Whether to expand horizontally.
148    ///
149    /// Readable | Writable
150    ///
151    ///
152    /// #### `hexpand-set`
153    ///  Whether to use the `hexpand` property.
154    ///
155    /// Readable | Writable
156    ///
157    ///
158    /// #### `layout-manager`
159    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
160    /// the preferred size of the widget, and allocate its children.
161    ///
162    /// This property is meant to be set by widget implementations,
163    /// typically in their instance init function.
164    ///
165    /// Readable | Writable
166    ///
167    ///
168    /// #### `limit-events`
169    ///  Makes this widget act like a modal dialog, with respect to
170    /// event delivery.
171    ///
172    /// Global event controllers will not handle events with targets
173    /// inside the widget, unless they are set up to ignore propagation
174    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
175    ///
176    /// Readable | Writable
177    ///
178    ///
179    /// #### `margin-bottom`
180    ///  Margin on bottom side of widget.
181    ///
182    /// This property adds margin outside of the widget's normal size
183    /// request, the margin will be added in addition to the size from
184    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
185    ///
186    /// Readable | Writable
187    ///
188    ///
189    /// #### `margin-end`
190    ///  Margin on end of widget, horizontally.
191    ///
192    /// This property supports left-to-right and right-to-left text
193    /// directions.
194    ///
195    /// This property adds margin outside of the widget's normal size
196    /// request, the margin will be added in addition to the size from
197    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
198    ///
199    /// Readable | Writable
200    ///
201    ///
202    /// #### `margin-start`
203    ///  Margin on start of widget, horizontally.
204    ///
205    /// This property supports left-to-right and right-to-left text
206    /// directions.
207    ///
208    /// This property adds margin outside of the widget's normal size
209    /// request, the margin will be added in addition to the size from
210    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
211    ///
212    /// Readable | Writable
213    ///
214    ///
215    /// #### `margin-top`
216    ///  Margin on top side of widget.
217    ///
218    /// This property adds margin outside of the widget's normal size
219    /// request, the margin will be added in addition to the size from
220    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
221    ///
222    /// Readable | Writable
223    ///
224    ///
225    /// #### `name`
226    ///  The name of the widget.
227    ///
228    /// Readable | Writable
229    ///
230    ///
231    /// #### `opacity`
232    ///  The requested opacity of the widget.
233    ///
234    /// Readable | Writable
235    ///
236    ///
237    /// #### `overflow`
238    ///  How content outside the widget's content area is treated.
239    ///
240    /// This property is meant to be set by widget implementations,
241    /// typically in their instance init function.
242    ///
243    /// Readable | Writable
244    ///
245    ///
246    /// #### `parent`
247    ///  The parent widget of this widget.
248    ///
249    /// Readable
250    ///
251    ///
252    /// #### `receives-default`
253    ///  Whether the widget will receive the default action when it is focused.
254    ///
255    /// Readable | Writable
256    ///
257    ///
258    /// #### `root`
259    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
260    ///
261    /// This will be `NULL` if the widget is not contained in a root widget.
262    ///
263    /// Readable
264    ///
265    ///
266    /// #### `scale-factor`
267    ///  The scale factor of the widget.
268    ///
269    /// Readable
270    ///
271    ///
272    /// #### `sensitive`
273    ///  Whether the widget responds to input.
274    ///
275    /// Readable | Writable
276    ///
277    ///
278    /// #### `tooltip-markup`
279    ///  Sets the text of tooltip to be the given string, which is marked up
280    /// with Pango markup.
281    ///
282    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
283    ///
284    /// This is a convenience property which will take care of getting the
285    /// tooltip shown if the given string is not `NULL`:
286    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
287    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
288    /// the default signal handler.
289    ///
290    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
291    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
292    ///
293    /// Readable | Writable
294    ///
295    ///
296    /// #### `tooltip-text`
297    ///  Sets the text of tooltip to be the given string.
298    ///
299    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
300    ///
301    /// This is a convenience property which will take care of getting the
302    /// tooltip shown if the given string is not `NULL`:
303    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
304    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
305    /// the default signal handler.
306    ///
307    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
308    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
309    ///
310    /// Readable | Writable
311    ///
312    ///
313    /// #### `valign`
314    ///  How to distribute vertical space if widget gets extra space.
315    ///
316    /// Readable | Writable
317    ///
318    ///
319    /// #### `vexpand`
320    ///  Whether to expand vertically.
321    ///
322    /// Readable | Writable
323    ///
324    ///
325    /// #### `vexpand-set`
326    ///  Whether to use the `vexpand` property.
327    ///
328    /// Readable | Writable
329    ///
330    ///
331    /// #### `visible`
332    ///  Whether the widget is visible.
333    ///
334    /// Readable | Writable
335    ///
336    ///
337    /// #### `width-request`
338    ///  Overrides for width request of the widget.
339    ///
340    /// If this is -1, the natural request will be used.
341    ///
342    /// Readable | Writable
343    /// </details>
344    /// <details><summary><h4>Accessible</h4></summary>
345    ///
346    ///
347    /// #### `accessible-role`
348    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
349    ///
350    /// The accessible role cannot be changed once set.
351    ///
352    /// Readable | Writable
353    /// </details>
354    /// <details><summary><h4>ColorChooser</h4></summary>
355    ///
356    ///
357    /// #### `rgba`
358    ///  The currently selected color, as a [`gdk::RGBA`][crate::gdk::RGBA] struct.
359    ///
360    /// The property can be set to change the current selection
361    /// programmatically.
362    ///
363    /// Readable | Writable
364    ///
365    ///
366    /// #### `use-alpha`
367    ///  Whether colors may have alpha (translucency).
368    ///
369    /// When ::use-alpha is [`false`], the [`gdk::RGBA`][crate::gdk::RGBA] struct obtained
370    /// via the [`rgba`][struct@crate::ColorChooser#rgba] property will be
371    /// forced to have alpha == 1.
372    ///
373    /// Implementations are expected to show alpha by rendering the color
374    /// over a non-uniform background (like a checkerboard pattern).
375    ///
376    /// Readable | Writable
377    /// </details>
378    ///
379    /// ## Signals
380    ///
381    ///
382    /// #### `activate`
383    ///  Emitted to when the color button is activated.
384    ///
385    /// The `::activate` signal on [`MenuButton`][crate::MenuButton] is an action signal and
386    /// emitting it causes the button to pop up its dialog.
387    ///
388    /// Action
389    ///
390    ///
391    /// #### `color-set`
392    ///  Emitted when the user selects a color.
393    ///
394    /// When handling this signal, use [`ColorChooserExt::rgba()`][crate::prelude::ColorChooserExt::rgba()]
395    /// to find out which color was just selected.
396    ///
397    /// Note that this signal is only emitted when the user changes the color.
398    /// If you need to react to programmatic color changes as well, use
399    /// the notify::rgba signal.
400    ///
401    ///
402    /// <details><summary><h4>Widget</h4></summary>
403    ///
404    ///
405    /// #### `destroy`
406    ///  Signals that all holders of a reference to the widget should release
407    /// the reference that they hold.
408    ///
409    /// May result in finalization of the widget if all references are released.
410    ///
411    /// This signal is not suitable for saving widget state.
412    ///
413    ///
414    ///
415    ///
416    /// #### `direction-changed`
417    ///  Emitted when the text direction of a widget changes.
418    ///
419    ///
420    ///
421    ///
422    /// #### `hide`
423    ///  Emitted when @widget is hidden.
424    ///
425    ///
426    ///
427    ///
428    /// #### `keynav-failed`
429    ///  Emitted if keyboard navigation fails.
430    ///
431    /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
432    ///
433    ///
434    ///
435    ///
436    /// #### `map`
437    ///  Emitted when @widget is going to be mapped.
438    ///
439    /// A widget is mapped when the widget is visible (which is controlled with
440    /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
441    /// are also visible.
442    ///
443    /// The `::map` signal can be used to determine whether a widget will be drawn,
444    /// for instance it can resume an animation that was stopped during the
445    /// emission of [`unmap`][struct@crate::Widget#unmap].
446    ///
447    ///
448    ///
449    ///
450    /// #### `mnemonic-activate`
451    ///  Emitted when a widget is activated via a mnemonic.
452    ///
453    /// The default handler for this signal activates @widget if @group_cycling
454    /// is false, or just makes @widget grab focus if @group_cycling is true.
455    ///
456    ///
457    ///
458    ///
459    /// #### `move-focus`
460    ///   to move backward.
461    ///
462    /// Action
463    ///
464    ///
465    /// #### `query-tooltip`
466    ///  s tooltip is about to be shown.
467    ///
468    /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
469    /// is true and the hover timeout has expired with the cursor hovering
470    /// above @widget; or emitted when @widget got focus in keyboard mode.
471    ///
472    /// Using the given coordinates, the signal handler should determine
473    /// whether a tooltip should be shown for @widget. If this is the case
474    /// true should be returned, false otherwise. Note that if @keyboard_mode
475    /// is true, the values of @x and @y are undefined and should not be used.
476    ///
477    /// The signal handler is free to manipulate @tooltip with the therefore
478    /// destined function calls.
479    ///
480    ///
481    ///
482    ///
483    /// #### `realize`
484    ///  Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
485    ///
486    /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
487    /// or the widget has been mapped (that is, it is going to be drawn).
488    ///
489    ///
490    ///
491    ///
492    /// #### `show`
493    ///  Emitted when @widget is shown.
494    ///
495    ///
496    ///
497    ///
498    /// #### `state-flags-changed`
499    ///  Emitted when the widget state changes.
500    ///
501    /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
502    ///
503    ///
504    ///
505    ///
506    /// #### `unmap`
507    ///  Emitted when @widget is going to be unmapped.
508    ///
509    /// A widget is unmapped when either it or any of its parents up to the
510    /// toplevel widget have been set as hidden.
511    ///
512    /// As `::unmap` indicates that a widget will not be shown any longer,
513    /// it can be used to, for example, stop an animation on the widget.
514    ///
515    ///
516    ///
517    ///
518    /// #### `unrealize`
519    ///  Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
520    ///
521    /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
522    /// or the widget has been unmapped (that is, it is going to be hidden).
523    ///
524    ///
525    /// </details>
526    /// <details><summary><h4>ColorChooser</h4></summary>
527    ///
528    ///
529    /// #### `color-activated`
530    ///  Emitted when a color is activated from the color chooser.
531    ///
532    /// This usually happens when the user clicks a color swatch,
533    /// or a color is selected and the user presses one of the keys
534    /// Space, Shift+Space, Return or Enter.
535    ///
536    ///
537    /// </details>
538    ///
539    /// # Implements
540    ///
541    /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`ColorChooserExt`][trait@crate::prelude::ColorChooserExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual], [`ColorChooserExtManual`][trait@crate::prelude::ColorChooserExtManual]
542    #[doc(alias = "GtkColorButton")]
543    pub struct ColorButton(Object<ffi::GtkColorButton>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, ColorChooser;
544
545    match fn {
546        type_ => || ffi::gtk_color_button_get_type(),
547    }
548}
549
550#[cfg(not(feature = "v4_10"))]
551glib::wrapper! {
552    #[doc(alias = "GtkColorButton")]
553    pub struct ColorButton(Object<ffi::GtkColorButton>) @extends Widget, @implements Buildable, ConstraintTarget, ColorChooser;
554
555    match fn {
556        type_ => || ffi::gtk_color_button_get_type(),
557    }
558}
559
560impl ColorButton {
561    /// Creates a new color button.
562    ///
563    /// This returns a widget in the form of a small button containing
564    /// a swatch representing the current selected color. When the button
565    /// is clicked, a color chooser dialog will open, allowing the user
566    /// to select a color. The swatch will be updated to reflect the new
567    /// color when the user finishes.
568    ///
569    /// # Deprecated since 4.10
570    ///
571    /// Use [`ColorDialogButton`][crate::ColorDialogButton] instead
572    ///
573    /// # Returns
574    ///
575    /// a new color button
576    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
577    #[allow(deprecated)]
578    #[doc(alias = "gtk_color_button_new")]
579    pub fn new() -> ColorButton {
580        assert_initialized_main_thread!();
581        unsafe { Widget::from_glib_none(ffi::gtk_color_button_new()).unsafe_cast() }
582    }
583
584    /// Creates a new color button showing the given color.
585    ///
586    /// # Deprecated since 4.10
587    ///
588    /// ## `rgba`
589    /// A [`gdk::RGBA`][crate::gdk::RGBA] to set the current color with
590    ///
591    /// # Returns
592    ///
593    /// a new color button
594    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
595    #[allow(deprecated)]
596    #[doc(alias = "gtk_color_button_new_with_rgba")]
597    #[doc(alias = "new_with_rgba")]
598    pub fn with_rgba(rgba: &gdk::RGBA) -> ColorButton {
599        assert_initialized_main_thread!();
600        unsafe {
601            Widget::from_glib_none(ffi::gtk_color_button_new_with_rgba(rgba.to_glib_none().0))
602                .unsafe_cast()
603        }
604    }
605
606    // rustdoc-stripper-ignore-next
607    /// Creates a new builder-pattern struct instance to construct [`ColorButton`] objects.
608    ///
609    /// This method returns an instance of [`ColorButtonBuilder`](crate::builders::ColorButtonBuilder) which can be used to create [`ColorButton`] objects.
610    pub fn builder() -> ColorButtonBuilder {
611        ColorButtonBuilder::new()
612    }
613
614    /// Gets whether the dialog is modal.
615    ///
616    /// # Deprecated since 4.10
617    ///
618    /// Use [`ColorDialogButton`][crate::ColorDialogButton] instead
619    ///
620    /// # Returns
621    ///
622    /// [`true`] if the dialog is modal
623    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
624    #[allow(deprecated)]
625    #[doc(alias = "gtk_color_button_get_modal")]
626    #[doc(alias = "get_modal")]
627    #[doc(alias = "modal")]
628    pub fn is_modal(&self) -> bool {
629        unsafe { from_glib(ffi::gtk_color_button_get_modal(self.to_glib_none().0)) }
630    }
631
632    /// Gets the title of the color chooser dialog.
633    ///
634    /// # Deprecated since 4.10
635    ///
636    /// Use [`ColorDialogButton`][crate::ColorDialogButton] instead
637    ///
638    /// # Returns
639    ///
640    /// An internal string, do not free the return value
641    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
642    #[allow(deprecated)]
643    #[doc(alias = "gtk_color_button_get_title")]
644    #[doc(alias = "get_title")]
645    pub fn title(&self) -> glib::GString {
646        unsafe { from_glib_none(ffi::gtk_color_button_get_title(self.to_glib_none().0)) }
647    }
648
649    /// Sets whether the dialog should be modal.
650    ///
651    /// # Deprecated since 4.10
652    ///
653    /// Use [`ColorDialogButton`][crate::ColorDialogButton] instead
654    /// ## `modal`
655    /// [`true`] to make the dialog modal
656    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
657    #[allow(deprecated)]
658    #[doc(alias = "gtk_color_button_set_modal")]
659    #[doc(alias = "modal")]
660    pub fn set_modal(&self, modal: bool) {
661        unsafe {
662            ffi::gtk_color_button_set_modal(self.to_glib_none().0, modal.into_glib());
663        }
664    }
665
666    /// Sets the title for the color chooser dialog.
667    ///
668    /// # Deprecated since 4.10
669    ///
670    /// Use [`ColorDialogButton`][crate::ColorDialogButton] instead
671    /// ## `title`
672    /// String containing new window title
673    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
674    #[allow(deprecated)]
675    #[doc(alias = "gtk_color_button_set_title")]
676    #[doc(alias = "title")]
677    pub fn set_title(&self, title: &str) {
678        unsafe {
679            ffi::gtk_color_button_set_title(self.to_glib_none().0, title.to_glib_none().0);
680        }
681    }
682
683    /// Whether the color chooser should open in editor mode.
684    ///
685    /// This property should be used in cases where the palette
686    /// in the editor would be redundant, such as when the color
687    /// button is already part of a palette.
688    #[doc(alias = "show-editor")]
689    pub fn shows_editor(&self) -> bool {
690        ObjectExt::property(self, "show-editor")
691    }
692
693    /// Whether the color chooser should open in editor mode.
694    ///
695    /// This property should be used in cases where the palette
696    /// in the editor would be redundant, such as when the color
697    /// button is already part of a palette.
698    #[doc(alias = "show-editor")]
699    pub fn set_show_editor(&self, show_editor: bool) {
700        ObjectExt::set_property(self, "show-editor", show_editor)
701    }
702
703    /// Emitted to when the color button is activated.
704    ///
705    /// The `::activate` signal on [`MenuButton`][crate::MenuButton] is an action signal and
706    /// emitting it causes the button to pop up its dialog.
707    #[cfg(feature = "v4_4")]
708    #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
709    #[doc(alias = "activate")]
710    pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
711        unsafe extern "C" fn activate_trampoline<F: Fn(&ColorButton) + 'static>(
712            this: *mut ffi::GtkColorButton,
713            f: glib::ffi::gpointer,
714        ) {
715            unsafe {
716                let f: &F = &*(f as *const F);
717                f(&from_glib_borrow(this))
718            }
719        }
720        unsafe {
721            let f: Box_<F> = Box_::new(f);
722            connect_raw(
723                self.as_ptr() as *mut _,
724                c"activate".as_ptr(),
725                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
726                    activate_trampoline::<F> as *const (),
727                )),
728                Box_::into_raw(f),
729            )
730        }
731    }
732
733    #[cfg(feature = "v4_4")]
734    #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
735    pub fn emit_activate(&self) {
736        self.emit_by_name::<()>("activate", &[]);
737    }
738
739    /// Emitted when the user selects a color.
740    ///
741    /// When handling this signal, use [`ColorChooserExt::rgba()`][crate::prelude::ColorChooserExt::rgba()]
742    /// to find out which color was just selected.
743    ///
744    /// Note that this signal is only emitted when the user changes the color.
745    /// If you need to react to programmatic color changes as well, use
746    /// the notify::rgba signal.
747    #[doc(alias = "color-set")]
748    pub fn connect_color_set<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
749        unsafe extern "C" fn color_set_trampoline<F: Fn(&ColorButton) + 'static>(
750            this: *mut ffi::GtkColorButton,
751            f: glib::ffi::gpointer,
752        ) {
753            unsafe {
754                let f: &F = &*(f as *const F);
755                f(&from_glib_borrow(this))
756            }
757        }
758        unsafe {
759            let f: Box_<F> = Box_::new(f);
760            connect_raw(
761                self.as_ptr() as *mut _,
762                c"color-set".as_ptr(),
763                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
764                    color_set_trampoline::<F> as *const (),
765                )),
766                Box_::into_raw(f),
767            )
768        }
769    }
770
771    #[doc(alias = "modal")]
772    pub fn connect_modal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
773        unsafe extern "C" fn notify_modal_trampoline<F: Fn(&ColorButton) + 'static>(
774            this: *mut ffi::GtkColorButton,
775            _param_spec: glib::ffi::gpointer,
776            f: glib::ffi::gpointer,
777        ) {
778            unsafe {
779                let f: &F = &*(f as *const F);
780                f(&from_glib_borrow(this))
781            }
782        }
783        unsafe {
784            let f: Box_<F> = Box_::new(f);
785            connect_raw(
786                self.as_ptr() as *mut _,
787                c"notify::modal".as_ptr(),
788                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
789                    notify_modal_trampoline::<F> as *const (),
790                )),
791                Box_::into_raw(f),
792            )
793        }
794    }
795
796    #[doc(alias = "show-editor")]
797    pub fn connect_show_editor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
798        unsafe extern "C" fn notify_show_editor_trampoline<F: Fn(&ColorButton) + 'static>(
799            this: *mut ffi::GtkColorButton,
800            _param_spec: glib::ffi::gpointer,
801            f: glib::ffi::gpointer,
802        ) {
803            unsafe {
804                let f: &F = &*(f as *const F);
805                f(&from_glib_borrow(this))
806            }
807        }
808        unsafe {
809            let f: Box_<F> = Box_::new(f);
810            connect_raw(
811                self.as_ptr() as *mut _,
812                c"notify::show-editor".as_ptr(),
813                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
814                    notify_show_editor_trampoline::<F> as *const (),
815                )),
816                Box_::into_raw(f),
817            )
818        }
819    }
820
821    #[doc(alias = "title")]
822    pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
823        unsafe extern "C" fn notify_title_trampoline<F: Fn(&ColorButton) + 'static>(
824            this: *mut ffi::GtkColorButton,
825            _param_spec: glib::ffi::gpointer,
826            f: glib::ffi::gpointer,
827        ) {
828            unsafe {
829                let f: &F = &*(f as *const F);
830                f(&from_glib_borrow(this))
831            }
832        }
833        unsafe {
834            let f: Box_<F> = Box_::new(f);
835            connect_raw(
836                self.as_ptr() as *mut _,
837                c"notify::title".as_ptr(),
838                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
839                    notify_title_trampoline::<F> as *const (),
840                )),
841                Box_::into_raw(f),
842            )
843        }
844    }
845}
846
847impl Default for ColorButton {
848    fn default() -> Self {
849        Self::new()
850    }
851}
852
853// rustdoc-stripper-ignore-next
854/// A [builder-pattern] type to construct [`ColorButton`] objects.
855///
856/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
857#[must_use = "The builder must be built to be used"]
858pub struct ColorButtonBuilder {
859    builder: glib::object::ObjectBuilder<'static, ColorButton>,
860}
861
862impl ColorButtonBuilder {
863    fn new() -> Self {
864        Self {
865            builder: glib::object::Object::builder(),
866        }
867    }
868
869    /// Whether the color chooser dialog should be modal.
870    pub fn modal(self, modal: bool) -> Self {
871        Self {
872            builder: self.builder.property("modal", modal),
873        }
874    }
875
876    /// Whether the color chooser should open in editor mode.
877    ///
878    /// This property should be used in cases where the palette
879    /// in the editor would be redundant, such as when the color
880    /// button is already part of a palette.
881    pub fn show_editor(self, show_editor: bool) -> Self {
882        Self {
883            builder: self.builder.property("show-editor", show_editor),
884        }
885    }
886
887    /// The title of the color chooser dialog
888    pub fn title(self, title: impl Into<glib::GString>) -> Self {
889        Self {
890            builder: self.builder.property("title", title.into()),
891        }
892    }
893
894    /// Whether the widget or any of its descendents can accept
895    /// the input focus.
896    ///
897    /// This property is meant to be set by widget implementations,
898    /// typically in their instance init function.
899    pub fn can_focus(self, can_focus: bool) -> Self {
900        Self {
901            builder: self.builder.property("can-focus", can_focus),
902        }
903    }
904
905    /// Whether the widget can receive pointer events.
906    pub fn can_target(self, can_target: bool) -> Self {
907        Self {
908            builder: self.builder.property("can-target", can_target),
909        }
910    }
911
912    /// A list of css classes applied to this widget.
913    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
914        Self {
915            builder: self.builder.property("css-classes", css_classes.into()),
916        }
917    }
918
919    /// The name of this widget in the CSS tree.
920    ///
921    /// This property is meant to be set by widget implementations,
922    /// typically in their instance init function.
923    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
924        Self {
925            builder: self.builder.property("css-name", css_name.into()),
926        }
927    }
928
929    /// The cursor used by @widget.
930    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
931        Self {
932            builder: self.builder.property("cursor", cursor.clone()),
933        }
934    }
935
936    /// Whether the widget should grab focus when it is clicked with the mouse.
937    ///
938    /// This property is only relevant for widgets that can take focus.
939    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
940        Self {
941            builder: self.builder.property("focus-on-click", focus_on_click),
942        }
943    }
944
945    /// Whether this widget itself will accept the input focus.
946    pub fn focusable(self, focusable: bool) -> Self {
947        Self {
948            builder: self.builder.property("focusable", focusable),
949        }
950    }
951
952    /// How to distribute horizontal space if widget gets extra space.
953    pub fn halign(self, halign: Align) -> Self {
954        Self {
955            builder: self.builder.property("halign", halign),
956        }
957    }
958
959    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
960    /// signal on @widget.
961    ///
962    /// A true value indicates that @widget can have a tooltip, in this case
963    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
964    /// determine whether it will provide a tooltip or not.
965    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
966        Self {
967            builder: self.builder.property("has-tooltip", has_tooltip),
968        }
969    }
970
971    /// Overrides for height request of the widget.
972    ///
973    /// If this is -1, the natural request will be used.
974    pub fn height_request(self, height_request: i32) -> Self {
975        Self {
976            builder: self.builder.property("height-request", height_request),
977        }
978    }
979
980    /// Whether to expand horizontally.
981    pub fn hexpand(self, hexpand: bool) -> Self {
982        Self {
983            builder: self.builder.property("hexpand", hexpand),
984        }
985    }
986
987    /// Whether to use the `hexpand` property.
988    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
989        Self {
990            builder: self.builder.property("hexpand-set", hexpand_set),
991        }
992    }
993
994    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
995    /// the preferred size of the widget, and allocate its children.
996    ///
997    /// This property is meant to be set by widget implementations,
998    /// typically in their instance init function.
999    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1000        Self {
1001            builder: self
1002                .builder
1003                .property("layout-manager", layout_manager.clone().upcast()),
1004        }
1005    }
1006
1007    /// Makes this widget act like a modal dialog, with respect to
1008    /// event delivery.
1009    ///
1010    /// Global event controllers will not handle events with targets
1011    /// inside the widget, unless they are set up to ignore propagation
1012    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1013    #[cfg(feature = "v4_18")]
1014    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1015    pub fn limit_events(self, limit_events: bool) -> Self {
1016        Self {
1017            builder: self.builder.property("limit-events", limit_events),
1018        }
1019    }
1020
1021    /// Margin on bottom side of widget.
1022    ///
1023    /// This property adds margin outside of the widget's normal size
1024    /// request, the margin will be added in addition to the size from
1025    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1026    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1027        Self {
1028            builder: self.builder.property("margin-bottom", margin_bottom),
1029        }
1030    }
1031
1032    /// Margin on end of widget, horizontally.
1033    ///
1034    /// This property supports left-to-right and right-to-left text
1035    /// directions.
1036    ///
1037    /// This property adds margin outside of the widget's normal size
1038    /// request, the margin will be added in addition to the size from
1039    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1040    pub fn margin_end(self, margin_end: i32) -> Self {
1041        Self {
1042            builder: self.builder.property("margin-end", margin_end),
1043        }
1044    }
1045
1046    /// Margin on start of widget, horizontally.
1047    ///
1048    /// This property supports left-to-right and right-to-left text
1049    /// directions.
1050    ///
1051    /// This property adds margin outside of the widget's normal size
1052    /// request, the margin will be added in addition to the size from
1053    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1054    pub fn margin_start(self, margin_start: i32) -> Self {
1055        Self {
1056            builder: self.builder.property("margin-start", margin_start),
1057        }
1058    }
1059
1060    /// Margin on top side of widget.
1061    ///
1062    /// This property adds margin outside of the widget's normal size
1063    /// request, the margin will be added in addition to the size from
1064    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1065    pub fn margin_top(self, margin_top: i32) -> Self {
1066        Self {
1067            builder: self.builder.property("margin-top", margin_top),
1068        }
1069    }
1070
1071    /// The name of the widget.
1072    pub fn name(self, name: impl Into<glib::GString>) -> Self {
1073        Self {
1074            builder: self.builder.property("name", name.into()),
1075        }
1076    }
1077
1078    /// The requested opacity of the widget.
1079    pub fn opacity(self, opacity: f64) -> Self {
1080        Self {
1081            builder: self.builder.property("opacity", opacity),
1082        }
1083    }
1084
1085    /// How content outside the widget's content area is treated.
1086    ///
1087    /// This property is meant to be set by widget implementations,
1088    /// typically in their instance init function.
1089    pub fn overflow(self, overflow: Overflow) -> Self {
1090        Self {
1091            builder: self.builder.property("overflow", overflow),
1092        }
1093    }
1094
1095    /// Whether the widget will receive the default action when it is focused.
1096    pub fn receives_default(self, receives_default: bool) -> Self {
1097        Self {
1098            builder: self.builder.property("receives-default", receives_default),
1099        }
1100    }
1101
1102    /// Whether the widget responds to input.
1103    pub fn sensitive(self, sensitive: bool) -> Self {
1104        Self {
1105            builder: self.builder.property("sensitive", sensitive),
1106        }
1107    }
1108
1109    /// Sets the text of tooltip to be the given string, which is marked up
1110    /// with Pango markup.
1111    ///
1112    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1113    ///
1114    /// This is a convenience property which will take care of getting the
1115    /// tooltip shown if the given string is not `NULL`:
1116    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1117    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1118    /// the default signal handler.
1119    ///
1120    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1121    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1122    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1123        Self {
1124            builder: self
1125                .builder
1126                .property("tooltip-markup", tooltip_markup.into()),
1127        }
1128    }
1129
1130    /// Sets the text of tooltip to be the given string.
1131    ///
1132    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1133    ///
1134    /// This is a convenience property which will take care of getting the
1135    /// tooltip shown if the given string is not `NULL`:
1136    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1137    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1138    /// the default signal handler.
1139    ///
1140    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1141    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1142    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1143        Self {
1144            builder: self.builder.property("tooltip-text", tooltip_text.into()),
1145        }
1146    }
1147
1148    /// How to distribute vertical space if widget gets extra space.
1149    pub fn valign(self, valign: Align) -> Self {
1150        Self {
1151            builder: self.builder.property("valign", valign),
1152        }
1153    }
1154
1155    /// Whether to expand vertically.
1156    pub fn vexpand(self, vexpand: bool) -> Self {
1157        Self {
1158            builder: self.builder.property("vexpand", vexpand),
1159        }
1160    }
1161
1162    /// Whether to use the `vexpand` property.
1163    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1164        Self {
1165            builder: self.builder.property("vexpand-set", vexpand_set),
1166        }
1167    }
1168
1169    /// Whether the widget is visible.
1170    pub fn visible(self, visible: bool) -> Self {
1171        Self {
1172            builder: self.builder.property("visible", visible),
1173        }
1174    }
1175
1176    /// Overrides for width request of the widget.
1177    ///
1178    /// If this is -1, the natural request will be used.
1179    pub fn width_request(self, width_request: i32) -> Self {
1180        Self {
1181            builder: self.builder.property("width-request", width_request),
1182        }
1183    }
1184
1185    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1186    ///
1187    /// The accessible role cannot be changed once set.
1188    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1189        Self {
1190            builder: self.builder.property("accessible-role", accessible_role),
1191        }
1192    }
1193
1194    /// The currently selected color, as a [`gdk::RGBA`][crate::gdk::RGBA] struct.
1195    ///
1196    /// The property can be set to change the current selection
1197    /// programmatically.
1198    /// Use [`ColorDialog`][crate::ColorDialog] and [`ColorDialogButton`][crate::ColorDialogButton]
1199    ///   instead of widgets implementing [`ColorChooser`][crate::ColorChooser]
1200    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1201    pub fn rgba(self, rgba: &gdk::RGBA) -> Self {
1202        Self {
1203            builder: self.builder.property("rgba", rgba),
1204        }
1205    }
1206
1207    /// Whether colors may have alpha (translucency).
1208    ///
1209    /// When ::use-alpha is [`false`], the [`gdk::RGBA`][crate::gdk::RGBA] struct obtained
1210    /// via the [`rgba`][struct@crate::ColorChooser#rgba] property will be
1211    /// forced to have alpha == 1.
1212    ///
1213    /// Implementations are expected to show alpha by rendering the color
1214    /// over a non-uniform background (like a checkerboard pattern).
1215    /// Use [`ColorDialog`][crate::ColorDialog] and [`ColorDialogButton`][crate::ColorDialogButton]
1216    ///   instead of widgets implementing [`ColorChooser`][crate::ColorChooser]
1217    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1218    pub fn use_alpha(self, use_alpha: bool) -> Self {
1219        Self {
1220            builder: self.builder.property("use-alpha", use_alpha),
1221        }
1222    }
1223
1224    // rustdoc-stripper-ignore-next
1225    /// Build the [`ColorButton`].
1226    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1227    pub fn build(self) -> ColorButton {
1228        assert_initialized_main_thread!();
1229        self.builder.build()
1230    }
1231}