diff --git a/Dalamud/Interface/Components/ImGuiComponents.DisabledButton.cs b/Dalamud/Interface/Components/ImGuiComponents.DisabledButton.cs
index c308bb972..59f1a7fd7 100644
--- a/Dalamud/Interface/Components/ImGuiComponents.DisabledButton.cs
+++ b/Dalamud/Interface/Components/ImGuiComponents.DisabledButton.cs
@@ -45,28 +45,10 @@ public static partial class ImGuiComponents
/// Indicator if button is clicked.
public static bool DisabledButton(string labelWithId, Vector4? defaultColor = null, Vector4? activeColor = null, Vector4? hoveredColor = null, float alphaMult = .5f)
{
- using var col = new ImRaii.ColorDisposable();
-
- if (defaultColor.HasValue)
- {
- col.Push(ImGuiCol.Button, defaultColor.Value);
- }
-
- if (activeColor.HasValue)
- {
- col.Push(ImGuiCol.ButtonActive, activeColor.Value);
- }
-
- if (hoveredColor.HasValue)
- {
- col.Push(ImGuiCol.ButtonHovered, hoveredColor.Value);
- }
-
- var style = ImGui.GetStyle();
-
- using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, style.Alpha * alphaMult))
- {
- return ImGui.Button(labelWithId);
- }
+ using var col = ImRaii.PushColor(ImGuiCol.Button, defaultColor)
+ .Push(ImGuiCol.ButtonActive, activeColor)
+ .Push(ImGuiCol.ButtonHovered, hoveredColor);
+ using var style = ImRaii.PushStyle(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * alphaMult);
+ return ImGui.Button(labelWithId);
}
}
diff --git a/Dalamud/Interface/Components/ImGuiComponents.HelpMarker.cs b/Dalamud/Interface/Components/ImGuiComponents.HelpMarker.cs
index 3744e4d8b..e80e373e3 100644
--- a/Dalamud/Interface/Components/ImGuiComponents.HelpMarker.cs
+++ b/Dalamud/Interface/Components/ImGuiComponents.HelpMarker.cs
@@ -1,8 +1,8 @@
+using System.Numerics;
+
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Utility.Raii;
-using FFXIVClientStructs.FFXIV.Common.Math;
-
namespace Dalamud.Interface.Components;
///
@@ -24,12 +24,7 @@ public static partial class ImGuiComponents
/// The color of the icon.
public static void HelpMarker(string helpText, FontAwesomeIcon icon, Vector4? color = null)
{
- using var col = new ImRaii.ColorDisposable();
-
- if (color.HasValue)
- {
- col.Push(ImGuiCol.TextDisabled, color.Value);
- }
+ using var col = ImRaii.PushColor(ImGuiCol.TextDisabled, color);
ImGui.SameLine();
diff --git a/Dalamud/Interface/Components/ImGuiComponents.IconButton.cs b/Dalamud/Interface/Components/ImGuiComponents.IconButton.cs
index 69d1bbb0e..65eab0274 100644
--- a/Dalamud/Interface/Components/ImGuiComponents.IconButton.cs
+++ b/Dalamud/Interface/Components/ImGuiComponents.IconButton.cs
@@ -123,22 +123,9 @@ public static partial class ImGuiComponents
/// Indicator if button is clicked.
public static bool IconButton(string iconText, Vector4? defaultColor, Vector4? activeColor = null, Vector4? hoveredColor = null, Vector2? size = null)
{
- using var col = new ImRaii.ColorDisposable();
-
- if (defaultColor.HasValue)
- {
- col.Push(ImGuiCol.Button, defaultColor.Value);
- }
-
- if (activeColor.HasValue)
- {
- col.Push(ImGuiCol.ButtonActive, activeColor.Value);
- }
-
- if (hoveredColor.HasValue)
- {
- col.Push(ImGuiCol.ButtonHovered, hoveredColor.Value);
- }
+ using var col = ImRaii.PushColor(ImGuiCol.Button, defaultColor)
+ .Push(ImGuiCol.ButtonActive, activeColor)
+ .Push(ImGuiCol.ButtonHovered, hoveredColor);
if (size.HasValue)
{
@@ -203,22 +190,9 @@ public static partial class ImGuiComponents
/// Indicator if button is clicked.
public static bool IconButtonWithText(FontAwesomeIcon icon, string text, Vector4? defaultColor = null, Vector4? activeColor = null, Vector4? hoveredColor = null, Vector2? size = null)
{
- using var col = new ImRaii.ColorDisposable();
-
- if (defaultColor.HasValue)
- {
- col.Push(ImGuiCol.Button, defaultColor.Value);
- }
-
- if (activeColor.HasValue)
- {
- col.Push(ImGuiCol.ButtonActive, activeColor.Value);
- }
-
- if (hoveredColor.HasValue)
- {
- col.Push(ImGuiCol.ButtonHovered, hoveredColor.Value);
- }
+ using var col = ImRaii.PushColor(ImGuiCol.Button, defaultColor)
+ .Push(ImGuiCol.ButtonActive, activeColor)
+ .Push(ImGuiCol.ButtonHovered, hoveredColor);
if (size.HasValue)
{
diff --git a/Dalamud/Interface/Utility/ImGuiHelpers.cs b/Dalamud/Interface/Utility/ImGuiHelpers.cs
index 5cfcc8dec..35c44c13a 100644
--- a/Dalamud/Interface/Utility/ImGuiHelpers.cs
+++ b/Dalamud/Interface/Utility/ImGuiHelpers.cs
@@ -172,13 +172,8 @@ public static partial class ImGuiHelpers
/// The color of the text.
public static void ClickToCopyText(ImU8String text, ImU8String textCopy = default, Vector4? color = null)
{
- using (var col = new ImRaii.ColorDisposable())
+ using (ImRaii.PushColor(ImGuiCol.Text, color))
{
- if (color.HasValue)
- {
- col.Push(ImGuiCol.Text, color.Value);
- }
-
ImGui.Text(text.Span);
}
diff --git a/Dalamud/Interface/Utility/Raii/Disposables/ColorDisposable.cs b/Dalamud/Interface/Utility/Raii/Disposables/ColorDisposable.cs
index ebcd056f5..6df60156a 100644
--- a/Dalamud/Interface/Utility/Raii/Disposables/ColorDisposable.cs
+++ b/Dalamud/Interface/Utility/Raii/Disposables/ColorDisposable.cs
@@ -26,13 +26,27 @@ public static partial class ImRaii
/// Push a color to the color stack.
/// The type of color to change.
- /// The color to change it to. If this is null/default, no color will be set.
+ /// The color to change it to.
/// /// If this is false, the color is not pushed.
/// A disposable object that can be used to push further colors and pops those colors after leaving scope. Use with using.
/// If you need to keep colors pushed longer than the current scope, use without using and use .
public ColorDisposable Push(ImGuiCol type, Vector4 color, bool condition = true)
=> condition ? this.InternalPush(type, color) : this;
+ /// Push a color to the color stack.
+ /// The type of color to change.
+ /// The color to change it to. If this is null, no color will be set.
+ /// /// If this is false, the color is not pushed.
+ /// A disposable object that can be used to push further colors and pops those colors after leaving scope. Use with using.
+ /// If you need to keep colors pushed longer than the current scope, use without using and use .
+ public ColorDisposable Push(ImGuiCol type, Vector4? color, bool condition = true)
+ {
+ if (!color.HasValue)
+ return this;
+
+ return condition ? this.InternalPush(type, color.Value) : this;
+ }
+
private ColorDisposable InternalPush(ImGuiCol type, uint color)
{
Stack.Add((type, ImGui.GetColorU32(type)));
diff --git a/Dalamud/Interface/Utility/Raii/EndObjects.cs b/Dalamud/Interface/Utility/Raii/EndObjects.cs
index c7dc10d09..1d3ce1dad 100644
--- a/Dalamud/Interface/Utility/Raii/EndObjects.cs
+++ b/Dalamud/Interface/Utility/Raii/EndObjects.cs
@@ -26,6 +26,9 @@ public static partial class ImRaii
public static ColorDisposable PushColor(ImGuiCol idx, Vector4 color, bool condition = true)
=> new ColorDisposable().Push(idx, color, condition);
+ public static ColorDisposable PushColor(ImGuiCol idx, Vector4? color, bool condition = true)
+ => new ColorDisposable().Push(idx, color, condition);
+
public static ColorDisposable DefaultColors()
=> ColorDisposable.DefaultColors();