PalacePal/Pal.Client/Extensions/PalImGui.cs

36 lines
1.1 KiB
C#
Raw Normal View History

2023-02-21 13:58:30 +00:00
using System;
using System.Runtime.InteropServices;
using System.Text;
using ImGuiNET;
2023-03-30 20:01:43 +00:00
namespace Pal.Client.Extensions;
internal static class PalImGui
2023-02-21 13:58:30 +00:00
{
2023-03-30 20:01:43 +00:00
/// <summary>
/// None of the default BeginTabItem methods allow using flags without making the tab have a close button for some reason.
/// </summary>
internal static unsafe bool BeginTabItemWithFlags(string label, ImGuiTabItemFlags flags)
2023-02-21 13:58:30 +00:00
{
2023-03-30 20:01:43 +00:00
int labelLength = Encoding.UTF8.GetByteCount(label);
byte* labelPtr = stackalloc byte[labelLength + 1];
byte[] labelBytes = Encoding.UTF8.GetBytes(label);
2023-02-21 13:58:30 +00:00
2023-03-30 20:01:43 +00:00
Marshal.Copy(labelBytes, 0, (IntPtr)labelPtr, labelLength);
labelPtr[labelLength] = 0;
2023-02-21 13:58:30 +00:00
2023-03-30 20:01:43 +00:00
return ImGuiNative.igBeginTabItem(labelPtr, null, flags) != 0;
}
2023-02-21 13:58:30 +00:00
2023-03-30 20:01:43 +00:00
public static void RadioButtonWrapped(string label, ref int choice, int value)
{
ImGui.BeginGroup();
ImGui.RadioButton($"##radio{value}", value == choice);
ImGui.SameLine();
ImGui.TextWrapped(label);
ImGui.EndGroup();
if (ImGui.IsItemClicked())
choice = value;
2023-02-21 13:58:30 +00:00
}
}