{"id":22886593,"url":"https://github.com/silkcommunity/silkynvg","last_synced_at":"2025-06-15T08:04:59.067Z","repository":{"id":53113306,"uuid":"338348677","full_name":"SilkCommunity/SilkyNvg","owner":"SilkCommunity","description":"NanoVectorGraphicsExceptItUsesSilkNETNowWooHoo (Thank KoziLord for the name)","archived":false,"fork":false,"pushed_at":"2025-03-13T21:25:28.000Z","size":2832,"stargazers_count":29,"open_issues_count":5,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T10:29:11.969Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SilkCommunity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-02-12T14:56:25.000Z","updated_at":"2025-03-08T12:48:23.000Z","dependencies_parsed_at":"2025-03-05T23:23:42.199Z","dependency_job_id":"9fad488a-f775-40e3-9955-be258c97aca4","html_url":"https://github.com/SilkCommunity/SilkyNvg","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/SilkCommunity/SilkyNvg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SilkCommunity%2FSilkyNvg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SilkCommunity%2FSilkyNvg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SilkCommunity%2FSilkyNvg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SilkCommunity%2FSilkyNvg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SilkCommunity","download_url":"https://codeload.github.com/SilkCommunity/SilkyNvg/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SilkCommunity%2FSilkyNvg/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259942766,"owners_count":22935326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-13T20:19:23.243Z","updated_at":"2025-06-15T08:04:59.040Z","avatar_url":"https://github.com/SilkCommunity.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SilkyNvg\n[![NuGet](https://img.shields.io/nuget/v/SilkyNvg)](https://nuget.org/packages/SilkyNvg)\n\nNanoVectorGraphicsExceptItUsesSilkNETNowWooHoo (Thank KoziLord for the description)\n(A port of [memononen/nanovg](https://github.com/memononen/nanovg/) to .NET)\n\nSilkyNvg is a small library providing basic 2D-Drawing functionallity well suited for UI and other such applications. It provides basic shape capabillities like rectangles or circles, as well as the abillity to build custom paths which can either be filled or stroked (lines).\nThe colour can either be a colour (`SilkyNvg.Colour`), a paint (`SilkyNvg.Paint`) or an image (`SilkyNvg.Paint`).\nOn top of this a simple text-drawing-API is provided. See [FontStash.NET](https://github.com/MatijaBrown/FontStash.NET) for further details.\n\n## Usage / Examples\n\u003e A transcription of the NanoVG example can be found in the '[samples](https://github.com/MatijaBrown/SilkyNvg/tree/main/samples)' directory.\n\n### Initialization And Rendering\nTo create a new Nvg instance, an implementation of `SilkyNvg.Rendering.INvgRenderer` must be specified,\nthen an instance can simply be created like this: `Nvg nvg = Nvg.Create(renderer);`.\n\nAll calls to the render-API must be wrapped between `Nvg.BeginFrame(width, height, pixelRatio);`\nand ``Nvg.EndFrame();``. To transform from a pixel-based coordinate system to any other, with and height can have any values independant from the actual window's size.\n\n### Further Details\nFor further details, see the [NanoVG doc](https://github.com/memononen/nanovg/), as the API and implementations are intentionally kept similar.\n\n## API Description\n\n### Paths\n*Paths* form the basis of *SilkyNvg* rendering. To begin drawing a *path*, call `NvgPaths.BeginPath`, which clears the path cache and intialises drawing a new path.\nA *path* is composed of five basic instructions: *MoveTo*, *LineTo* *BezierTo* and *Close*. *MoveTo* jumps to the specified point, *Close* is special in that it\nreturns to the paths origin with a straight line.\nIt is easiest to imagine this as a pen, tracing out the desired shape on a canvas, picking up and setting down for *MoveTo* instructions.\n\nAdditionaly, many convenience methods are provided to draw more complex shapes such as *arcs*, *ellipses* or *rectangles*. These are constructed from the atomic\nsegments above.\n\nThe following example would create the *path* for a simple rectangle.\n```csharp\nnvg.BeginPath();\nnvg.MoveTo(100, 100);\nnvg.LineTo(150, 100);\nnvg.LineTo(150, 150);\nnvg.LineTo(100, 150);\nnvg.Close();\n```\n\n### Fill and Stroke\nThere are two ways to render your *path*: **Stroke** and **Fill**.\n**Fill** fills the traced out path according to the specified *winding rule*. `Winding.Cw // Clockwise` winding draws the path as a hole, `Winding.Ccw // Counter-Clockwise` fills it regularly.\n**Stroke** draws along the path, tracing out then \"pen's\" journey about the canvas. Behaviour at sharp corners and ends can be specified using `NvgRenderStyle.LineJoin` and `NvgRenderStyle.LineCap`.\n\n### Paints\nThe manner in which the *fill* and *stroke*s actually show up is handled by **paints**. These can be either specified as\n1. A solid colour\n2. A linear, radial or box gradient\n3. An image\n\n*SilkyNvg* uses different *paints* for **fill** and **stroke** rendering, which can be set by `Nvg.FillPaint` and `Nvg.StrokePain` respectively.\nAdditionaly there are convenience methods `Nvg.FillColour` and `Nvg.StrokeColour` provided so that no new paint need be explicitly created for solid colour filling.\n\nFinally the `Paint` struct also exposes all settings in a public constructor, allowing the implementation of custom gradients using a paint transform.\n\n### Images\nAs mentioned above, instead of gradients or solid colours *paints* also provide the ability to set images as background for drawing *paths*.\nImages can be loaded, either from a file or memory using `NvgImages.CreateImage` / `NvgImages.CreateImageMem` / `NvgImages.CreateImageRgba`.\n\n### Fonts\n**[WORK IN PROGRESS]**\n\n### API structure\nThe implementations are split up into different components, these being:\n- SilkyNvg.Blending *for global blending*\n- SilkyNvg.Graphics *for render styles*\n- SilkyNvg.Images *for images*\n- SilkyNvg.Paths *for creating and drawing paths*\n- SilkyNvg.Scissoring *for custom scissors*\n- SilkyNvg.Text *for text*\n- SilkyNvg.Transforms *for creating and altering the transform*\n- SilkyNvg *for core methods, such as BeginFrame, DebugDumpCache, Colour and Paint*\nAll components are linked to `SilkyNvg.Nvg` via extension methods in their respective namespaces.\n\n## Renderers\nThe renderers are specified when creating the Nvg instance in `Nvg.Create`.\nSilkyNvg provides a Vulkan- and OpenGL-Renderer out of the box, but custom renderers can easilly be built using the `SilkyNvg.Rendering.INvgRenderer` interface.\nIt is standard for renderers taking a `CreateFlags` mask in their constructor used to specifiy renderer-specific settings.\n\n### Antialiasing\nSilkyNvg automatically calculates antialiased vertices if `SilkyNvg.Rendering.INvgRenderer.EdgeAntiAlias` is set to true. This is done because some renderers might not support antialiasing. In the custom renderers, the CreateFlags specify wheather or not antialiasing should be done.\n\n### OpenGL Renderer\nThe [OpenGL renderer](https://github.com/MatijaBrown/SilkyNvg/tree/main/src/rendering/SilkyNvg.Rendering.OpenGL)'s constructor takes 2 arguments; `SilkyNvg.Rendering.OpenGL.CreateFlags` and `Silk.NET.OpenGL.GL`. The second parameter is an API-Instance of OpenGL, the `CreateFlags` mask has the following options:\n- `CreateFlags.Antialias` States that the renderer should draw antialiased or raw meshes.\n- `CreateFlags.StencilStrokes` States that the renderer should use the stencil buffer when drawing strokes (lines).\n- `CreateFlags.Debug` States that the renderer should print errors.\n\n**Note**: *SilkyNvg* OpenGL renderer makes heavy use of the stencil buffer. Please remember to `glClear(... | ClearBufferMask.StencilBufferBit)`!\n\n### Vulkan Renderer\nThe [Vulkan renderer](https://github.com/MatijaBrown/SilkyNvg/tree/main/src/rendering/SilkyNvg.Rendering.Vulkan) is currently **deprectated** and only compatible with older versions of *Silky*. A faster update is in the works.\n\n### Custom Renderer Implementations\nTo create a custom render implementation, the renderer class musst implement `SilkyNvg.Rendering.INvgRenderer`.\nThis interface contains the following methods and properties:\n\n#### INvgRenderer\n- `bool EdgeAntiAlias` Wheather or not antialiasing was enabled when creating the renderer. Can depend on wheather antialiasing is supported and if its use was specified when instantiating the renderer.\n- `bool Create()` Is called when NanoVG is initialized. Initialize the renderer here. Return false if initialization failed, otherwise return true.\n- `int CreateTexture(Texture type, SizeF size, ImageFlags imageFlags, ReadOnlySpan\u003cbyte\u003e data)` Is called to create a new image. *type* parameter specifies wheather *data* should be interpreted either as **RGBA** or **Alpha** values. Return handle to the new image.\n- `bool DeleteTexture(int image)` Is called to delete an image. Return false if image was not found, otherwise return true.\n- `bool UpdateTexture(int image, Rectangle bounds, ReadOnlySpan\u003cbyte\u003e data)` Updates a specific section of the image to the new *data*. Return false if the image was not found, otherwise true.\n- `bool GetTextureSize(int image, out SizeF size)` Returns the size of the specified image. Return false if the image was not found, otherwise true.\n- `void Viewport(SizeF size, float devicePxRatio)` Is called once per frame during `Nvg.BeginFrame` to set the viewport size and pixel ratio.\n- `void Cancel()` Stops drawing the frame. Clear all cached data.\n- `void Flush()` Draws the frame. Render everything here.\n- `void Fill(Paint paint, CompositeOperationState compositeOperation, Scissor scissor, float fringe, RectangleF bounds, IReadOnlyList\u003cPath\u003e paths)` Is called on ``Nvg.Fill()``. Signals that the data contained in *paths* should be added to the rendered when flushing.\n- `Stroke(Paint paint, CompositeOperationState compositeOperation, Scissor scissor, float fringe, float strokeWidth, IReadOnlyList\u003cPath\u003e paths)` Is called on ``Nvg.Stroke()``. Signals that the data contained in *paths* should be added to the rendered when flushing.\n- `Triangles(Paint paint, CompositeOperationState compositeOperation, Scissor scissor, ICollection\u003cVertex\u003e vertices, float fringeWidth)` Is called when rendering text. Signals that the *vertices* should be added should be added to the rendered when flushing.\n- `Dispose()` Delete and shut down the renderer.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilkcommunity%2Fsilkynvg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsilkcommunity%2Fsilkynvg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilkcommunity%2Fsilkynvg/lists"}