mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-24 13:41:49 +01:00
- Add new PushColor overload that checks for nullable Vector4
This commit is contained in:
parent
f593433fcb
commit
8d55dccd75
6 changed files with 33 additions and 70 deletions
|
|
@ -45,28 +45,10 @@ public static partial class ImGuiComponents
|
|||
/// <returns>Indicator if button is clicked.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -24,12 +24,7 @@ public static partial class ImGuiComponents
|
|||
/// <param name="color">The color of the icon.</param>
|
||||
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();
|
||||
|
||||
|
|
|
|||
|
|
@ -123,22 +123,9 @@ public static partial class ImGuiComponents
|
|||
/// <returns>Indicator if button is clicked.</returns>
|
||||
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
|
|||
/// <returns>Indicator if button is clicked.</returns>
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -172,13 +172,8 @@ public static partial class ImGuiHelpers
|
|||
/// <param name="color">The color of the text.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,13 +26,27 @@ public static partial class ImRaii
|
|||
|
||||
/// <summary> Push a color to the color stack. </summary>
|
||||
/// <param name="type"> The type of color to change. </param>
|
||||
/// <param name="color"> The color to change it to. If this is null/default, no color will be set. </param>
|
||||
/// <param name="color"> The color to change it to. </param>
|
||||
/// /// <param name="condition"> If this is false, the color is not pushed. </param>
|
||||
/// <returns> A disposable object that can be used to push further colors and pops those colors after leaving scope. Use with using. </returns>
|
||||
/// <remarks> If you need to keep colors pushed longer than the current scope, use without using and use <seealso cref="PopUnsafe"/>. </remarks>
|
||||
public ColorDisposable Push(ImGuiCol type, Vector4 color, bool condition = true)
|
||||
=> condition ? this.InternalPush(type, color) : this;
|
||||
|
||||
/// <summary> Push a color to the color stack. </summary>
|
||||
/// <param name="type"> The type of color to change. </param>
|
||||
/// <param name="color"> The color to change it to. If this is null, no color will be set. </param>
|
||||
/// /// <param name="condition"> If this is false, the color is not pushed. </param>
|
||||
/// <returns> A disposable object that can be used to push further colors and pops those colors after leaving scope. Use with using. </returns>
|
||||
/// <remarks> If you need to keep colors pushed longer than the current scope, use without using and use <seealso cref="PopUnsafe"/>. </remarks>
|
||||
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)));
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue