-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API] Include ImPlot #56
Conversation
Hm. I tried to add only the method that shows the demo window, unfortunately it gives an error when I enable the checkbox.
Any ideas? Maybe I have to implement the whole thing to get one method to work? |
Generator creates JNI layer, so it could be defined much easier. But everything else should be created manually. See PR with ImGuizmo, classes has a code where they are calling native API. |
😭 I already referenced ImGuizmo. As far as I can tell, I'm doing it as closely the same as possible, however ImNodes and ImGuizmo have some differences to ImPlot. Not sure what to try. |
Either you are not correctly building the dll files or you are not using the newest dll file. The UnsatisfiedLinkError is thrown when an application attempts to load a native library like .so in Linux, .dll on Windows or .dylib in Mac and that library does not exist. |
Ohhh! It works now. I didn't perform the step of copying from 2021-05-14.11-23-54.mp4 |
@calvertdw Can you please mark your PR as a WIP in the title? So I will understand when it will be good to review. |
de78a7c
to
cf09a20
Compare
(except for PlotImage, which is not currently supported)
@SpaiR @perrymacmurray has helped me put together the rest of this PR. It is ready for your review. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please remove bin/libimgui-java64.so
file from the list of modified stuff.
With minor adjustments changes look very decent and clean. Great job!
import java.net.URI; | ||
|
||
public class ExampleImPlot { | ||
private static final String URL = "https://github.com/epezent/implot"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the url to point to the concrete commit, instead of repo in general. As for other examples.
ImGui.checkbox("Show ImPlot Built-In Demo", showDemo); | ||
|
||
final Integer[] xs = {0, 1, 2, 3, 4, 5}; | ||
final Integer[] ys = {0, 1, 2, 3, 4, 5}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to move those axes to the class fields.
ImGui.setNextWindowSize(500, 400, ImGuiCond.Once); | ||
ImGui.setNextWindowPos(ImGui.getMainViewport().getPosX() + 100, ImGui.getMainViewport().getPosY() + 100, ImGuiCond.Once); | ||
if (ImGui.begin("ImPlot Demo", showImPlotWindow)) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use java style braces.
|
||
if (ImPlot.beginPlot("Example Plot")) { | ||
|
||
ImPlot.plotLine("Line", xs, ys); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broken indentation.
example/src/main/java/Main.java
Outdated
@@ -32,6 +36,11 @@ protected void initImGui(final Configuration config) { | |||
io.addConfigFlags(ImGuiConfigFlags.ViewportsEnable); // Enable Multi-Viewport / Platform Windows | |||
io.setConfigViewportsNoTaskBarIcon(true); | |||
|
|||
ImNodes.createContext(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below, you've fixed merge conflicts imporperly. See how this method looks in master.
IMPLOT_POINT = new ImPlotPoint(0); | ||
IMPLOT_LIMITS = new ImPlotLimits(0); | ||
IMPLOT_STYLE = new ImPlotStyle(0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create objects directly, without creating separate static block.
} | ||
|
||
private static native long nMin(long ptr); /* | ||
ImPlotPoint* p = new ImPlotPoint(((ImPlotLimits*)ptr)->Min()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like in all places with calling new
you'll create a memory leak, since in C++ we need to deallocate the heap memory.
} | ||
|
||
private static native boolean nContains(long ptr, double x, double y); /* | ||
return ((ImPlotLimits*)ptr)->Contains(x, y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
((ImPlotLimits*)ptr)
Instead of this construction you can use define like here: https://github.com/SpaiR/imgui-java/blob/master/imgui-binding/src/main/java/imgui/ImFont.java#L23 It's a common way I use everywhere.
I won't go through all places, but it's a common problem of the PR.
Changed ImPlotLimits, ImPlotRange, and ImPlotPoint to extend ImGuiStructDestroyable instead of ImGuiStruct so user-created instances can be destroyed. Methods that create instances that must be destroyed manually specify this in the docs.
@SpaiR I went ahead and fixed the problems you pointed out. I addressed the memory leaks by making the returned instances of the affected classes (ImPlotLimits, ImPlotRange, and ImPlotPoint) extend ImGuiStructDestroyable - this preserves allowing modifying passed data for ImPlot functions that return a Limit or Point pointer (such as for modifying a Range inside a Limit). I also added ImVec2 versions of some getters for when a user might want to simply get data and not worry about manual deallocation. If there's another way of handling memory that you would prefer so users don't have to worry about calling destroy(), I can change how I implemented the classes, but this method was the best way I could think of. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
For #27
I might need some help. When I run
./gradlew :imgui-binding:generateLibs -Denvs=linux64 -Dlocal
I don't see any generated Java. Am I missing something? I tried to copy from what @AAstroPhysiCS was doing with Imguizmo.Do I have to write the Java classes by hand? 😅
No problem if so.