4bb4 / implot-rs

Rust bindings to https://github.com/epezent/implot
Apache License 2.0
54 stars 23 forks source link

Drawing many rects possible? #2

Closed Boscop closed 3 years ago

Boscop commented 4 years ago

Thanks for providing bindings to ImPlot, it seems to have a lot of great potential! :) (Unfortunately it's not on crates.io, I first searched there and couldn't find it, I only found it by accident.)

I'm familiar with imgui-rs but haven't use implot yet. I need to decide what the best way is to render dynamic data (rendering as ~10k rects each frame).

Is it possible to render something like this with implot?

image

Does it support the following?

  1. (transparent) rects
  2. with border color different from fill color
  3. border thickness
  4. 10k rects without high CPU usage?
  5. text labels anywhere in the "canvas" with flat-colored background to make them more readable
  6. rendering without axes & axis labels
4bb4 commented 4 years ago

(Unfortunately it's not on crates.io, I first searched there and couldn't find it, I only found it by accident.)

The reason for that is that I'm waiting for a release of implot-rs that includes https://github.com/Gekkio/imgui-rs/pull/339 - until that time, I have to depend on an unreleased version of imgui-rs, which in turn means I can't publish to crates.io. I plan on publishing as soon as that imgui-rs release comes out though. I considered "parking" the crate name with a redirect to the repo here, but that might be frowned upon by crates.io and could lead to confusion if people don't read the readme.

I've been adding features at a relatively comfortable pace because I've only used the library for myself so far, but I'd try to be as responsive as possible if anyone starts using it more seriously. I'd also be open to adding collaborators to the repo or just getting PRs.

Is it possible to render something like this with implot?

I'll answer to the best of my knowledge so far, but it may be better to ask over at implot itself (https://github.com/epezent/implot) - the author is pretty responsive and will be able to answer your questions in more detail. One thing to note is that I'm currently pointing to an older version of implot-rs. I plan on reaching out to @epezent to ask what the API stability looks like and whether it's a good idea to "move to the current release" now, or if there are major API changes to be expected in the near future.

  1. (transparent) rects

I don't know of a "PlotBox" function in implot, at least not in the release I'm currently wrapping here. Could likely be added though, but that'd have to be done in implot itself and then wrapped here - I'd prefer contributing new functionality to the base library and then wrapping it over adding functionality in the wrapper. You can definitely draw outlines of rectangles with PlotLine, but I guess that's clear and doesn't add filling.

  1. with border color different from fill color

Once 1. is addressed, adding a different border should not be hard - one can draw the outline separately with PlotLine, for example.

  1. border thickness

Lines can have thicknesses and colors, yes.

  1. 10k rects without high CPU usage?

This part I'm not that convinced about - especially if drawing things with imgui primitives itself is slow, I'm not sure if ImPlot (which, I presume, uses the same primitives internally) will be faster. The only thing that might be nice is that ImPlot has a feature where the data for plots is culled to only what is visible in the current viewport, so I presume things that are not currently shown are also not drawn.

  1. text labels anywhere in the "canvas" with flat-colored background to make them more readable

Text is supported using PlotText, I don't know about any background feature though.

  1. rendering without axes & axis labels

You can fully turn off axis labels, the grid and ticks, or also customize axis ticks if you like.

@epezent If you happen to read this and spot anything wrong, please correct me!

4bb4 commented 3 years ago

Closing this due to inactivity.