Skip to main content

LayoutContext

Struct LayoutContext 

Source
pub struct LayoutContext<B: Brush = [u8; 4]> { /* private fields */ }
Expand description

Shared scratch space used when constructing text layouts.

This type is designed to be a global resource with only one per-application (or per-thread).

Implementations§

Source§

impl<B: Brush> LayoutContext<B>

Source

pub fn new() -> Self

Source

pub fn ranged_builder<'a>( &'a mut self, fcx: &'a mut FontContext, text: &'a str, scale: f32, quantize: bool, ) -> RangedBuilder<'a, B>

Create a ranged style layout builder.

Set quantize as true to have the layout coordinates aligned to pixel boundaries. That is the easiest way to avoid blurry text and to receive ready-to-paint layout metrics.

For advanced rendering use cases you can set quantize as false and receive fractional coordinates. This ensures the most accurate results if you want to perform some post-processing on the coordinates before painting. To avoid blurry text you will still need to quantize the coordinates just before painting.

Your should round at least the following:

  • Glyph run baseline
  • Inline box baseline
    • box.y = (box.y + box.height).round() - box.height
  • Selection geometry’s y0 & y1
  • Cursor geometry’s y0 & y1

Keep in mind that for the simple f32::round to be effective, you need to first ensure the coordinates are in physical pixel space.

Source

pub fn style_run_builder<'a>( &'a mut self, fcx: &'a mut FontContext, text: &'a str, scale: f32, quantize: bool, ) -> StyleRunBuilder<'a, B>

Create a builder for constructing a layout from indexed style runs.

Unlike Self::ranged_builder, this builder expects callers to provide:

Parley then skips its internal range-splitting logic.

Source

pub fn tree_builder<'a>( &'a mut self, fcx: &'a mut FontContext, scale: f32, quantize: bool, root_style: &TextStyle<'_, '_, B>, ) -> TreeBuilder<'a, B>

Create a tree style layout builder.

Set quantize as true to have the layout coordinates aligned to pixel boundaries. That is the easiest way to avoid blurry text and to receive ready-to-paint layout metrics.

For advanced rendering use cases you can set quantize as false and receive fractional coordinates. This ensures the most accurate results if you want to perform some post-processing on the coordinates before painting. To avoid blurry text you will still need to quantize the coordinates just before painting.

Your should round at least the following:

  • Glyph run baseline
  • Inline box baseline
    • box.y = (box.y + box.height).round() - box.height
  • Selection geometry’s y0 & y1
  • Cursor geometry’s y0 & y1

Keep in mind that for the simple f32::round to be effective, you need to first ensure the coordinates are in physical pixel space.

Trait Implementations§

Source§

impl<B: Brush> Clone for LayoutContext<B>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B: Brush> Default for LayoutContext<B>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<B = [u8; 4]> !Freeze for LayoutContext<B>

§

impl<B = [u8; 4]> !RefUnwindSafe for LayoutContext<B>

§

impl<B = [u8; 4]> !UnwindSafe for LayoutContext<B>

§

impl<B> Forget for LayoutContext<B>

§

impl<B> Move for LayoutContext<B>

§

impl<B> Send for LayoutContext<B>
where Vec<ResolvedStyle<B>>: Send, RangedStyleBuilder<B>: Send, TreeStyleBuilder<B>: Send,

§

impl<B> Sync for LayoutContext<B>
where Vec<ResolvedStyle<B>>: Sync, RangedStyleBuilder<B>: Sync, TreeStyleBuilder<B>: Sync,

§

impl<B> Unpin for LayoutContext<B>
where Vec<ResolvedStyle<B>>: Unpin, RangedStyleBuilder<B>: Unpin, TreeStyleBuilder<B>: Unpin,

§

impl<B> UnsafeUnpin for LayoutContext<B>
where Vec<ResolvedStyle<B>>: UnsafeUnpin, RangedStyleBuilder<B>: UnsafeUnpin, TreeStyleBuilder<B>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.