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