pub struct LayoutJob {
    pub text: String,
    pub sections: Vec<LayoutSection>,
    pub wrap: TextWrapping,
    pub first_row_min_height: f32,
    pub break_on_newline: bool,
    pub halign: Align,
    pub justify: bool,
}
Expand description

Describes the task of laying out text.

This supports mixing different fonts, color and formats (underline etc).

Pass this to crate::Fonts::layout_job or crate::text::layout.

Example:

use epaint::{Color32, text::{LayoutJob, TextFormat}, FontFamily, FontId};

let mut job = LayoutJob::default();
job.append(
    "Hello ",
    0.0,
    TextFormat {
        font_id: FontId::new(14.0, FontFamily::Proportional),
        color: Color32::WHITE,
        ..Default::default()
    },
);
job.append(
    "World!",
    0.0,
    TextFormat {
        font_id: FontId::new(14.0, FontFamily::Monospace),
        color: Color32::BLACK,
        ..Default::default()
    },
);

As you can see, constructing a LayoutJob is currently a lot of work. It would be nice to have a helper macro for it!

Fields

text: String

The complete text of this job, referenced by LayoutSection.

sections: Vec<LayoutSection>

The different section, which can have different fonts, colors, etc.

wrap: TextWrappingfirst_row_min_height: f32

The first row must be at least this high. This is in case we lay out text that is the continuation of some earlier text (sharing the same row), in which case this will be the height of the earlier text. In other cases, set this to 0.0.

break_on_newline: bool

If false, all newlines characters will be ignored and show up as the replacement character. Default: true.

halign: Align

How to horizontally align the text (Align::LEFT, Align::Center, Align::RIGHT).

justify: bool

Justify text so that word-wrapped rows fill the whole TextWrapping::max_width

Implementations

Break on \n and at the given wrap width.

Does not break on \n, but shows the replacement character instead.

Helper for adding a new section when building a LayoutJob.

The height of the tallest used font in the job.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.