Various minor bug cleanups.

This commit is contained in:
2025-11-29 21:33:45 -08:00
parent 3de5ec68f8
commit b41946c470
18 changed files with 803 additions and 620 deletions

View File

@@ -19,7 +19,7 @@ static const char *kGlslVersion = "#version 150"; // GL 3.2 core (macOS compatib
bool
GUIFrontend::Init(Editor &ed)
{
(void)ed; // editor dimensions will be initialized during the first Step() frame
(void) ed; // editor dimensions will be initialized during the first Step() frame
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
return false;
}
@@ -49,25 +49,25 @@ GUIFrontend::Init(Editor &ed)
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();
(void) io;
ImGui::StyleColorsDark();
ImGuiIO &io = ImGui::GetIO();
(void) io;
ImGui::StyleColorsDark();
if (!ImGui_ImplSDL2_InitForOpenGL(window_, gl_ctx_))
return false;
if (!ImGui_ImplOpenGL3_Init(kGlslVersion))
return false;
// Cache initial window size; logical rows/cols will be computed in Step() once a valid ImGui frame exists
int w, h;
SDL_GetWindowSize(window_, &w, &h);
width_ = w;
height_ = h;
// Cache initial window size; logical rows/cols will be computed in Step() once a valid ImGui frame exists
int w, h;
SDL_GetWindowSize(window_, &w, &h);
width_ = w;
height_ = h;
// Initialize GUI font from embedded default
LoadGuiFont_(nullptr, 16.f);
// Initialize GUI font from embedded default
LoadGuiFont_(nullptr, 16.f);
return true;
return true;
}
@@ -78,77 +78,80 @@ GUIFrontend::Step(Editor &ed, bool &running)
while (SDL_PollEvent(&e)) {
ImGui_ImplSDL2_ProcessEvent(&e);
switch (e.type) {
case SDL_QUIT:
running = false;
break;
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
width_ = e.window.data1;
height_ = e.window.data2;
}
break;
default:
break;
case SDL_QUIT:
running = false;
break;
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
width_ = e.window.data1;
height_ = e.window.data2;
}
break;
default:
break;
}
// Map input to commands
input_.ProcessSDLEvent(e);
}
// Execute pending mapped inputs (drain queue)
// Execute pending mapped inputs (drain queue)
for (;;) {
MappedInput mi;
if (!input_.Poll(mi))
break;
if (mi.hasCommand) {
Execute(ed, mi.id, mi.arg, mi.count);
if (mi.id == CommandId::Quit || mi.id == CommandId::SaveAndQuit) {
running = false;
}
}
}
// Start a new ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(window_);
ImGui::NewFrame();
if (ed.QuitRequested()) {
running = false;
}
// Update editor logical rows/cols using current ImGui metrics and display size
{
ImGuiIO &io = ImGui::GetIO();
float line_h = ImGui::GetTextLineHeightWithSpacing();
float ch_w = ImGui::CalcTextSize("M").x;
if (line_h <= 0.0f) line_h = 16.0f;
if (ch_w <= 0.0f) ch_w = 8.0f;
// Prefer ImGui IO display size; fall back to cached SDL window size
float disp_w = io.DisplaySize.x > 0 ? io.DisplaySize.x : static_cast<float>(width_);
float disp_h = io.DisplaySize.y > 0 ? io.DisplaySize.y : static_cast<float>(height_);
// Start a new ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(window_);
ImGui::NewFrame();
// Account for the GUI window padding and the status bar height used in GUIRenderer
const ImGuiStyle &style = ImGui::GetStyle();
float pad_x = style.WindowPadding.x;
float pad_y = style.WindowPadding.y;
// Status bar reserves one frame height (with spacing) inside the window
float status_h = ImGui::GetFrameHeightWithSpacing();
// Update editor logical rows/cols using current ImGui metrics and display size
{
ImGuiIO &io = ImGui::GetIO();
float line_h = ImGui::GetTextLineHeightWithSpacing();
float ch_w = ImGui::CalcTextSize("M").x;
if (line_h <= 0.0f)
line_h = 16.0f;
if (ch_w <= 0.0f)
ch_w = 8.0f;
// Prefer ImGui IO display size; fall back to cached SDL window size
float disp_w = io.DisplaySize.x > 0 ? io.DisplaySize.x : static_cast<float>(width_);
float disp_h = io.DisplaySize.y > 0 ? io.DisplaySize.y : static_cast<float>(height_);
float avail_w = std::max(0.0f, disp_w - 2.0f * pad_x);
float avail_h = std::max(0.0f, disp_h - 2.0f * pad_y - status_h);
// Account for the GUI window padding and the status bar height used in GUIRenderer
const ImGuiStyle &style = ImGui::GetStyle();
float pad_x = style.WindowPadding.x;
float pad_y = style.WindowPadding.y;
// Status bar reserves one frame height (with spacing) inside the window
float status_h = ImGui::GetFrameHeightWithSpacing();
// Visible content rows inside the scroll child
std::size_t content_rows = static_cast<std::size_t>(std::floor(avail_h / line_h));
// Editor::Rows includes the status line; add 1 back for it.
std::size_t rows = std::max<std::size_t>(1, content_rows + 1);
std::size_t cols = static_cast<std::size_t>(std::max(1.0f, std::floor(avail_w / ch_w)));
float avail_w = std::max(0.0f, disp_w - 2.0f * pad_x);
float avail_h = std::max(0.0f, disp_h - 2.0f * pad_y - status_h);
// Only update if changed to avoid churn
if (rows != ed.Rows() || cols != ed.Cols()) {
ed.SetDimensions(rows, cols);
}
}
// Visible content rows inside the scroll child
std::size_t content_rows = static_cast<std::size_t>(std::floor(avail_h / line_h));
// Editor::Rows includes the status line; add 1 back for it.
std::size_t rows = std::max<std::size_t>(1, content_rows + 1);
std::size_t cols = static_cast<std::size_t>(std::max(1.0f, std::floor(avail_w / ch_w)));
// No runtime font UI; always use embedded font.
// Only update if changed to avoid churn
if (rows != ed.Rows() || cols != ed.Cols()) {
ed.SetDimensions(rows, cols);
}
}
// Draw editor UI
renderer_.Draw(ed);
// No runtime font UI; always use embedded font.
// Draw editor UI
renderer_.Draw(ed);
// Render
ImGui::Render();
@@ -184,18 +187,19 @@ GUIFrontend::Shutdown()
bool
GUIFrontend::LoadGuiFont_(const char * /*path*/, float size_px)
{
ImGuiIO &io = ImGui::GetIO();
io.Fonts->Clear();
ImFont *font = io.Fonts->AddFontFromMemoryCompressedTTF(
(void*)DefaultFontRegularCompressedData,
(int)DefaultFontRegularCompressedSize,
size_px);
if (!font) {
font = io.Fonts->AddFontDefault();
}
(void) font;
io.Fonts->Build();
return true;
ImGuiIO &io = ImGui::GetIO();
io.Fonts->Clear();
ImFont *font = io.Fonts->AddFontFromMemoryCompressedTTF(
(void *) DefaultFontRegularCompressedData,
(int) DefaultFontRegularCompressedSize,
size_px);
if (!font) {
font = io.Fonts->AddFontDefault();
}
(void) font;
io.Fonts->Build();
return true;
}
// No runtime font reload or system font resolution in this simplified build.
// No runtime font reload or system font resolution in this simplified build.