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