Enhance window ID logic

This commit is contained in:
Johannes Frohnmeyer 2022-02-06 16:00:14 +01:00
parent 0988aefbeb
commit f669060d1e
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 13 additions and 7 deletions

View File

@ -27,9 +27,7 @@ import java.io.InputStream;
import java.nio.IntBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
import java.util.*;
public class InceptumGui {
public static final Set<Window> WINDOWS = new LinkedHashSet<>();
@ -159,6 +157,7 @@ public class InceptumGui {
* Main application loop.
*/
public static void run() {
Map<String, Integer> windowCountByName = new HashMap<>();
while (!GLFW.glfwWindowShouldClose(handle)) {
//frame
clearBuffer();
@ -167,11 +166,18 @@ public class InceptumGui {
//render
if (WINDOWS.isEmpty()) exit();
else {
Window[] array = WINDOWS.toArray(new Window[0]);
for (int i = 0, arrayLength = array.length; i < arrayLength; i++) {
Window window = array[i];
windowCountByName.clear();
for (Window window : WINDOWS.toArray(new Window[0])) {
if (window.isNew()) window.preFirstDraw();
if (ImGui.begin(window.getName() + "##" + i, window.getOpenState(), window.getFlags()))
String title = window.getName();
if (!windowCountByName.containsKey(title))
windowCountByName.put(title, 1);
else {
int count = windowCountByName.get(title) + 1;
windowCountByName.put(title, count);
title += "##" + count;
}
if (ImGui.begin(title, window.getOpenState(), window.getFlags()))
window.draw();
ImGui.end();
if (!window.getOpenState().get() && !window.isClosed()) window.close();