Using vector with Dear Imgui #8547
Replies: 5 comments 1 reply
-
I do believe I know the basics of Dear ImGui though. I need the last selected button to be known every frame, because another frame, it could be another button or control, but the iterator never seems to figure out where the last selected button is in the vector, even if I assign it by reference. I forgot to share how I call the panels in order. I call the Canvas first, then the Controls List Panel, then the inspector window panel. |
Beta Was this translation helpful? Give feedback.
-
Okay, so on debugging, I figured out, the iterator knows where the index is based on the last selected button, so when I go to actually It does access the correct index, but for some reason the inputs in my program editor just don't save. |
Beta Was this translation helpful? Give feedback.
-
I fixed it, although it doesn't make much sense to me. Instead of initializing the iterator to std::find_if, I needed to initialize it to std::button_macros.begin(), then I assign the iterator to std::find_if later. I don't quite understand because the iterator should have been initializing correctly, since there is a last selected button. I am doing this now: auto button_finder = button_macros.begin();
if (last_selected == nullptr)
{
spdlog::info("Nothing Selected...");
}
else
{
button_finder = std::find_if(button_macros.begin(), button_macros.end(), [&](Button& button) {return button.get_idName() == last_selected->get_idName(); });
} I also needed to make my input_cc and input_cm static for my inputs to save. The only issue that I'm have now is that my inputs aren't exactly saving. They "save", but the values reset soon after choose another object. |
Beta Was this translation helpful? Give feedback.
-
I have fixed the formatting in your posts to make them less discouraging to read (the code seems abnormally complex), but TL;DR nothing in your problem has anything to do with Dear ImGui, this is a general C++ question. |
Beta Was this translation helpful? Give feedback.
-
Thanks - I had a tough time with it. So my code actually works fine- The iterator works properly, the problem is where I go to calculate the distance.
button_finder works, it's just the index is always zero, making my inputs not saving and incorrect readouts. |
Beta Was this translation helpful? Give feedback.
-
Hi folks,
I've dabbled with programming for so many years but have never built a complete project before. I started working on my own midi controller for my music. It's going pretty well so far, but I'm stumped right now.
I have buttons that will send my midi data out(I do not have any midi code yet). They are stored in std::vector. No problems adding these to the vector. The issue is searching for these buttons. Basically when I click on a button inside my canvas, it will find the item and tell the code what the last selected button is and send it to my Inspector Panel. I've been using an iterator to find the element in the vector based on the Button last selected's name. The iterator index is always out of range. My program has no problems counting the number of elements or adding elements to the vector, it just cannot find the Button element I'm looking for.
Plain C++ has no problems finding elements so I bet I have a misunderstanding of Dear Imgui. I've been going at this issue for a week now and have researched quite a bit on using std::find_if without any luck. I hope I added my code correctly.
Thanks!
Global Declarations:
Button.h
Inspector Window:
Control List Panel:
Beta Was this translation helpful? Give feedback.
All reactions