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

Multiple windows with the same name. #4366

Closed
Stanlyhalo opened this issue Jul 26, 2021 · 1 comment
Closed

Multiple windows with the same name. #4366

Stanlyhalo opened this issue Jul 26, 2021 · 1 comment

Comments

@Stanlyhalo
Copy link

Version: 1.83
Branch: docking

**My Issue/Question:**How can I have multiple windows (initialized with ::Begin) with the same name?

I'm trying to have multiple windows for my game engine called "Project Hierarchy" and "Map Hierarchy", which works fine... until I have two instances of a window like "Map Hierarchy" open, in which case they will have duplicated instances on one window instead of separate windows.

Screenshot
image

ui.cpp

void Styler::startWindow(const char* title) {
	static ImGuiWindowFlags titlebar_flags = ImGuiWindowFlags_None;
	const ImGuiViewport* viewport = ImGui::GetMainViewport();

	ImGui::SetNextWindowViewport(viewport->ID);

	ImGui::Begin(title, (bool*)true, titlebar_flags);
}
void Styler::endWindow() {
	ImGui::End();
}
// ***
void WindowMapHierarchy::Render() {
	Styler::startWindow("Map Hierarchy");
	ImGui::LabelText("", "Game Objects in Scene.");
	Styler::endWindow();
};

ui.hpp

class Styler {
public:
	static void startWindow(const char* title);
	static void endWindow();
};
class BaseWindow {
public:
	BaseWindow() {};
	~BaseWindow() {};

	virtual void Render() {};
};
class WindowMapHierarchy : public BaseWindow { public: void Render(); };

app.cpp

WindowMapHierarchy win_mapHierarchy{};

If you do use this code, just call the Render function of win_mapHierarchy, I did remove a lot of code from this uploaded code to simplify it and still have it usable, but yeah, if you make two instances of WindowMapHierarchy win_mapHierarchy{}; in the app implementation file, and call both of the Render functions one after another, all the elements get combined into one, any solution for this?

@ocornut
Copy link
Owner

ocornut commented Jul 26, 2021

See Demo>Examples>Manipulating window titles

And see FAQ entries:
"How can I have multiple widgets with the same label?"
https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-can-i-have-multiple-widgets-with-the-same-label

Same answer applies.

Using Begin() with the same identifier allows appending to a same window from a different location.

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