Add ImGuiIdIssuer class for child id

This commit is contained in:
scawful
2023-11-24 13:27:59 -05:00
parent 5f3ca25c80
commit 8448697c4d
2 changed files with 36 additions and 0 deletions

View File

@@ -1,6 +1,12 @@
#include "common.h"
#include <imgui/imgui.h>
#include <chrono>
#include <cstdint>
#include <functional>
#include <memory>
#include <stack>
#include <string>
namespace yaze {
@@ -139,6 +145,9 @@ uint16_t ldle16b_i(uint8_t const *const p_arr, size_t const p_index) {
return ldle16b(p_arr + (2 * p_index));
}
// Initialize the static member
std::stack<ImGuiID> ImGuiIdIssuer::idStack;
} // namespace core
} // namespace app
} // namespace yaze

View File

@@ -1,10 +1,13 @@
#ifndef YAZE_CORE_COMMON_H
#define YAZE_CORE_COMMON_H
#include <imgui/imgui.h>
#include <chrono>
#include <cstdint>
#include <functional>
#include <memory>
#include <stack>
#include <string>
namespace yaze {
@@ -38,6 +41,9 @@ class ExperimentFlags {
// Attempt to run the dungeon room draw routine when opening a room.
bool kDrawDungeonRoomGraphics = true;
// Use the new platform specific file dialog wrappers.
bool kNewFileDialogWrapper = true;
};
ExperimentFlags() = default;
@@ -164,6 +170,27 @@ class TaskManager {
}
};
class ImGuiIdIssuer {
private:
static std::stack<ImGuiID> idStack;
public:
// Generate and push a new ID onto the stack
static ImGuiID GetNewID() {
static int counter = 1; // Start from 1 to ensure uniqueness
ImGuiID child_id = ImGui::GetID((void *)(intptr_t)counter++);
idStack.push(child_id);
return child_id;
}
// Pop all IDs from the stack (can be called explicitly or upon program exit)
static void Cleanup() {
while (!idStack.empty()) {
idStack.pop();
}
}
};
uint32_t SnesToPc(uint32_t addr);
uint32_t PcToSnes(uint32_t addr);