Multi-window: - Per-window ImGui contexts (fixes input, scroll, and rendering isolation) - Per-instance scroll and mouse state in ImGuiRenderer (no more statics) - Proper GL context activation during window destruction - ValidateBufferIndex guards against stale curbuf_ across shared buffers - Editor methods (CurrentBuffer, SwitchTo, CloseBuffer, etc.) use Buffers() accessor to respect shared buffer lists - New windows open with an untitled buffer - Scratch buffer reuse works in secondary windows - CMD-w on macOS closes only the focused window - Deferred new-window creation to avoid mid-frame ImGui context corruption Swap file cleanup: - SaveAs prompt handler now calls ResetJournal - cmd_save_and_quit now calls ResetJournal - Editor::Reset detaches all buffers before clearing - Tests for save-and-quit and editor-reset swap cleanup Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
/*
|
|
* GUIFrontend - couples ImGuiInputHandler + GUIRenderer and owns SDL2/ImGui lifecycle
|
|
*/
|
|
#pragma once
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "Frontend.h"
|
|
#include "GUIConfig.h"
|
|
#include "ImGuiInputHandler.h"
|
|
#include "ImGuiRenderer.h"
|
|
#include "Editor.h"
|
|
|
|
|
|
struct SDL_Window;
|
|
struct ImGuiContext;
|
|
typedef void *SDL_GLContext;
|
|
|
|
class GUIFrontend final : public Frontend {
|
|
public:
|
|
GUIFrontend() = default;
|
|
|
|
~GUIFrontend() override = default;
|
|
|
|
bool Init(int &argc, char **argv, Editor &ed) override;
|
|
|
|
void Step(Editor &ed, bool &running) override;
|
|
|
|
void Shutdown() override;
|
|
|
|
private:
|
|
// Per-window state — each window owns its own ImGui context so that
|
|
// NewFrame/Render cycles are fully independent (ImGui requires exactly
|
|
// one NewFrame per Render per context).
|
|
struct WindowState {
|
|
SDL_Window *window = nullptr;
|
|
SDL_GLContext gl_ctx = nullptr;
|
|
ImGuiContext *imgui_ctx = nullptr;
|
|
ImGuiInputHandler input{};
|
|
ImGuiRenderer renderer{};
|
|
Editor editor{};
|
|
int width = 1280;
|
|
int height = 800;
|
|
bool alive = true;
|
|
};
|
|
|
|
// Open a new secondary window sharing the primary editor's buffer list.
|
|
// Returns false if window creation fails.
|
|
bool OpenNewWindow_(Editor &primary);
|
|
|
|
// Initialize fonts and theme for a given ImGui context (must be current).
|
|
void SetupImGuiStyle_();
|
|
static void DestroyWindowResources_(WindowState &ws);
|
|
static bool LoadGuiFont_(const char *path, float size_px);
|
|
|
|
GUIConfig config_{};
|
|
// Primary window (index 0 in windows_); created during Init.
|
|
std::vector<std::unique_ptr<WindowState> > windows_;
|
|
}; |