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,
) -> Paragraph
pub fn new( shaper: &(impl TextShaper + ?Sized), text: impl Into<String>, style: &TextStyle, align: TextAlign, max_width: f32, ) -> Paragraph
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.