Use textwrap for radio buttons
This commit is contained in:
parent
7c968fa9d4
commit
7b5bb3ee3a
36
Pal.Client/Extensions/PalImGui.cs
Normal file
36
Pal.Client/Extensions/PalImGui.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace Pal.Client.Extensions
|
||||
{
|
||||
internal static class PalImGui
|
||||
{
|
||||
/// <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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// None of the default BeginTabItem methods allow using flags without making the tab have a close button for some reason.
|
||||
/// </summary>
|
||||
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 () =>
|
||||
|
Loading…
Reference in New Issue
Block a user