pub struct Paragraph { /* private fields */ }Expand description
Text wrapped to a width and laid out once, to measure and then paint.
Lay a paragraph out in measure and keep it on the widget. paint draws
the layout that was measured, so the painted lines always fit the size the
widget reported.
ⓘ
fn measure(&mut self, ctx: &mut MeasureCtx, constraints: Constraints) -> Size {
self.paragraph = Paragraph::new(
ctx,
&self.text,
&self.style,
TextAlign::Start,
constraints.max.width,
);
constraints.clamp(self.paragraph.size())
}
fn paint(&self, ctx: &mut PaintCtx) {
self.paragraph.paint(ctx, ctx.bounds(), VerticalAlign::Top);
}Implementations§
Source§impl Paragraph
impl Paragraph
Sourcepub fn new(
shaper: &(impl TextShaper + ?Sized),
text: impl Into<String>,
style: &TextStyle,
align: TextAlign,
max_width: f32,
) -> Self
pub fn new( shaper: &(impl TextShaper + ?Sized), text: impl Into<String>, style: &TextStyle, align: TextAlign, max_width: f32, ) -> Self
Lay out text wrapped to max_width, or unwrapped when it is
infinite, with each line aligned by align.
pub fn text(&self) -> &str
Sourcepub fn size(&self) -> Size
pub fn size(&self) -> Size
The size the text takes: its widest line by the height of its lines.
pub fn line_count(&self) -> usize
Sourcepub fn paint(&self, ctx: &mut PaintCtx, rect: Rect, vertical: VerticalAlign)
pub fn paint(&self, ctx: &mut PaintCtx, rect: Rect, vertical: VerticalAlign)
Paint into rect, placed vertically by vertical and horizontally by
the alignment the paragraph was laid out with.
Sourcepub fn paint_with_color(
&self,
ctx: &mut PaintCtx,
rect: Rect,
vertical: VerticalAlign,
color: Color,
)
pub fn paint_with_color( &self, ctx: &mut PaintCtx, rect: Rect, vertical: VerticalAlign, color: Color, )
Paint like paint, in color instead of the style’s,
for a color that can change without laying the text out again.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Paragraph
impl Freeze for Paragraph
impl Move for Paragraph
impl RefUnwindSafe for Paragraph
impl Send for Paragraph
impl Sync for Paragraph
impl Unpin for Paragraph
impl UnsafeUnpin for Paragraph
impl UnwindSafe for Paragraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more