pub struct TextState { /* private fields */ }Expand description
Glyphon-backed text batching for a single frame.
Text is queued during crate::drawable::WgpuDrawable::draw execution and flushed once
per frame. On glyphon prepare/render failure, a warning is logged and queued lines are cleared.
Implementations§
Source§impl TextState
impl TextState
Sourcepub fn new(
device: &Device,
queue: &Queue,
pixel_format: TextureFormat,
size: (u32, u32),
dpi_scale: f32,
) -> Self
pub fn new( device: &Device, queue: &Queue, pixel_format: TextureFormat, size: (u32, u32), dpi_scale: f32, ) -> Self
Creates glyphon font system, atlas, and text renderer for the given surface format.
Sourcepub fn set_dpi_scale(&mut self, dpi_scale: f32)
pub fn set_dpi_scale(&mut self, dpi_scale: f32)
Updates the DPI scale factor used when measuring text.
Sourcepub fn font_system(&self) -> Arc<Mutex<FontSystem>>
pub fn font_system(&self) -> Arc<Mutex<FontSystem>>
Returns a shared handle to the glyphon font system.
Used by crate::cotis_traits to provide layout-time text measurement.
Sourcepub fn queue_text(
&mut self,
text: &str,
font_size: f32,
line_height: f32,
position: UIPosition,
bounds: Option<(UIPosition, UIPosition)>,
color: Color,
draw_order: f32,
)
pub fn queue_text( &mut self, text: &str, font_size: f32, line_height: f32, position: UIPosition, bounds: Option<(UIPosition, UIPosition)>, color: Color, draw_order: f32, )
Queues a line of text for rendering at the end of the current frame.
font_size and line_height should already include DPI scaling when called from
crate::default_drawables. draw_order maps to glyphon depth metadata for z-ordering.
Sourcepub fn flush(
&mut self,
device: &Device,
queue: &Queue,
render_pass: &mut RenderPass<'_>,
surface_config: &SurfaceConfiguration,
)
pub fn flush( &mut self, device: &Device, queue: &Queue, render_pass: &mut RenderPass<'_>, surface_config: &SurfaceConfiguration, )
Prepares and renders all queued text lines, then clears the queue.
On prepare failure, logs a warning and clears queued lines without rendering. On render failure, logs a warning but still clears the queue.
Sourcepub fn measure(&mut self, text: &str, config: &TextConfig) -> Dimensions
pub fn measure(&mut self, text: &str, config: &TextConfig) -> Dimensions
Measures the pixel dimensions of text using the given layout config.
Font size and line height are multiplied by the current DPI scale. Always uses
Family::SansSerif; font_id is not consulted.
Auto Trait Implementations§
impl !RefUnwindSafe for TextState
impl !UnwindSafe for TextState
impl Freeze for TextState
impl Send for TextState
impl Sync for TextState
impl Unpin for TextState
impl UnsafeUnpin for TextState
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<H, TailTarget, Source, Idx> Embed<RenderTList<H, TailTarget>, There<Idx>> for Sourcewhere
TailTarget: IsRenderList,
Source: Embed<TailTarget, Idx>,
impl<H, TailTarget, Source, Idx> Embed<RenderTList<H, TailTarget>, There<Idx>> for Sourcewhere
TailTarget: IsRenderList,
Source: Embed<TailTarget, Idx>,
Source§fn embed(self) -> RenderTList<H, TailTarget>
fn embed(self) -> RenderTList<H, TailTarget>
self into Target.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 more