refactor: simplify imgui extensions

This commit is contained in:
2026-01-16 14:08:08 -05:00
parent c75c0551ee
commit fa500f4c30
+10 -11
View File
@@ -8,7 +8,7 @@ namespace Spectrum
{
public static class ImGuiExtensions
{
private static readonly Dictionary<string, string> _sliderEditBuffers = new();
private static readonly Dictionary<string, string> _sliderEditBuffers = [];
public static bool ColorEditHSV3(string label, ref Scalar hsv)
{
ImGui.PushID(label);
@@ -54,8 +54,8 @@ namespace Spectrum
Vector3 rgbColor = OpenCvHsvToRgb(hsv);
ImGui.SameLine();
Vector2 btnSize = new Vector2(previewWidth, previewWidth);
Vector4 previewCol4 = new Vector4(rgbColor.X, rgbColor.Y, rgbColor.Z, 1.0f);
Vector2 btnSize = new(previewWidth, previewWidth);
Vector4 previewCol4 = new(rgbColor.X, rgbColor.Y, rgbColor.Z, 1.0f);
string previewBtnId = $"##ColorPreview_{label}";
if (ImGui.ColorButton(previewBtnId, previewCol4, ImGuiColorEditFlags.NoInputs, btnSize))
{
@@ -101,13 +101,12 @@ namespace Spectrum
double huePrime = hueDeg / 60.0;
double x = c * (1 - Math.Abs(huePrime % 2 - 1));
double m = value - c;
double r1 = 0, g1 = 0, b1 = 0;
int region = (int)Math.Floor(huePrime);
if (region >= 6)
region = 0;
double r1;
double b1;
double g1;
switch (region)
{
case 0:
@@ -224,7 +223,7 @@ namespace Spectrum
int fPos = core.IndexOf('f', pos + 2);
if (fPos > pos)
{
string digits = core.Substring(pos + 2, fPos - (pos + 2));
string digits = core[(pos + 2)..fPos];
if (int.TryParse(digits, out int prec))
result = v.ToString("F" + prec, CultureInfo.InvariantCulture);
else
@@ -286,7 +285,7 @@ namespace Spectrum
int fPos = format.IndexOf('f', pos + 2);
if (fPos > pos)
{
string digits = format.Substring(pos + 2, fPos - (pos + 2));
string digits = format[(pos + 2)..fPos];
if (int.TryParse(digits, out int prec))
newValue = (float)Math.Round(newValue, prec);
}
@@ -311,7 +310,7 @@ namespace Spectrum
if (ImGui.InputText($"##SliderFillEdit_{label}", ref buffer, 32, inputFlags))
{
string parseStr = buffer.Trim();
if (parseStr.EndsWith("%")) parseStr = parseStr.TrimEnd('%');
if (parseStr.EndsWith('%')) parseStr = parseStr.TrimEnd('%');
if (float.TryParse(parseStr, NumberStyles.Float, CultureInfo.InvariantCulture, out float typed))
{
float clamped;
@@ -428,7 +427,7 @@ namespace Spectrum
Vector2 headerMin = ImGui.GetCursorScreenPos();
Vector2 headerMax = new Vector2(headerMin.X + g.Width, headerMin.Y + headerHeight);
Vector2 headerMax = new(headerMin.X + g.Width, headerMin.Y + headerHeight);
var drawList = ImGui.GetWindowDrawList();
uint bgCol = ImGui.GetColorU32(ImGuiCol.FrameBg);