ocornut / imgui Goto Github PK
View Code? Open in Web Editor NEWDear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
License: MIT License
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
License: MIT License
I have noticed that a couple of assignments are used in the constructor bodies.
Examples:
The recommended way for performing efficient construction is to use the initialisation list.
Hi Omar,
This is not really an issue, but more a suggestion about the library. I wanted to open the discussion with you before trying to implement something and send a PR. Let me know what you think!
I noticed the handy system to change colors per call using the PushStyleColor/PopStyleColor. That made me think about adding a PushTexCoords/PopTexCoords. If I'm correct every draw call that is not a text have texcoords that point to the upper-left corner of the font texture atlas, where a white pixel allow everything to get coloured correctly. Adding the pushpop methods I'm suggesting would allow to bypass this system and specify the texture coordinate of a custom skin. Allowing the library to render widgets with a much more customisable and complete style. At the same time it will continue to leverage the texture atlas and have only one texture binding for the whole batch of draw calls. The PushTexCoord would allow to specify the position of the skin in the atlas, and the PopTexCoord will at some point come back to the default notexture (0,0).
To be able to properly texture the different rectangles, I guess that it means that we will have to double the number of vertices per rectangles (to properly scale the texture at the corners). This can probably be done in the fragment shader without changing the number of vertices.
Except for this last bit, I think it would be a relatively easy and awesome feature to add to the library. Skinning is never totally required for a gui library but when well designed, it definitely push it to the next level.
So that was my random thoughts about your already really nice library!
Cheers,
Simon.
I'm using a little endian machine.
I was wondering if the library would still work on big endian systems (I guess I'll never use one, but my mind seems to like to create problems...).
Possible issues I can see:
These problems could be solved in two ways:
a) creating all the binaries on the same machine they're supposed to be used.
b) using a more robust approach:
I don't think this is a high-priority problem [solution (a) above needs no code change], but maybe some note should be written about it...
mattiasljungstrom says:
"I'm using SDL2, and when I input the key mappings from SDL2 for special keys they all have very large values. This also seems to brake the internal code of ImGui. I think it assumes all key code values are between 0-255?"
Function is declared as (imgui.h, 211):
bool SliderFloat4(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
but defined as (imgui.cpp, 3469):
bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format, float power) {
Parameter in declaration v[3] should be v[4], obviously (functionality is fine since the array size is basically just a comment, but users might declare v without enough storage space and end up stomping memory).
Running the OpenGL sample on a macbook, doing a physical click on the trackpad works fine with ImGui, but using tap-to-click produces about 50/50 UI response to no response.
This can be observed in the sample application.
It seems like if you split the slider into 1/4ths, the 3rd quarter is the section that is skipped.
Just that.
Are there any examples of using this library with C? The readme mentions that it works with C and C++, but I don't see any C function definitions.
I'm missing some way to give keyboard focus to a specific text input field.
Hi Omar.
There is no way to save/restore style, a cool feature !!!
In a separate file or in .ini would be fine.
I was looking to make a sort of script console with ImGui but as it is the text input is pretty un-customizable. I'd like to be able to hit the up arrow to go through history (which I could manage myself, no need to put input history in ImGui) and use tab for autocompletion (again, I can handle that).
InputText looks for a bunch of specific keys with IsKeyPressedMap() and then delegates them to edit_state or the stb_textedit control. Obviously that's where the customized keys need to be intercepted. Maybe it could take a structure that holds two arrays, one that flags which keys have custom behavior, and one to put the state of the key in:
struct InputTextKeyOverrides
{
bool IsOverridden[ImGuiKey_Count];
bool IsPressed[ImGuiKey_Count];
};
...
bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, InputTextKeyOverrides* overrides)
{
...
if (IsKeyPressedMap(ImGuiKey_UpArrow)) {
if(overrides->IsOverridden[ImGuiKey_UpArrow])
overrides->IsKeyPressed[ImGuiKey_UpArrow] = true;
else
edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_UP | k_mask);
}
And then user code would check for a keypress after calling InputText and handle it appropriately. (Would be nice to have an ImGuiKey_Tab for this as well.)
I dunno, just a thought.
First of all, thanks for this great little tool!
In my game engine I can sometimes call update() several times before I call render(). If I do this it seems like it triggers asserts in the ImGui code. Would it be possible to support this? I can code around it, but I figured it was worth mentioning.
Also, I'm using SDL2, and when I input the key mappings from SDL2 for special keys they all have very large values. This also seems to brake the internal code of ImGui. I think it assumes all key code values are between 0-255?
Thanks!
The sample would be shorter than programmable pipeline based one, and run on more architectures. (we can keep both samples)
Before rattling any discussion: This could be considered improper usage of ImGui, however in my ignorance I did use ImGui like this. I noticed the issue, and I think you should now about it.
Onto the issue:
Having Buttons with the same label, can cause unpredictable results.
In my case, with 2 buttons controlling two separate settings:
ImGui::Text("Settting 1:");
ImGui::SameLine();
if (ImGui::Button((setting1enabled) ? "Yes" : "No")){
setting1enabled = !setting1enabled;
}
ImGui::Text("Settting 2:");
ImGui::SameLine();
if (ImGui::Button((setting2enabled) ? "Yes" : "No")){
setting2enabled = !setting2enabled;
}
In both settings are true
, the label is identical ("Yes"
) for both buttons.
When the 2nd button is then clicked, ImGui::Button
will return false because
window->GetID(label);
(imgui.cpp: line 3076) will return the ID of the 1st item with that label.
Since it will check the mouse coordinates against the coordinates of the wrong button, it will report as not being pressed.
When setting1enabled = false
(or setting1enabled != setting2enabled
), the label on each button will be different, and everything works as expected.
In case more than two buttons have an identical label, button Bn
will only respond if the labels of B0,B1,...,Bn-1 != Bn
(I have not tried this, but this is what will happen most likely).
Idea for a solution:
This problem may also apply to other widgets.
Note: You may close this issue I you regard this issue as being unintended library usage. That being said, I think it would be nice if users could choose to use it like this anyway
They encode a float in a fixed-point format, but use 8096 as the scaling factor. I'd think it should be 8192, a proper power of 2. (Maybe you were thinking 4096?)
I'm writing a binding to ImGui for my scripting language and the existing API for PlotLines/Histogram isn't a very good fit. Something like the Combo() API that takes a callback function would be much nicer.
Actually, I may just make my own implementation and then submit a pull request! :)
It would be great if PlotLines could handle multiple graphs and get a format string for tooltip, for example "x %f\ny %f\nz %f" for a vector
Have you thought much about adding image widgets? Along with that: buttons as widgets, checkboxes, radio buttons, etc.
I'm adding it to my fork at the moment but it would help you had any thoughts on how you'd approach it.
One option of course is to just add fonts to the glyph.
Would you like to add more error handling for return values from functions like the following?
i'm missing simple interpolation widget editor like http://cubic-bezier.com , simply t=<0, 1>, two movable inner points. through sliders it's unintuitive for editing. Do you planning something like that? if not, i'll try to implement myself as imgui_user.inl
On my machine I get blurry text when multisampling is enabled.
I fixed it with the following change in void ImBitmapFont::RenderText
(line)
// Align to be pixel perfect
pos.x = (float)(int)(pos.x + 0.5f);
pos.y = (float)(int)(pos.y + 0.5f);
Note the brackets. I also set the io.PixelCenterOffset to 0.375 instead of 0.5.
Tested on an AMD HD6850 and Intel HD 3000.
In the openGL demo glDisable(GL_CULL_FACE) is used.
I'm not an expert of openGL, so I'm not sure if screen rendering is faster with cull face or not.
However I've found out that in ImImpl_RenderDrawLists(...) by using:
glEnable(GL_CULL_FACE);glCullFace(GL_FRONT);
// rendering code
glCullFace(GL_BACK); // at the end
everything seems to work, except the rendering of the caret when inserting text, that is missing.
I didn't test it very much, but if it's possible and if it's faster, maybe we can add some variable
that we can use to render the caret correctly with these settings.
This issue probably needs more testing to see if it's really worthy and if all the widgets get rendered in the correct way...
First of all, thanks for this marvelous gui library!
I've just started using it, and it looks quite promising.
I found it is easy to integrate in existing, however the example provided isn't completely explanatory.
In my case i'm using GLUT, and the issue is that rendering the ImGui overwrites anything that has already been drawn.
The ImGui::Render call is made just before glutSwapBuffers(); and after the application's drawing calls.
However, the background of the gui has the same color of the glClearColor, and is not transparent.
If I move a gui window around, or fiddle with its size, the background sometimes becomes transparent (See the enclosed example images, nr1 is the expected result)
I've copied the ImImpl_RenderDrawLists() function and most of the InitImGui() function of the opengl example.
My question is, how do I set up the ImGui rendering using GLUT such that it doesn't interfere with the items that have already been drawn?
Thanks in advance!
Hi Omar,
I bound uSynergy on imgui but I need to manually draw a mouse cursor on top of imgui on platform that lacks "hardware" one, typically, smartphone and consoles.
I tried to implement it in imgui but it' s a bit tricky. I need to create a fake window with tooltip flag set to be put at the end of the draw list and as method in ImGuiWindow are not virtual i must set a custom GUIStyle...
So, It can be convenient to add a method to display a cursor (ImGui::DisplayMouseCursor()) on demand, don't you think ?
This is more of a question. How do I detect if the mouse is currently over any ImGui window? Is this supported? Also, how do I detect if any input box currently has focus?
ImGui is a generic term which makes googling for this library uneasy.
While we can keep the git and source code "imgui" (if desired), it would be beneficial to include a keyword or two that would uniquely identify the library. Any suggestions?
This only affects the ImGuiColorEditMode_HEX code. I fixed it by just casting the pointers to unsigned int*:
if (alpha)
sscanf(p, "%02X%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz, (unsigned int*)&iw);
else
sscanf(p, "%02X%02X%02X", (unsigned int*)&ix, (unsigned int*)&iy, (unsigned int*)&iz);
This is more of a request than an issue.
Is there an easy way to change the font? I'm trying to embed this in my application, and the font is somewhat anti-aliased and pixelated.
In certain cases the clip rectangle in the command lists can have the max bounds (z,w) less than the min bounds (x,y). In the OpenGL example, expand the "Child regions" section and scroll the "With borders" all the way down. Then expand the "Widgets" section. The column separator for the "With border" widget is not clipped properly:
In this case, a negative height is passed to glScissor, which causes an invalid value error (GL_INVALID_VALUE).
This might be a nice-to-have feature.
Currently, all content that doesn't fit into a window is cut off at the window edge (apart from margin & padding) besides for several autofit widgets.
Would it be nice for ImGui::Text
to support autofitting as well?
This especially applies when the ImGuiWindowFlags_NoResize
flag is set, since there is no way to reveal any text not fitting into the window.
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.
For my engine it would be better if ImDrawVert had this layout instead. (Note: col and uv are flipped.) I can then memcpy the draw calls into my existing 2D pipeline.
struct ImDrawVert
{
ImVec2 pos;
ImU32 col;
ImVec2 uv;
};
At this moment I just hacked this into the code. It would be nice it there was a way to define this externally if possible.
Considering changing all tabs to spaces because it create noise in patches and makes the readability of code on GitHub a bit awkward. This will probably break the existing Pull Requests and perhaps forks. Better done earlier than later.
Hi everybody. Many compliments for the project! That's what I was looking for...
I'm new to ImGui (and to Github thanx to ImGui), so please be patient with me...
Now the issue:
I've found out that when I clamp the frame rate of my application to save CPU/GPU usage, double clicks stop working.
That's probably caused to the fact that ImGui::NewFrame() is called less frequently and the ImGui::MouseDoubleClickTime is too small to catch double clicks in these cases.
I've been able to work around the issue by using my own variables, catching double click events myself and refeeding the ImGui::MouseDoubleClicked array with them soon after ImGui::NewFrame().
This works, but maybe we could add a variable to tell ImGui we're going to set the ImGui::MouseDoubleClicked array directly ourself and ImGui should skip updating it inside ImGui::NewFrame(), can't we?
Another think I would like to know is whether or not ImGui can be used at zero frame per seconds.
I mean in 3D editor-like applications, where a postUpdate() should be called only as a response to some action by the user (e.g. dragging a window and stuff like that). That's the main reason why I've tried clamping the frame rate in the first place (currently I've tested it at 10 fps: ImGui works well with the double click fix, it's only not very smooth when dragging a window).
P.S. I'm using openGL on Ubuntu Linux 64 bit, but that shouldn't make any difference.
P.S.2. Actually another minor issue happened when working at low frame rates with my fix: in the demo project I wasn't able to minimize the "Debug" window (double clicking its title bar). All the other windows work as expected. And if I add the ImGui::Begin()/End() when creating it PLUS a name different from "Debug" it starts working again.
Hello!
ImGui looks very cool to me. A question though: in the README.md there are about ~5-7 lines of code to create the UI shown, but the examples include a rather long OpenGL/DirectX setup.
I understand the setup is required, because the library itself is agnostic of it.
Could you please write about how-to best setup OpenGL for the use with the library? Is it possible that at some moment the setup code would be included as a part of the library facilities?
Thanks ๐
An idea I had in mind for a bit - recently people at my previous workplace started implementing something along the same line so I'd thought I'd describe the idea here.
Implement a way for ImGui to export its output to a client on the network (likely local network). The client would display the UI and feed back mouse/keyboard inputs. This would be useful to save screen real-estate on the host.
Jordi at Media Molecule has been working on a web client to do that:
The "simple" implementation of that would be to be sending vertex buffers along the network.
Pros:
Aside from that the application or protocol needs a way to
And we need to implement a client. Jordi's approach to create a web based client using webgl sounds like a good approach to me.
Based on this idea it looks like the amount of vertex data may be the bottleneck.
a) Obviously we need to compress data. we need a compressor that is efficient and "imgui" friendly in the sense that ideally it would be added to ImGui.cpp without doubling its size. we also need a suitable decompressor on the client side (javascript if we are aiming for a web client).
b) Split the stream for each ImDrawList (corresponding to each window) and only send a diff of the data. Need to look for a diff engine. The imgui code would be able to place extra marker based on the layout to minimize the diff size if it can help.
c) Deinterleave the stream (e.g store all x position, then all y position, then all colors, etc.) + store everything as delta from the previous vertex. This will make operations such as moving a window very cheap (only the first vertex will change). Will result in lots of zeros (highly compressible) or patterns using value within close range.
d) Use indexed triangles or quads. Currently Imgui uses non-indexed triangles to simplify the implementation of the ImDrawList renderer but it isn't optimal when it comes to data size.
A combination of those things hopefully can get the data small enough to work over local network.
I have just set up a Patreon page - http://www.patreon.com/imgui
I'm interested in feedback about this. Obviously this won't change the license and it's not aimed at changing the dynamics of the project. It is just a way for me to see if it could allow me to sit down and spend focused days working on ImGui.
The idea is that I'm currently out of job, about to start a freelancing lifestyle. As much as I would love spending lots of time on ImGui I can't really justify it from an economical point of view so my time on it is rather limited at the moment. Because I have been hearing of various companies using ImGui for their work I would like the test the waters and see if Patreon might provide enough financial support to allow me to spend more time on ImGui (xxx days a week).
I don't expect small developers to financially support the project but for a middle-sized company it may be make sense to provide Patreon support rather than invest their own developers on improving/maintaining the library.
Again just testing the waters, please feedback!
It's strange to get a window without any content with null size.
And I didn't find any method to adjust window size to fit his content !
I'm trying to execute a command entered into an InputText when the user presses the enter key, but it doesn't seem to be possible.
InputText could return true not only if the text changed, but also if enter was pressed. Or a bool* or callback parameter could be added.
I would find a range slider very handy. Any plans to implement one?
When compiling with gcc 4.6 in Linux, two needed includes are missing from imgui.cpp:
limits.h
stdint.h
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.