Struct msfs::nvg::Context

source ·
pub struct Context { /* private fields */ }
Expand description

A NanoVG render context.

Implementations§

source§

impl Context

source

pub fn create(fs_ctx: FsContext) -> Option<Self>

Create a NanoVG render context from an FsContext.

source

pub fn draw_frame<F: Fn(&Frame) -> Result<(), Box<dyn Error>>>( &self, width: usize, height: usize, f: F )

Draw a frame.

source

pub fn create_font( &self, name: &str, filename: &str ) -> Result<Font, Box<dyn Error>>

NanoVG allows you to load .ttf files and use the font to render text.

The appearance of the text can be defined by setting the current text style and by specifying the fill color. Common text and font settings such as font size, letter spacing and text align are supported. Font blur allows you to create simple text effects such as drop shadows.

At render time the font face can be set based on the font handles or name.

Font measure functions return values in local space, the calculations are carried in the same resolution as the final rendering. This is done because the text glyph positions are snapped to the nearest pixels sharp rendering.

The local space means that values are not rotated or scale as per the current transformation. For example if you set font size to 12, which would mean that line height is 16, then regardless of the current scaling and rotation, the returned line height is always 16. Some measures may vary because of the scaling since aforementioned pixel snapping.

While this may sound a little odd, the setup allows you to always render the same way regardless of scaling.

Note: currently only solid color fill is supported for text.

source

pub fn create_image(&self, filename: &str) -> Result<Image, Box<dyn Error>>

NanoVG allows you to load jpg, png, psd, tga, pic and gif files to be used for rendering. In addition you can upload your own image. The image loading is provided by stb_image.

Trait Implementations§

source§

impl Drop for Context

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> 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, 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.