pub struct Context { /* private fields */ }
Expand description
A NanoVG render context.
Implementations§
source§impl Context
impl Context
sourcepub fn create(fs_ctx: FsContext) -> Option<Self>
pub fn create(fs_ctx: FsContext) -> Option<Self>
Create a NanoVG render context from an FsContext
.
sourcepub fn draw_frame<F: Fn(&Frame) -> Result<(), Box<dyn Error>>>(
&self,
width: usize,
height: usize,
f: F
)
pub fn draw_frame<F: Fn(&Frame) -> Result<(), Box<dyn Error>>>( &self, width: usize, height: usize, f: F )
Draw a frame.
sourcepub fn create_font(
&self,
name: &str,
filename: &str
) -> Result<Font, Box<dyn Error>>
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.