OXYGENHUB
◆ main enhanced-x16-emulator / src / debug_ui / debug_ui_panels.h
1.9 KiB · Objective-C · last changed chore(): initial commit 25 days ago source blame history raw
1
// Commander X16 Emulator — ImGui debugger panel registry (C++).
2
//
3
// THE KEY TO PARALLELISM: every panel lives in its own .cpp under panels/ and
4
// self-registers via a file-static DebugPanelRegistration object. There is NO
5
// central list any panel must edit — debug_ui.cpp just iterates
6
// debug_ui_panels(). Five sessions can therefore each own one panel file with
7
// zero merge conflicts.
8
//
9
// To add a panel, create panels/<name>_panel.cpp:
10
//
11
//     #include "imgui.h"
12
//     #include "debug_ui_panels.h"
13
//     // (optional, to read emulator state) #include "debug_ui_bridge.h"
14
//
15
//     static void mypanel_render(bool *p_open) {
16
//         if (ImGui::Begin("My Panel", p_open)) {
17
//             ImGui::TextUnformatted("...");
18
//         }
19
//         ImGui::End();
20
//     }
21
//     static DebugPanelRegistration s_reg("My Panel", mypanel_render, true);
22
//
23
// and add the file to CMakeLists.txt X16_SOURCES. (The five foundation panels
24
// are already listed, so editing their *contents* needs no CMake change.)
25
#ifndef DEBUG_UI_PANELS_H
26
#define DEBUG_UI_PANELS_H
27
28
#include <vector>
29
30
struct DebugPanel {
31
    const char *name;             // window title / identity
32
    void (*render)(bool *p_open); // draws the panel; clearing *p_open hides it
33
    bool open;                    // current visibility
34
};
35
36
// Function-LOCAL static registry. Returning a static defined inside the
37
// function guarantees the vector is constructed on first use — before any
38
// panel's file-static registration runs — which sidesteps the static
39
// initialization-order fiasco across translation units.
40
std::vector<DebugPanel> &debug_ui_panels();
41
42
// Constructing one of these (as a file-static in a panel .cpp) appends the
43
// panel to the registry. `open` is the initial visibility.
44
struct DebugPanelRegistration {
45
    DebugPanelRegistration(const char *name, void (*render)(bool *p_open), bool open);
46
};
47
48
#endif // DEBUG_UI_PANELS_H