diff options
| author | 2023-10-27 05:04:14 +0200 | |
|---|---|---|
| committer | 2023-10-27 05:04:14 +0200 | |
| commit | 625cd745f38215b1cb8f629cdc6d2fa41c9a739a (patch) | |
| tree | af96038ba4800937b3b3c7c0383cd47776bbb69c /graphics/src/text/paragraph.rs | |
| parent | 65823875791ecebf24d049cc0782e7475a37899b (diff) | |
| download | iced-625cd745f38215b1cb8f629cdc6d2fa41c9a739a.tar.gz iced-625cd745f38215b1cb8f629cdc6d2fa41c9a739a.tar.bz2 iced-625cd745f38215b1cb8f629cdc6d2fa41c9a739a.zip | |
Write documentation for the new text APIs
Diffstat (limited to '')
| -rw-r--r-- | graphics/src/text/paragraph.rs | 14 | 
1 files changed, 14 insertions, 0 deletions
| diff --git a/graphics/src/text/paragraph.rs b/graphics/src/text/paragraph.rs index d0396e8e..ccfe4a61 100644 --- a/graphics/src/text/paragraph.rs +++ b/graphics/src/text/paragraph.rs @@ -1,3 +1,4 @@ +//! Draw paragraphs.  use crate::core;  use crate::core::alignment;  use crate::core::text::{Hit, LineHeight, Shaping, Text}; @@ -7,6 +8,7 @@ use crate::text;  use std::fmt;  use std::sync::{self, Arc}; +/// A bunch of text.  #[derive(Clone, PartialEq)]  pub struct Paragraph(Option<Arc<Internal>>); @@ -23,14 +25,21 @@ struct Internal {  }  impl Paragraph { +    /// Creates a new empty [`Paragraph`].      pub fn new() -> Self {          Self::default()      } +    /// Returns the buffer of the [`Paragraph`].      pub fn buffer(&self) -> &cosmic_text::Buffer {          &self.internal().buffer      } +    /// Creates a [`Weak`] reference to the [`Paragraph`]. +    /// +    /// This is useful to avoid cloning the [`Editor`] when +    /// referential guarantees are unnecessary. For instance, +    /// when creating a rendering tree.      pub fn downgrade(&self) -> Weak {          let paragraph = self.internal(); @@ -269,15 +278,20 @@ impl Default for Internal {      }  } +/// A weak reference to a [`Paragraph`].  #[derive(Debug, Clone)]  pub struct Weak {      raw: sync::Weak<Internal>, +    /// The minimum bounds of the [`Paragraph`].      pub min_bounds: Size, +    /// The horizontal alignment of the [`Paragraph`].      pub horizontal_alignment: alignment::Horizontal, +    /// The vertical alignment of the [`Paragraph`].      pub vertical_alignment: alignment::Vertical,  }  impl Weak { +    /// Tries to update the reference into a [`Paragraph`].      pub fn upgrade(&self) -> Option<Paragraph> {          self.raw.upgrade().map(Some).map(Paragraph)      } | 
