qstbak/Questionable/Questionable.Windows/ThemedWindow.cs
2026-08-17 20:29:32 +10:00

116 lines
4.2 KiB
C#

using System;
using System.Numerics;
using Dalamud.Bindings.ImGui;
using LLib.ImGui;
namespace Questionable.Windows;
internal abstract class ThemedWindow : LWindow
{
private sealed class ThemeScope(int colors, int styles) : IDisposable
{
private bool _disposed;
public void Dispose()
{
if (!_disposed)
{
_disposed = true;
if (styles > 0)
{
ImGui.PopStyleVar(styles);
}
if (colors > 0)
{
ImGui.PopStyleColor(colors);
}
}
}
}
private IDisposable? _theme;
protected ThemedWindow(string windowName, ImGuiWindowFlags flags = ImGuiWindowFlags.None, bool forceMainWindow = false)
: base(windowName, flags, forceMainWindow)
{
}
public override void PreDraw()
{
base.PreDraw();
_theme = PushTheme();
}
public override void PostDraw()
{
_theme?.Dispose();
_theme = null;
base.PostDraw();
}
public static IDisposable PushTheme()
{
int colors = 0;
int styles = 0;
C(ImGuiCol.WindowBg, new Vector4(0.08f, 0.06f, 0.12f, 0.94f));
C(ImGuiCol.ChildBg, new Vector4(0.1f, 0.08f, 0.14f, 0f));
C(ImGuiCol.PopupBg, new Vector4(0.1f, 0.08f, 0.14f, 0.94f));
C(ImGuiCol.Border, new Vector4(0.55f, 0.45f, 0.75f, 0.3f));
C(ImGuiCol.BorderShadow, new Vector4(0f, 0f, 0f, 0f));
C(ImGuiCol.TitleBg, new Vector4(0.12f, 0.08f, 0.18f, 1f));
C(ImGuiCol.TitleBgActive, new Vector4(0.2f, 0.15f, 0.3f, 1f));
C(ImGuiCol.TitleBgCollapsed, new Vector4(0.08f, 0.05f, 0.12f, 0.75f));
C(ImGuiCol.Text, new Vector4(0.95f, 0.95f, 1f, 1f));
C(ImGuiCol.TextDisabled, new Vector4(0.5f, 0.45f, 0.6f, 1f));
C(ImGuiCol.FrameBg, new Vector4(0.25f, 0.2f, 0.35f, 0.7f));
C(ImGuiCol.FrameBgHovered, new Vector4(0.35f, 0.28f, 0.48f, 0.8f));
C(ImGuiCol.FrameBgActive, new Vector4(0.45f, 0.35f, 0.6f, 0.9f));
C(ImGuiCol.ScrollbarBg, new Vector4(0.1f, 0.08f, 0.14f, 0.53f));
C(ImGuiCol.ScrollbarGrab, new Vector4(0.55f, 0.45f, 0.75f, 0.4f));
C(ImGuiCol.ScrollbarGrabHovered, new Vector4(0.65f, 0.55f, 0.85f, 0.6f));
C(ImGuiCol.ScrollbarGrabActive, new Vector4(0.75f, 0.55f, 0.95f, 0.8f));
C(ImGuiCol.Button, new Vector4(0.35f, 0.3f, 0.55f, 0.65f));
C(ImGuiCol.ButtonHovered, new Vector4(0.5f, 0.42f, 0.78f, 0.8f));
C(ImGuiCol.ButtonActive, new Vector4(0.6f, 0.5f, 0.9f, 0.95f));
C(ImGuiCol.Header, new Vector4(0.2f, 0.18f, 0.28f, 0.6f));
C(ImGuiCol.HeaderHovered, new Vector4(0.3f, 0.25f, 0.4f, 0.8f));
C(ImGuiCol.HeaderActive, new Vector4(0.25f, 0.22f, 0.35f, 1f));
C(ImGuiCol.Separator, new Vector4(0.55f, 0.45f, 0.75f, 0.3f));
C(ImGuiCol.SeparatorHovered, new Vector4(0.65f, 0.55f, 0.85f, 0.6f));
C(ImGuiCol.SeparatorActive, new Vector4(0.75f, 0.55f, 0.95f, 0.8f));
C(ImGuiCol.Tab, new Vector4(0.18f, 0.15f, 0.25f, 0.7f));
C(ImGuiCol.TabHovered, new Vector4(0.45f, 0.35f, 0.65f, 0.8f));
C(ImGuiCol.TabActive, new Vector4(0.35f, 0.28f, 0.5f, 1f));
C(ImGuiCol.CheckMark, new Vector4(0.85f, 0.75f, 1f, 1f));
C(ImGuiCol.SliderGrab, new Vector4(0.65f, 0.55f, 0.85f, 0.9f));
C(ImGuiCol.SliderGrabActive, new Vector4(0.75f, 0.55f, 0.95f, 1f));
C(ImGuiCol.ResizeGrip, new Vector4(0.55f, 0.45f, 0.75f, 0.2f));
C(ImGuiCol.ResizeGripHovered, new Vector4(0.65f, 0.55f, 0.85f, 0.67f));
C(ImGuiCol.ResizeGripActive, new Vector4(0.75f, 0.55f, 0.95f, 0.95f));
C(ImGuiCol.TableHeaderBg, new Vector4(0.15f, 0.12f, 0.22f, 1f));
C(ImGuiCol.TableBorderStrong, new Vector4(0.55f, 0.45f, 0.75f, 0.3f));
C(ImGuiCol.TableBorderLight, new Vector4(0.55f, 0.45f, 0.75f, 0.15f));
C(ImGuiCol.TableRowBg, new Vector4(0f, 0f, 0f, 0f));
C(ImGuiCol.TableRowBgAlt, new Vector4(0.15f, 0.12f, 0.2f, 0.3f));
C(ImGuiCol.TextSelectedBg, new Vector4(0.55f, 0.45f, 0.75f, 0.35f));
C(ImGuiCol.NavHighlight, new Vector4(0.75f, 0.55f, 0.95f, 1f));
C(ImGuiCol.MenuBarBg, new Vector4(0.12f, 0.1f, 0.18f, 1f));
S(ImGuiStyleVar.FrameRounding, 4f);
S(ImGuiStyleVar.ChildRounding, 4f);
S(ImGuiStyleVar.PopupRounding, 4f);
S(ImGuiStyleVar.ScrollbarRounding, 6f);
S(ImGuiStyleVar.GrabRounding, 3f);
S(ImGuiStyleVar.TabRounding, 4f);
return new ThemeScope(colors, styles);
void C(ImGuiCol col, Vector4 color)
{
ImGui.PushStyleColor(col, color);
colors++;
}
void S(ImGuiStyleVar var, float val)
{
ImGui.PushStyleVar(var, val);
styles++;
}
}
}