Skip to main content

pango/auto/
layout.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
5#[cfg(feature = "v1_46")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
7use crate::Direction;
8#[cfg(feature = "v1_50")]
9#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
10use crate::LayoutSerializeFlags;
11use crate::{
12    Alignment, AttrList, Context, EllipsizeMode, FontDescription, LayoutIter, LayoutLine,
13    Rectangle, TabArray, WrapMode, ffi,
14};
15use glib::translate::*;
16
17glib::wrapper! {
18    ///
19    ///
20    /// The following images demonstrate the effect of alignment and
21    /// justification on the layout of text:
22    ///
23    /// | | |
24    /// | --- | --- |
25    /// | ![align=left](align-left.png) | ![align=left, justify](align-left-justify.png) |
26    /// | ![align=center](align-center.png) | ![align=center, justify](align-center-justify.png) |
27    /// | ![align=right](align-right.png) | ![align=right, justify](align-right-justify.png) |
28    ///
29    ///
30    /// It is possible, as well, to ignore the 2-D setup,
31    /// and simply treat the results of a [`Layout`][crate::Layout] as a list of lines.
32    #[doc(alias = "PangoLayout")]
33    pub struct Layout(Object<ffi::PangoLayout, ffi::PangoLayoutClass>);
34
35    match fn {
36        type_ => || ffi::pango_layout_get_type(),
37    }
38}
39
40impl Layout {
41    /// Create a new [`Layout`][crate::Layout] object with attributes initialized to
42    /// default values for a particular [`Context`][crate::Context].
43    /// ## `context`
44    /// a [`Context`][crate::Context]
45    ///
46    /// # Returns
47    ///
48    /// the newly allocated [`Layout`][crate::Layout]
49    #[doc(alias = "pango_layout_new")]
50    pub fn new(context: &Context) -> Layout {
51        unsafe { from_glib_full(ffi::pango_layout_new(context.to_glib_none().0)) }
52    }
53
54    /// Forces recomputation of any state in the [`Layout`][crate::Layout] that
55    /// might depend on the layout's context.
56    ///
57    /// This function should be called if you make changes to the context
58    /// subsequent to creating the layout.
59    #[doc(alias = "pango_layout_context_changed")]
60    pub fn context_changed(&self) {
61        unsafe {
62            ffi::pango_layout_context_changed(self.to_glib_none().0);
63        }
64    }
65
66    #[doc(alias = "pango_layout_copy")]
67    #[must_use]
68    pub fn copy(&self) -> Layout {
69        unsafe { from_glib_full(ffi::pango_layout_copy(self.to_glib_none().0)) }
70    }
71
72    /// Gets the alignment for the layout: how partial lines are
73    /// positioned within the horizontal space available.
74    ///
75    /// # Returns
76    ///
77    /// the alignment
78    #[doc(alias = "pango_layout_get_alignment")]
79    #[doc(alias = "get_alignment")]
80    pub fn alignment(&self) -> Alignment {
81        unsafe { from_glib(ffi::pango_layout_get_alignment(self.to_glib_none().0)) }
82    }
83
84    /// Gets the attribute list for the layout, if any.
85    ///
86    /// # Returns
87    ///
88    /// a [`AttrList`][crate::AttrList]
89    #[doc(alias = "pango_layout_get_attributes")]
90    #[doc(alias = "get_attributes")]
91    pub fn attributes(&self) -> Option<AttrList> {
92        unsafe { from_glib_none(ffi::pango_layout_get_attributes(self.to_glib_none().0)) }
93    }
94
95    /// Gets whether to calculate the base direction for the layout
96    /// according to its contents.
97    ///
98    /// See [`set_auto_dir()`][Self::set_auto_dir()].
99    ///
100    /// # Returns
101    ///
102    /// [`true`] if the bidirectional base direction
103    ///   is computed from the layout's contents, [`false`] otherwise
104    #[doc(alias = "pango_layout_get_auto_dir")]
105    #[doc(alias = "get_auto_dir")]
106    pub fn is_auto_dir(&self) -> bool {
107        unsafe { from_glib(ffi::pango_layout_get_auto_dir(self.to_glib_none().0)) }
108    }
109
110    /// Gets the Y position of baseline of the first line in @self.
111    ///
112    /// # Returns
113    ///
114    /// baseline of first line, from top of @self
115    #[doc(alias = "pango_layout_get_baseline")]
116    #[doc(alias = "get_baseline")]
117    pub fn baseline(&self) -> i32 {
118        unsafe { ffi::pango_layout_get_baseline(self.to_glib_none().0) }
119    }
120
121    /// /picture
122    /// ## `index_`
123    /// the byte index of the cursor
124    ///
125    /// # Returns
126    ///
127    ///
128    /// ## `strong_pos`
129    /// location to store the strong cursor position
130    ///
131    /// ## `weak_pos`
132    /// location to store the weak cursor position
133    #[cfg(feature = "v1_50")]
134    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
135    #[doc(alias = "pango_layout_get_caret_pos")]
136    #[doc(alias = "get_caret_pos")]
137    pub fn caret_pos(&self, index_: i32) -> (Rectangle, Rectangle) {
138        unsafe {
139            let mut strong_pos = Rectangle::uninitialized();
140            let mut weak_pos = Rectangle::uninitialized();
141            ffi::pango_layout_get_caret_pos(
142                self.to_glib_none().0,
143                index_,
144                strong_pos.to_glib_none_mut().0,
145                weak_pos.to_glib_none_mut().0,
146            );
147            (strong_pos, weak_pos)
148        }
149    }
150
151    /// Returns the number of Unicode characters in the
152    /// the text of @self.
153    ///
154    /// # Returns
155    ///
156    /// the number of Unicode characters
157    ///   in the text of @self
158    #[doc(alias = "pango_layout_get_character_count")]
159    #[doc(alias = "get_character_count")]
160    pub fn character_count(&self) -> i32 {
161        unsafe { ffi::pango_layout_get_character_count(self.to_glib_none().0) }
162    }
163
164    /// Retrieves the [`Context`][crate::Context] used for this layout.
165    ///
166    /// # Returns
167    ///
168    /// the [`Context`][crate::Context] for the layout
169    #[doc(alias = "pango_layout_get_context")]
170    #[doc(alias = "get_context")]
171    pub fn context(&self) -> Context {
172        unsafe { from_glib_none(ffi::pango_layout_get_context(self.to_glib_none().0)) }
173    }
174
175    /// ',
176    /// will insert it at the end.
177    /// ## `index_`
178    /// the byte index of the cursor
179    ///
180    /// # Returns
181    ///
182    ///
183    /// ## `strong_pos`
184    /// location to store the strong cursor position
185    ///
186    /// ## `weak_pos`
187    /// location to store the weak cursor position
188    #[doc(alias = "pango_layout_get_cursor_pos")]
189    #[doc(alias = "get_cursor_pos")]
190    pub fn cursor_pos(&self, index_: i32) -> (Rectangle, Rectangle) {
191        unsafe {
192            let mut strong_pos = Rectangle::uninitialized();
193            let mut weak_pos = Rectangle::uninitialized();
194            ffi::pango_layout_get_cursor_pos(
195                self.to_glib_none().0,
196                index_,
197                strong_pos.to_glib_none_mut().0,
198                weak_pos.to_glib_none_mut().0,
199            );
200            (strong_pos, weak_pos)
201        }
202    }
203
204    /// Gets the text direction at the given character position in @self.
205    /// ## `index`
206    /// the byte index of the char
207    ///
208    /// # Returns
209    ///
210    /// the text direction at @index
211    #[cfg(feature = "v1_46")]
212    #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
213    #[doc(alias = "pango_layout_get_direction")]
214    #[doc(alias = "get_direction")]
215    pub fn direction(&self, index: i32) -> Direction {
216        unsafe {
217            from_glib(ffi::pango_layout_get_direction(
218                self.to_glib_none().0,
219                index,
220            ))
221        }
222    }
223
224    /// Gets the type of ellipsization being performed for @self.
225    ///
226    /// See [`set_ellipsize()`][Self::set_ellipsize()].
227    ///
228    /// Use [`is_ellipsized()`][Self::is_ellipsized()] to query whether any
229    /// paragraphs were actually ellipsized.
230    ///
231    /// # Returns
232    ///
233    /// the current ellipsization mode for @self
234    #[doc(alias = "pango_layout_get_ellipsize")]
235    #[doc(alias = "get_ellipsize")]
236    pub fn ellipsize(&self) -> EllipsizeMode {
237        unsafe { from_glib(ffi::pango_layout_get_ellipsize(self.to_glib_none().0)) }
238    }
239
240    /// Computes the logical and ink extents of @self.
241    ///
242    /// Logical extents are usually what you want for positioning things. Note
243    /// that both extents may have non-zero x and y. You may want to use those
244    /// to offset where you render the layout. Not doing that is a very typical
245    /// bug that shows up as right-to-left layouts not being correctly positioned
246    /// in a layout with a set width.
247    ///
248    /// The extents are given in layout coordinates and in Pango units; layout
249    /// coordinates begin at the top left corner of the layout.
250    ///
251    /// # Returns
252    ///
253    ///
254    /// ## `ink_rect`
255    /// rectangle used to store the extents of the
256    ///   layout as drawn
257    ///
258    /// ## `logical_rect`
259    /// rectangle used to store the logical
260    ///   extents of the layout
261    #[doc(alias = "pango_layout_get_extents")]
262    #[doc(alias = "get_extents")]
263    pub fn extents(&self) -> (Rectangle, Rectangle) {
264        unsafe {
265            let mut ink_rect = Rectangle::uninitialized();
266            let mut logical_rect = Rectangle::uninitialized();
267            ffi::pango_layout_get_extents(
268                self.to_glib_none().0,
269                ink_rect.to_glib_none_mut().0,
270                logical_rect.to_glib_none_mut().0,
271            );
272            (ink_rect, logical_rect)
273        }
274    }
275
276    /// Gets the font description for the layout, if any.
277    ///
278    /// # Returns
279    ///
280    /// a pointer to the
281    ///   layout's font description, or [`None`] if the font description
282    ///   from the layout's context is inherited.
283    #[doc(alias = "pango_layout_get_font_description")]
284    #[doc(alias = "get_font_description")]
285    pub fn font_description(&self) -> Option<FontDescription> {
286        unsafe {
287            from_glib_none(ffi::pango_layout_get_font_description(
288                self.to_glib_none().0,
289            ))
290        }
291    }
292
293    /// Gets the height of layout used for ellipsization.
294    ///
295    /// See [`set_height()`][Self::set_height()] for details.
296    ///
297    /// # Returns
298    ///
299    /// the height, in Pango units if positive,
300    ///   or number of lines if negative.
301    #[doc(alias = "pango_layout_get_height")]
302    #[doc(alias = "get_height")]
303    pub fn height(&self) -> i32 {
304        unsafe { ffi::pango_layout_get_height(self.to_glib_none().0) }
305    }
306
307    /// Gets the paragraph indent width in Pango units.
308    ///
309    /// A negative value indicates a hanging indentation.
310    ///
311    /// # Returns
312    ///
313    /// the indent in Pango units
314    #[doc(alias = "pango_layout_get_indent")]
315    #[doc(alias = "get_indent")]
316    pub fn indent(&self) -> i32 {
317        unsafe { ffi::pango_layout_get_indent(self.to_glib_none().0) }
318    }
319
320    /// Returns an iterator to iterate over the visual extents of the layout.
321    ///
322    /// # Returns
323    ///
324    /// the new [`LayoutIter`][crate::LayoutIter]
325    #[doc(alias = "pango_layout_get_iter")]
326    #[doc(alias = "get_iter")]
327    pub fn iter(&self) -> LayoutIter {
328        unsafe { from_glib_full(ffi::pango_layout_get_iter(self.to_glib_none().0)) }
329    }
330
331    /// Gets whether each complete line should be stretched to fill the entire
332    /// width of the layout.
333    ///
334    /// # Returns
335    ///
336    /// the justify value
337    #[doc(alias = "pango_layout_get_justify")]
338    #[doc(alias = "get_justify")]
339    pub fn is_justify(&self) -> bool {
340        unsafe { from_glib(ffi::pango_layout_get_justify(self.to_glib_none().0)) }
341    }
342
343    /// Gets whether the last line should be stretched
344    /// to fill the entire width of the layout.
345    ///
346    /// # Returns
347    ///
348    /// the justify value
349    #[cfg(feature = "v1_50")]
350    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
351    #[doc(alias = "pango_layout_get_justify_last_line")]
352    #[doc(alias = "get_justify_last_line")]
353    pub fn is_justify_last_line(&self) -> bool {
354        unsafe {
355            from_glib(ffi::pango_layout_get_justify_last_line(
356                self.to_glib_none().0,
357            ))
358        }
359    }
360
361    /// Retrieves a particular line from a [`Layout`][crate::Layout].
362    ///
363    /// Use the faster [`line_readonly()`][Self::line_readonly()] if you do not
364    /// plan to modify the contents of the line (glyphs, glyph widths, etc.).
365    /// ## `line`
366    /// the index of a line, which must be between 0 and
367    ///   `pango_layout_get_line_count(layout) - 1`, inclusive.
368    ///
369    /// # Returns
370    ///
371    /// the requested [`LayoutLine`][crate::LayoutLine],
372    ///   or [`None`] if the index is out of range. This layout line can be ref'ed
373    ///   and retained, but will become invalid if changes are made to the
374    ///   [`Layout`][crate::Layout].
375    #[doc(alias = "pango_layout_get_line")]
376    #[doc(alias = "get_line")]
377    pub fn line(&self, line: i32) -> Option<LayoutLine> {
378        unsafe { from_glib_none(ffi::pango_layout_get_line(self.to_glib_none().0, line)) }
379    }
380
381    /// Retrieves the count of lines for the @self.
382    ///
383    /// # Returns
384    ///
385    /// the line count
386    #[doc(alias = "pango_layout_get_line_count")]
387    #[doc(alias = "get_line_count")]
388    pub fn line_count(&self) -> i32 {
389        unsafe { ffi::pango_layout_get_line_count(self.to_glib_none().0) }
390    }
391
392    /// Retrieves a particular line from a [`Layout`][crate::Layout].
393    ///
394    /// This is a faster alternative to [`line()`][Self::line()],
395    /// but the user is not expected to modify the contents of the line
396    /// (glyphs, glyph widths, etc.).
397    /// ## `line`
398    /// the index of a line, which must be between 0 and
399    ///   `pango_layout_get_line_count(layout) - 1`, inclusive.
400    ///
401    /// # Returns
402    ///
403    /// the requested [`LayoutLine`][crate::LayoutLine],
404    ///   or [`None`] if the index is out of range. This layout line can be ref'ed
405    ///   and retained, but will become invalid if changes are made to the
406    ///   [`Layout`][crate::Layout]. No changes should be made to the line.
407    #[doc(alias = "pango_layout_get_line_readonly")]
408    #[doc(alias = "get_line_readonly")]
409    pub fn line_readonly(&self, line: i32) -> Option<LayoutLine> {
410        unsafe {
411            from_glib_none(ffi::pango_layout_get_line_readonly(
412                self.to_glib_none().0,
413                line,
414            ))
415        }
416    }
417
418    /// Gets the line spacing factor of @self.
419    ///
420    /// See [`set_line_spacing()`][Self::set_line_spacing()].
421    #[cfg(feature = "v1_44")]
422    #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
423    #[doc(alias = "pango_layout_get_line_spacing")]
424    #[doc(alias = "get_line_spacing")]
425    pub fn line_spacing(&self) -> f32 {
426        unsafe { ffi::pango_layout_get_line_spacing(self.to_glib_none().0) }
427    }
428
429    /// Returns the lines of the @self as a list.
430    ///
431    /// Use the faster [`lines_readonly()`][Self::lines_readonly()] if you do not
432    /// plan to modify the contents of the lines (glyphs, glyph widths, etc.).
433    ///
434    /// # Returns
435    ///
436    /// a `GSList`
437    ///   containing the lines in the layout. This points to internal data of the
438    ///   [`Layout`][crate::Layout] and must be used with care. It will become invalid on any
439    ///   change to the layout's text or properties.
440    #[doc(alias = "pango_layout_get_lines")]
441    #[doc(alias = "get_lines")]
442    pub fn lines(&self) -> Vec<LayoutLine> {
443        unsafe {
444            FromGlibPtrContainer::from_glib_none(ffi::pango_layout_get_lines(self.to_glib_none().0))
445        }
446    }
447
448    /// Returns the lines of the @self as a list.
449    ///
450    /// This is a faster alternative to [`lines()`][Self::lines()],
451    /// but the user is not expected to modify the contents of the lines
452    /// (glyphs, glyph widths, etc.).
453    ///
454    /// # Returns
455    ///
456    /// a `GSList`
457    ///   containing the lines in the layout. This points to internal data of the
458    ///   [`Layout`][crate::Layout] and must be used with care. It will become invalid on any
459    ///   change to the layout's text or properties. No changes should be made to
460    ///   the lines.
461    #[doc(alias = "pango_layout_get_lines_readonly")]
462    #[doc(alias = "get_lines_readonly")]
463    pub fn lines_readonly(&self) -> Vec<LayoutLine> {
464        unsafe {
465            FromGlibPtrContainer::from_glib_none(ffi::pango_layout_get_lines_readonly(
466                self.to_glib_none().0,
467            ))
468        }
469    }
470
471    //#[doc(alias = "pango_layout_get_log_attrs")]
472    //#[doc(alias = "get_log_attrs")]
473    //pub fn log_attrs(&self, attrs: /*Ignored*/Vec<LogAttr>) -> i32 {
474    //    unsafe { TODO: call ffi:pango_layout_get_log_attrs() }
475    //}
476
477    //#[doc(alias = "pango_layout_get_log_attrs_readonly")]
478    //#[doc(alias = "get_log_attrs_readonly")]
479    //pub fn log_attrs_readonly(&self) -> /*Ignored*/Vec<LogAttr> {
480    //    unsafe { TODO: call ffi:pango_layout_get_log_attrs_readonly() }
481    //}
482
483    /// Computes the logical and ink extents of @self in device units.
484    ///
485    /// This function just calls [`extents()`][Self::extents()] followed by
486    /// two [`extents_to_pixels()`][crate::extents_to_pixels()] calls, rounding @ink_rect and @logical_rect
487    /// such that the rounded rectangles fully contain the unrounded one (that is,
488    /// passes them as first argument to [`extents_to_pixels()`][crate::extents_to_pixels()]).
489    ///
490    /// # Returns
491    ///
492    ///
493    /// ## `ink_rect`
494    /// rectangle used to store the extents of the
495    ///   layout as drawn
496    ///
497    /// ## `logical_rect`
498    /// rectangle used to store the logical
499    ///   extents of the layout
500    #[doc(alias = "pango_layout_get_pixel_extents")]
501    #[doc(alias = "get_pixel_extents")]
502    pub fn pixel_extents(&self) -> (Rectangle, Rectangle) {
503        unsafe {
504            let mut ink_rect = Rectangle::uninitialized();
505            let mut logical_rect = Rectangle::uninitialized();
506            ffi::pango_layout_get_pixel_extents(
507                self.to_glib_none().0,
508                ink_rect.to_glib_none_mut().0,
509                logical_rect.to_glib_none_mut().0,
510            );
511            (ink_rect, logical_rect)
512        }
513    }
514
515    /// Determines the logical width and height of a [`Layout`][crate::Layout] in device
516    /// units.
517    ///
518    /// [`size()`][Self::size()] returns the width and height
519    /// scaled by `PANGO_SCALE`. This is simply a convenience function
520    /// around [`pixel_extents()`][Self::pixel_extents()].
521    ///
522    /// # Returns
523    ///
524    ///
525    /// ## `width`
526    /// location to store the logical width
527    ///
528    /// ## `height`
529    /// location to store the logical height
530    #[doc(alias = "pango_layout_get_pixel_size")]
531    #[doc(alias = "get_pixel_size")]
532    pub fn pixel_size(&self) -> (i32, i32) {
533        unsafe {
534            let mut width = std::mem::MaybeUninit::uninit();
535            let mut height = std::mem::MaybeUninit::uninit();
536            ffi::pango_layout_get_pixel_size(
537                self.to_glib_none().0,
538                width.as_mut_ptr(),
539                height.as_mut_ptr(),
540            );
541            (width.assume_init(), height.assume_init())
542        }
543    }
544
545    /// Returns the current serial number of @self.
546    ///
547    /// The serial number is initialized to an small number larger than zero
548    /// when a new layout is created and is increased whenever the layout is
549    /// changed using any of the setter functions, or the [`Context`][crate::Context] it
550    /// uses has changed. The serial may wrap, but will never have the value 0.
551    /// Since it can wrap, never compare it with "less than", always use "not equals".
552    ///
553    /// This can be used to automatically detect changes to a [`Layout`][crate::Layout],
554    /// and is useful for example to decide whether a layout needs redrawing.
555    /// To force the serial to be increased, use
556    /// [`context_changed()`][Self::context_changed()].
557    ///
558    /// # Returns
559    ///
560    /// The current serial number of @self.
561    #[doc(alias = "pango_layout_get_serial")]
562    #[doc(alias = "get_serial")]
563    pub fn serial(&self) -> u32 {
564        unsafe { ffi::pango_layout_get_serial(self.to_glib_none().0) }
565    }
566
567    /// Obtains whether @self is in single paragraph mode.
568    ///
569    /// See [`set_single_paragraph_mode()`][Self::set_single_paragraph_mode()].
570    ///
571    /// # Returns
572    ///
573    /// [`true`] if the layout does not break paragraphs
574    ///   at paragraph separator characters, [`false`] otherwise
575    #[doc(alias = "pango_layout_get_single_paragraph_mode")]
576    #[doc(alias = "get_single_paragraph_mode")]
577    pub fn is_single_paragraph_mode(&self) -> bool {
578        unsafe {
579            from_glib(ffi::pango_layout_get_single_paragraph_mode(
580                self.to_glib_none().0,
581            ))
582        }
583    }
584
585    /// Determines the logical width and height of a [`Layout`][crate::Layout] in Pango
586    /// units.
587    ///
588    /// This is simply a convenience function around [`extents()`][Self::extents()].
589    ///
590    /// # Returns
591    ///
592    ///
593    /// ## `width`
594    /// location to store the logical width
595    ///
596    /// ## `height`
597    /// location to store the logical height
598    #[doc(alias = "pango_layout_get_size")]
599    #[doc(alias = "get_size")]
600    pub fn size(&self) -> (i32, i32) {
601        unsafe {
602            let mut width = std::mem::MaybeUninit::uninit();
603            let mut height = std::mem::MaybeUninit::uninit();
604            ffi::pango_layout_get_size(
605                self.to_glib_none().0,
606                width.as_mut_ptr(),
607                height.as_mut_ptr(),
608            );
609            (width.assume_init(), height.assume_init())
610        }
611    }
612
613    /// Gets the amount of spacing between the lines of the layout.
614    ///
615    /// # Returns
616    ///
617    /// the spacing in Pango units
618    #[doc(alias = "pango_layout_get_spacing")]
619    #[doc(alias = "get_spacing")]
620    pub fn spacing(&self) -> i32 {
621        unsafe { ffi::pango_layout_get_spacing(self.to_glib_none().0) }
622    }
623
624    /// Gets the current [`TabArray`][crate::TabArray] used by this layout.
625    ///
626    /// If no [`TabArray`][crate::TabArray] has been set, then the default tabs are
627    /// in use and [`None`] is returned. Default tabs are every 8 spaces.
628    ///
629    /// The return value should be freed with `Pango::TabArray::free()`.
630    ///
631    /// # Returns
632    ///
633    /// a copy of the tabs for this layout
634    #[doc(alias = "pango_layout_get_tabs")]
635    #[doc(alias = "get_tabs")]
636    pub fn tabs(&self) -> Option<TabArray> {
637        unsafe { from_glib_full(ffi::pango_layout_get_tabs(self.to_glib_none().0)) }
638    }
639
640    /// Gets the text in the layout.
641    ///
642    /// The returned text should not be freed or modified.
643    ///
644    /// # Returns
645    ///
646    /// the text in the @self
647    #[doc(alias = "pango_layout_get_text")]
648    #[doc(alias = "get_text")]
649    pub fn text(&self) -> glib::GString {
650        unsafe { from_glib_none(ffi::pango_layout_get_text(self.to_glib_none().0)) }
651    }
652
653    /// Counts the number of unknown glyphs in @self.
654    ///
655    /// This function can be used to determine if there are any fonts
656    /// available to render all characters in a certain string, or when
657    /// used in combination with [`AttrType::Fallback`][crate::AttrType::Fallback], to check if a
658    /// certain font supports all the characters in the string.
659    ///
660    /// # Returns
661    ///
662    /// The number of unknown glyphs in @self
663    #[doc(alias = "pango_layout_get_unknown_glyphs_count")]
664    #[doc(alias = "get_unknown_glyphs_count")]
665    pub fn unknown_glyphs_count(&self) -> i32 {
666        unsafe { ffi::pango_layout_get_unknown_glyphs_count(self.to_glib_none().0) }
667    }
668
669    /// Gets the width to which the lines of the [`Layout`][crate::Layout] should wrap.
670    ///
671    /// # Returns
672    ///
673    /// the width in Pango units, or -1 if no width set.
674    #[doc(alias = "pango_layout_get_width")]
675    #[doc(alias = "get_width")]
676    pub fn width(&self) -> i32 {
677        unsafe { ffi::pango_layout_get_width(self.to_glib_none().0) }
678    }
679
680    /// Gets the wrap mode for the layout.
681    ///
682    /// Use [`is_wrapped()`][Self::is_wrapped()] to query whether
683    /// any paragraphs were actually wrapped.
684    ///
685    /// # Returns
686    ///
687    /// active wrap mode.
688    #[doc(alias = "pango_layout_get_wrap")]
689    #[doc(alias = "get_wrap")]
690    pub fn wrap(&self) -> WrapMode {
691        unsafe { from_glib(ffi::pango_layout_get_wrap(self.to_glib_none().0)) }
692    }
693
694    /// Converts from byte @index_ within the @self to line and X position.
695    ///
696    /// The X position is measured from the left edge of the line.
697    /// ## `index_`
698    /// the byte index of a grapheme within the layout
699    /// ## `trailing`
700    ///  0, the trailing edge of the grapheme, if 0,
701    ///   the leading of the grapheme
702    ///
703    /// # Returns
704    ///
705    ///
706    /// ## `line`
707    /// location to store resulting line index. (which will
708    ///   between 0 and pango_layout_get_line_count(layout) - 1)
709    ///
710    /// ## `x_pos`
711    /// location to store resulting position within line
712    ///   (`PANGO_SCALE` units per device unit)
713    #[doc(alias = "pango_layout_index_to_line_x")]
714    pub fn index_to_line_x(&self, index_: i32, trailing: bool) -> (i32, i32) {
715        unsafe {
716            let mut line = std::mem::MaybeUninit::uninit();
717            let mut x_pos = std::mem::MaybeUninit::uninit();
718            ffi::pango_layout_index_to_line_x(
719                self.to_glib_none().0,
720                index_,
721                trailing.into_glib(),
722                line.as_mut_ptr(),
723                x_pos.as_mut_ptr(),
724            );
725            (line.assume_init(), x_pos.assume_init())
726        }
727    }
728
729    /// width` will be negative.
730    /// ## `index_`
731    /// byte index within @self
732    ///
733    /// # Returns
734    ///
735    ///
736    /// ## `pos`
737    /// rectangle in which to store the position of the grapheme
738    #[doc(alias = "pango_layout_index_to_pos")]
739    pub fn index_to_pos(&self, index_: i32) -> Rectangle {
740        unsafe {
741            let mut pos = Rectangle::uninitialized();
742            ffi::pango_layout_index_to_pos(self.to_glib_none().0, index_, pos.to_glib_none_mut().0);
743            pos
744        }
745    }
746
747    /// Queries whether the layout had to ellipsize any paragraphs.
748    ///
749    /// This returns [`true`] if the ellipsization mode for @self
750    /// is not [`EllipsizeMode::None`][crate::EllipsizeMode::None], a positive width is set on @self,
751    /// and there are paragraphs exceeding that width that have to be
752    /// ellipsized.
753    ///
754    /// # Returns
755    ///
756    /// [`true`] if any paragraphs had to be ellipsized,
757    ///   [`false`] otherwise
758    #[doc(alias = "pango_layout_is_ellipsized")]
759    pub fn is_ellipsized(&self) -> bool {
760        unsafe { from_glib(ffi::pango_layout_is_ellipsized(self.to_glib_none().0)) }
761    }
762
763    /// Queries whether the layout had to wrap any paragraphs.
764    ///
765    /// This returns [`true`] if a positive width is set on @self,
766    /// and there are paragraphs exceeding the layout width that have
767    /// to be wrapped.
768    ///
769    /// # Returns
770    ///
771    /// [`true`] if any paragraphs had to be wrapped, [`false`]
772    ///   otherwise
773    #[doc(alias = "pango_layout_is_wrapped")]
774    pub fn is_wrapped(&self) -> bool {
775        unsafe { from_glib(ffi::pango_layout_is_wrapped(self.to_glib_none().0)) }
776    }
777
778    /// Computes a new cursor position from an old position and a direction.
779    ///
780    /// If @direction is positive, then the new position will cause the strong
781    /// or weak cursor to be displayed one position to right of where it was
782    /// with the old cursor position. If @direction is negative, it will be
783    /// moved to the left.
784    ///
785    /// In the presence of bidirectional text, the correspondence between
786    /// logical and visual order will depend on the direction of the current
787    /// run, and there may be jumps when the cursor is moved off of the end
788    /// of a run.
789    ///
790    /// Motion here is in cursor positions, not in characters, so a single
791    /// call to this function may move the cursor over multiple characters
792    /// when multiple characters combine to form a single grapheme.
793    /// ## `strong`
794    /// whether the moving cursor is the strong cursor or the
795    ///   weak cursor. The strong cursor is the cursor corresponding
796    ///   to text insertion in the base direction for the layout.
797    /// ## `old_index`
798    /// the byte index of the current cursor position
799    /// ## `old_trailing`
800    ///  0, the cursor
801    ///   was at the trailing edge.
802    /// ## `direction`
803    /// direction to move cursor. A negative
804    ///   value indicates motion to the left
805    ///
806    /// # Returns
807    ///
808    ///
809    /// ## `new_index`
810    /// location to store the new cursor byte index.
811    ///   A value of -1 indicates that the cursor has been moved off the
812    ///   beginning of the layout. A value of `G_MAXINT` indicates that
813    ///   the cursor has been moved off the end of the layout.
814    ///
815    /// ## `new_trailing`
816    /// number of characters to move forward from
817    ///   the location returned for @new_index to get the position where
818    ///   the cursor should be displayed. This allows distinguishing the
819    ///   position at the beginning of one line from the position at the
820    ///   end of the preceding line. @new_index is always on the line where
821    ///   the cursor should be displayed.
822    #[doc(alias = "pango_layout_move_cursor_visually")]
823    pub fn move_cursor_visually(
824        &self,
825        strong: bool,
826        old_index: i32,
827        old_trailing: i32,
828        direction: i32,
829    ) -> (i32, i32) {
830        unsafe {
831            let mut new_index = std::mem::MaybeUninit::uninit();
832            let mut new_trailing = std::mem::MaybeUninit::uninit();
833            ffi::pango_layout_move_cursor_visually(
834                self.to_glib_none().0,
835                strong.into_glib(),
836                old_index,
837                old_trailing,
838                direction,
839                new_index.as_mut_ptr(),
840                new_trailing.as_mut_ptr(),
841            );
842            (new_index.assume_init(), new_trailing.assume_init())
843        }
844    }
845
846    /// Serializes the @self for later deserialization via `Pango::Layout::deserialize()`.
847    ///
848    /// There are no guarantees about the format of the output across different
849    /// versions of Pango and `Pango::Layout::deserialize()` will reject data
850    /// that it cannot parse.
851    ///
852    /// The intended use of this function is testing, benchmarking and debugging.
853    /// The format is not meant as a permanent storage format.
854    /// ## `flags`
855    /// [`LayoutSerializeFlags`][crate::LayoutSerializeFlags]
856    ///
857    /// # Returns
858    ///
859    /// a `GBytes` containing the serialized form of @self
860    #[cfg(feature = "v1_50")]
861    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
862    #[doc(alias = "pango_layout_serialize")]
863    pub fn serialize(&self, flags: LayoutSerializeFlags) -> glib::Bytes {
864        unsafe {
865            from_glib_full(ffi::pango_layout_serialize(
866                self.to_glib_none().0,
867                flags.into_glib(),
868            ))
869        }
870    }
871
872    /// Sets the alignment for the layout: how partial lines are
873    /// positioned within the horizontal space available.
874    ///
875    /// The default alignment is [`Alignment::Left`][crate::Alignment::Left].
876    /// ## `alignment`
877    /// the alignment
878    #[doc(alias = "pango_layout_set_alignment")]
879    pub fn set_alignment(&self, alignment: Alignment) {
880        unsafe {
881            ffi::pango_layout_set_alignment(self.to_glib_none().0, alignment.into_glib());
882        }
883    }
884
885    /// Sets the text attributes for a layout object.
886    ///
887    /// References @attrs, so the caller can unref its reference.
888    /// ## `attrs`
889    /// a [`AttrList`][crate::AttrList]
890    #[doc(alias = "pango_layout_set_attributes")]
891    pub fn set_attributes(&self, attrs: Option<&AttrList>) {
892        unsafe {
893            ffi::pango_layout_set_attributes(self.to_glib_none().0, attrs.to_glib_none().0);
894        }
895    }
896
897    /// Sets whether to calculate the base direction
898    /// for the layout according to its contents.
899    ///
900    /// When this flag is on (the default), then paragraphs in @self that
901    /// begin with strong right-to-left characters (Arabic and Hebrew principally),
902    /// will have right-to-left layout, paragraphs with letters from other scripts
903    /// will have left-to-right layout. Paragraphs with only neutral characters
904    /// get their direction from the surrounding paragraphs.
905    ///
906    /// When [`false`], the choice between left-to-right and right-to-left
907    /// layout is done according to the base direction of the layout's
908    /// [`Context`][crate::Context]. (See [`Context::set_base_dir()`][crate::Context::set_base_dir()]).
909    ///
910    /// When the auto-computed direction of a paragraph differs from the
911    /// base direction of the context, the interpretation of
912    /// [`Alignment::Left`][crate::Alignment::Left] and [`Alignment::Right`][crate::Alignment::Right] are swapped.
913    /// ## `auto_dir`
914    /// if [`true`], compute the bidirectional base direction
915    ///   from the layout's contents
916    #[doc(alias = "pango_layout_set_auto_dir")]
917    pub fn set_auto_dir(&self, auto_dir: bool) {
918        unsafe {
919            ffi::pango_layout_set_auto_dir(self.to_glib_none().0, auto_dir.into_glib());
920        }
921    }
922
923    /// Sets the type of ellipsization being performed for @self.
924    ///
925    /// Depending on the ellipsization mode @ellipsize text is
926    /// removed from the start, middle, or end of text so they
927    /// fit within the width and height of layout set with
928    /// [`set_width()`][Self::set_width()] and [`set_height()`][Self::set_height()].
929    ///
930    /// If the layout contains characters such as newlines that
931    /// force it to be layed out in multiple paragraphs, then whether
932    /// each paragraph is ellipsized separately or the entire layout
933    /// is ellipsized as a whole depends on the set height of the layout.
934    ///
935    /// The default value is [`EllipsizeMode::None`][crate::EllipsizeMode::None].
936    ///
937    /// See [`set_height()`][Self::set_height()] for details.
938    /// ## `ellipsize`
939    /// the new ellipsization mode for @self
940    #[doc(alias = "pango_layout_set_ellipsize")]
941    pub fn set_ellipsize(&self, ellipsize: EllipsizeMode) {
942        unsafe {
943            ffi::pango_layout_set_ellipsize(self.to_glib_none().0, ellipsize.into_glib());
944        }
945    }
946
947    /// Sets the default font description for the layout.
948    ///
949    /// If no font description is set on the layout, the
950    /// font description from the layout's context is used.
951    /// ## `desc`
952    /// the new [`FontDescription`][crate::FontDescription]
953    ///   to unset the current font description
954    #[doc(alias = "pango_layout_set_font_description")]
955    pub fn set_font_description(&self, desc: Option<&FontDescription>) {
956        unsafe {
957            ffi::pango_layout_set_font_description(self.to_glib_none().0, desc.to_glib_none().0);
958        }
959    }
960
961    /// Sets the height to which the [`Layout`][crate::Layout] should be ellipsized at.
962    ///
963    /// There are two different behaviors, based on whether @height is positive
964    /// or negative.
965    ///
966    /// If @height is positive, it will be the maximum height of the layout. Only
967    /// lines would be shown that would fit, and if there is any text omitted,
968    /// an ellipsis added. At least one line is included in each paragraph regardless
969    /// of how small the height value is. A value of zero will render exactly one
970    /// line for the entire layout.
971    ///
972    /// If @height is negative, it will be the (negative of) maximum number of lines
973    /// per paragraph. That is, the total number of lines shown may well be more than
974    /// this value if the layout contains multiple paragraphs of text.
975    /// The default value of -1 means that the first line of each paragraph is ellipsized.
976    /// This behavior may be changed in the future to act per layout instead of per
977    /// paragraph. File a bug against pango at
978    /// [https://gitlab.gnome.org/gnome/pango](https://gitlab.gnome.org/gnome/pango)
979    /// if your code relies on this behavior.
980    ///
981    /// Height setting only has effect if a positive width is set on
982    /// @self and ellipsization mode of @self is not [`EllipsizeMode::None`][crate::EllipsizeMode::None].
983    /// The behavior is undefined if a height other than -1 is set and
984    /// ellipsization mode is set to [`EllipsizeMode::None`][crate::EllipsizeMode::None], and may change in the
985    /// future.
986    /// ## `height`
987    /// the desired height of the layout in Pango units if positive,
988    ///   or desired number of lines if negative.
989    #[doc(alias = "pango_layout_set_height")]
990    pub fn set_height(&self, height: i32) {
991        unsafe {
992            ffi::pango_layout_set_height(self.to_glib_none().0, height);
993        }
994    }
995
996    /// Sets the width in Pango units to indent each paragraph.
997    ///
998    /// A negative value of @indent will produce a hanging indentation.
999    /// That is, the first line will have the full width, and subsequent
1000    /// lines will be indented by the absolute value of @indent.
1001    ///
1002    /// The indent setting is ignored if layout alignment is set to
1003    /// [`Alignment::Center`][crate::Alignment::Center].
1004    ///
1005    /// The default value is 0.
1006    /// ## `indent`
1007    /// the amount by which to indent
1008    #[doc(alias = "pango_layout_set_indent")]
1009    pub fn set_indent(&self, indent: i32) {
1010        unsafe {
1011            ffi::pango_layout_set_indent(self.to_glib_none().0, indent);
1012        }
1013    }
1014
1015    /// Sets whether each complete line should be stretched to fill the
1016    /// entire width of the layout.
1017    ///
1018    /// Stretching is typically done by adding whitespace, but for some scripts
1019    /// (such as Arabic), the justification may be done in more complex ways,
1020    /// like extending the characters.
1021    ///
1022    /// Note that this setting is not implemented and so is ignored in
1023    /// Pango older than 1.18.
1024    ///
1025    /// Note that tabs and justification conflict with each other:
1026    /// Justification will move content away from its tab-aligned
1027    /// positions.
1028    ///
1029    /// The default value is [`false`].
1030    ///
1031    /// Also see [`set_justify_last_line()`][Self::set_justify_last_line()].
1032    /// ## `justify`
1033    /// whether the lines in the layout should be justified
1034    #[doc(alias = "pango_layout_set_justify")]
1035    pub fn set_justify(&self, justify: bool) {
1036        unsafe {
1037            ffi::pango_layout_set_justify(self.to_glib_none().0, justify.into_glib());
1038        }
1039    }
1040
1041    /// Sets whether the last line should be stretched to fill the
1042    /// entire width of the layout.
1043    ///
1044    /// This only has an effect if [`set_justify()`][Self::set_justify()] has
1045    /// been called as well.
1046    ///
1047    /// The default value is [`false`].
1048    /// ## `justify`
1049    /// whether the last line in the layout should be justified
1050    #[cfg(feature = "v1_50")]
1051    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
1052    #[doc(alias = "pango_layout_set_justify_last_line")]
1053    pub fn set_justify_last_line(&self, justify: bool) {
1054        unsafe {
1055            ffi::pango_layout_set_justify_last_line(self.to_glib_none().0, justify.into_glib());
1056        }
1057    }
1058
1059    /// Sets a factor for line spacing.
1060    ///
1061    /// Typical values are: 0, 1, 1.5, 2. The default values is 0.
1062    ///
1063    /// If @factor is non-zero, lines are placed so that
1064    ///
1065    ///     baseline2 = baseline1 + factor * height2
1066    ///
1067    /// where height2 is the line height of the second line
1068    /// (as determined by the font(s)). In this case, the spacing
1069    /// set with [`set_spacing()`][Self::set_spacing()] is ignored.
1070    ///
1071    /// If @factor is zero (the default), spacing is applied as before.
1072    ///
1073    /// Note: for semantics that are closer to the CSS line-height
1074    /// property, see `attr_line_height_new()`.
1075    /// ## `factor`
1076    /// the new line spacing factor
1077    #[cfg(feature = "v1_44")]
1078    #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
1079    #[doc(alias = "pango_layout_set_line_spacing")]
1080    pub fn set_line_spacing(&self, factor: f32) {
1081        unsafe {
1082            ffi::pango_layout_set_line_spacing(self.to_glib_none().0, factor);
1083        }
1084    }
1085
1086    /// Sets the layout text and attribute list from marked-up text.
1087    ///
1088    /// See [Pango Markup](pango_markup.html)).
1089    ///
1090    /// Replaces the current text and attribute list.
1091    ///
1092    /// This is the same as [`set_markup_with_accel()`][Self::set_markup_with_accel()],
1093    /// but the markup text isn't scanned for accelerators.
1094    /// ## `markup`
1095    /// marked-up text
1096    /// ## `length`
1097    /// length of marked-up text in bytes, or -1 if @markup is
1098    ///   `NUL`-terminated
1099    #[doc(alias = "pango_layout_set_markup")]
1100    pub fn set_markup(&self, markup: &str) {
1101        let length = markup.len() as _;
1102        unsafe {
1103            ffi::pango_layout_set_markup(self.to_glib_none().0, markup.to_glib_none().0, length);
1104        }
1105    }
1106
1107    /// Sets the layout text and attribute list from marked-up text.
1108    ///
1109    /// See [Pango Markup](pango_markup.html)).
1110    ///
1111    /// Replaces the current text and attribute list.
1112    ///
1113    /// If @accel_marker is nonzero, the given character will mark the
1114    /// character following it as an accelerator. For example, @accel_marker
1115    /// might be an ampersand or underscore. All characters marked
1116    /// as an accelerator will receive a [`Underline::Low`][crate::Underline::Low] attribute,
1117    /// and the first character so marked will be returned in @accel_char.
1118    /// Two @accel_marker characters following each other produce a single
1119    /// literal @accel_marker character.
1120    /// ## `markup`
1121    /// marked-up text (see [Pango Markup](pango_markup.html))
1122    /// ## `length`
1123    /// length of marked-up text in bytes, or -1 if @markup is
1124    ///   `NUL`-terminated
1125    /// ## `accel_marker`
1126    /// marker for accelerators in the text
1127    ///
1128    /// # Returns
1129    ///
1130    ///
1131    /// ## `accel_char`
1132    /// return location
1133    ///   for first located accelerator
1134    #[doc(alias = "pango_layout_set_markup_with_accel")]
1135    pub fn set_markup_with_accel(&self, markup: &str, accel_marker: char) -> char {
1136        let length = markup.len() as _;
1137        unsafe {
1138            let mut accel_char = std::mem::MaybeUninit::uninit();
1139            ffi::pango_layout_set_markup_with_accel(
1140                self.to_glib_none().0,
1141                markup.to_glib_none().0,
1142                length,
1143                accel_marker.into_glib(),
1144                accel_char.as_mut_ptr(),
1145            );
1146            std::convert::TryFrom::try_from(accel_char.assume_init())
1147                .expect("conversion from an invalid Unicode value attempted")
1148        }
1149    }
1150
1151    /// Sets the single paragraph mode of @self.
1152    ///
1153    /// If @setting is [`true`], do not treat newlines and similar characters
1154    /// as paragraph separators; instead, keep all text in a single paragraph,
1155    /// and display a glyph for paragraph separator characters. Used when
1156    /// you want to allow editing of newlines on a single text line.
1157    ///
1158    /// The default value is [`false`].
1159    /// ## `setting`
1160    /// new setting
1161    #[doc(alias = "pango_layout_set_single_paragraph_mode")]
1162    pub fn set_single_paragraph_mode(&self, setting: bool) {
1163        unsafe {
1164            ffi::pango_layout_set_single_paragraph_mode(self.to_glib_none().0, setting.into_glib());
1165        }
1166    }
1167
1168    /// Sets the amount of spacing in Pango units between
1169    /// the lines of the layout.
1170    ///
1171    /// When placing lines with spacing, Pango arranges things so that
1172    ///
1173    ///     line2.top = line1.bottom + spacing
1174    ///
1175    /// The default value is 0.
1176    ///
1177    /// Note: Since 1.44, Pango is using the line height (as determined
1178    /// by the font) for placing lines when the line spacing factor is set
1179    /// to a non-zero value with [`set_line_spacing()`][Self::set_line_spacing()].
1180    /// In that case, the @spacing set with this function is ignored.
1181    ///
1182    /// Note: for semantics that are closer to the CSS line-height
1183    /// property, see `attr_line_height_new()`.
1184    /// ## `spacing`
1185    /// the amount of spacing
1186    #[doc(alias = "pango_layout_set_spacing")]
1187    pub fn set_spacing(&self, spacing: i32) {
1188        unsafe {
1189            ffi::pango_layout_set_spacing(self.to_glib_none().0, spacing);
1190        }
1191    }
1192
1193    /// Sets the tabs to use for @self, overriding the default tabs.
1194    ///
1195    /// [`Layout`][crate::Layout] will place content at the next tab position
1196    /// whenever it meets a Tab character (U+0009).
1197    ///
1198    /// By default, tabs are every 8 spaces. If @tabs is [`None`], the
1199    /// default tabs are reinstated. @tabs is copied into the layout;
1200    /// you must free your copy of @tabs yourself.
1201    ///
1202    /// Note that tabs and justification conflict with each other:
1203    /// Justification will move content away from its tab-aligned
1204    /// positions. The same is true for alignments other than
1205    /// [`Alignment::Left`][crate::Alignment::Left].
1206    /// ## `tabs`
1207    /// a [`TabArray`][crate::TabArray]
1208    #[doc(alias = "pango_layout_set_tabs")]
1209    pub fn set_tabs(&self, tabs: Option<&TabArray>) {
1210        unsafe {
1211            ffi::pango_layout_set_tabs(self.to_glib_none().0, mut_override(tabs.to_glib_none().0));
1212        }
1213    }
1214
1215    /// Sets the text of the layout.
1216    ///
1217    /// This function validates @text and renders invalid UTF-8
1218    /// with a placeholder glyph.
1219    ///
1220    /// Note that if you have used [`set_markup()`][Self::set_markup()] or
1221    /// [`set_markup_with_accel()`][Self::set_markup_with_accel()] on @self before, you
1222    /// may want to call [`set_attributes()`][Self::set_attributes()] to clear the
1223    /// attributes set on the layout from the markup as this function does
1224    /// not clear attributes.
1225    /// ## `text`
1226    /// the text
1227    /// ## `length`
1228    /// maximum length of @text, in bytes. -1 indicates that
1229    ///   the string is nul-terminated and the length should be calculated.
1230    ///   The text will also be truncated on encountering a nul-termination
1231    ///   even when @length is positive.
1232    #[doc(alias = "pango_layout_set_text")]
1233    pub fn set_text(&self, text: &str) {
1234        let length = text.len() as _;
1235        unsafe {
1236            ffi::pango_layout_set_text(self.to_glib_none().0, text.to_glib_none().0, length);
1237        }
1238    }
1239
1240    /// Sets the width to which the lines of the [`Layout`][crate::Layout] should wrap or
1241    /// get ellipsized.
1242    ///
1243    /// The default value is -1: no width set.
1244    /// ## `width`
1245    /// the desired width in Pango units, or -1 to indicate that no
1246    ///   wrapping or ellipsization should be performed.
1247    #[doc(alias = "pango_layout_set_width")]
1248    pub fn set_width(&self, width: i32) {
1249        unsafe {
1250            ffi::pango_layout_set_width(self.to_glib_none().0, width);
1251        }
1252    }
1253
1254    /// Sets the wrap mode.
1255    ///
1256    /// The wrap mode only has effect if a width is set on the layout
1257    /// with [`set_width()`][Self::set_width()]. To turn off wrapping,
1258    /// set the width to -1.
1259    ///
1260    /// The default value is [`WrapMode::Word`][crate::WrapMode::Word].
1261    /// ## `wrap`
1262    /// the wrap mode
1263    #[doc(alias = "pango_layout_set_wrap")]
1264    pub fn set_wrap(&self, wrap: WrapMode) {
1265        unsafe {
1266            ffi::pango_layout_set_wrap(self.to_glib_none().0, wrap.into_glib());
1267        }
1268    }
1269
1270    /// A convenience method to serialize a layout to a file.
1271    ///
1272    /// It is equivalent to calling [`serialize()`][Self::serialize()]
1273    /// followed by `file_set_contents()`.
1274    ///
1275    /// See those two functions for details on the arguments.
1276    ///
1277    /// It is mostly intended for use inside a debugger to quickly dump
1278    /// a layout to a file for later inspection.
1279    /// ## `flags`
1280    /// [`LayoutSerializeFlags`][crate::LayoutSerializeFlags]
1281    /// ## `filename`
1282    /// the file to save it to
1283    ///
1284    /// # Returns
1285    ///
1286    /// [`true`] if saving was successful
1287    #[cfg(feature = "v1_50")]
1288    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
1289    #[doc(alias = "pango_layout_write_to_file")]
1290    pub fn write_to_file(
1291        &self,
1292        flags: LayoutSerializeFlags,
1293        filename: impl AsRef<std::path::Path>,
1294    ) -> Result<(), glib::Error> {
1295        unsafe {
1296            let mut error = std::ptr::null_mut();
1297            let is_ok = ffi::pango_layout_write_to_file(
1298                self.to_glib_none().0,
1299                flags.into_glib(),
1300                filename.as_ref().to_glib_none().0,
1301                &mut error,
1302            );
1303            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1304            if error.is_null() {
1305                Ok(())
1306            } else {
1307                Err(from_glib_full(error))
1308            }
1309        }
1310    }
1311
1312    /// Converts from X and Y position within a layout to the byte index to the
1313    /// character at that logical position.
1314    ///
1315    /// If the Y position is not inside the layout, the closest position is
1316    /// chosen (the position will be clamped inside the layout). If the X position
1317    /// is not within the layout, then the start or the end of the line is
1318    /// chosen as described for [`LayoutLine::x_to_index()`][crate::LayoutLine::x_to_index()]. If either
1319    /// the X or Y positions were not inside the layout, then the function returns
1320    /// [`false`]; on an exact hit, it returns [`true`].
1321    /// ## `x`
1322    /// the X offset (in Pango units) from the left edge of the layout
1323    /// ## `y`
1324    /// the Y offset (in Pango units) from the top edge of the layout
1325    ///
1326    /// # Returns
1327    ///
1328    /// [`true`] if the coordinates were inside text, [`false`] otherwise
1329    ///
1330    /// ## `index_`
1331    /// location to store calculated byte index
1332    ///
1333    /// ## `trailing`
1334    /// location to store a integer indicating where
1335    ///   in the grapheme the user clicked. It will either be zero, or the
1336    ///   number of characters in the grapheme. 0 represents the leading edge
1337    ///   of the grapheme.
1338    #[doc(alias = "pango_layout_xy_to_index")]
1339    pub fn xy_to_index(&self, x: i32, y: i32) -> (bool, i32, i32) {
1340        unsafe {
1341            let mut index_ = std::mem::MaybeUninit::uninit();
1342            let mut trailing = std::mem::MaybeUninit::uninit();
1343            let ret = from_glib(ffi::pango_layout_xy_to_index(
1344                self.to_glib_none().0,
1345                x,
1346                y,
1347                index_.as_mut_ptr(),
1348                trailing.as_mut_ptr(),
1349            ));
1350            (ret, index_.assume_init(), trailing.assume_init())
1351        }
1352    }
1353}