Closed calioranged closed 5 years ago
Yes, ImGui::Button will display a single clickable button with a label. As you said the return of that function will tell you if it was clicked or not.
The example below code will show a Button with "Save" label, on the moment when it's clicked it will call whatever code you have in it. You can call it more times for more buttons.
if (ImGui::Button("Save"))
{
//... my_code
}
if (ImGui::Button("Cancel"))
{
//... my_code
}
Hope this helps.
DJLink thanks a lot for that information.
So just to confirm, are you saying that with the following snippet:
if (ImGui::Button("Clear Colour"))
{
// do something
}
The first time that if (ImGui::Button("Clear Colour"))
is run, it will create a button with the label "Clear Colour", and then all subsequent runs will check if the 'Clear Colour' button was pressed, and if it was pressed then the body of the if() statement in the above code snippet will run?
it will create a button with the label "Clear Colour", and then all subsequent runs will check if the 'Clear Colour' button was pressed,
Your notion of "creating" a button is anchored in the classic retained-mode paradigm (RMGUI).
The idea with the IMGUI paradigm is that the button only exist if you call the function. From Dear ImGui point of view, the button only exists during the Button()
call. There's no trace of it before and after, apart from the visual output (we emit vertices that will be rendered to look like a button).
Essentially this will have the same effect you described. And if you stop calling the Button()
function, the button will stop appearing.
EDIT I suggest you read the links/references provided in the README regarding the IMGUI paradigm, it will help you understand what is going on.
ocornut I just followed some of those links and now I understand the difference between RMGUI and IMGUI. Thanks a lot for your help.
ImGui Button Freeze
i am using ImGui in my application for UI, my question is when i press the button the code in side if condition will execute , but once i pressed the button , I can't press the other button including pressed button , could any one let me know the solution, thank you in advance
if (ImGui::Button("Button")) { //... my_code }
ImGui Button Freeze
if (ImGui::Button("Button")) { //... my_code }
Hi could you provide a more complete sample, this code only has 1 button, where is the other button being used, inside the //my_code scope, outside?
Hi, no other button not inside the my_code , outside the my_code, for example, if (ImGui::Button("Save")) { //... my_code }
if (ImGui::Button("Cancel")) { //... my_code }
both those buttons should work even after pressing one time. When you say can't be pressed does the button not even highlight on mouse hover, or is only your logic inside that scope that doesn't run again? could it be some sort of internal condition on your logic that blocks it after one press?
Does this code allow you to press the buttons multiple times?
static bool show_window = true;
ImGui::Begin("My Window", &show_window);
if (ImGui::Button("Save"))
{
cout << "Button Pressed"; //or your IDE equivalent output log
}
if (ImGui::Button("Cancel"))
{
cout << "Button Pressed"; //or your IDE equivalent output log
}
ImGui::End();
Hi, thank you for the reply yes , once I press the button , that button even not highlight on mouse hover the next time and i can't modify window or i can press the other button or the same button
Yes the above code allow me to press buttons multiple time and also ,FPS also stop once press the button
Yes the above code allow me to press buttons multiple time and also ,FPS also stop once press the button
In this case, and if after pressing a button your code inside that scope is not using any imgui API call that means that the problem is not imgui but something else about your code logic which makes it difficult to help. My suggestions examining your code line by line, see what makes it break, since with fps stopped that means you are freezing the program somehow. Sorry can't help more but it doesn't seem to be imgui related.
Hi, thank you so much for the reply ok I will check my code once again and get back
Depends on what you are doing in your code.
If its something blocking and takes some time it will freeze the main loop of the application. May need to create a thread for that processing or some other method let the gui do some rendering.
Not aware of how imgui is implemented but this should be the case.
On Fri, Jun 26, 2020 at 11:31 AM chethana notifications@github.com wrote:
Hi, thank you for the reply yes , once I press the button , that button even not highlight on mouse hover the next time and i can't modify window or i can press the other button or the same button
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ocornut/imgui/issues/2481#issuecomment-650056787, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHA3RGP7GWU5BVP74R3TODRYRMGLANCNFSM4HEHRERQ .
i am using ImGui in my application for UI, my question is when i press the button the code in side if condition will execute , but once i pressed the button , I can't press the other button including pressed button , could any one let me know the solution,
Example Code
while(window)
{
// Poll and handle events (inputs, window resize, etc.)
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
glfwPollEvents();
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
{
static float f = 0.0f;
static int counter = 0;
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
ImGui::Checkbox("Another Window", &show_another_window);
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
{
for (int i = 0; i < 1000000; i++)
{
cout << i;
}
}
I Tried using thread but still have the same problem, it would be helpful if some one give me suggestion.
for (int i = 0; i < 1000000; i++)
{ cout << i; }
looping for 1000000 is a sure way to momentarily freeze the program. Code is executed in sequence, so until this finishes it won't allow the rest to execute. Games and Imgui are executed inside a "main" loop, which typically executes 60 times per second (60FPS), if you lock it somehow it won't be able to draw the next frame.
This might not be the best place for getting help with this part and threads. Here's the thing, once you enter that if(Imgui::Button) { } scope you are supposed to do your calculations and exit asap, otherwise you lock the whole program, this is not related to imgui, it would happen in anything else too. If you need something running in parallel, like a thread you mentioned I recommend looking at these resources:
https://en.cppreference.com/w/cpp/thread/thread https://www.tutorialspoint.com/cplusplus/cpp_multithreading.htm
But my best suggestion is to keep it simple inside that scope, run a small calculation/execution if possible, threads are a complicated thing at first, and feels like it might put even more confusion.
Hi, I wonder how to perform some task like calling multiple functions by pressing button and with out button freeze, i would like to get some suggestion
How about when you want to use ImGui::SameLine(); but the if is screwing everything cuz it won't let it stay on the same line, what option do i have to align the buttons?
How about when you want to use ImGui::SameLine(); but the if is screwing everything cuz it won't let it stay on the same line, what option do i have to align the buttons?
Where are you putting the SameLine()? Inside our outside The if? Please provide a sample so it's easier to evaluate
if (ImGui::Button("Unload")); SameLine(); { // Nvm, it's solved, i was doing this } if (ImGui::Button("Unload")) { //And its like this, was being dumb xD }; SameLine();
Newcomer to this
Beginner Question
What does ImGui::Button do? There is no explanation of this function in either the declaration or definition, but in the main.cpp file there is a line which says 'Buttons return true when clicked', which makes sense. But does ImGui::Button have any other use? Does this create buttons as well as check if they have been clicked? If not, then how are buttons initially created?