Which 2D graphics library for a UI toolkit

Hi,

I am trying to create a simple UI toolkit and I am trying to wrap my head around which graphic library fits better to my requirements:

  1. Easy to use.
  2. Portable (Linux, macOS, Windows 10)
  3. Pretty stable (API and implementation).
  4. Allow accelerated drawing operations inside an image (see later).
  5. 3D primitives [optional at the moment]

As I understood Piston Graphics is a simple 2D high level library with multiple back-ends, so even it is not maybe super optimized, it satisfies almost my requirements, but I am not sure about the point 4 (point 5 at the moment is more a nice-to-have).

So what I mean with point 4 ("accelerated drawing operations inside an image")?
Since I am designing a UI toolkit I was thinking that most of the UI widgets/elements could be cached as image and layering them on top of each other (using alpha blending), avoiding to redraw (using drawing primitive) from scratch at every frame. So it would be great to have a graphics library that allows to draw graphics primitive inside a pixels buffer (image) and then just blit them to the video card memory.

Thank you.

1 Like

Have you looked into webrender? It's not stable, but I think it could be a solid foundation to build a UI tookit upon. An example project using webrender is limn: https://github.com/christolliday/limn.

2 Likes

Here's my current reading list of drawing APIs on crates.io, in case this can help. I have not yet started the project which led me to explore them (namely building a fancy plotting GTK widget), so I cannot comment on how nice they feel in practice.

  • https://github.com/nical/lyon : A GPU-accelerated 2D drawing library designed for rendering SVG. Looked the most interesting to me at the time, if it is mature enough.
  • https://github.com/gfx-rs/gfx : For lower-level "just give me an OpenGL context" use cases. Or in case I'm not satisfied with higher-level crates.
  • https://github.com/gtk-rs/cairo : A Rust binding for cairo. Not the flashiest drawing toolkit out there, it shows its age in some ways, but the popularity of the C library should make it easier to find documentation/help.
1 Like

Have you seen conrod? Might be higher level than you are looking for though.

Thank you all for the hints.

@matklad webrender seems interesting, but it's difficult to understand how it works. I would prefer base my software in something that it is easy to understand and use and it is not doing lot of stuff under the hood. But maybe I wrong.

@HadrienG my idea was using graphics since it is very generic, high level and easy to use, and I could also change the back-end in the future without changing my code, gfx-rs seems a little harder to be used, but anyway offers lot of stuff that maybe could be useful if I need some advanced stuff in my toolkit.
Cairo is a binding, and I am trying to avoid C/C++ binding in order to make portability easier.

@johnthagen I know conrod, but I don't like too much immediate UI, I am an old school guy :wink:

1 Like