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

A problem about ImGui::Selectable with using Linknode #2667

Closed
kwangsing3 opened this issue Jul 15, 2019 · 2 comments
Closed

A problem about ImGui::Selectable with using Linknode #2667

kwangsing3 opened this issue Jul 15, 2019 · 2 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@kwangsing3
Copy link

kwangsing3 commented Jul 15, 2019

Platform: Windows10
Using: opengl3
defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
#include <glad/glad.h>

Sorry, but I had read many bunch of questions about how to dynamic add items to listbox or combo, follow those examples, I failed once and once again.

Now, I trying to do that with Linknode, it doesn't work perfectly, but I do not understand why,
and I opened a new place, sorry about that :P

Here is the code I copied and edited from ImGuiDemo.cpp to my GUI.

struct listbool
{
	bool selected=false;
	listbool* next=NULL;
};

static listbool _headlistbool;
static listbool *_currentlistbool = &_headlistbool;
if (SceneManager::Objects.size() > 0)
{
	_currentlistbool = &_headlistbool;
	//static bool selection[5] = { false, false, false, false, false };
	for (int n = 0; n < SceneManager::Objects.size(); n++)
	{
		char buf[32];
		sprintf(buf, SceneManager::Objects[n]->transform.name, n);
		if (ImGui::Selectable(buf, _currentlistbool->selected))
		{
		//	if (!ImGui::GetIO().KeyCtrl)    // Clear selection when CTRL is not held
			//	Clear_ListBool(_headlistbool);
			_currentlistbool->selected =!_currentlistbool->selected;
		}
		if (_currentlistbool->next == NULL)
			_currentlistbool->next = new listbool();
		_currentlistbool = _currentlistbool->next;
	}	
}
else
	_currentlistbool->next = NULL;

Here's the video: https://youtu.be/tvHkQp5C0zw

---Update---
If I just using array, it works fine normally, I found that, this code couldn't be triggered, (except the first objects of them)
https://imgur.com/OumfQi1

if (ImGui::Selectable(buf, _currentlistbool->selected))
{
    _currentlistbool->selected =!_currentlistbool->selected;
}

Thanks and sorry, again :q

@ocornut
Copy link
Owner

ocornut commented Jul 15, 2019

Your IDs will collide if you have the same name multiple times at same point of hierarchy.
You probably need to use ImGui::PushID(SceneManager::Objects[n]); ... Selectable .. ImGui::PopID() to avoid the ID collision.

Please read the FAQ!

@ocornut ocornut closed this as completed Jul 15, 2019
@kwangsing3
Copy link
Author

kwangsing3 commented Jul 15, 2019

Sorry, I solved it 5 minutes ago, and you're right. :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack
Projects
None yet
Development

No branches or pull requests

2 participants