Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

nanovg (C++)

NanoVG: antialiased 2D vector drawing (paths, fills, strokes, gradients, images, text), in an ImGui app.

The C++ API of NanoVG as it is bound to Python: the entries of the module imgui_bundle.nanovg, in the same order, with their C++ signatures and the headers’ comments. From the stubs: the functions excluded from the bindings, the typedefs and the macros are absent.

nanovg.h

Paint (struct)

Member
float xform[6];ndarray[type=float, size=6]
float extent[2];ndarray[type=float, size=2]
float radius;
float feather;
NVGcolor innerColor;
NVGcolor outerColor;
int image;

Winding (enum)

MemberValue
NVG_CCW = 11Winding for solid shapes
NVG_CW = 22Winding for holes

Solidity (enum)

MemberValue
NVG_SOLID = 11CCW
NVG_HOLE = 22CW

LineCap (enum)

MemberValue
NVG_BUTT0
NVG_ROUND1
NVG_SQUARE2
NVG_BEVEL3
NVG_MITER, }4

Align (enum)

MemberValue
NVG_ALIGN_LEFT = 1<<01<<0Default, align text horizontally to left.
NVG_ALIGN_CENTER = 1<<11<<1Align text horizontally to center.
NVG_ALIGN_RIGHT = 1<<21<<2Align text horizontally to right.
NVG_ALIGN_TOP = 1<<31<<3Align text vertically to top.
NVG_ALIGN_MIDDLE = 1<<41<<4Align text vertically to middle.
NVG_ALIGN_BOTTOM = 1<<51<<5Align text vertically to bottom.
NVG_ALIGN_BASELINE = 1<<61<<6Default, align text vertically to baseline.

BlendFactor (enum)

MemberValue
NVG_ZERO = 1<<01<<0
NVG_ONE = 1<<11<<1
NVG_SRC_COLOR = 1<<21<<2
NVG_ONE_MINUS_SRC_COLOR = 1<<31<<3
NVG_DST_COLOR = 1<<41<<4
NVG_ONE_MINUS_DST_COLOR = 1<<51<<5
NVG_SRC_ALPHA = 1<<61<<6
NVG_ONE_MINUS_SRC_ALPHA = 1<<71<<7
NVG_DST_ALPHA = 1<<81<<8
NVG_ONE_MINUS_DST_ALPHA = 1<<91<<9
NVG_SRC_ALPHA_SATURATE = 1<<10, }1<<10

CompositeOperation (enum)

MemberValue
NVG_SOURCE_OVER0
NVG_SOURCE_IN1
NVG_SOURCE_OUT2
NVG_ATOP3
NVG_DESTINATION_OVER4
NVG_DESTINATION_IN5
NVG_DESTINATION_OUT6
NVG_DESTINATION_ATOP7
NVG_LIGHTER8
NVG_COPY9
NVG_XOR, }10

CompositeOperationState (struct)

Member
int srcRGB;
int dstRGB;
int srcAlpha;
int dstAlpha;

GlyphPosition (struct)

Member
const char* str;Position of the glyph in the input string. # (const)
float x;The x-coordinate of the logical glyph position.
float minx,The bounds of the glyph shape.
maxx;The bounds of the glyph shape.

TextRow (struct)

Member
const char* start;Pointer to the input text where the row starts. # (const)
const char* end;Pointer to the input text where the row ends (one past the last character). # (const)
const char* next;Pointer to the beginning of the next row. # (const)
float width;Logical width of the row.
float minx,Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
maxx;Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.

ImageFlags (enum)

MemberValue
NVG_IMAGE_GENERATE_MIPMAPS = 1<<01<<0Generate mipmaps during creation of the image.
NVG_IMAGE_REPEATX = 1<<11<<1Repeat image in X direction.
NVG_IMAGE_REPEATY = 1<<21<<2Repeat image in Y direction.
NVG_IMAGE_FLIPY = 1<<31<<3Flips (inverses) image in Y direction when rendered.
NVG_IMAGE_PREMULTIPLIED = 1<<41<<4Image data has premultiplied alpha.
NVG_IMAGE_NEAREST = 1<<51<<5Image interpolation is Nearest instead Linear

nvgBeginFrame

void nvgBeginFrame(NVGcontext* ctx, float windowWidth, float windowHeight, float devicePixelRatio);

Begin drawing a new frame
Calls to nanovg drawing API should be wrapped in nvgBeginFrame() & nvgEndFrame() nvgBeginFrame() defines the size of the window to render to in relation currently set viewport (i.e. glViewport on GL backends). Device pixel ration allows to control the rendering on Hi-DPI devices.
For example, GLFW returns two dimension for an opened window: window size and frame buffer size. In that case you would set windowWidth/Height to the window size devicePixelRatio to: frameBufferWidth / windowWidth.

nvgCancelFrame

void nvgCancelFrame(NVGcontext* ctx);

Cancels drawing the current frame.

nvgEndFrame

void nvgEndFrame(NVGcontext* ctx);

Ends drawing flushing remaining render state.

Composite operation

The composite operations in NanoVG are modeled after HTML Canvas API, and the blend func is based on OpenGL (see corresponding manuals for more info).
The colors in the blending state have premultiplied alpha.

nvgGlobalCompositeOperation

void nvgGlobalCompositeOperation(NVGcontext* ctx, int op);

Sets the composite operation. The op parameter should be one of NVGcompositeOperation.

nvgGlobalCompositeBlendFunc

void nvgGlobalCompositeBlendFunc(NVGcontext* ctx, int sfactor, int dfactor);

Sets the composite operation with custom pixel arithmetic. The parameters should be one of NVGblendFactor.

nvgGlobalCompositeBlendFuncSeparate

void nvgGlobalCompositeBlendFuncSeparate(NVGcontext* ctx, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);

Sets the composite operation with custom pixel arithmetic for RGB and alpha components separately. The parameters should be one of NVGblendFactor.

Color utils

Colors in NanoVG are stored as unsigned ints in ABGR format.

nvgRGB

NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b);

Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0).

nvgRGBf

NVGcolor nvgRGBf(float r, float g, float b);

Returns a color value from red, green, blue values. Alpha will be set to 1.0.

nvgRGBA

NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);

Returns a color value from red, green, blue and alpha values.

nvgRGBAf

NVGcolor nvgRGBAf(float r, float g, float b, float a);

Returns a color value from red, green, blue and alpha values.

nvgLerpRGBA

NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u);

Linearly interpolates from color c0 to c1, and returns resulting color value.

nvgTransRGBA

NVGcolor nvgTransRGBA(NVGcolor c0, unsigned char a);

Sets transparency of a color value.

nvgTransRGBAf

NVGcolor nvgTransRGBAf(NVGcolor c0, float a);

Sets transparency of a color value.

nvgHSL

NVGcolor nvgHSL(float h, float s, float l);

Returns color value specified by hue, saturation and lightness.
HSL values are all in range [0..1], alpha will be set to 255.

nvgHSLA

NVGcolor nvgHSLA(float h, float s, float l, unsigned char a);

Returns color value specified by hue, saturation and lightness and alpha.
HSL values are all in range [0..1], alpha in range [0..255]

State Handling

NanoVG contains state which represents how paths will be rendered.
The state contains transform, fill and stroke styles, text and font styles, and scissor clipping.

nvgSave

void nvgSave(NVGcontext* ctx);

Pushes and saves the current render state into a state stack.
A matching nvgRestore() must be used to restore the state.

nvgRestore

void nvgRestore(NVGcontext* ctx);

Pops and restores current render state.

nvgReset

void nvgReset(NVGcontext* ctx);

Resets current render state to default values. Does not affect the render state stack.

Render styles

Fill and stroke render style can be either a solid color or a paint which is a gradient or a pattern.
Solid color is simply defined as a color value, different kinds of paints can be created using nvgLinearGradient(), nvgBoxGradient(), nvgRadialGradient() and nvgImagePattern().
Current render style can be saved and restored using nvgSave() and nvgRestore().

nvgShapeAntiAlias

void nvgShapeAntiAlias(NVGcontext* ctx, int enabled);

Sets whether to draw antialias for nvgStroke() and nvgFill(). It’s enabled by default.

nvgStrokeColor

void nvgStrokeColor(NVGcontext* ctx, NVGcolor color);

Sets current stroke style to a solid color.

nvgStrokePaint

void nvgStrokePaint(NVGcontext* ctx, NVGpaint paint);

Sets current stroke style to a paint, which can be a one of the gradients or a pattern.

nvgFillColor

void nvgFillColor(NVGcontext* ctx, NVGcolor color);

Sets current fill style to a solid color.

nvgFillPaint

void nvgFillPaint(NVGcontext* ctx, NVGpaint paint);

Sets current fill style to a paint, which can be a one of the gradients or a pattern.

nvgMiterLimit

void nvgMiterLimit(NVGcontext* ctx, float limit);

Sets the miter limit of the stroke style.
Miter limit controls when a sharp corner is beveled.

nvgStrokeWidth

void nvgStrokeWidth(NVGcontext* ctx, float size);

Sets the stroke width of the stroke style.

nvgLineCap

void nvgLineCap(NVGcontext* ctx, int cap);

Sets how the end of the line (cap) is drawn,
Can be one of: NVG_BUTT (default), NVG_ROUND, NVG_SQUARE.

nvgLineJoin

void nvgLineJoin(NVGcontext* ctx, int join);

Sets how sharp path corners are drawn.
Can be one of NVG_MITER (default), NVG_ROUND, NVG_BEVEL.

nvgGlobalAlpha

void nvgGlobalAlpha(NVGcontext* ctx, float alpha);

Sets the transparency applied to all rendered shapes.
Already transparent paths will get proportionally more transparent as well.

Transforms

The paths, gradients, patterns and scissor region are transformed by an transformation matrix at the time when they are passed to the API.
The current transformation matrix is a affine matrix:
[sx kx tx]
[ky sy ty]
[ 0 0 1]
Where: sx,sy define scaling, kx,ky skewing, and tx,ty translation.
The last row is assumed to be 0,0,1 and is not stored.
Apart from nvgResetTransform(), each transformation function first creates specific transformation matrix and pre-multiplies the current transformation by it.
Current coordinate system (transformation) can be saved and restored using nvgSave() and nvgRestore().

nvgResetTransform

void nvgResetTransform(NVGcontext* ctx);

Resets current transform to a identity matrix.

nvgTransform

void nvgTransform(NVGcontext* ctx, float a, float b, float c, float d, float e, float f);

Premultiplies current coordinate system by specified matrix.
The parameters are interpreted as matrix as follows:
[a c e]
[b d f]
[0 0 1]

nvgTranslate

void nvgTranslate(NVGcontext* ctx, float x, float y);

Translates current coordinate system.

nvgRotate

void nvgRotate(NVGcontext* ctx, float angle);

Rotates current coordinate system. Angle is specified in radians.

nvgSkewX

void nvgSkewX(NVGcontext* ctx, float angle);

Skews the current coordinate system along X axis. Angle is specified in radians.

nvgSkewY

void nvgSkewY(NVGcontext* ctx, float angle);

Skews the current coordinate system along Y axis. Angle is specified in radians.

nvgScale

void nvgScale(NVGcontext* ctx, float x, float y);

Scales the current coordinate system.

nvgCurrentTransform

void nvgCurrentTransform(NVGcontext* ctx, float* xform);

Stores the top part (a-f) of the current transformation matrix in to the specified buffer.
[a c e]
[b d f]
[0 0 1]
There should be space for 6 floats in the return buffer for the values a-f.

nvgTransformIdentity

void nvgTransformIdentity(float* dst);

Sets the transform to identity matrix.

The following functions can be used to make calculations on 2x3 transformation matrices.
A 2x3 matrix is represented as float[6].

nvgTransformTranslate

void nvgTransformTranslate(float* dst, float tx, float ty);

Sets the transform to translation matrix matrix.

nvgTransformScale

void nvgTransformScale(float* dst, float sx, float sy);

Sets the transform to scale matrix.

nvgTransformRotate

void nvgTransformRotate(float* dst, float a);

Sets the transform to rotate matrix. Angle is specified in radians.

nvgTransformSkewX

void nvgTransformSkewX(float* dst, float a);

Sets the transform to skew-x matrix. Angle is specified in radians.

nvgTransformSkewY

void nvgTransformSkewY(float* dst, float a);

Sets the transform to skew-y matrix. Angle is specified in radians.

nvgTransformMultiply

void nvgTransformMultiply(float* dst, const float* src);

Sets the transform to the result of multiplication of two transforms, of A = A*B.

nvgTransformPremultiply

void nvgTransformPremultiply(float* dst, const float* src);

Sets the transform to the result of multiplication of two transforms, of A = B*A.

nvgTransformInverse

int nvgTransformInverse(float* dst, const float* src);

Sets the destination to inverse of specified transform.
Returns 1 if the inverse could be calculated, else 0.

nvgTransformPoint

void nvgTransformPoint(float* dstx, float* dsty, const float* xform, float srcx, float srcy);

Transform a point by given transform.

nvgDegToRad

float nvgDegToRad(float deg);

Converts degrees to radians and vice versa.

nvgRadToDeg

float nvgRadToDeg(float rad);

Images

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.
The parameter imageFlags is combination of flags defined in NVGimageFlags.

nvgCreateImage

int nvgCreateImage(NVGcontext* ctx, const char* filename, int imageFlags);

Creates image by loading it from the disk from specified file name.
Returns handle to the image.

nvgCreateImageMem

int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata);

Creates image by loading it from the specified chunk of memory.
Returns handle to the image.

nvgCreateImageRGBA

int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data);

Creates image from specified image data.
Returns handle to the image.

nvgUpdateImage

void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data);

Updates image data specified by image handle.

nvgDeleteImage

void nvgDeleteImage(NVGcontext* ctx, int image);

Deletes created image.

Paints

NanoVG supports four types of paints: linear gradient, box gradient, radial gradient and image pattern.
These can be used as paints for strokes and fills.

nvgLinearGradient

NVGpaint nvgLinearGradient(NVGcontext* ctx, float sx, float sy, float ex, float ey, NVGcolor icol, NVGcolor ocol);

Creates and returns a linear gradient. Parameters (sx,sy)-(ex,ey) specify the start and end coordinates of the linear gradient, icol specifies the start color and ocol the end color.
The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().

nvgBoxGradient

NVGpaint nvgBoxGradient(NVGcontext* ctx, float x, float y, float w, float h, float r, float f, NVGcolor icol, NVGcolor ocol);

Creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering drop shadows or highlights for boxes. Parameters (x,y) define the top-left corner of the rectangle, (w,h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient.
The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().

nvgRadialGradient

NVGpaint nvgRadialGradient(NVGcontext* ctx, float cx, float cy, float inr, float outr, NVGcolor icol, NVGcolor ocol);

Creates and returns a radial gradient. Parameters (cx,cy) specify the center, inr and outr specify the inner and outer radius of the gradient, icol specifies the start color and ocol the end color.
The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().

nvgImagePattern

NVGpaint nvgImagePattern(NVGcontext* ctx, float ox, float oy, float ex, float ey, float angle, int image, float alpha);

Creates and returns an image pattern. Parameters (ox,oy) specify the left-top location of the image pattern, (ex,ey) the size of one image, angle rotation around the top-left corner, image is handle to the image to render.
The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().

Scissoring

Scissoring allows you to clip the rendering into a rectangle. This is useful for various user interface cases like rendering a text edit or a timeline.

nvgScissor

void nvgScissor(NVGcontext* ctx, float x, float y, float w, float h);

Sets the current scissor rectangle.
The scissor rectangle is transformed by the current transform.

nvgIntersectScissor

void nvgIntersectScissor(NVGcontext* ctx, float x, float y, float w, float h);

Intersects current scissor rectangle with the specified rectangle.
The scissor rectangle is transformed by the current transform.
Note: in case the rotation of previous scissor rect differs from the current one, the intersection will be done between the specified rectangle and the previous scissor rectangle transformed in the current transform space. The resulting shape is always rectangle.

nvgResetScissor

void nvgResetScissor(NVGcontext* ctx);

Reset and disables scissoring.

Paths

Drawing a new shape starts with nvgBeginPath(), it clears all the currently defined paths.
Then you define one or more paths and sub-paths which describe the shape. The are functions to draw common shapes like rectangles and circles, and lower level step-by-step functions, which allow to define a path curve by curve.
NanoVG uses even-odd fill rule to draw the shapes. Solid shapes should have counter clockwise winding and holes should have counter clockwise order. To specify winding of a path you can call nvgPathWinding(). This is useful especially for the common shapes, which are drawn CCW.
Finally you can fill the path using current fill style by calling nvgFill(), and stroke it with current stroke style by calling nvgStroke().
The curve segments and sub-paths are transformed by the current transform.

nvgBeginPath

void nvgBeginPath(NVGcontext* ctx);

Clears the current path and sub-paths.

nvgMoveTo

void nvgMoveTo(NVGcontext* ctx, float x, float y);

Starts new sub-path with specified point as first point.

nvgLineTo

void nvgLineTo(NVGcontext* ctx, float x, float y);

Adds line segment from the last point in the path to the specified point.

nvgBezierTo

void nvgBezierTo(NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y);

Adds cubic bezier segment from last point in the path via two control points to the specified point.

nvgQuadTo

void nvgQuadTo(NVGcontext* ctx, float cx, float cy, float x, float y);

Adds quadratic bezier segment from last point in the path via a control point to the specified point.

nvgArcTo

void nvgArcTo(NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius);

Adds an arc segment at the corner defined by the last path point, and two specified points.

nvgClosePath

void nvgClosePath(NVGcontext* ctx);

Closes current sub-path with a line segment.

nvgPathWinding

void nvgPathWinding(NVGcontext* ctx, int dir);

Sets the current sub-path winding, see NVGwinding and NVGsolidity.

nvgArc

void nvgArc(NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir);

Creates new circle arc shaped sub-path. The arc center is at cx,cy, the arc radius is r, and the arc is drawn from angle a0 to a1, and swept in direction dir (NVG_CCW, or NVG_CW).
Angles are specified in radians.

nvgRect

void nvgRect(NVGcontext* ctx, float x, float y, float w, float h);

Creates new rectangle shaped sub-path.

nvgRoundedRect

void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r);

Creates new rounded rectangle shaped sub-path.

nvgRoundedRectVarying

void nvgRoundedRectVarying(NVGcontext* ctx, float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft);

Creates new rounded rectangle shaped sub-path with varying radii for each corner.

nvgEllipse

void nvgEllipse(NVGcontext* ctx, float cx, float cy, float rx, float ry);

Creates new ellipse shaped sub-path.

nvgCircle

void nvgCircle(NVGcontext* ctx, float cx, float cy, float r);

Creates new circle shaped sub-path.

nvgFill

void nvgFill(NVGcontext* ctx);

Fills the current path with current fill style.

nvgStroke

void nvgStroke(NVGcontext* ctx);

Fills the current path with current stroke style.

Text

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. I.e. following works regardless of scaling:

	const char* txt = "Text me up.";
	nvgTextBounds(vg, x,y, txt, None, bounds);
	nvgBeginPath(vg);
	nvgRect(vg, bounds[0],bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]);
	nvgFill(vg);

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

nvgCreateFont

int nvgCreateFont(NVGcontext* ctx, const char* name, const char* filename);

Creates font by loading it from the disk from specified file name.
Returns handle to the font.

nvgCreateFontAtIndex

int nvgCreateFontAtIndex(NVGcontext* ctx, const char* name, const char* filename, const int fontIndex);

fontIndex specifies which font face to load from a .ttf/.ttc file.

nvgCreateFontMem

int nvgCreateFontMem(NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData);

Creates font by loading it from the specified memory chunk.
Returns handle to the font.

nvgCreateFontMemAtIndex

int nvgCreateFontMemAtIndex(NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData, const int fontIndex);

fontIndex specifies which font face to load from a .ttf/.ttc file.

nvgFindFont

int nvgFindFont(NVGcontext* ctx, const char* name);

Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.

nvgAddFallbackFontId

int nvgAddFallbackFontId(NVGcontext* ctx, int baseFont, int fallbackFont);

Adds a fallback font by handle.

nvgAddFallbackFont

int nvgAddFallbackFont(NVGcontext* ctx, const char* baseFont, const char* fallbackFont);

Adds a fallback font by name.

nvgResetFallbackFontsId

void nvgResetFallbackFontsId(NVGcontext* ctx, int baseFont);

Resets fallback fonts by handle.

nvgResetFallbackFonts

void nvgResetFallbackFonts(NVGcontext* ctx, const char* baseFont);

Resets fallback fonts by name.

nvgFontSize

void nvgFontSize(NVGcontext* ctx, float size);

Sets the font size of current text style.

nvgFontBlur

void nvgFontBlur(NVGcontext* ctx, float blur);

Sets the blur of current text style.

nvgFontFaceId

void nvgFontFaceId(NVGcontext* ctx, int font);

Sets the font face based on specified id of current text style.

nvgFontFace

void nvgFontFace(NVGcontext* ctx, const char* font);

Sets the font face based on specified name of current text style.

Texture (enum)

Internal Render API

MemberValue
NVG_TEXTURE_ALPHA = 0x010x01
NVG_TEXTURE_RGBA = 0x02, }0x02

Scissor (struct)

Member
float xform[6];ndarray[type=float, size=6]
float extent[2];ndarray[type=float, size=2]

Vertex (struct)

Member
float x,
y,
u,
v;

Path (struct)

Member
int first;
int count;
unsigned char closed;
int nbevel;
NVGvertex* fill;
int nfill;
NVGvertex* stroke;
int nstroke;
int winding;
int convex;

Params (struct)

Member
void* userPtr;
int edgeAntiAlias;

nvgCreateInternal

NVGcontext* nvgCreateInternal(NVGparams* params);

Constructor and destructor, called by the render back-end.

nvgDeleteInternal

void nvgDeleteInternal(NVGcontext* ctx);

nvgInternalParams

NVGparams* nvgInternalParams(NVGcontext* ctx);

nvgDebugDumpPathCache

void nvgDebugDumpPathCache(NVGcontext* ctx);

Debug function to dump cached path data.

nvg_imgui.h

Submodule nvg_imgui

nvg_imgui (struct)

nvg_imgui::NvgCreateFlags (enum)

Combination of NVGcreateFlags in nanovg_gl.h + nanovg_mtl.h

MemberValue
NVG_ANTIALIAS = 1<<0, Flag indicating if geometry based antialiasing is used (may not be needed when using MSAA).1<<0
NVG_STENCIL_STROKES = 1<<1, Flag indicating if strokes should be drawn using stencil buffer. The rendering will be a little slower, but path overlaps (i.e. self-intersecting or sharp turns) will be drawn just once.1<<1
NVG_DEBUG = 1<<2, Flag indicating that additional debug checks are done.1<<2
NVG_DOUBLE_BUFFER = 1 << 12, Flag indicating if double buffering scheme is used (Metal only!)1 << 12
NVG_TRIPLE_BUFFER = 1 << 13, } Flag indicating if triple buffering scheme is used (Metal only!)1 << 13
nvg_imgui::CreateNvgContext_HelloImGui
NVGcontext* CreateNvgContext_HelloImGui(int flags = 0);

If using HelloImGui, you can use this function to create a NanoVG context (it will select the correct function depending on the rendering backend)

nvg_imgui::DeleteNvgContext_HelloImGui
void DeleteNvgContext_HelloImGui(NVGcontext* vg);
nvg_imgui::NvgFramebuffer (struct)

NvgFramebuffer: a framebuffer that can be used by NanoVG + ImGui
Internally stored inside the renderer backend (e.g. OpenGL)
Note: this class can be instantiated only after a valid renderer backend (OpenGL) has been created

Member
NVGcontext *vg = nullptr;
int Width = 0,
Height = 0;
int NvgImageFlags = 0;
ImTextureID TextureId = {};
nvg_imgui::NvgFramebuffer::NvgFramebuffer
NvgFramebuffer( NVGcontext *vg, int width, int height, int nvgImageFlags );

See NVGimageFlags

Warning: this constructor can be called only after a valid renderer backend (OpenGL) has been created (will call Init())

nvg_imgui::NvgFramebuffer::Bind
void Bind();

Make the framebuffer the current render target

nvg_imgui::NvgFramebuffer::Unbind
void Unbind();

Restore the previous render target

nvg_imgui::RenderNvgToBackground
void RenderNvgToBackground( NVGcontext* vg, NvgDrawingFunction nvgDrawingFunction, ImVec4 clearColor = ImVec4(0.f, 0.f, 0.f, 1.f) );

Render the given drawing function to the background of the application (i.e. the main viewport)
If clearColor.w > 0., the background will be cleared with this color

nvg_imgui::RenderNvgToFrameBuffer
void RenderNvgToFrameBuffer( NVGcontext* vg, NvgFramebuffer& texture, NvgDrawingFunction drawFunc, ImVec4 clearColor = ImVec4(0.f, 0.f, 0.f, 1.f) );

Render the given drawing function to the given framebuffer
If clearColor.w > 0., the background will be cleared with this color

nvg_cpp_text.h

nvgcpp_Text

float nvgcpp_Text(NVGcontext* ctx, float x, float y, const std::string& text);

Draws text string at specified location. If end is specified only the sub-string up to the end is drawn.

C++ Wrappers to NanoVG text functions, to simplify python bindings

nvgcpp_TextBox

void nvgcpp_TextBox(NVGcontext* ctx, float x, float y, float breakRowWidth, const std::string& text);

Draws multi-line text string at specified location wrapped at the specified width. If end is specified only the sub-string up to the end is drawn.
White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
Words longer than the max width are split at nearest character (i.e. no hyphenation).

nvgcpp_TextBounds

std::tuple<Bounds, float> nvgcpp_TextBounds(NVGcontext* ctx, float x, float y, const std::string& text);

Measures the specified text string. Parameter bounds should be a pointer to float[4], if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
Returns the bounds + the horizontal advance of the measured text (i.e. where the next character should drawn)
Measured values are returned in local coordinate space.

nvgcpp_TextBoxBounds

Bounds nvgcpp_TextBoxBounds(NVGcontext* ctx, float x, float y, float breakRowWidth, const std::string& text);

Measures the specified multi-text string. Parameter bounds should be a pointer to float[4], if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
Measured values are returned in local coordinate space.

nvgcpp_TextGlyphPositions

std::vector<NVGglyphPosition> nvgcpp_TextGlyphPositions(NVGcontext* ctx, float x, float y, const std::string& text);

Calculates the glyph x positions of the specified text. If end is specified only the sub-string will be used.
Measured values are returned in local coordinate space.

TextMetricsData (struct)

Member
float ascender;
float descender;
float lineh;

nvgcpp_TextMetrics

TextMetricsData nvgcpp_TextMetrics(NVGcontext* ctx);

Returns the vertical metrics based on the current text style.
Measured values are returned in local coordinate space.

TextRowSimple (struct)

Member
std::string row_text;
float width;Logical width of the row.
float minx,Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
maxx;Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.

nvgcpp_TextBreakLines

std::vector<NVGtextRowSimple> nvgcpp_TextBreakLines(NVGcontext* ctx, const std::string& text, float breakRowWidth);

Breaks the specified text into lines. If end is specified only the sub-string will be used.
White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
Words longer than the max width are split at nearest character (i.e. no hyphenation).

nvgcpp_TextAlign

void nvgcpp_TextAlign(NVGcontext* ctx, int align);

Sets the text align of current text style, see NVGalign for options.

nvgcpp_TextLineHeight

void nvgcpp_TextLineHeight(NVGcontext* ctx, float lineHeight);

Sets the proportional line height of current text style. The line height is specified as multiple of font size.

nvgcpp_ImageSize

std::tuple<int, int> nvgcpp_ImageSize(NVGcontext* ctx, int image);

Returns the dimensions of a created image.