From d392eb5ba589d74863f637ccbd1160ebfb8e3464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Fri, 23 Oct 2026 22:11:11 +0200 Subject: [PATCH] ImGui extension to push GlitchyEngine color types (and scoped push) --- .../src/EditWindows/ComponentEditWindow.bf | 2 +- GlitchyEditor/src/EditWindows/LogWindow.bf | 9 +++-- GlitchyEditor/src/ImGui/ImGuiExtension.bf | 39 ++++++++++++++++++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf index e8b249e..93f8b84 100644 --- a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf +++ b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf @@ -178,7 +178,7 @@ namespace GlitchyEditor.EditWindows float2 buttonSize = ImGui.GetTextLineHeight().XX; - ImGui.PushStyleColor(.Button, .(0, 0, 0, 0)); + ImGui.PushStyleColor(.Button, ColorRGBA(0, 0, 0, 0)); if (showComponentContextMenu != null) { diff --git a/GlitchyEditor/src/EditWindows/LogWindow.bf b/GlitchyEditor/src/EditWindows/LogWindow.bf index fd8c44c..9a8537b 100644 --- a/GlitchyEditor/src/EditWindows/LogWindow.bf +++ b/GlitchyEditor/src/EditWindows/LogWindow.bf @@ -10,6 +10,7 @@ using GlitchyEngine; using GlitchyEditor.CodeEditors; using System.IO; using GlitchyEditor.Settings; +using GlitchyEngine.Math; namespace GlitchyEditor.EditWindows; @@ -138,7 +139,7 @@ class LogWindow : EditorWindow if (_visibleMessageTypes.HasFlag(.Trace)) ImGui.PushStyleColor(.Button, *col); else - ImGui.PushStyleColor(.Button, .(0, 0, 0, 0)); + ImGui.PushStyleColor(.Button, ColorRGBA(0, 0, 0, 0)); if (ImGui.ImageButtonEx(1, s_TraceIcon, buttonSize, .Zero, .Ones)) _visibleMessageTypes ^= .Trace; @@ -148,7 +149,7 @@ class LogWindow : EditorWindow if (_visibleMessageTypes.HasFlag(.Info)) ImGui.PushStyleColor(.Button, *col); else - ImGui.PushStyleColor(.Button, .(0, 0, 0, 0)); + ImGui.PushStyleColor(.Button, ColorRGBA(0, 0, 0, 0)); if (ImGui.ImageButtonEx(2, s_InfoIcon, buttonSize, .Zero, .Ones)) _visibleMessageTypes ^= .Info; @@ -158,7 +159,7 @@ class LogWindow : EditorWindow if (_visibleMessageTypes.HasFlag(.Warning)) ImGui.PushStyleColor(.Button, *col); else - ImGui.PushStyleColor(.Button, .(0, 0, 0, 0)); + ImGui.PushStyleColor(.Button, ColorRGBA(0, 0, 0, 0)); if (ImGui.ImageButtonEx(3, s_WarningIcon, buttonSize, .Zero, .Ones)) _visibleMessageTypes ^= .Warning; @@ -168,7 +169,7 @@ class LogWindow : EditorWindow if (_visibleMessageTypes.HasFlag(.Error)) ImGui.PushStyleColor(.Button, *col); else - ImGui.PushStyleColor(.Button, .(0, 0, 0, 0)); + ImGui.PushStyleColor(.Button, ColorRGBA(0, 0, 0, 0)); if (ImGui.ImageButtonEx(4, s_ErrorIcon, buttonSize, .Zero, .Ones)) diff --git a/GlitchyEditor/src/ImGui/ImGuiExtension.bf b/GlitchyEditor/src/ImGui/ImGuiExtension.bf index 22e1270..32d2e90 100644 --- a/GlitchyEditor/src/ImGui/ImGuiExtension.bf +++ b/GlitchyEditor/src/ImGui/ImGuiExtension.bf @@ -675,7 +675,7 @@ namespace ImGui { PushStyleVar(value); defer:mixin PopStyleVar(); - } + } public static void PushStyleVar(TypedStyleVar value) { @@ -743,6 +743,43 @@ namespace ImGui PushStyleVar(.DockingSeparatorSize, Value); } } + + public static mixin PushScopedStyleColor(ImGui.Col idx, uint32 color) + { + PushStyleColor(idx, color); + defer:mixin PopStyleColor(); + } + + public static mixin PushScopedStyleColor(ImGui.Col idx, Vec4 color) + { + PushStyleColor(idx, color); + defer:mixin PopStyleColor(); + } + + public static mixin PushScopedStyleColor(ImGui.Col idx, GlitchyEngine.Math.Color color) + { + PushStyleColor(idx, color); + defer:mixin PopStyleColor(); + } + + public static void PushStyleColor(ImGui.Col idx, GlitchyEngine.Math.Color color) + { +#unwarn + uint32 bitColor = *(uint32*)(void*)&color; + + ImGui.PushStyleColor(.Text, bitColor); + } + + public static mixin PushScopedStyleColor(ImGui.Col idx, GlitchyEngine.Math.ColorRGBA color) + { + PushStyleColor(idx, color); + defer:mixin PopStyleColor(); + } + + public static void PushStyleColor(ImGui.Col idx, GlitchyEngine.Math.ColorRGBA color) + { + ImGui.PushStyleColor(.Text, ((Color)color).Value); + } public struct DisabledScope : IDisposable {