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 Accessible, AccessibleRole, Align, Buildable, ColorChooser, ConstraintTarget, LayoutManager,
8 Overflow, Widget, ffi,
9};
10use glib::{
11 object::ObjectType as _,
12 prelude::*,
13 signal::{SignalHandlerId, connect_raw},
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 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() as *const _,
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() as *const _,
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() as *const _,
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() as *const _,
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() as *const _,
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}