pub struct LayoutCtx<'a> { /* private fields */ }Expand description
Borrowed text system used by layout code to shape and measure text.
Measurements are not cached here; the underlying TextSystem owns any
caching that may occur.
Implementations§
Source§impl<'a> LayoutCtx<'a>
impl<'a> LayoutCtx<'a>
Sourcepub fn new(text: &'a mut TextSystem, default_font_size: f32) -> LayoutCtx<'a>
pub fn new(text: &'a mut TextSystem, default_font_size: f32) -> LayoutCtx<'a>
Creates a context that borrows text and uses default_font_size for
callers that do not specify a size.
Sourcepub fn default_font_size(&self) -> f32
pub fn default_font_size(&self) -> f32
Returns the default font size for this layout pass.
Sourcepub fn set_available_width(&mut self, width: f32)
pub fn set_available_width(&mut self, width: f32)
Sets the width available to the view currently being measured.
Sourcepub fn available_width(&self) -> f32
pub fn available_width(&self) -> f32
Returns the width available to the view currently being measured.
Sourcepub fn text_width(&mut self, text: &str, size: f32) -> f32
pub fn text_width(&mut self, text: &str, size: f32) -> f32
Measures the width of a single line of text.
Sourcepub fn text_width_weighted(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
) -> f32
pub fn text_width_weighted( &mut self, text: &str, size: f32, weight: FontWeight, ) -> f32
Measures the width of a single line using the given font weight.
Sourcepub fn text_width_spaced(&mut self, text: &str, size: f32, spacing: f32) -> f32
pub fn text_width_spaced(&mut self, text: &str, size: f32, spacing: f32) -> f32
Measures the width of a single line with letter spacing.
Sourcepub fn text_width_weighted_spaced(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
spacing: f32,
) -> f32
pub fn text_width_weighted_spaced( &mut self, text: &str, size: f32, weight: FontWeight, spacing: f32, ) -> f32
Measures the width of a single line with weight and letter spacing.
Sourcepub fn text_width_styled_spaced(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
spacing: f32,
family: Option<&str>,
style: FontStyle,
) -> f32
pub fn text_width_styled_spaced( &mut self, text: &str, size: f32, weight: FontWeight, spacing: f32, family: Option<&str>, style: FontStyle, ) -> f32
Measures the width of a single line with weight, spacing, family, and style.
Sourcepub fn caret_positions(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
) -> Vec<f32>
pub fn caret_positions( &mut self, text: &str, size: f32, weight: FontWeight, ) -> Vec<f32>
Returns caret positions along a single line of text.
Sourcepub fn caret_positions_spaced(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
spacing: f32,
) -> Vec<f32>
pub fn caret_positions_spaced( &mut self, text: &str, size: f32, weight: FontWeight, spacing: f32, ) -> Vec<f32>
Returns caret positions along a single line with letter spacing.
Sourcepub fn text_wrapped_size(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
width: f32,
mode: WrapMode,
) -> Size
pub fn text_wrapped_size( &mut self, text: &str, size: f32, weight: FontWeight, width: f32, mode: WrapMode, ) -> Size
Measures wrapped text within width, returning its size.
Sourcepub fn text_wrapped_size_spaced(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
width: f32,
mode: WrapMode,
spacing: f32,
) -> Size
pub fn text_wrapped_size_spaced( &mut self, text: &str, size: f32, weight: FontWeight, width: f32, mode: WrapMode, spacing: f32, ) -> Size
Measures wrapped text within width with letter spacing.
Sourcepub fn text_wrapped_size_styled_spaced(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
width: f32,
mode: WrapMode,
spacing: f32,
family: Option<&str>,
style: FontStyle,
) -> Size
pub fn text_wrapped_size_styled_spaced( &mut self, text: &str, size: f32, weight: FontWeight, width: f32, mode: WrapMode, spacing: f32, family: Option<&str>, style: FontStyle, ) -> Size
Measures wrapped text with weight, spacing, family, and style.
Sourcepub fn text_wrapped_size_styled_spaced_lh(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
width: f32,
mode: WrapMode,
spacing: f32,
family: Option<&str>,
style: FontStyle,
line_height: LineHeight,
) -> Size
pub fn text_wrapped_size_styled_spaced_lh( &mut self, text: &str, size: f32, weight: FontWeight, width: f32, mode: WrapMode, spacing: f32, family: Option<&str>, style: FontStyle, line_height: LineHeight, ) -> Size
Measures wrapped text with a custom line height.
Sourcepub fn text_min_content_width_styled_spaced(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
spacing: f32,
family: Option<&str>,
style: FontStyle,
mode: WrapMode,
) -> f32
pub fn text_min_content_width_styled_spaced( &mut self, text: &str, size: f32, weight: FontWeight, spacing: f32, family: Option<&str>, style: FontStyle, mode: WrapMode, ) -> f32
Measures the longest unbreakable unit of text for the given wrap mode.
Sourcepub fn text_elide_lines_styled_spaced(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
width: f32,
mode: WrapMode,
spacing: f32,
family: Option<&str>,
style: FontStyle,
line_height: LineHeight,
max_lines: usize,
) -> String
pub fn text_elide_lines_styled_spaced( &mut self, text: &str, size: f32, weight: FontWeight, width: f32, mode: WrapMode, spacing: f32, family: Option<&str>, style: FontStyle, line_height: LineHeight, max_lines: usize, ) -> String
Elides wrapped text to max_lines, returning the visible string.
Sourcepub fn text_elided_size(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
max_width: f32,
mode: ElideMode,
) -> Size
pub fn text_elided_size( &mut self, text: &str, size: f32, weight: FontWeight, max_width: f32, mode: ElideMode, ) -> Size
Measures text elided to max_width with the given elision mode.
Sourcepub fn text_elided_size_spaced(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
max_width: f32,
mode: ElideMode,
spacing: f32,
) -> Size
pub fn text_elided_size_spaced( &mut self, text: &str, size: f32, weight: FontWeight, max_width: f32, mode: ElideMode, spacing: f32, ) -> Size
Measures elided text with letter spacing.
Sourcepub fn text_elided_size_styled_spaced(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
max_width: f32,
mode: ElideMode,
spacing: f32,
family: Option<&str>,
style: FontStyle,
) -> Size
pub fn text_elided_size_styled_spaced( &mut self, text: &str, size: f32, weight: FontWeight, max_width: f32, mode: ElideMode, spacing: f32, family: Option<&str>, style: FontStyle, ) -> Size
Measures elided text with weight, spacing, family, and style.
Sourcepub fn text_elided_size_styled_spaced_lh(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
max_width: f32,
mode: ElideMode,
spacing: f32,
family: Option<&str>,
style: FontStyle,
line_height: LineHeight,
) -> Size
pub fn text_elided_size_styled_spaced_lh( &mut self, text: &str, size: f32, weight: FontWeight, max_width: f32, mode: ElideMode, spacing: f32, family: Option<&str>, style: FontStyle, line_height: LineHeight, ) -> Size
Measures elided text with a custom line height.
Sourcepub fn text_line_height(size: f32) -> f32
pub fn text_line_height(size: f32) -> f32
Returns the line height used for a font size with the default factor.
Sourcepub fn text_line_height_with(size: f32, line_height: LineHeight) -> f32
pub fn text_line_height_with(size: f32, line_height: LineHeight) -> f32
Returns the line height used for a font size.
Sourcepub fn text_first_baseline_styled_spaced_lh(
&mut self,
text: &str,
size: f32,
weight: FontWeight,
width: f32,
mode: WrapMode,
spacing: f32,
family: Option<&str>,
style: FontStyle,
line_height: LineHeight,
) -> f32
pub fn text_first_baseline_styled_spaced_lh( &mut self, text: &str, size: f32, weight: FontWeight, width: f32, mode: WrapMode, spacing: f32, family: Option<&str>, style: FontStyle, line_height: LineHeight, ) -> f32
Returns the first baseline offset of a shaped single/wrapped line.
Sourcepub fn rich_size(
&mut self,
spans: &[TextSpan],
size: f32,
width: f32,
mode: WrapMode,
spacing: f32,
align: RichAlign,
) -> Size
pub fn rich_size( &mut self, spans: &[TextSpan], size: f32, width: f32, mode: WrapMode, spacing: f32, align: RichAlign, ) -> Size
Measures rich text spans, returning their shaped size.
Sourcepub fn rich_size_lh(
&mut self,
spans: &[TextSpan],
size: f32,
width: f32,
mode: WrapMode,
spacing: f32,
align: RichAlign,
line_height: LineHeight,
) -> Size
pub fn rich_size_lh( &mut self, spans: &[TextSpan], size: f32, width: f32, mode: WrapMode, spacing: f32, align: RichAlign, line_height: LineHeight, ) -> Size
Measures rich text spans with a custom line height.
Sourcepub fn rich_elide_lines(
&mut self,
spans: &[TextSpan],
size: f32,
width: f32,
mode: WrapMode,
spacing: f32,
align: RichAlign,
line_height: LineHeight,
max_lines: usize,
) -> Vec<TextSpan>
pub fn rich_elide_lines( &mut self, spans: &[TextSpan], size: f32, width: f32, mode: WrapMode, spacing: f32, align: RichAlign, line_height: LineHeight, max_lines: usize, ) -> Vec<TextSpan>
Elides rich text to max_lines.
Sourcepub fn rich_first_baseline(
&mut self,
spans: &[TextSpan],
size: f32,
width: f32,
mode: WrapMode,
spacing: f32,
align: RichAlign,
line_height: LineHeight,
) -> f32
pub fn rich_first_baseline( &mut self, spans: &[TextSpan], size: f32, width: f32, mode: WrapMode, spacing: f32, align: RichAlign, line_height: LineHeight, ) -> f32
Returns the first baseline of shaped rich text.