Struct wgpu_text::BrushBuilder

source ·
#[non_exhaustive]
pub struct BrushBuilder<F, H = DefaultSectionHasher> { /* private fields */ }
Expand description

Builder for TextBrush.

Implementations§

source§

impl BrushBuilder<()>

source

pub fn using_font<F: Font>(font: F) -> BrushBuilder<F>

Creates a BrushBuilder with Font.

source

pub fn using_font_bytes( data: &[u8] ) -> Result<BrushBuilder<FontRef<'_>>, InvalidFont>

Creates a BrushBuilder with font byte data.

source

pub fn using_font_bytes_vec( data: &[u8] ) -> Result<BrushBuilder<FontRef<'_>>, InvalidFont>

Creates a BrushBuilder with multiple fonts byte data.

source

pub fn using_fonts<F: Font>(fonts: Vec<F>) -> BrushBuilder<F>

Creates a BrushBuilder with multiple Font.

source§

impl<F, H> BrushBuilder<F, H>
where F: Font, H: BuildHasher,

source

pub fn add_font(&mut self, font_data: F) -> FontId

Adds additional fonts to the one added in using_font. Returns a FontId to reference this font.

source

pub fn initial_cache_size(self, size: (u32, u32)) -> Self

Initial size of 2D texture used as a gpu cache, pixels (width, height). The GPU cache will dynamically quadruple in size whenever the current size is insufficient.

Defaults to (256, 256)

source

pub fn draw_cache_scale_tolerance(self, tolerance: f32) -> Self

Sets the maximum allowed difference in scale used for judging whether to reuse an existing glyph in the GPU cache.

Defaults to 0.5

See docs for glyph_brush_draw_cache::DrawCache

source

pub fn draw_cache_position_tolerance(self, tolerance: f32) -> Self

Sets the maximum allowed difference in subpixel position used for judging whether to reuse an existing glyph in the GPU cache. Anything greater than or equal to 1.0 means “don’t care”.

Defaults to 0.1

See docs for glyph_brush_draw_cache::DrawCache

source

pub fn draw_cache_align_4x4(self, b: bool) -> Self

Align glyphs in texture cache to 4x4 texel boundaries.

If your backend requires texture updates to be aligned to 4x4 texel boundaries (e.g. WebGL), this should be set to true.

Defaults to false

See docs for glyph_brush_draw_cache::DrawCache

source

pub fn cache_glyph_positioning(self, cache: bool) -> Self

Sets whether perform the calculation of glyph positioning according to the layout every time, or use a cached result if the input Section and GlyphPositioner are the same hash as a previous call.

Improves performance. Should only disable if using a custom GlyphPositioner that is impure according to it’s inputs, so caching a previous call is not desired. Disabling also disables cache_redraws.

Defaults to true

source

pub fn cache_redraws(self, cache: bool) -> Self

Sets optimising drawing by reusing the last draw requesting an identical draw queue.

Improves performance. Is disabled if cache_glyph_positioning is disabled.

Defaults to true

source

pub fn with_matrix<M>(self, matrix: M) -> Self
where M: Into<Matrix>,

Uses the provided matrix when rendering.

To update the render matrix use TextBrush::update_matrix().

source

pub fn with_multisample(self, multisample: MultisampleState) -> Self

Provide the wgpu::MultisampleState used by the inner pipeline.

Defaults to value returned by wgpu::MultisampleState::default().

source

pub fn with_multiview(self, multiview: NonZeroU32) -> Self

Provide the multiview attribute used by the inner pipeline.

Defaults to None.

source

pub fn with_depth_stencil( self, depth_stencil: Option<DepthStencilState> ) -> BrushBuilder<F, H>

Provide the depth_stencil if you are planning to utilize depth testing.

For each section, depth can be set by modifying the z coordinate (glyph_brush::OwnedText::with_z()).

z coordinate should be in range [0.0, 1.0] not including 1.0.

source

pub fn build( self, device: &Device, render_width: u32, render_height: u32, render_format: TextureFormat ) -> TextBrush<F, H>

Builds a TextBrush while consuming BrushBuilder, for later drawing text onto a texture of the specified render_width, render_height and wgpu::TextureFormat.

If you are drawing a basic UI, you’d most likely want to be using wgpu::SurfaceConfiguration’s dimensions and texture format.

Auto Trait Implementations§

§

impl<F, H> Freeze for BrushBuilder<F, H>
where H: Freeze,

§

impl<F, H> RefUnwindSafe for BrushBuilder<F, H>

§

impl<F, H> Send for BrushBuilder<F, H>
where H: Send, F: Send,

§

impl<F, H> Sync for BrushBuilder<F, H>
where H: Sync, F: Sync,

§

impl<F, H> Unpin for BrushBuilder<F, H>
where H: Unpin, F: Unpin,

§

impl<F, H> UnwindSafe for BrushBuilder<F, H>
where H: UnwindSafe, F: UnwindSafe,

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> Downcast<T> for T

source§

fn downcast(&self) -> &T

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

impl<T> WasmNotSync for T
where T: Sync,