Open dbr opened 3 years ago
I did not look into the specific code but I think this could be used instead https://doc.rust-lang.org/std/ops/struct.Range.html
or a From/ Into impl could be added.
As of https://github.com/4bb4/implot-rs/commit/f2a4c6a3d8919ec3438631873ce6a9f94135089c, one can do this almost as conveniently as listed in the issue, as demo-ed in https://github.com/4bb4/implot-rs/blob/f2a4c6a3d8919ec3438631873ce6a9f94135089c/implot-examples/examples-shared/src/line_plots.rs#L342.
I'll work on it a bit more to make it even more convenient and then create a release. The next few weeks are a bit busy though, so if you're in a rush, maybe fork the repo and point to that for the time being.
@dbr I finally got some time again to work on this - I added convenience functions y1_limits
through y3_limits
for direct limit setting, and improved the API so that you can directly pass in anything that is convertible to ImPlotRange
, which means your example code from above should also work now. The code is currently on master. Let me know if that suits your needs, then I'll create a release (I'd also like to use that code in projects and not point to git revisions :sweat_smile:). I can't upgrade to a newer imgui-rs yet before I fix that WGPU issue, but at least we get a better API in the meantime.
The new API looks great! Can't properly test yet as I'm using it in project with imgui-rs 0.7 (via the 13-upgrade-to-imgui-rs-0.7
branch), but roughing in the new API lets rustfmt condense my 8 lines of "set Y axis range" into 1 which is exactly what I was hoping for :partying_face:
I've now also merged those API changes over into the branch you mention. I've done more debugging to try and fix the issue I'm referring to in https://github.com/4bb4/implot-rs/issues/13#issuecomment-798972470, but have not yet been able to resolve the problem.
I may be missing something in the API, but currently to set the ranges of the X and Y axes requires quite a long chunk of code
..which is quite verbose
One simple change which would make things more consistent with
imgui-rs
would to take the ranges at[f32; 2]
(and convert them to ImPlotRange internally if required), this would shorten the example to:I always wonder if the
y_limits
could be by for the first Y limit, and a second method for the secondary Y axis if present,..or something along those lines (not too sure about the specific naming, would probably be easier to find if
y_limits_2
etc)Only semi-related, but
Plot::new().size(100.0, 200.0)
could also use this same convention for passing sizes as an array, which would fit more neatly with imgui-rs:could become just: