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