Struct comfy_wgpu::epaint::text::LayoutJob
pub struct LayoutJob {
pub text: String,
pub sections: Vec<LayoutSection, Global>,
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: StringThe complete text of this job, referenced by LayoutSection.
sections: Vec<LayoutSection, Global>The different section, which can have different fonts, colors, etc.
wrap: TextWrapping§first_row_min_height: f32The 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: boolIf false, all newlines characters will be ignored
and show up as the replacement character.
Default: true.
halign: AlignHow to horizontally align the text (Align::LEFT, Align::Center, Align::RIGHT).
justify: boolJustify text so that word-wrapped rows fill the whole TextWrapping::max_width
Implementations§
§impl LayoutJob
impl LayoutJob
pub fn simple(
text: String,
font_id: FontId,
color: Color32,
wrap_width: f32
) -> LayoutJob
pub fn simple( text: String, font_id: FontId, color: Color32, wrap_width: f32 ) -> LayoutJob
Break on \n and at the given wrap width.
pub fn simple_singleline(
text: String,
font_id: FontId,
color: Color32
) -> LayoutJob
pub fn simple_singleline( text: String, font_id: FontId, color: Color32 ) -> LayoutJob
Does not break on \n, but shows the replacement character instead.
pub fn single_section(text: String, format: TextFormat) -> LayoutJob
pub fn is_empty(&self) -> bool
pub fn append(&mut self, text: &str, leading_space: f32, format: TextFormat)
pub fn append(&mut self, text: &str, leading_space: f32, format: TextFormat)
Helper for adding a new section when building a LayoutJob.
pub fn font_height(&self, fonts: &Fonts) -> f32
pub fn font_height(&self, fonts: &Fonts) -> f32
The height of the tallest used font in the job.