Skip to main content

gtk4/auto/
font_dialog.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
5use crate::{Filter, Window, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::{boxed::Box as Box_, pin::Pin};
12
13glib::wrapper! {
14    /// Asynchronous API to present a font chooser dialog.
15    ///
16    /// [`FontDialog`][crate::FontDialog] collects the arguments that are needed to present
17    /// the dialog to the user, such as a title for the dialog and whether
18    /// it should be modal.
19    ///
20    /// The dialog is shown with the [`choose_font()`][Self::choose_font()]
21    /// function or its variants.
22    ///
23    /// See [`FontDialogButton`][crate::FontDialogButton] for a convenient control
24    /// that uses [`FontDialog`][crate::FontDialog] and presents the results.
25    ///
26    /// ## Properties
27    ///
28    ///
29    /// #### `filter`
30    ///  A filter to restrict what fonts are shown in the font chooser dialog.
31    ///
32    /// Readable | Writeable
33    ///
34    ///
35    /// #### `font-map`
36    ///  A custom font map to select fonts from.
37    ///
38    /// A custom font map can be used to present application-specific
39    /// fonts instead of or in addition to the normal system fonts.
40    ///
41    /// Readable | Writeable
42    ///
43    ///
44    /// #### `language`
45    ///  The language for which the font features are selected.
46    ///
47    /// Readable | Writeable
48    ///
49    ///
50    /// #### `modal`
51    ///  Whether the font chooser dialog is modal.
52    ///
53    /// Readable | Writeable
54    ///
55    ///
56    /// #### `title`
57    ///  A title that may be shown on the font chooser
58    /// dialog that is presented by [`FontDialog::choose_font()`][crate::FontDialog::choose_font()].
59    ///
60    /// Readable | Writeable
61    ///
62    /// # Implements
63    ///
64    /// [`trait@glib::ObjectExt`]
65    #[doc(alias = "GtkFontDialog")]
66    pub struct FontDialog(Object<ffi::GtkFontDialog, ffi::GtkFontDialogClass>);
67
68    match fn {
69        type_ => || ffi::gtk_font_dialog_get_type(),
70    }
71}
72
73impl FontDialog {
74    /// Creates a new [`FontDialog`][crate::FontDialog] object.
75    ///
76    /// # Returns
77    ///
78    /// the new [`FontDialog`][crate::FontDialog]
79    #[doc(alias = "gtk_font_dialog_new")]
80    pub fn new() -> FontDialog {
81        assert_initialized_main_thread!();
82        unsafe { from_glib_full(ffi::gtk_font_dialog_new()) }
83    }
84
85    // rustdoc-stripper-ignore-next
86    /// Creates a new builder-pattern struct instance to construct [`FontDialog`] objects.
87    ///
88    /// This method returns an instance of [`FontDialogBuilder`](crate::builders::FontDialogBuilder) which can be used to create [`FontDialog`] objects.
89    pub fn builder() -> FontDialogBuilder {
90        FontDialogBuilder::new()
91    }
92
93    /// Presents a font chooser dialog to the user.
94    ///
95    /// The font chooser dialog will be set up for selecting a font face.
96    ///
97    /// A font face represents a font family and style, but no specific font size.
98    /// ## `parent`
99    /// the parent window
100    /// ## `initial_value`
101    /// the initial value
102    /// ## `cancellable`
103    /// a cancellable to cancel the operation
104    /// ## `callback`
105    /// a callback to call when the
106    ///   operation is complete
107    #[doc(alias = "gtk_font_dialog_choose_face")]
108    pub fn choose_face<P: FnOnce(Result<pango::FontFace, glib::Error>) + 'static>(
109        &self,
110        parent: Option<&impl IsA<Window>>,
111        initial_value: Option<&impl IsA<pango::FontFace>>,
112        cancellable: Option<&impl IsA<gio::Cancellable>>,
113        callback: P,
114    ) {
115        let main_context = glib::MainContext::ref_thread_default();
116        let is_main_context_owner = main_context.is_owner();
117        let has_acquired_main_context = (!is_main_context_owner)
118            .then(|| main_context.acquire().ok())
119            .flatten();
120        assert!(
121            is_main_context_owner || has_acquired_main_context.is_some(),
122            "Async operations only allowed if the thread is owning the MainContext"
123        );
124
125        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
126            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
127        unsafe extern "C" fn choose_face_trampoline<
128            P: FnOnce(Result<pango::FontFace, glib::Error>) + 'static,
129        >(
130            _source_object: *mut glib::gobject_ffi::GObject,
131            res: *mut gio::ffi::GAsyncResult,
132            user_data: glib::ffi::gpointer,
133        ) {
134            unsafe {
135                let mut error = std::ptr::null_mut();
136                let ret = ffi::gtk_font_dialog_choose_face_finish(
137                    _source_object as *mut _,
138                    res,
139                    &mut error,
140                );
141                let result = if error.is_null() {
142                    Ok(from_glib_full(ret))
143                } else {
144                    Err(from_glib_full(error))
145                };
146                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
147                    Box_::from_raw(user_data as *mut _);
148                let callback: P = callback.into_inner();
149                callback(result);
150            }
151        }
152        let callback = choose_face_trampoline::<P>;
153        unsafe {
154            ffi::gtk_font_dialog_choose_face(
155                self.to_glib_none().0,
156                parent.map(|p| p.as_ref()).to_glib_none().0,
157                initial_value.map(|p| p.as_ref()).to_glib_none().0,
158                cancellable.map(|p| p.as_ref()).to_glib_none().0,
159                Some(callback),
160                Box_::into_raw(user_data) as *mut _,
161            );
162        }
163    }
164
165    pub fn choose_face_future(
166        &self,
167        parent: Option<&(impl IsA<Window> + Clone + 'static)>,
168        initial_value: Option<&(impl IsA<pango::FontFace> + Clone + 'static)>,
169    ) -> Pin<Box_<dyn std::future::Future<Output = Result<pango::FontFace, glib::Error>> + 'static>>
170    {
171        let parent = parent.map(ToOwned::to_owned);
172        let initial_value = initial_value.map(ToOwned::to_owned);
173        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
174            obj.choose_face(
175                parent.as_ref().map(::std::borrow::Borrow::borrow),
176                initial_value.as_ref().map(::std::borrow::Borrow::borrow),
177                Some(cancellable),
178                move |res| {
179                    send.resolve(res);
180                },
181            );
182        }))
183    }
184
185    /// Presents a font chooser dialog to the user.
186    ///
187    /// The font chooser dialog will be set up for selecting a font family.
188    /// ## `parent`
189    /// the parent window
190    /// ## `initial_value`
191    /// the initial value
192    /// ## `cancellable`
193    /// a cancellable to cancel the operation
194    /// ## `callback`
195    /// a callback to call when the
196    ///   operation is complete
197    #[doc(alias = "gtk_font_dialog_choose_family")]
198    pub fn choose_family<P: FnOnce(Result<pango::FontFamily, glib::Error>) + 'static>(
199        &self,
200        parent: Option<&impl IsA<Window>>,
201        initial_value: Option<&impl IsA<pango::FontFamily>>,
202        cancellable: Option<&impl IsA<gio::Cancellable>>,
203        callback: P,
204    ) {
205        let main_context = glib::MainContext::ref_thread_default();
206        let is_main_context_owner = main_context.is_owner();
207        let has_acquired_main_context = (!is_main_context_owner)
208            .then(|| main_context.acquire().ok())
209            .flatten();
210        assert!(
211            is_main_context_owner || has_acquired_main_context.is_some(),
212            "Async operations only allowed if the thread is owning the MainContext"
213        );
214
215        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
216            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
217        unsafe extern "C" fn choose_family_trampoline<
218            P: FnOnce(Result<pango::FontFamily, glib::Error>) + 'static,
219        >(
220            _source_object: *mut glib::gobject_ffi::GObject,
221            res: *mut gio::ffi::GAsyncResult,
222            user_data: glib::ffi::gpointer,
223        ) {
224            unsafe {
225                let mut error = std::ptr::null_mut();
226                let ret = ffi::gtk_font_dialog_choose_family_finish(
227                    _source_object as *mut _,
228                    res,
229                    &mut error,
230                );
231                let result = if error.is_null() {
232                    Ok(from_glib_full(ret))
233                } else {
234                    Err(from_glib_full(error))
235                };
236                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
237                    Box_::from_raw(user_data as *mut _);
238                let callback: P = callback.into_inner();
239                callback(result);
240            }
241        }
242        let callback = choose_family_trampoline::<P>;
243        unsafe {
244            ffi::gtk_font_dialog_choose_family(
245                self.to_glib_none().0,
246                parent.map(|p| p.as_ref()).to_glib_none().0,
247                initial_value.map(|p| p.as_ref()).to_glib_none().0,
248                cancellable.map(|p| p.as_ref()).to_glib_none().0,
249                Some(callback),
250                Box_::into_raw(user_data) as *mut _,
251            );
252        }
253    }
254
255    pub fn choose_family_future(
256        &self,
257        parent: Option<&(impl IsA<Window> + Clone + 'static)>,
258        initial_value: Option<&(impl IsA<pango::FontFamily> + Clone + 'static)>,
259    ) -> Pin<Box_<dyn std::future::Future<Output = Result<pango::FontFamily, glib::Error>> + 'static>>
260    {
261        let parent = parent.map(ToOwned::to_owned);
262        let initial_value = initial_value.map(ToOwned::to_owned);
263        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
264            obj.choose_family(
265                parent.as_ref().map(::std::borrow::Borrow::borrow),
266                initial_value.as_ref().map(::std::borrow::Borrow::borrow),
267                Some(cancellable),
268                move |res| {
269                    send.resolve(res);
270                },
271            );
272        }))
273    }
274
275    /// Presents a font chooser dialog to the user.
276    ///
277    /// The font chooser dialog will be set up for selecting a font.
278    ///
279    /// If you want to let the user select font features as well,
280    /// use [`choose_font_and_features()`][Self::choose_font_and_features()] instead.
281    /// ## `parent`
282    /// the parent window
283    /// ## `initial_value`
284    /// the font to select initially
285    /// ## `cancellable`
286    /// a cancellable to cancel the operation
287    /// ## `callback`
288    /// a callback to call when the
289    ///   operation is complete
290    #[doc(alias = "gtk_font_dialog_choose_font")]
291    pub fn choose_font<P: FnOnce(Result<pango::FontDescription, glib::Error>) + 'static>(
292        &self,
293        parent: Option<&impl IsA<Window>>,
294        initial_value: Option<&pango::FontDescription>,
295        cancellable: Option<&impl IsA<gio::Cancellable>>,
296        callback: P,
297    ) {
298        let main_context = glib::MainContext::ref_thread_default();
299        let is_main_context_owner = main_context.is_owner();
300        let has_acquired_main_context = (!is_main_context_owner)
301            .then(|| main_context.acquire().ok())
302            .flatten();
303        assert!(
304            is_main_context_owner || has_acquired_main_context.is_some(),
305            "Async operations only allowed if the thread is owning the MainContext"
306        );
307
308        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
309            Box_::new(glib::thread_guard::ThreadGuard::new(callback));
310        unsafe extern "C" fn choose_font_trampoline<
311            P: FnOnce(Result<pango::FontDescription, glib::Error>) + 'static,
312        >(
313            _source_object: *mut glib::gobject_ffi::GObject,
314            res: *mut gio::ffi::GAsyncResult,
315            user_data: glib::ffi::gpointer,
316        ) {
317            unsafe {
318                let mut error = std::ptr::null_mut();
319                let ret = ffi::gtk_font_dialog_choose_font_finish(
320                    _source_object as *mut _,
321                    res,
322                    &mut error,
323                );
324                let result = if error.is_null() {
325                    Ok(from_glib_full(ret))
326                } else {
327                    Err(from_glib_full(error))
328                };
329                let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
330                    Box_::from_raw(user_data as *mut _);
331                let callback: P = callback.into_inner();
332                callback(result);
333            }
334        }
335        let callback = choose_font_trampoline::<P>;
336        unsafe {
337            ffi::gtk_font_dialog_choose_font(
338                self.to_glib_none().0,
339                parent.map(|p| p.as_ref()).to_glib_none().0,
340                mut_override(initial_value.to_glib_none().0),
341                cancellable.map(|p| p.as_ref()).to_glib_none().0,
342                Some(callback),
343                Box_::into_raw(user_data) as *mut _,
344            );
345        }
346    }
347
348    pub fn choose_font_future(
349        &self,
350        parent: Option<&(impl IsA<Window> + Clone + 'static)>,
351        initial_value: Option<&pango::FontDescription>,
352    ) -> Pin<
353        Box_<
354            dyn std::future::Future<Output = Result<pango::FontDescription, glib::Error>> + 'static,
355        >,
356    > {
357        let parent = parent.map(ToOwned::to_owned);
358        let initial_value = initial_value.map(ToOwned::to_owned);
359        Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
360            obj.choose_font(
361                parent.as_ref().map(::std::borrow::Borrow::borrow),
362                initial_value.as_ref().map(::std::borrow::Borrow::borrow),
363                Some(cancellable),
364                move |res| {
365                    send.resolve(res);
366                },
367            );
368        }))
369    }
370
371    /// Returns the filter that decides which fonts to display
372    /// in the font chooser dialog.
373    ///
374    /// # Returns
375    ///
376    /// the filter
377    #[doc(alias = "gtk_font_dialog_get_filter")]
378    #[doc(alias = "get_filter")]
379    pub fn filter(&self) -> Option<Filter> {
380        unsafe { from_glib_none(ffi::gtk_font_dialog_get_filter(self.to_glib_none().0)) }
381    }
382
383    /// Returns the fontmap from which fonts are selected,
384    /// or `NULL` for the default fontmap.
385    ///
386    /// # Returns
387    ///
388    /// the fontmap
389    #[doc(alias = "gtk_font_dialog_get_font_map")]
390    #[doc(alias = "get_font_map")]
391    #[doc(alias = "font-map")]
392    pub fn font_map(&self) -> Option<pango::FontMap> {
393        unsafe { from_glib_none(ffi::gtk_font_dialog_get_font_map(self.to_glib_none().0)) }
394    }
395
396    /// Returns the language for which font features are applied.
397    ///
398    /// # Returns
399    ///
400    /// the language for font features
401    #[doc(alias = "gtk_font_dialog_get_language")]
402    #[doc(alias = "get_language")]
403    pub fn language(&self) -> Option<pango::Language> {
404        unsafe { from_glib_full(ffi::gtk_font_dialog_get_language(self.to_glib_none().0)) }
405    }
406
407    /// Returns whether the font chooser dialog blocks interaction
408    /// with the parent window while it is presented.
409    ///
410    /// # Returns
411    ///
412    /// true if the font chooser dialog is modal
413    #[doc(alias = "gtk_font_dialog_get_modal")]
414    #[doc(alias = "get_modal")]
415    #[doc(alias = "modal")]
416    pub fn is_modal(&self) -> bool {
417        unsafe { from_glib(ffi::gtk_font_dialog_get_modal(self.to_glib_none().0)) }
418    }
419
420    /// Returns the title that will be shown on the font chooser dialog.
421    ///
422    /// # Returns
423    ///
424    /// the title
425    #[doc(alias = "gtk_font_dialog_get_title")]
426    #[doc(alias = "get_title")]
427    pub fn title(&self) -> glib::GString {
428        unsafe { from_glib_none(ffi::gtk_font_dialog_get_title(self.to_glib_none().0)) }
429    }
430
431    /// Adds a filter that decides which fonts to display
432    /// in the font chooser dialog.
433    ///
434    /// The filter must be able to handle both [`pango::FontFamily`][crate::pango::FontFamily]
435    /// and [`pango::FontFace`][crate::pango::FontFace] objects.
436    /// ## `filter`
437    /// the filter
438    #[doc(alias = "gtk_font_dialog_set_filter")]
439    #[doc(alias = "filter")]
440    pub fn set_filter(&self, filter: Option<&impl IsA<Filter>>) {
441        unsafe {
442            ffi::gtk_font_dialog_set_filter(
443                self.to_glib_none().0,
444                filter.map(|p| p.as_ref()).to_glib_none().0,
445            );
446        }
447    }
448
449    /// Sets the fontmap from which fonts are selected.
450    ///
451    /// If @fontmap is `NULL`, the default fontmap is used.
452    /// ## `fontmap`
453    /// the fontmap
454    #[doc(alias = "gtk_font_dialog_set_font_map")]
455    #[doc(alias = "font-map")]
456    pub fn set_font_map(&self, fontmap: Option<&impl IsA<pango::FontMap>>) {
457        unsafe {
458            ffi::gtk_font_dialog_set_font_map(
459                self.to_glib_none().0,
460                fontmap.map(|p| p.as_ref()).to_glib_none().0,
461            );
462        }
463    }
464
465    /// Sets the language for which font features are applied.
466    /// ## `language`
467    /// the language for font features
468    #[doc(alias = "gtk_font_dialog_set_language")]
469    #[doc(alias = "language")]
470    pub fn set_language(&self, language: &pango::Language) {
471        unsafe {
472            ffi::gtk_font_dialog_set_language(
473                self.to_glib_none().0,
474                mut_override(language.to_glib_none().0),
475            );
476        }
477    }
478
479    /// Sets whether the font chooser dialog blocks interaction
480    /// with the parent window while it is presented.
481    /// ## `modal`
482    /// the new value
483    #[doc(alias = "gtk_font_dialog_set_modal")]
484    #[doc(alias = "modal")]
485    pub fn set_modal(&self, modal: bool) {
486        unsafe {
487            ffi::gtk_font_dialog_set_modal(self.to_glib_none().0, modal.into_glib());
488        }
489    }
490
491    /// Sets the title that will be shown on the font chooser dialog.
492    /// ## `title`
493    /// the new title
494    #[doc(alias = "gtk_font_dialog_set_title")]
495    #[doc(alias = "title")]
496    pub fn set_title(&self, title: &str) {
497        unsafe {
498            ffi::gtk_font_dialog_set_title(self.to_glib_none().0, title.to_glib_none().0);
499        }
500    }
501
502    #[cfg(feature = "v4_10")]
503    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
504    #[doc(alias = "filter")]
505    pub fn connect_filter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
506        unsafe extern "C" fn notify_filter_trampoline<F: Fn(&FontDialog) + 'static>(
507            this: *mut ffi::GtkFontDialog,
508            _param_spec: glib::ffi::gpointer,
509            f: glib::ffi::gpointer,
510        ) {
511            unsafe {
512                let f: &F = &*(f as *const F);
513                f(&from_glib_borrow(this))
514            }
515        }
516        unsafe {
517            let f: Box_<F> = Box_::new(f);
518            connect_raw(
519                self.as_ptr() as *mut _,
520                c"notify::filter".as_ptr() as *const _,
521                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
522                    notify_filter_trampoline::<F> as *const (),
523                )),
524                Box_::into_raw(f),
525            )
526        }
527    }
528
529    #[cfg(feature = "v4_10")]
530    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
531    #[doc(alias = "font-map")]
532    pub fn connect_font_map_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
533        unsafe extern "C" fn notify_font_map_trampoline<F: Fn(&FontDialog) + 'static>(
534            this: *mut ffi::GtkFontDialog,
535            _param_spec: glib::ffi::gpointer,
536            f: glib::ffi::gpointer,
537        ) {
538            unsafe {
539                let f: &F = &*(f as *const F);
540                f(&from_glib_borrow(this))
541            }
542        }
543        unsafe {
544            let f: Box_<F> = Box_::new(f);
545            connect_raw(
546                self.as_ptr() as *mut _,
547                c"notify::font-map".as_ptr() as *const _,
548                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
549                    notify_font_map_trampoline::<F> as *const (),
550                )),
551                Box_::into_raw(f),
552            )
553        }
554    }
555
556    #[cfg(feature = "v4_10")]
557    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
558    #[doc(alias = "language")]
559    pub fn connect_language_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
560        unsafe extern "C" fn notify_language_trampoline<F: Fn(&FontDialog) + 'static>(
561            this: *mut ffi::GtkFontDialog,
562            _param_spec: glib::ffi::gpointer,
563            f: glib::ffi::gpointer,
564        ) {
565            unsafe {
566                let f: &F = &*(f as *const F);
567                f(&from_glib_borrow(this))
568            }
569        }
570        unsafe {
571            let f: Box_<F> = Box_::new(f);
572            connect_raw(
573                self.as_ptr() as *mut _,
574                c"notify::language".as_ptr() as *const _,
575                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
576                    notify_language_trampoline::<F> as *const (),
577                )),
578                Box_::into_raw(f),
579            )
580        }
581    }
582
583    #[cfg(feature = "v4_10")]
584    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
585    #[doc(alias = "modal")]
586    pub fn connect_modal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
587        unsafe extern "C" fn notify_modal_trampoline<F: Fn(&FontDialog) + 'static>(
588            this: *mut ffi::GtkFontDialog,
589            _param_spec: glib::ffi::gpointer,
590            f: glib::ffi::gpointer,
591        ) {
592            unsafe {
593                let f: &F = &*(f as *const F);
594                f(&from_glib_borrow(this))
595            }
596        }
597        unsafe {
598            let f: Box_<F> = Box_::new(f);
599            connect_raw(
600                self.as_ptr() as *mut _,
601                c"notify::modal".as_ptr() as *const _,
602                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
603                    notify_modal_trampoline::<F> as *const (),
604                )),
605                Box_::into_raw(f),
606            )
607        }
608    }
609
610    #[cfg(feature = "v4_10")]
611    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
612    #[doc(alias = "title")]
613    pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
614        unsafe extern "C" fn notify_title_trampoline<F: Fn(&FontDialog) + 'static>(
615            this: *mut ffi::GtkFontDialog,
616            _param_spec: glib::ffi::gpointer,
617            f: glib::ffi::gpointer,
618        ) {
619            unsafe {
620                let f: &F = &*(f as *const F);
621                f(&from_glib_borrow(this))
622            }
623        }
624        unsafe {
625            let f: Box_<F> = Box_::new(f);
626            connect_raw(
627                self.as_ptr() as *mut _,
628                c"notify::title".as_ptr() as *const _,
629                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
630                    notify_title_trampoline::<F> as *const (),
631                )),
632                Box_::into_raw(f),
633            )
634        }
635    }
636}
637
638#[cfg(feature = "v4_10")]
639#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
640impl Default for FontDialog {
641    fn default() -> Self {
642        Self::new()
643    }
644}
645
646// rustdoc-stripper-ignore-next
647/// A [builder-pattern] type to construct [`FontDialog`] objects.
648///
649/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
650#[must_use = "The builder must be built to be used"]
651pub struct FontDialogBuilder {
652    builder: glib::object::ObjectBuilder<'static, FontDialog>,
653}
654
655impl FontDialogBuilder {
656    fn new() -> Self {
657        Self {
658            builder: glib::object::Object::builder(),
659        }
660    }
661
662    /// A filter to restrict what fonts are shown in the font chooser dialog.
663    #[cfg(feature = "v4_10")]
664    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
665    pub fn filter(self, filter: &impl IsA<Filter>) -> Self {
666        Self {
667            builder: self.builder.property("filter", filter.clone().upcast()),
668        }
669    }
670
671    /// A custom font map to select fonts from.
672    ///
673    /// A custom font map can be used to present application-specific
674    /// fonts instead of or in addition to the normal system fonts.
675    #[cfg(feature = "v4_10")]
676    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
677    pub fn font_map(self, font_map: &impl IsA<pango::FontMap>) -> Self {
678        Self {
679            builder: self.builder.property("font-map", font_map.clone().upcast()),
680        }
681    }
682
683    /// The language for which the font features are selected.
684    #[cfg(feature = "v4_10")]
685    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
686    pub fn language(self, language: &pango::Language) -> Self {
687        Self {
688            builder: self.builder.property("language", language),
689        }
690    }
691
692    /// Whether the font chooser dialog is modal.
693    #[cfg(feature = "v4_10")]
694    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
695    pub fn modal(self, modal: bool) -> Self {
696        Self {
697            builder: self.builder.property("modal", modal),
698        }
699    }
700
701    /// A title that may be shown on the font chooser
702    /// dialog that is presented by [`FontDialog::choose_font()`][crate::FontDialog::choose_font()].
703    #[cfg(feature = "v4_10")]
704    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
705    pub fn title(self, title: impl Into<glib::GString>) -> Self {
706        Self {
707            builder: self.builder.property("title", title.into()),
708        }
709    }
710
711    // rustdoc-stripper-ignore-next
712    /// Build the [`FontDialog`].
713    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
714    pub fn build(self) -> FontDialog {
715        assert_initialized_main_thread!();
716        self.builder.build()
717    }
718}