gtk4/auto/font_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, ConstraintTarget, FontChooser, FontChooserLevel,
11 LayoutManager, Overflow, 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 [`FontDialogButton`][crate::FontDialogButton] instead
25 ///
26 ///
27 /// It is suitable widget for selecting a font in a preference dialog.
28 ///
29 /// # CSS nodes
30 ///
31 /// ```text
32 /// fontbutton
33 /// ╰── button.font
34 /// ╰── [content]
35 /// ```
36 ///
37 /// [`FontButton`][crate::FontButton] has a single CSS node with name fontbutton which
38 /// contains a button node with the .font style class.
39 ///
40 /// ## Properties
41 ///
42 ///
43 /// #### `modal`
44 /// Whether the font chooser dialog should be modal.
45 ///
46 /// Readable | Writable
47 ///
48 ///
49 /// #### `title`
50 /// The title of the font chooser dialog.
51 ///
52 /// Readable | Writable
53 ///
54 ///
55 /// #### `use-font`
56 /// Whether the buttons label will be drawn in the selected font.
57 ///
58 /// Readable | Writable
59 ///
60 ///
61 /// #### `use-size`
62 /// Whether the buttons label will use the selected font size.
63 ///
64 /// Readable | Writable
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 | Writable
76 ///
77 ///
78 /// #### `can-target`
79 /// Whether the widget can receive pointer events.
80 ///
81 /// Readable | Writable
82 ///
83 ///
84 /// #### `css-classes`
85 /// A list of css classes applied to this widget.
86 ///
87 /// Readable | Writable
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 | Writable | Construct Only
97 ///
98 ///
99 /// #### `cursor`
100 /// The cursor used by @widget.
101 ///
102 /// Readable | Writable
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 | Writable
111 ///
112 ///
113 /// #### `focusable`
114 /// Whether this widget itself will accept the input focus.
115 ///
116 /// Readable | Writable
117 ///
118 ///
119 /// #### `halign`
120 /// How to distribute horizontal space if widget gets extra space.
121 ///
122 /// Readable | Writable
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 | Writable
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 | Writable
154 ///
155 ///
156 /// #### `hexpand`
157 /// Whether to expand horizontally.
158 ///
159 /// Readable | Writable
160 ///
161 ///
162 /// #### `hexpand-set`
163 /// Whether to use the `hexpand` property.
164 ///
165 /// Readable | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
233 ///
234 ///
235 /// #### `name`
236 /// The name of the widget.
237 ///
238 /// Readable | Writable
239 ///
240 ///
241 /// #### `opacity`
242 /// The requested opacity of the widget.
243 ///
244 /// Readable | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
321 ///
322 ///
323 /// #### `valign`
324 /// How to distribute vertical space if widget gets extra space.
325 ///
326 /// Readable | Writable
327 ///
328 ///
329 /// #### `vexpand`
330 /// Whether to expand vertically.
331 ///
332 /// Readable | Writable
333 ///
334 ///
335 /// #### `vexpand-set`
336 /// Whether to use the `vexpand` property.
337 ///
338 /// Readable | Writable
339 ///
340 ///
341 /// #### `visible`
342 /// Whether the widget is visible.
343 ///
344 /// Readable | Writable
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 | Writable
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 | Writable
363 /// </details>
364 /// <details><summary><h4>FontChooser</h4></summary>
365 ///
366 ///
367 /// #### `font`
368 /// The font description as a string, e.g. "Sans Italic 12".
369 ///
370 /// Readable | Writable
371 ///
372 ///
373 /// #### `font-desc`
374 /// The font description as a [`pango::FontDescription`][crate::pango::FontDescription].
375 ///
376 /// Readable | Writable
377 ///
378 ///
379 /// #### `font-features`
380 /// The selected font features.
381 ///
382 /// The format of the string is compatible with
383 /// CSS and with Pango attributes.
384 ///
385 /// Readable
386 ///
387 ///
388 /// #### `language`
389 /// The language for which the font features were selected.
390 ///
391 /// Readable | Writable
392 ///
393 ///
394 /// #### `level`
395 /// The level of granularity to offer for selecting fonts.
396 ///
397 /// Readable | Writable
398 ///
399 ///
400 /// #### `preview-text`
401 /// The string with which to preview the font.
402 ///
403 /// Readable | Writable
404 ///
405 ///
406 /// #### `show-preview-entry`
407 /// Whether to show an entry to change the preview text.
408 ///
409 /// Readable | Writable
410 /// </details>
411 ///
412 /// ## Signals
413 ///
414 ///
415 /// #### `activate`
416 /// Emitted to when the font button is activated.
417 ///
418 /// The `::activate` signal on [`FontButton`][crate::FontButton] is an action signal and
419 /// emitting it causes the button to present its dialog.
420 ///
421 /// Action
422 ///
423 ///
424 /// #### `font-set`
425 /// Emitted when the user selects a font.
426 ///
427 /// When handling this signal, use [`FontChooserExt::font()`][crate::prelude::FontChooserExt::font()]
428 /// to find out which font was just selected.
429 ///
430 /// Note that this signal is only emitted when the user changes the font.
431 /// If you need to react to programmatic font changes as well, use
432 /// the notify::font signal.
433 ///
434 ///
435 /// <details><summary><h4>Widget</h4></summary>
436 ///
437 ///
438 /// #### `destroy`
439 /// Signals that all holders of a reference to the widget should release
440 /// the reference that they hold.
441 ///
442 /// May result in finalization of the widget if all references are released.
443 ///
444 /// This signal is not suitable for saving widget state.
445 ///
446 ///
447 ///
448 ///
449 /// #### `direction-changed`
450 /// Emitted when the text direction of a widget changes.
451 ///
452 ///
453 ///
454 ///
455 /// #### `hide`
456 /// Emitted when @widget is hidden.
457 ///
458 ///
459 ///
460 ///
461 /// #### `keynav-failed`
462 /// Emitted if keyboard navigation fails.
463 ///
464 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
465 ///
466 ///
467 ///
468 ///
469 /// #### `map`
470 /// Emitted when @widget is going to be mapped.
471 ///
472 /// A widget is mapped when the widget is visible (which is controlled with
473 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
474 /// are also visible.
475 ///
476 /// The `::map` signal can be used to determine whether a widget will be drawn,
477 /// for instance it can resume an animation that was stopped during the
478 /// emission of [`unmap`][struct@crate::Widget#unmap].
479 ///
480 ///
481 ///
482 ///
483 /// #### `mnemonic-activate`
484 /// Emitted when a widget is activated via a mnemonic.
485 ///
486 /// The default handler for this signal activates @widget if @group_cycling
487 /// is false, or just makes @widget grab focus if @group_cycling is true.
488 ///
489 ///
490 ///
491 ///
492 /// #### `move-focus`
493 /// to move backward.
494 ///
495 /// Action
496 ///
497 ///
498 /// #### `query-tooltip`
499 /// Emitted when the widget’s tooltip is about to be shown.
500 ///
501 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
502 /// is true and the hover timeout has expired with the cursor hovering
503 /// above @widget; or emitted when @widget got focus in keyboard mode.
504 ///
505 /// Using the given coordinates, the signal handler should determine
506 /// whether a tooltip should be shown for @widget. If this is the case
507 /// true should be returned, false otherwise. Note that if @keyboard_mode
508 /// is true, the values of @x and @y are undefined and should not be used.
509 ///
510 /// The signal handler is free to manipulate @tooltip with the therefore
511 /// destined function calls.
512 ///
513 ///
514 ///
515 ///
516 /// #### `realize`
517 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
518 ///
519 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
520 /// or the widget has been mapped (that is, it is going to be drawn).
521 ///
522 ///
523 ///
524 ///
525 /// #### `show`
526 /// Emitted when @widget is shown.
527 ///
528 ///
529 ///
530 ///
531 /// #### `state-flags-changed`
532 /// Emitted when the widget state changes.
533 ///
534 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
535 ///
536 ///
537 ///
538 ///
539 /// #### `unmap`
540 /// Emitted when @widget is going to be unmapped.
541 ///
542 /// A widget is unmapped when either it or any of its parents up to the
543 /// toplevel widget have been set as hidden.
544 ///
545 /// As `::unmap` indicates that a widget will not be shown any longer,
546 /// it can be used to, for example, stop an animation on the widget.
547 ///
548 ///
549 ///
550 ///
551 /// #### `unrealize`
552 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
553 ///
554 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
555 /// or the widget has been unmapped (that is, it is going to be hidden).
556 ///
557 ///
558 /// </details>
559 /// <details><summary><h4>FontChooser</h4></summary>
560 ///
561 ///
562 /// #### `font-activated`
563 /// Emitted when a font is activated.
564 ///
565 /// This usually happens when the user double clicks an item,
566 /// or an item is selected and the user presses one of the keys
567 /// Space, Shift+Space, Return or Enter.
568 ///
569 ///
570 /// </details>
571 ///
572 /// # Implements
573 ///
574 /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`FontChooserExt`][trait@crate::prelude::FontChooserExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual], [`FontChooserExtManual`][trait@crate::prelude::FontChooserExtManual]
575 #[doc(alias = "GtkFontButton")]
576 pub struct FontButton(Object<ffi::GtkFontButton>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, FontChooser;
577
578 match fn {
579 type_ => || ffi::gtk_font_button_get_type(),
580 }
581}
582
583#[cfg(not(feature = "v4_10"))]
584glib::wrapper! {
585 #[doc(alias = "GtkFontButton")]
586 pub struct FontButton(Object<ffi::GtkFontButton>) @extends Widget, @implements Buildable, ConstraintTarget, FontChooser;
587
588 match fn {
589 type_ => || ffi::gtk_font_button_get_type(),
590 }
591}
592
593impl FontButton {
594 /// Creates a new font picker widget.
595 ///
596 /// # Deprecated since 4.10
597 ///
598 /// Use [`FontDialogButton`][crate::FontDialogButton] instead
599 ///
600 /// # Returns
601 ///
602 /// a new font picker widget.
603 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
604 #[allow(deprecated)]
605 #[doc(alias = "gtk_font_button_new")]
606 pub fn new() -> FontButton {
607 assert_initialized_main_thread!();
608 unsafe { Widget::from_glib_none(ffi::gtk_font_button_new()).unsafe_cast() }
609 }
610
611 /// Creates a new font picker widget showing the given font.
612 ///
613 /// # Deprecated since 4.10
614 ///
615 /// Use [`FontDialogButton`][crate::FontDialogButton] instead
616 /// ## `fontname`
617 /// Name of font to display in font chooser dialog
618 ///
619 /// # Returns
620 ///
621 /// a new font picker widget.
622 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
623 #[allow(deprecated)]
624 #[doc(alias = "gtk_font_button_new_with_font")]
625 #[doc(alias = "new_with_font")]
626 pub fn with_font(fontname: &str) -> FontButton {
627 assert_initialized_main_thread!();
628 unsafe {
629 Widget::from_glib_none(ffi::gtk_font_button_new_with_font(
630 fontname.to_glib_none().0,
631 ))
632 .unsafe_cast()
633 }
634 }
635
636 // rustdoc-stripper-ignore-next
637 /// Creates a new builder-pattern struct instance to construct [`FontButton`] objects.
638 ///
639 /// This method returns an instance of [`FontButtonBuilder`](crate::builders::FontButtonBuilder) which can be used to create [`FontButton`] objects.
640 pub fn builder() -> FontButtonBuilder {
641 FontButtonBuilder::new()
642 }
643
644 /// Gets whether the dialog is modal.
645 ///
646 /// # Deprecated since 4.10
647 ///
648 /// Use [`FontDialogButton`][crate::FontDialogButton] instead
649 ///
650 /// # Returns
651 ///
652 /// [`true`] if the dialog is modal
653 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
654 #[allow(deprecated)]
655 #[doc(alias = "gtk_font_button_get_modal")]
656 #[doc(alias = "get_modal")]
657 #[doc(alias = "modal")]
658 pub fn is_modal(&self) -> bool {
659 unsafe { from_glib(ffi::gtk_font_button_get_modal(self.to_glib_none().0)) }
660 }
661
662 /// Retrieves the title of the font chooser dialog.
663 ///
664 /// # Deprecated since 4.10
665 ///
666 /// Use [`FontDialogButton`][crate::FontDialogButton] instead
667 ///
668 /// # Returns
669 ///
670 /// an internal copy of the title string
671 /// which must not be freed.
672 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
673 #[allow(deprecated)]
674 #[doc(alias = "gtk_font_button_get_title")]
675 #[doc(alias = "get_title")]
676 pub fn title(&self) -> glib::GString {
677 unsafe { from_glib_none(ffi::gtk_font_button_get_title(self.to_glib_none().0)) }
678 }
679
680 /// Returns whether the selected font is used in the label.
681 ///
682 /// # Deprecated since 4.10
683 ///
684 /// Use [`FontDialogButton`][crate::FontDialogButton] instead
685 ///
686 /// # Returns
687 ///
688 /// whether the selected font is used in the label.
689 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
690 #[allow(deprecated)]
691 #[doc(alias = "gtk_font_button_get_use_font")]
692 #[doc(alias = "get_use_font")]
693 #[doc(alias = "use-font")]
694 pub fn uses_font(&self) -> bool {
695 unsafe { from_glib(ffi::gtk_font_button_get_use_font(self.to_glib_none().0)) }
696 }
697
698 /// Returns whether the selected size is used in the label.
699 ///
700 /// # Deprecated since 4.10
701 ///
702 /// Use [`FontDialogButton`][crate::FontDialogButton] instead
703 ///
704 /// # Returns
705 ///
706 /// whether the selected size is used in the label.
707 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
708 #[allow(deprecated)]
709 #[doc(alias = "gtk_font_button_get_use_size")]
710 #[doc(alias = "get_use_size")]
711 #[doc(alias = "use-size")]
712 pub fn uses_size(&self) -> bool {
713 unsafe { from_glib(ffi::gtk_font_button_get_use_size(self.to_glib_none().0)) }
714 }
715
716 /// Sets whether the dialog should be modal.
717 ///
718 /// # Deprecated since 4.10
719 ///
720 /// Use [`FontDialogButton`][crate::FontDialogButton] instead
721 /// ## `modal`
722 /// [`true`] to make the dialog modal
723 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
724 #[allow(deprecated)]
725 #[doc(alias = "gtk_font_button_set_modal")]
726 #[doc(alias = "modal")]
727 pub fn set_modal(&self, modal: bool) {
728 unsafe {
729 ffi::gtk_font_button_set_modal(self.to_glib_none().0, modal.into_glib());
730 }
731 }
732
733 /// Sets the title for the font chooser dialog.
734 ///
735 /// # Deprecated since 4.10
736 ///
737 /// Use [`FontDialogButton`][crate::FontDialogButton] instead
738 /// ## `title`
739 /// a string containing the font chooser dialog title
740 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
741 #[allow(deprecated)]
742 #[doc(alias = "gtk_font_button_set_title")]
743 #[doc(alias = "title")]
744 pub fn set_title(&self, title: &str) {
745 unsafe {
746 ffi::gtk_font_button_set_title(self.to_glib_none().0, title.to_glib_none().0);
747 }
748 }
749
750 /// If @use_font is [`true`], the font name will be written
751 /// using the selected font.
752 ///
753 /// # Deprecated since 4.10
754 ///
755 /// Use [`FontDialogButton`][crate::FontDialogButton] instead
756 /// ## `use_font`
757 /// If [`true`], font name will be written using font chosen.
758 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
759 #[allow(deprecated)]
760 #[doc(alias = "gtk_font_button_set_use_font")]
761 #[doc(alias = "use-font")]
762 pub fn set_use_font(&self, use_font: bool) {
763 unsafe {
764 ffi::gtk_font_button_set_use_font(self.to_glib_none().0, use_font.into_glib());
765 }
766 }
767
768 /// If @use_size is [`true`], the font name will be written using
769 /// the selected size.
770 ///
771 /// # Deprecated since 4.10
772 ///
773 /// Use [`FontDialogButton`][crate::FontDialogButton] instead
774 /// ## `use_size`
775 /// If [`true`], font name will be written using the
776 /// selected size.
777 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
778 #[allow(deprecated)]
779 #[doc(alias = "gtk_font_button_set_use_size")]
780 #[doc(alias = "use-size")]
781 pub fn set_use_size(&self, use_size: bool) {
782 unsafe {
783 ffi::gtk_font_button_set_use_size(self.to_glib_none().0, use_size.into_glib());
784 }
785 }
786
787 /// Emitted to when the font button is activated.
788 ///
789 /// The `::activate` signal on [`FontButton`][crate::FontButton] is an action signal and
790 /// emitting it causes the button to present its dialog.
791 #[cfg(feature = "v4_4")]
792 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
793 #[doc(alias = "activate")]
794 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
795 unsafe extern "C" fn activate_trampoline<F: Fn(&FontButton) + 'static>(
796 this: *mut ffi::GtkFontButton,
797 f: glib::ffi::gpointer,
798 ) {
799 unsafe {
800 let f: &F = &*(f as *const F);
801 f(&from_glib_borrow(this))
802 }
803 }
804 unsafe {
805 let f: Box_<F> = Box_::new(f);
806 connect_raw(
807 self.as_ptr() as *mut _,
808 c"activate".as_ptr(),
809 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
810 activate_trampoline::<F> as *const (),
811 )),
812 Box_::into_raw(f),
813 )
814 }
815 }
816
817 #[cfg(feature = "v4_4")]
818 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
819 pub fn emit_activate(&self) {
820 self.emit_by_name::<()>("activate", &[]);
821 }
822
823 /// Emitted when the user selects a font.
824 ///
825 /// When handling this signal, use [`FontChooserExt::font()`][crate::prelude::FontChooserExt::font()]
826 /// to find out which font was just selected.
827 ///
828 /// Note that this signal is only emitted when the user changes the font.
829 /// If you need to react to programmatic font changes as well, use
830 /// the notify::font signal.
831 #[doc(alias = "font-set")]
832 pub fn connect_font_set<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
833 unsafe extern "C" fn font_set_trampoline<F: Fn(&FontButton) + 'static>(
834 this: *mut ffi::GtkFontButton,
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"font-set".as_ptr(),
847 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
848 font_set_trampoline::<F> as *const (),
849 )),
850 Box_::into_raw(f),
851 )
852 }
853 }
854
855 #[doc(alias = "modal")]
856 pub fn connect_modal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
857 unsafe extern "C" fn notify_modal_trampoline<F: Fn(&FontButton) + 'static>(
858 this: *mut ffi::GtkFontButton,
859 _param_spec: glib::ffi::gpointer,
860 f: glib::ffi::gpointer,
861 ) {
862 unsafe {
863 let f: &F = &*(f as *const F);
864 f(&from_glib_borrow(this))
865 }
866 }
867 unsafe {
868 let f: Box_<F> = Box_::new(f);
869 connect_raw(
870 self.as_ptr() as *mut _,
871 c"notify::modal".as_ptr(),
872 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
873 notify_modal_trampoline::<F> as *const (),
874 )),
875 Box_::into_raw(f),
876 )
877 }
878 }
879
880 #[doc(alias = "title")]
881 pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
882 unsafe extern "C" fn notify_title_trampoline<F: Fn(&FontButton) + 'static>(
883 this: *mut ffi::GtkFontButton,
884 _param_spec: glib::ffi::gpointer,
885 f: glib::ffi::gpointer,
886 ) {
887 unsafe {
888 let f: &F = &*(f as *const F);
889 f(&from_glib_borrow(this))
890 }
891 }
892 unsafe {
893 let f: Box_<F> = Box_::new(f);
894 connect_raw(
895 self.as_ptr() as *mut _,
896 c"notify::title".as_ptr(),
897 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
898 notify_title_trampoline::<F> as *const (),
899 )),
900 Box_::into_raw(f),
901 )
902 }
903 }
904
905 #[doc(alias = "use-font")]
906 pub fn connect_use_font_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
907 unsafe extern "C" fn notify_use_font_trampoline<F: Fn(&FontButton) + 'static>(
908 this: *mut ffi::GtkFontButton,
909 _param_spec: glib::ffi::gpointer,
910 f: glib::ffi::gpointer,
911 ) {
912 unsafe {
913 let f: &F = &*(f as *const F);
914 f(&from_glib_borrow(this))
915 }
916 }
917 unsafe {
918 let f: Box_<F> = Box_::new(f);
919 connect_raw(
920 self.as_ptr() as *mut _,
921 c"notify::use-font".as_ptr(),
922 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
923 notify_use_font_trampoline::<F> as *const (),
924 )),
925 Box_::into_raw(f),
926 )
927 }
928 }
929
930 #[doc(alias = "use-size")]
931 pub fn connect_use_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
932 unsafe extern "C" fn notify_use_size_trampoline<F: Fn(&FontButton) + 'static>(
933 this: *mut ffi::GtkFontButton,
934 _param_spec: glib::ffi::gpointer,
935 f: glib::ffi::gpointer,
936 ) {
937 unsafe {
938 let f: &F = &*(f as *const F);
939 f(&from_glib_borrow(this))
940 }
941 }
942 unsafe {
943 let f: Box_<F> = Box_::new(f);
944 connect_raw(
945 self.as_ptr() as *mut _,
946 c"notify::use-size".as_ptr(),
947 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
948 notify_use_size_trampoline::<F> as *const (),
949 )),
950 Box_::into_raw(f),
951 )
952 }
953 }
954}
955
956impl Default for FontButton {
957 fn default() -> Self {
958 Self::new()
959 }
960}
961
962// rustdoc-stripper-ignore-next
963/// A [builder-pattern] type to construct [`FontButton`] objects.
964///
965/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
966#[must_use = "The builder must be built to be used"]
967pub struct FontButtonBuilder {
968 builder: glib::object::ObjectBuilder<'static, FontButton>,
969}
970
971impl FontButtonBuilder {
972 fn new() -> Self {
973 Self {
974 builder: glib::object::Object::builder(),
975 }
976 }
977
978 /// Whether the font chooser dialog should be modal.
979 pub fn modal(self, modal: bool) -> Self {
980 Self {
981 builder: self.builder.property("modal", modal),
982 }
983 }
984
985 /// The title of the font chooser dialog.
986 pub fn title(self, title: impl Into<glib::GString>) -> Self {
987 Self {
988 builder: self.builder.property("title", title.into()),
989 }
990 }
991
992 /// Whether the buttons label will be drawn in the selected font.
993 pub fn use_font(self, use_font: bool) -> Self {
994 Self {
995 builder: self.builder.property("use-font", use_font),
996 }
997 }
998
999 /// Whether the buttons label will use the selected font size.
1000 pub fn use_size(self, use_size: bool) -> Self {
1001 Self {
1002 builder: self.builder.property("use-size", use_size),
1003 }
1004 }
1005
1006 /// Whether the widget or any of its descendents can accept
1007 /// the input focus.
1008 ///
1009 /// This property is meant to be set by widget implementations,
1010 /// typically in their instance init function.
1011 pub fn can_focus(self, can_focus: bool) -> Self {
1012 Self {
1013 builder: self.builder.property("can-focus", can_focus),
1014 }
1015 }
1016
1017 /// Whether the widget can receive pointer events.
1018 pub fn can_target(self, can_target: bool) -> Self {
1019 Self {
1020 builder: self.builder.property("can-target", can_target),
1021 }
1022 }
1023
1024 /// A list of css classes applied to this widget.
1025 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
1026 Self {
1027 builder: self.builder.property("css-classes", css_classes.into()),
1028 }
1029 }
1030
1031 /// The name of this widget in the CSS tree.
1032 ///
1033 /// This property is meant to be set by widget implementations,
1034 /// typically in their instance init function.
1035 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
1036 Self {
1037 builder: self.builder.property("css-name", css_name.into()),
1038 }
1039 }
1040
1041 /// The cursor used by @widget.
1042 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
1043 Self {
1044 builder: self.builder.property("cursor", cursor.clone()),
1045 }
1046 }
1047
1048 /// Whether the widget should grab focus when it is clicked with the mouse.
1049 ///
1050 /// This property is only relevant for widgets that can take focus.
1051 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
1052 Self {
1053 builder: self.builder.property("focus-on-click", focus_on_click),
1054 }
1055 }
1056
1057 /// Whether this widget itself will accept the input focus.
1058 pub fn focusable(self, focusable: bool) -> Self {
1059 Self {
1060 builder: self.builder.property("focusable", focusable),
1061 }
1062 }
1063
1064 /// How to distribute horizontal space if widget gets extra space.
1065 pub fn halign(self, halign: Align) -> Self {
1066 Self {
1067 builder: self.builder.property("halign", halign),
1068 }
1069 }
1070
1071 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
1072 /// signal on @widget.
1073 ///
1074 /// A true value indicates that @widget can have a tooltip, in this case
1075 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
1076 /// determine whether it will provide a tooltip or not.
1077 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
1078 Self {
1079 builder: self.builder.property("has-tooltip", has_tooltip),
1080 }
1081 }
1082
1083 /// Overrides for height request of the widget.
1084 ///
1085 /// If this is -1, the natural request will be used.
1086 pub fn height_request(self, height_request: i32) -> Self {
1087 Self {
1088 builder: self.builder.property("height-request", height_request),
1089 }
1090 }
1091
1092 /// Whether to expand horizontally.
1093 pub fn hexpand(self, hexpand: bool) -> Self {
1094 Self {
1095 builder: self.builder.property("hexpand", hexpand),
1096 }
1097 }
1098
1099 /// Whether to use the `hexpand` property.
1100 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1101 Self {
1102 builder: self.builder.property("hexpand-set", hexpand_set),
1103 }
1104 }
1105
1106 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
1107 /// the preferred size of the widget, and allocate its children.
1108 ///
1109 /// This property is meant to be set by widget implementations,
1110 /// typically in their instance init function.
1111 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1112 Self {
1113 builder: self
1114 .builder
1115 .property("layout-manager", layout_manager.clone().upcast()),
1116 }
1117 }
1118
1119 /// Makes this widget act like a modal dialog, with respect to
1120 /// event delivery.
1121 ///
1122 /// Global event controllers will not handle events with targets
1123 /// inside the widget, unless they are set up to ignore propagation
1124 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1125 #[cfg(feature = "v4_18")]
1126 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1127 pub fn limit_events(self, limit_events: bool) -> Self {
1128 Self {
1129 builder: self.builder.property("limit-events", limit_events),
1130 }
1131 }
1132
1133 /// Margin on bottom side of widget.
1134 ///
1135 /// This property adds margin outside of the widget's normal size
1136 /// request, the margin will be added in addition to the size from
1137 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1138 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1139 Self {
1140 builder: self.builder.property("margin-bottom", margin_bottom),
1141 }
1142 }
1143
1144 /// Margin on end of widget, horizontally.
1145 ///
1146 /// This property supports left-to-right and right-to-left text
1147 /// directions.
1148 ///
1149 /// This property adds margin outside of the widget's normal size
1150 /// request, the margin will be added in addition to the size from
1151 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1152 pub fn margin_end(self, margin_end: i32) -> Self {
1153 Self {
1154 builder: self.builder.property("margin-end", margin_end),
1155 }
1156 }
1157
1158 /// Margin on start of widget, horizontally.
1159 ///
1160 /// This property supports left-to-right and right-to-left text
1161 /// directions.
1162 ///
1163 /// This property adds margin outside of the widget's normal size
1164 /// request, the margin will be added in addition to the size from
1165 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1166 pub fn margin_start(self, margin_start: i32) -> Self {
1167 Self {
1168 builder: self.builder.property("margin-start", margin_start),
1169 }
1170 }
1171
1172 /// Margin on top side of widget.
1173 ///
1174 /// This property adds margin outside of the widget's normal size
1175 /// request, the margin will be added in addition to the size from
1176 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1177 pub fn margin_top(self, margin_top: i32) -> Self {
1178 Self {
1179 builder: self.builder.property("margin-top", margin_top),
1180 }
1181 }
1182
1183 /// The name of the widget.
1184 pub fn name(self, name: impl Into<glib::GString>) -> Self {
1185 Self {
1186 builder: self.builder.property("name", name.into()),
1187 }
1188 }
1189
1190 /// The requested opacity of the widget.
1191 pub fn opacity(self, opacity: f64) -> Self {
1192 Self {
1193 builder: self.builder.property("opacity", opacity),
1194 }
1195 }
1196
1197 /// How content outside the widget's content area is treated.
1198 ///
1199 /// This property is meant to be set by widget implementations,
1200 /// typically in their instance init function.
1201 pub fn overflow(self, overflow: Overflow) -> Self {
1202 Self {
1203 builder: self.builder.property("overflow", overflow),
1204 }
1205 }
1206
1207 /// Whether the widget will receive the default action when it is focused.
1208 pub fn receives_default(self, receives_default: bool) -> Self {
1209 Self {
1210 builder: self.builder.property("receives-default", receives_default),
1211 }
1212 }
1213
1214 /// Whether the widget responds to input.
1215 pub fn sensitive(self, sensitive: bool) -> Self {
1216 Self {
1217 builder: self.builder.property("sensitive", sensitive),
1218 }
1219 }
1220
1221 /// Sets the text of tooltip to be the given string, which is marked up
1222 /// with Pango markup.
1223 ///
1224 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1225 ///
1226 /// This is a convenience property which will take care of getting the
1227 /// tooltip shown if the given string is not `NULL`:
1228 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1229 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1230 /// the default signal handler.
1231 ///
1232 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1233 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1234 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1235 Self {
1236 builder: self
1237 .builder
1238 .property("tooltip-markup", tooltip_markup.into()),
1239 }
1240 }
1241
1242 /// Sets the text of tooltip to be the given string.
1243 ///
1244 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1245 ///
1246 /// This is a convenience property which will take care of getting the
1247 /// tooltip shown if the given string is not `NULL`:
1248 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1249 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1250 /// the default signal handler.
1251 ///
1252 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1253 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1254 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1255 Self {
1256 builder: self.builder.property("tooltip-text", tooltip_text.into()),
1257 }
1258 }
1259
1260 /// How to distribute vertical space if widget gets extra space.
1261 pub fn valign(self, valign: Align) -> Self {
1262 Self {
1263 builder: self.builder.property("valign", valign),
1264 }
1265 }
1266
1267 /// Whether to expand vertically.
1268 pub fn vexpand(self, vexpand: bool) -> Self {
1269 Self {
1270 builder: self.builder.property("vexpand", vexpand),
1271 }
1272 }
1273
1274 /// Whether to use the `vexpand` property.
1275 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1276 Self {
1277 builder: self.builder.property("vexpand-set", vexpand_set),
1278 }
1279 }
1280
1281 /// Whether the widget is visible.
1282 pub fn visible(self, visible: bool) -> Self {
1283 Self {
1284 builder: self.builder.property("visible", visible),
1285 }
1286 }
1287
1288 /// Overrides for width request of the widget.
1289 ///
1290 /// If this is -1, the natural request will be used.
1291 pub fn width_request(self, width_request: i32) -> Self {
1292 Self {
1293 builder: self.builder.property("width-request", width_request),
1294 }
1295 }
1296
1297 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1298 ///
1299 /// The accessible role cannot be changed once set.
1300 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1301 Self {
1302 builder: self.builder.property("accessible-role", accessible_role),
1303 }
1304 }
1305
1306 /// The font description as a string, e.g. "Sans Italic 12".
1307 /// Use [`FontDialog`][crate::FontDialog] and [`FontDialogButton`][crate::FontDialogButton] instead
1308 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1309 pub fn font(self, font: impl Into<glib::GString>) -> Self {
1310 Self {
1311 builder: self.builder.property("font", font.into()),
1312 }
1313 }
1314
1315 /// The font description as a [`pango::FontDescription`][crate::pango::FontDescription].
1316 /// Use [`FontDialog`][crate::FontDialog] and [`FontDialogButton`][crate::FontDialogButton] instead
1317 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1318 pub fn font_desc(self, font_desc: &pango::FontDescription) -> Self {
1319 Self {
1320 builder: self.builder.property("font-desc", font_desc),
1321 }
1322 }
1323
1324 /// The language for which the font features were selected.
1325 /// Use [`FontDialog`][crate::FontDialog] and [`FontDialogButton`][crate::FontDialogButton] instead
1326 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1327 pub fn language(self, language: impl Into<glib::GString>) -> Self {
1328 Self {
1329 builder: self.builder.property("language", language.into()),
1330 }
1331 }
1332
1333 /// The level of granularity to offer for selecting fonts.
1334 /// Use [`FontDialog`][crate::FontDialog] and [`FontDialogButton`][crate::FontDialogButton] instead
1335 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1336 pub fn level(self, level: FontChooserLevel) -> Self {
1337 Self {
1338 builder: self.builder.property("level", level),
1339 }
1340 }
1341
1342 /// The string with which to preview the font.
1343 /// Use [`FontDialog`][crate::FontDialog] and [`FontDialogButton`][crate::FontDialogButton] instead
1344 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1345 pub fn preview_text(self, preview_text: impl Into<glib::GString>) -> Self {
1346 Self {
1347 builder: self.builder.property("preview-text", preview_text.into()),
1348 }
1349 }
1350
1351 /// Whether to show an entry to change the preview text.
1352 /// Use [`FontDialog`][crate::FontDialog] and [`FontDialogButton`][crate::FontDialogButton] instead
1353 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1354 pub fn show_preview_entry(self, show_preview_entry: bool) -> Self {
1355 Self {
1356 builder: self
1357 .builder
1358 .property("show-preview-entry", show_preview_entry),
1359 }
1360 }
1361
1362 // rustdoc-stripper-ignore-next
1363 /// Build the [`FontButton`].
1364 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1365 pub fn build(self) -> FontButton {
1366 assert_initialized_main_thread!();
1367 self.builder.build()
1368 }
1369}