diff --git a/Pal.Client/Extensions/PalImGui.cs b/Pal.Client/Extensions/PalImGui.cs new file mode 100644 index 0000000..e6215c8 --- /dev/null +++ b/Pal.Client/Extensions/PalImGui.cs @@ -0,0 +1,36 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; +using ImGuiNET; + +namespace Pal.Client.Extensions +{ + internal static class PalImGui + { + /// + /// None of the default BeginTabItem methods allow using flags without making the tab have a close button for some reason. + /// + internal static unsafe bool BeginTabItemWithFlags(string label, ImGuiTabItemFlags flags) + { + int labelLength = Encoding.UTF8.GetByteCount(label); + byte* labelPtr = stackalloc byte[labelLength + 1]; + byte[] labelBytes = Encoding.UTF8.GetBytes(label); + + Marshal.Copy(labelBytes, 0, (IntPtr)labelPtr, labelLength); + labelPtr[labelLength] = 0; + + return ImGuiNative.igBeginTabItem(labelPtr, null, flags) != 0; + } + + 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; + } + } +} diff --git a/Pal.Client/Windows/AgreementWindow.cs b/Pal.Client/Windows/AgreementWindow.cs index 3cd3a29..377ac64 100644 --- a/Pal.Client/Windows/AgreementWindow.cs +++ b/Pal.Client/Windows/AgreementWindow.cs @@ -3,6 +3,7 @@ using Dalamud.Interface.Windowing; using ECommons; using ImGuiNET; using System.Numerics; +using Pal.Client.Extensions; using Pal.Client.Properties; namespace Pal.Client.Windows @@ -49,8 +50,8 @@ namespace Pal.Client.Windows ImGui.TextWrapped(Localization.Explanation_3); ImGui.TextWrapped(Localization.Explanation_4); - ImGui.RadioButton(Localization.Config_UploadMyDiscoveries_ShowOtherTraps, ref _choice, (int)Configuration.EMode.Online); - ImGui.RadioButton(Localization.Config_NeverUploadDiscoveries_ShowMyTraps, ref _choice, (int)Configuration.EMode.Offline); + PalImGui.RadioButtonWrapped(Localization.Config_UploadMyDiscoveries_ShowOtherTraps, ref _choice, (int)Configuration.EMode.Online); + PalImGui.RadioButtonWrapped(Localization.Config_NeverUploadDiscoveries_ShowMyTraps, ref _choice, (int)Configuration.EMode.Offline); ImGui.Separator(); diff --git a/Pal.Client/Windows/ConfigWindow.cs b/Pal.Client/Windows/ConfigWindow.cs index 7787296..dbf0623 100644 --- a/Pal.Client/Windows/ConfigWindow.cs +++ b/Pal.Client/Windows/ConfigWindow.cs @@ -18,6 +18,7 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; +using Pal.Client.Extensions; using Pal.Client.Properties; namespace Pal.Client.Windows @@ -183,15 +184,15 @@ namespace Pal.Client.Windows private void DrawCommunityTab(ref bool saveAndClose) { - if (BeginTabItemEx($"{Localization.ConfigTab_Community}###TabCommunity", _switchToCommunityTab ? ImGuiTabItemFlags.SetSelected : ImGuiTabItemFlags.None)) + if (PalImGui.BeginTabItemWithFlags($"{Localization.ConfigTab_Community}###TabCommunity", _switchToCommunityTab ? ImGuiTabItemFlags.SetSelected : ImGuiTabItemFlags.None)) { _switchToCommunityTab = false; ImGui.TextWrapped(Localization.Explanation_3); ImGui.TextWrapped(Localization.Explanation_4); - ImGui.RadioButton(Localization.Config_UploadMyDiscoveries_ShowOtherTraps, ref _mode, (int)Configuration.EMode.Online); - ImGui.RadioButton(Localization.Config_NeverUploadDiscoveries_ShowMyTraps, ref _mode, (int)Configuration.EMode.Offline); + PalImGui.RadioButtonWrapped(Localization.Config_UploadMyDiscoveries_ShowOtherTraps, ref _mode, (int)Configuration.EMode.Online); + PalImGui.RadioButtonWrapped(Localization.Config_NeverUploadDiscoveries_ShowMyTraps, ref _mode, (int)Configuration.EMode.Offline); saveAndClose = ImGui.Button(Localization.SaveAndClose); ImGui.Separator(); @@ -359,21 +360,6 @@ namespace Pal.Client.Windows } } - /// - /// None of the default BeginTabItem methods allow using flags without making the tab have a close button for some reason. - /// - private static unsafe bool BeginTabItemEx(string label, ImGuiTabItemFlags flags) - { - int labelLength = Encoding.UTF8.GetByteCount(label); - byte* labelPtr = stackalloc byte[labelLength + 1]; - byte[] labelBytes = Encoding.UTF8.GetBytes(label); - - Marshal.Copy(labelBytes, 0, (IntPtr)labelPtr, labelLength); - labelPtr[labelLength] = 0; - - return ImGuiNative.igBeginTabItem(labelPtr, null, flags) != 0; - } - internal void TestConnection() { Task.Run(async () =>