Skip to content
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

Extending ImGUI with custom widgets? #28

Closed
djoshea opened this issue Aug 22, 2014 · 4 comments
Closed

Extending ImGUI with custom widgets? #28

djoshea opened this issue Aug 22, 2014 · 4 comments

Comments

@djoshea
Copy link

djoshea commented Aug 22, 2014

Hey Omar,

In using ImGUI for a project, I'd like to make a custom plot widget (e.g. multiple timeseries on the same axis). I'm wondering how I should go about implementing something like this. I can't just copy the code for ImGui::Plot outside of imgui.cpp, because some of the methods it calls are declared static. I could just add a new method to your ImGui namespace, but then I'm editing the imgui.cpp file directly, which means I'd have to merge in any updates that you push. Have you given any thought to how a developer could add their own widgets?

Obviously messing around with the low level ImGui code might break things if I don't implement it correctly, but this seems fine given the purpose.

@ocornut
Copy link
Owner

ocornut commented Aug 26, 2014

Hello,

This is one area that I want to improve on and I expect many similar requests in the future (people around me who have been using the library asked for that as well).

a/
Exposing more of ImGui outside the .cpp file is faisable but I am concerned about the confusion it would add to the casual user. ImGui also relies on a few things not "leaking" outside of the .cpp file, such as the math operators defined on ImVec2 / ImVec4. The maths operators are ok as in but if the user wants to use implicit cast operators between ImVec2/4 and their own types, the maths operators becomes a problem if they leak to the header. So I will probably end up either not using them or reworking the file structure.

b)
The simple solution I propose that we try for now is the following:
Add an #include directive at the bottom of the .cpp file and you can add the code in this file. Then you can update without risking a merge conflict. It is nicely parallel to the use of imconfig.h and perhaps this file could be called imconfig.cpp ? imuser.cpp ?

I am interested in your feedback if you try that, and seeing how implementing new custom widgets goes for you. Any confusion you have is probably a hint toward something that can be improved. Then I can potentially make that change into core ImGui, make the #include optional via a #define in imconfig.h, etc.

@ocornut
Copy link
Owner

ocornut commented Sep 10, 2014

I added a #define IMGUI_INCLUDE_IMGUI_USER_CPP that implement the solution suggested in b)
You can create a file imgui_user.cpp (it isn't in the source control and won't be overriden)
Let me know if that works for you.

@ocornut
Copy link
Owner

ocornut commented Dec 10, 2014

This is solved afaik with IMGUI_INCLUDE_IMGUI_USER_INL / IMGUI_INCLUDE_IMGUI_USER_H

@ocornut ocornut closed this as completed Dec 10, 2014
@djoshea
Copy link
Author

djoshea commented Dec 10, 2014

Great, thanks Omar! I meant to tell you that your solution sounded fine, and I ended up just including your cpp code directly into my own file where I added a few extra functions. I also came up with a nice oscilloscope plot, based mostly on your graph but with units and the y-limits labeled. I'm really appreciative that you took the time to share this. It's been super helpful in putting simple frontends on tools I build in lab. This one monitors a load cell coming in via a DAQ and sends it out via UDP.

loadcell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants