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,
pub round_output_size_to_nearest_ui_point: 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: TextWrapping
Controls the text wrapping and elision.
first_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 true
, all \n
characters will result in a new paragraph,
starting on a new row.
If false
, all \n
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
.
round_output_size_to_nearest_ui_point: bool
Rounding to the closest ui point (not pixel!) allows the rest of the layout code to run on perfect integers, avoiding rounding errors.
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 font used in the job.
pub fn effective_wrap_width(&self) -> f32
pub fn effective_wrap_width(&self) -> f32
The wrap with, with a small margin in some cases.
Trait Implementations§
§impl<'de> Deserialize<'de> for LayoutJob
impl<'de> Deserialize<'de> for LayoutJob
§fn deserialize<__D>(
__deserializer: __D
) -> Result<LayoutJob, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<LayoutJob, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl From<LayoutJob> for WidgetText
impl From<LayoutJob> for WidgetText
§fn from(layout_job: LayoutJob) -> WidgetText
fn from(layout_job: LayoutJob) -> WidgetText
§impl Serialize for LayoutJob
impl Serialize for LayoutJob
§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for LayoutJob
Auto Trait Implementations§
impl Freeze for LayoutJob
impl RefUnwindSafe for LayoutJob
impl Send for LayoutJob
impl Sync for LayoutJob
impl Unpin for LayoutJob
impl UnwindSafe for LayoutJob
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
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request