]> code.bitgloo.com Git - clyne/stmdspgui.git/commitdiff
window and panel resizing
authorClyne Sullivan <clyne@bitgloo.com>
Sun, 22 May 2022 19:40:12 +0000 (15:40 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sun, 22 May 2022 19:40:12 +0000 (15:40 -0400)
source/config.h [deleted file]
source/gui.cpp
source/gui_code.cpp
source/main.cpp

diff --git a/source/config.h b/source/config.h
deleted file mode 100644 (file)
index 879a0ea..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef STMDSP_CONFIG_H
-#define STMDSP_CONFIG_H
-
-constexpr unsigned int WINDOW_WIDTH = 640;
-constexpr unsigned int WINDOW_HEIGHT = 720;
-
-#endif
-
index 80120c47d56b729a353c5fa1386be6b9f4950a69..0e6744647294c5b5d77ab17eaba27e4d78bd393d 100644 (file)
@@ -14,8 +14,6 @@
 #include "backends/imgui_impl_sdl.h"
 #include "backends/imgui_impl_opengl2.h"
 
-#include "config.h"
-
 #include <SDL2/SDL.h>
 #include <SDL2/SDL_opengl.h>
 
@@ -42,14 +40,16 @@ bool guiInitialize()
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
     window = SDL_CreateWindow("stmdsp gui",
         SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
-        WINDOW_WIDTH, WINDOW_HEIGHT,
-        SDL_WINDOW_OPENGL /*| SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI*/);
+        550, 700,
+        SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE /*| SDL_WINDOW_ALLOW_HIGHDPI*/);
 
     if (window == nullptr) {
         puts("Error: Could not create the window!");
         return false;
     }
 
+    SDL_SetWindowMinimumSize(window, 320, 320);
+
     gl_context = SDL_GL_CreateContext(window);
     SDL_GL_MakeCurrent(window, gl_context);
     SDL_GL_SetSwapInterval(1); // Enable vsync
index 19fa572910b1e2f537548fe92d8e04d0d403210c..50fd0c8274cb6eaa1cafdaf299a5ef8c84b1ef20 100644 (file)
@@ -14,8 +14,6 @@
 #include "backends/imgui_impl_opengl2.h"
 #include "TextEditor.h"
 
-#include "config.h"
-
 #include <string>
 
 extern void compileEditorCode(const std::string& code);
@@ -52,9 +50,9 @@ void codeRenderToolbar()
         codeCompile();
 }
 
-void codeRenderWidgets()
+void codeRenderWidgets(const ImVec2& size)
 {
-    editor.Render("code", {WINDOW_WIDTH - 15, 450}, true);
+    editor.Render("code", size, true);
 }
 
 static void codeCompile()
index e8641bc77a38eacaf16ae4f537bc93a50008a607..f913cf148ced358aa18f64749bd5c09fc85bf03b 100644 (file)
@@ -13,7 +13,6 @@
 #include "backends/imgui_impl_sdl.h"
 #include "backends/imgui_impl_opengl2.h"
 
-#include "config.h"
 #include "logview.h"
 #include "stmdsp.hpp"
 
@@ -26,7 +25,7 @@
 void codeEditorInit();
 void codeRenderMenu();
 void codeRenderToolbar();
-void codeRenderWidgets();
+void codeRenderWidgets(const ImVec2& size);
 void deviceRenderDraw();
 void deviceRenderMenu();
 void deviceRenderToolbar();
@@ -45,6 +44,7 @@ static LogView logView;
 static ImFont *fontSans = nullptr;
 static ImFont *fontMono = nullptr;
 
+template<bool first = false>
 static void renderWindow();
 
 int main(int, char **)
@@ -63,6 +63,8 @@ int main(int, char **)
     codeEditorInit();
     fileInit();
 
+    renderWindow<true>();
+
     while (1) {
         constexpr std::chrono::duration<double> fpsDelay (1. / 60.);
         const auto endTime = std::chrono::steady_clock::now() + fpsDelay;
@@ -85,6 +87,7 @@ void log(const std::string& str)
     logView.AddLog(str);
 }
 
+template<bool first>
 void renderWindow()
 {
     // Start the new window frame and render the menu bar.
@@ -99,35 +102,41 @@ void renderWindow()
         ImGui::EndMainMenuBar();
     }
 
-    // Begin the main view which the controls will be drawn onto.
-    constexpr float LOGVIEW_HEIGHT = 200;
-    constexpr ImVec2 WINDOW_POS (0, 22);
-    constexpr ImVec2 WINDOW_SIZE (WINDOW_WIDTH, WINDOW_HEIGHT - 22 - LOGVIEW_HEIGHT);
-    ImGui::SetNextWindowPos(WINDOW_POS);
-    ImGui::SetNextWindowSize(WINDOW_SIZE);
+    if constexpr (first) {
+        ImGui::SetNextWindowSize({550, 440});
+    }
+
+    constexpr int MainTopMargin = 22;
+    const auto& displaySize = ImGui::GetIO().DisplaySize;
+
+    ImGui::SetNextWindowPos({0, MainTopMargin});
+    ImGui::SetNextWindowSizeConstraints({displaySize.x, 150}, {displaySize.x, displaySize.y - 150});
     ImGui::Begin("main", nullptr,
-                 ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration |
+                 ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoTitleBar |
                      ImGuiWindowFlags_NoBringToFrontOnFocus);
 
-    // Render main controls (order is important).
-    {
-        ImGui::PushFont(fontSans);
-        codeRenderToolbar();
-        deviceRenderToolbar();
-        fileRenderDialog();
-        deviceRenderWidgets();
-        ImGui::PopFont();
-
-        ImGui::PushFont(fontMono);
-        codeRenderWidgets();
-        ImGui::SetNextWindowPos({0, WINDOW_HEIGHT - LOGVIEW_HEIGHT});
-        ImGui::SetNextWindowSize({WINDOW_WIDTH, LOGVIEW_HEIGHT});
-        logView.Draw("log", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBringToFrontOnFocus);
-        ImGui::PopFont();
-    }
+    const float mainWindowHeight = ImGui::GetWindowHeight();
+
+    ImGui::PushFont(fontSans);
+    codeRenderToolbar();
+    deviceRenderToolbar();
+    fileRenderDialog();
+    deviceRenderWidgets();
+    ImGui::PopFont();
+
+    ImGui::PushFont(fontMono);
+    codeRenderWidgets({displaySize.x - 16, mainWindowHeight - MainTopMargin - 24});
+    ImGui::PopFont();
 
     ImGui::End();
 
+    // The log window is kept separate from "main" to support panel resizing.
+    ImGui::PushFont(fontMono);
+    ImGui::SetNextWindowPos({0, mainWindowHeight + MainTopMargin});
+    ImGui::SetNextWindowSize({displaySize.x, displaySize.y - mainWindowHeight - MainTopMargin});
+    logView.Draw("log", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBringToFrontOnFocus);
+    ImGui::PopFont();
+
     deviceRenderDraw();
 
     // Draw everything to the screen.