From 8b0192c9b8a0f9b236bc3a6310e8e9ec76b4ddfd Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 5 Feb 2026 23:59:11 -0600 Subject: [PATCH] Sketchy Multi Viewports --- ExampleApps.nix | 4 +-- flake.lock | 19 +++++++++++- flake.nix | 15 ++++++---- .../Calculator/Calculator.cpp | 2 ++ .../Calculator/Calculator.h | 2 +- modules/ImguiModule/ImguiModule.cpp | 30 +++++++++++++++---- modules/ImguiModule/ImguiModule.h | 2 ++ modules/MainGUI/MainGUI.cpp | 2 ++ 8 files changed, 61 insertions(+), 15 deletions(-) diff --git a/ExampleApps.nix b/ExampleApps.nix index aac0471..361df0c 100644 --- a/ExampleApps.nix +++ b/ExampleApps.nix @@ -61,7 +61,7 @@ -DRENDERER=1 \ -DWINDOW=1 \ -I include -I $imgui -I . \ - -lGL -lEGL -lglfw -lGLEW \ + -lEGL -lGL -lglfw -lGLEW \ -Wall \ -o $name -DIMGUI_IMPL_GLFW_DISABLE_X11 ''; @@ -103,7 +103,7 @@ -DRENDERER=1 \ -DWINDOW=1 \ -I include -I $imgui -I . \ - -lEGL -lglfw -lGLEW \ + -lGL -lglfw -lGLEW \ -Wall \ -o $name -DIMGUI_IMPL_GLFW_DISABLE_X11 ''; diff --git a/flake.lock b/flake.lock index ff7d95f..8e3b330 100644 --- a/flake.lock +++ b/flake.lock @@ -49,11 +49,28 @@ "type": "github" } }, + "nixpkgs-old": { + "locked": { + "lastModified": 1720535198, + "narHash": "sha256-zwVvxrdIzralnSbcpghA92tWu2DV2lwv89xZc8MTrbg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "205fd4226592cc83fd4c0885a3e4c9c400efabb5", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "clay": "clay", "imgui": "imgui", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "nixpkgs-old": "nixpkgs-old" } } }, diff --git a/flake.nix b/flake.nix index 8888b71..c3c751f 100644 --- a/flake.nix +++ b/flake.nix @@ -3,6 +3,7 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11"; + nixpkgs-old.url = "github:nixos/nixpkgs/nixos-23.11"; # Until Dear ImGUI has multi viewports on wayland imgui = { url = "github:ocornut/imgui?ref=docking"; flake = false; @@ -15,15 +16,17 @@ outputs = { self, nixpkgs, imgui, clay, ... }@inputs: let system = "x86_64-linux"; - pkgs = import nixpkgs { inherit system; }; + pkgs-old = import inputs.nixpkgs-old { inherit system; }; + viewport-overlay = final: prev: { glfw = pkgs-old.glfw; }; + pkgs = import nixpkgs { inherit system; overlays = [ viewport-overlay ]; }; in { Archimedes = { - examples = import ./ExampleApps.nix { inherit inputs; inherit pkgs; }; + examples = import ./ExampleApps.nix { inherit inputs pkgs; }; }; Modules = { - examples = import ./ExampleModules.nix { inherit inputs; inherit pkgs; }; + examples = import ./ExampleModules.nix { inherit inputs pkgs; }; ServerModule = pkgs.stdenvNoCC.mkDerivation { @@ -114,7 +117,7 @@ -DRENDERER=1 \ -DWINDOW=1 \ -DWINDOWMODULE_DYNAMIC \ - -lEGL -lglfw -lGLEW \ + -lGL -lglfw -lGLEW \ -Wall \ -o $name -DIMGUI_IMPL_GLFW_DISABLE_X11 ''; @@ -157,7 +160,7 @@ -DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \ -fpic -shared \ -I include -I $imgui -I . \ - -lEGL -lglfw -lGLEW \ + -lGL -lglfw -lGLEW \ -Wall \ -o $name -DIMGUI_IMPL_GLFW_DISABLE_X11 ''; @@ -243,7 +246,7 @@ -DMAINGUI_DYNAMIC \ -fpic -shared \ -I include -I $imgui -I . \ - -lEGL -lglfw -lGLEW \ + -lGL -lglfw -lGLEW \ -Wall \ -o $name -DIMGUI_IMPL_GLFW_DISABLE_X11 ''; diff --git a/modules/Archimedes-Modules/Calculator/Calculator.cpp b/modules/Archimedes-Modules/Calculator/Calculator.cpp index 966b458..7d62cea 100644 --- a/modules/Archimedes-Modules/Calculator/Calculator.cpp +++ b/modules/Archimedes-Modules/Calculator/Calculator.cpp @@ -151,6 +151,8 @@ double Calculator::evaluate(std::string equation, std::unordered_mapAddFontFromFileTTF(STRINGIZE_VALUE_OF(CUSTOMFONT), 13.0f); #endif @@ -60,6 +60,18 @@ void ImguiModule::onLoad() { ImGui::StyleColorsDark(); //ImGui::StyleColorsLight(); + // Setup scaling + ImGuiStyle& style = ImGui::GetStyle(); + io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now. + io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes. + + // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones. + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + style.WindowRounding = 0.0f; + style.Colors[ImGuiCol_WindowBg].w = 1.0f; + } + // Setup Platform/Renderer backends if(!windowInit()) std::cout << "windowInit failed\n"; @@ -73,9 +85,12 @@ void ImguiModule::onLoad() { rendererRenderDrawData(); - rendererNewFrame(); - windowNewFrame(); - ImGui::NewFrame(); + if(ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) { + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); + + window->getWindowImpl().restoreContext(); + } }); rcmd_it = --wm->getRenderer()->getCmdList().end()++; @@ -92,9 +107,14 @@ void ImguiModule::onLoad() { rendererNewFrame(); windowNewFrame(); ImGui::NewFrame(); - } +void ImguiModule::run() { + rendererNewFrame(); + windowNewFrame(); + ImGui::NewFrame(); +}; + bool ImguiModule::onEvent(const Archimedes::Event &e) { return false; diff --git a/modules/ImguiModule/ImguiModule.h b/modules/ImguiModule/ImguiModule.h index 7a7eba5..b951023 100644 --- a/modules/ImguiModule/ImguiModule.h +++ b/modules/ImguiModule/ImguiModule.h @@ -38,6 +38,8 @@ class ImguiModule : public Archimedes::Module { ~ImguiModule(); void onLoad() override; + + void run() override; bool onEvent(const Archimedes::Event&) override; diff --git a/modules/MainGUI/MainGUI.cpp b/modules/MainGUI/MainGUI.cpp index b2cabf2..4c246f8 100644 --- a/modules/MainGUI/MainGUI.cpp +++ b/modules/MainGUI/MainGUI.cpp @@ -56,6 +56,8 @@ void MainGUI::run() { ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); ImGui::End(); + + ImGui::ShowDemoWindow(); } else { app->end(); }