8d6b603963
- Update Dalamud.NET.Sdk version in csproj - Regenerate packages.lock.json against SDK 15 - Migrate FFXIVClientStructs.FFXIV.Component.GUI.ValueType → AtkValueType (SynthesisValues.cs) - Introduce local IEndObject interface in ImRaii2.cs (Dalamud's nested ImRaii.IEndObject was removed in SDK 15) - Switch direct Dalamud ImRaii returns to typed disposables (ImRaii.TabItemDisposable, ImRaii.ColorDisposable) - Replace `if (!panel)` / `if (plot)` with `.Success` checks for the local IEndObject helpers - Fix ref-bool lifetime issue in Settings.TabItem by using the ImRaii.TabItem(label, flags) overload
91 lines
2.3 KiB
C#
91 lines
2.3 KiB
C#
using Dalamud.Interface.Utility.Raii;
|
|
using Dalamud.Bindings.ImGui;
|
|
using Dalamud.Bindings.ImPlot;
|
|
using System;
|
|
using System.Numerics;
|
|
|
|
namespace Craftimizer.Plugin;
|
|
|
|
public interface IEndObject : IDisposable
|
|
{
|
|
bool Success { get; }
|
|
}
|
|
|
|
public static class ImRaii2
|
|
{
|
|
private struct EndUnconditionally(Action endAction, bool success) : IEndObject
|
|
{
|
|
private Action EndAction { get; } = endAction;
|
|
|
|
public bool Success { get; } = success;
|
|
|
|
public bool Disposed { get; private set; } = false;
|
|
|
|
public void Dispose()
|
|
{
|
|
if (!Disposed)
|
|
{
|
|
EndAction();
|
|
Disposed = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct EndConditionally(Action endAction, bool success) : IEndObject
|
|
{
|
|
public bool Success { get; } = success;
|
|
|
|
public bool Disposed { get; private set; } = false;
|
|
|
|
private Action EndAction { get; } = endAction;
|
|
|
|
public void Dispose()
|
|
{
|
|
if (!Disposed)
|
|
{
|
|
if (Success)
|
|
{
|
|
EndAction();
|
|
}
|
|
|
|
Disposed = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static IEndObject GroupPanel(string name, float width, out float internalWidth)
|
|
{
|
|
internalWidth = ImGuiUtils.BeginGroupPanel(name, width);
|
|
return new EndUnconditionally(ImGuiUtils.EndGroupPanel, true);
|
|
}
|
|
|
|
public static IEndObject Plot(string title_id, Vector2 size, ImPlotFlags flags)
|
|
{
|
|
return new EndConditionally(new Action(ImPlot.EndPlot), ImPlot.BeginPlot(title_id, size, flags));
|
|
}
|
|
|
|
public static IEndObject PushStyle(ImPlotStyleVar idx, Vector2 val)
|
|
{
|
|
ImPlot.PushStyleVar(idx, val);
|
|
return new EndUnconditionally(ImPlot.PopStyleVar, true);
|
|
}
|
|
|
|
public static IEndObject PushStyle(ImPlotStyleVar idx, float val)
|
|
{
|
|
ImPlot.PushStyleVar(idx, val);
|
|
return new EndUnconditionally(ImPlot.PopStyleVar, true);
|
|
}
|
|
|
|
public static IEndObject PushColor(ImPlotCol idx, Vector4 col)
|
|
{
|
|
ImPlot.PushStyleColor(idx, col);
|
|
return new EndUnconditionally(ImPlot.PopStyleColor, true);
|
|
}
|
|
|
|
public static IEndObject TextWrapPos(float wrap_local_pos_x)
|
|
{
|
|
ImGui.PushTextWrapPos(wrap_local_pos_x);
|
|
return new EndUnconditionally(ImGui.PopTextWrapPos, true);
|
|
}
|
|
}
|