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