diff --git a/ChatTwo/Ui/SettingsTabs/About.cs b/ChatTwo/Ui/SettingsTabs/About.cs index 884e818..f3d7146 100755 --- a/ChatTwo/Ui/SettingsTabs/About.cs +++ b/ChatTwo/Ui/SettingsTabs/About.cs @@ -33,7 +33,7 @@ internal sealed class About : ISettingsTab public void Draw(bool changed) { - ImGui.PushTextWrapPos(); + using var wrap = ImGuiUtil.TextWrapPos(); ImGui.TextUnformatted(string.Format(Language.Options_About_Opening, Plugin.PluginName)); @@ -93,8 +93,6 @@ internal sealed class About : ISettingsTab } } } - ImGui.Spacing(); - ImGui.PopTextWrapPos(); } } diff --git a/ChatTwo/Ui/SettingsTabs/ChatLog.cs b/ChatTwo/Ui/SettingsTabs/ChatLog.cs index 11c3560..6ee10a5 100644 --- a/ChatTwo/Ui/SettingsTabs/ChatLog.cs +++ b/ChatTwo/Ui/SettingsTabs/ChatLog.cs @@ -21,63 +21,63 @@ internal sealed class ChatLog : ISettingsTab public void Draw(bool changed) { - ImGui.PushTextWrapPos(); - - ImGuiUtil.OptionCheckbox(ref Mutable.KeepInputFocus, Language.Options_KeepInputFocus_Name, Language.Options_KeepInputFocus_Description); - ImGui.Spacing(); - - ImGuiUtil.OptionCheckbox(ref Mutable.PlaySounds, Language.Options_PlaySounds_Name, Language.Options_PlaySounds_Description); - ImGui.Spacing(); - - ImGuiUtil.OptionCheckbox(ref Mutable.SidebarTabView, Language.Options_SidebarTabView_Name, string.Format(Language.Options_SidebarTabView_Description, Plugin.PluginName)); - ImGui.Spacing(); - - ImGuiUtil.OptionCheckbox(ref Mutable.ShowNoviceNetwork, Language.Options_ShowNoviceNetwork_Name, Language.Options_ShowNoviceNetwork_Description); - ImGui.Spacing(); - - ImGuiUtil.OptionCheckbox(ref Mutable.NativeItemTooltips, Language.Options_NativeItemTooltips_Name, string.Format(Language.Options_NativeItemTooltips_Description, Plugin.PluginName)); - ImGui.Spacing(); - - if (Mutable.NativeItemTooltips) + using (ImGuiUtil.TextWrapPos()) { - ImGuiUtil.DragFloatVertical(Language.Options_TooltipOffset_Name, Language.Options_TooltipOffset_Desc, ref Mutable.TooltipOffset, 1, 0f, 400f, $"{Mutable.TooltipOffset:N0}px", ImGuiSliderFlags.AlwaysClamp); + ImGuiUtil.OptionCheckbox(ref Mutable.KeepInputFocus, Language.Options_KeepInputFocus_Name, Language.Options_KeepInputFocus_Description); + ImGui.Spacing(); + + ImGuiUtil.OptionCheckbox(ref Mutable.PlaySounds, Language.Options_PlaySounds_Name, Language.Options_PlaySounds_Description); + ImGui.Spacing(); + + ImGuiUtil.OptionCheckbox(ref Mutable.SidebarTabView, Language.Options_SidebarTabView_Name, string.Format(Language.Options_SidebarTabView_Description, Plugin.PluginName)); + ImGui.Spacing(); + + ImGuiUtil.OptionCheckbox(ref Mutable.ShowNoviceNetwork, Language.Options_ShowNoviceNetwork_Name, Language.Options_ShowNoviceNetwork_Description); + ImGui.Spacing(); + + ImGuiUtil.OptionCheckbox(ref Mutable.NativeItemTooltips, Language.Options_NativeItemTooltips_Name, string.Format(Language.Options_NativeItemTooltips_Description, Plugin.PluginName)); + ImGui.Spacing(); + + if (Mutable.NativeItemTooltips) + { + ImGuiUtil.DragFloatVertical(Language.Options_TooltipOffset_Name, Language.Options_TooltipOffset_Desc, ref Mutable.TooltipOffset, 1, 0f, 400f, $"{Mutable.TooltipOffset:N0}px", ImGuiSliderFlags.AlwaysClamp); + ImGui.Spacing(); + } + + ImGuiUtil.DragFloatVertical(Language.Options_WindowOpacity_Name, ref Mutable.WindowAlpha, .25f, 0f, 100f, $"{Mutable.WindowAlpha:N2}%%", ImGuiSliderFlags.AlwaysClamp); + ImGui.Spacing(); + + if (ImGuiUtil.InputIntVertical(Language.Options_MaxLinesToShow_Name, Language.Options_MaxLinesToShow_Description, ref Mutable.MaxLinesToRender)) Mutable.MaxLinesToRender = Math.Clamp(Mutable.MaxLinesToRender, 1, 10_000); + ImGui.Spacing(); + + ImGuiUtil.OptionCheckbox(ref Mutable.CanMove, Language.Options_CanMove_Name); + ImGui.Spacing(); + + ImGuiUtil.OptionCheckbox(ref Mutable.CanResize, Language.Options_CanResize_Name); + ImGui.Spacing(); + + ImGuiUtil.OptionCheckbox(ref Mutable.ShowTitleBar, Language.Options_ShowTitleBar_Name); + ImGui.Spacing(); + + ImGuiUtil.OptionCheckbox(ref Mutable.ShowPopOutTitleBar, Language.Options_ShowPopOutTitleBar_Name); + ImGui.Spacing(); + + ImGuiUtil.OptionCheckbox(ref Mutable.OverrideStyle, Language.Options_OverrideStyle_Name, Language.Options_OverrideStyle_Name_Desc); + ImGui.Spacing(); + + ImGui.Spacing(); + ImGui.Separator(); + ImGui.Spacing(); + + ImGui.TextUnformatted(Language.Options_AdjustPosition_Name); + var pos = Plugin.ChatLogWindow.LastWindowPos; + ImGui.SetNextItemWidth(-1); + if (ImGui.DragFloat2($"##{Language.Options_AdjustPosition_Name}", ref pos, 1, 0, float.MaxValue, "%.0fpx")) + Plugin.ChatLogWindow.Position = pos; + ImGuiUtil.WarningText(Language.Options_AdjustPosition_Warning); ImGui.Spacing(); } - ImGuiUtil.DragFloatVertical(Language.Options_WindowOpacity_Name, ref Mutable.WindowAlpha, .25f, 0f, 100f, $"{Mutable.WindowAlpha:N2}%%", ImGuiSliderFlags.AlwaysClamp); - ImGui.Spacing(); - - if (ImGuiUtil.InputIntVertical(Language.Options_MaxLinesToShow_Name, Language.Options_MaxLinesToShow_Description, ref Mutable.MaxLinesToRender)) Mutable.MaxLinesToRender = Math.Clamp(Mutable.MaxLinesToRender, 1, 10_000); - ImGui.Spacing(); - - ImGuiUtil.OptionCheckbox(ref Mutable.CanMove, Language.Options_CanMove_Name); - ImGui.Spacing(); - - ImGuiUtil.OptionCheckbox(ref Mutable.CanResize, Language.Options_CanResize_Name); - ImGui.Spacing(); - - ImGuiUtil.OptionCheckbox(ref Mutable.ShowTitleBar, Language.Options_ShowTitleBar_Name); - ImGui.Spacing(); - - ImGuiUtil.OptionCheckbox(ref Mutable.ShowPopOutTitleBar, Language.Options_ShowPopOutTitleBar_Name); - ImGui.Spacing(); - - ImGuiUtil.OptionCheckbox(ref Mutable.OverrideStyle, Language.Options_OverrideStyle_Name, Language.Options_OverrideStyle_Name_Desc); - ImGui.Spacing(); - - ImGui.Spacing(); - ImGui.Separator(); - ImGui.Spacing(); - - ImGui.TextUnformatted(Language.Options_AdjustPosition_Name); - var pos = Plugin.ChatLogWindow.LastWindowPos; - ImGui.SetNextItemWidth(-1); - if (ImGui.DragFloat2($"##{Language.Options_AdjustPosition_Name}", ref pos, 1, 0, float.MaxValue, "%.0fpx")) - Plugin.ChatLogWindow.Position = pos; - ImGuiUtil.WarningText(Language.Options_AdjustPosition_Warning); - ImGui.Spacing(); - ImGui.PopTextWrapPos(); - if (!Mutable.OverrideStyle) return; diff --git a/ChatTwo/Ui/SettingsTabs/Database.cs b/ChatTwo/Ui/SettingsTabs/Database.cs index 30e9122..f12ceb4 100755 --- a/ChatTwo/Ui/SettingsTabs/Database.cs +++ b/ChatTwo/Ui/SettingsTabs/Database.cs @@ -147,9 +147,9 @@ internal sealed class Database : ISettingsTab return; using var treeNode = ImRaii.TreeNode(Language.Options_Database_Advanced); - ImGui.PushTextWrapPos(); - ImGuiUtil.WarningText(Language.Options_Database_Advanced_Warning); + using var wrap = ImGuiUtil.TextWrapPos(); + ImGuiUtil.WarningText(Language.Options_Database_Advanced_Warning); if (ImGuiUtil.CtrlShiftButton("Perform maintenance", "Ctrl+Shift: MessageManager.Store.PerformMaintenance()")) Plugin.MessageManager.Store.PerformMaintenance(); @@ -161,8 +161,6 @@ internal sealed class Database : ISettingsTab if (ImGuiUtil.CtrlShiftButton("Inject 10,000 messages", "Ctrl+Shift: creates 10,000 unique messages (async)")) new Thread(() => InsertMessages(10_000)).Start(); - - ImGui.PopTextWrapPos(); ImGui.Spacing(); } diff --git a/ChatTwo/Ui/SettingsTabs/Display.cs b/ChatTwo/Ui/SettingsTabs/Display.cs index 2a1529f..36a0171 100755 --- a/ChatTwo/Ui/SettingsTabs/Display.cs +++ b/ChatTwo/Ui/SettingsTabs/Display.cs @@ -19,7 +19,7 @@ internal sealed class Display : ISettingsTab public void Draw(bool changed) { - ImGui.PushTextWrapPos(); + using var wrap = ImGuiUtil.TextWrapPos(); ImGuiUtil.OptionCheckbox(ref Mutable.HideChat, Language.Options_HideChat_Name, Language.Options_HideChat_Description); ImGui.Spacing(); @@ -52,7 +52,5 @@ internal sealed class Display : ISettingsTab ImGuiUtil.OptionCheckbox(ref Mutable.CollapseDuplicateMessages, Language.Options_CollapseDuplicateMessages_Name, Language.Options_CollapseDuplicateMessages_Description); ImGui.Spacing(); - - ImGui.PopTextWrapPos(); } } diff --git a/ChatTwo/Ui/SettingsTabs/Emote.cs b/ChatTwo/Ui/SettingsTabs/Emote.cs index c8ae72a..7f8861c 100644 --- a/ChatTwo/Ui/SettingsTabs/Emote.cs +++ b/ChatTwo/Ui/SettingsTabs/Emote.cs @@ -38,7 +38,7 @@ internal sealed class Emote : ISettingsTab public void Draw(bool changed) { - ImGui.PushTextWrapPos(); + using var wrap = ImGuiUtil.TextWrapPos(); ImGuiUtil.OptionCheckbox(ref Mutable.ShowEmotes, Language.Options_ShowEmotes_Name, Language.Options_ShowEmotes_Desc); ImGui.Spacing(); @@ -109,7 +109,5 @@ internal sealed class Emote : ISettingsTab } } } - - ImGui.PopTextWrapPos(); } } diff --git a/ChatTwo/Ui/SettingsTabs/Fonts.cs b/ChatTwo/Ui/SettingsTabs/Fonts.cs index 3294e4f..d5548aa 100755 --- a/ChatTwo/Ui/SettingsTabs/Fonts.cs +++ b/ChatTwo/Ui/SettingsTabs/Fonts.cs @@ -29,7 +29,7 @@ public class Fonts : ISettingsTab if (changed) UpdateFonts(); - ImGui.PushTextWrapPos(); + using var wrap = ImGuiUtil.TextWrapPos(); ImGui.Checkbox(Language.Options_FontsEnabled, ref Mutable.FontsEnabled); ImGui.Spacing(); @@ -118,6 +118,5 @@ public class Fonts : ISettingsTab ImGuiUtil.HelpText(Language.Options_SymbolsFontSize_Description); ImGui.Spacing(); - ImGui.PopTextWrapPos(); } } diff --git a/ChatTwo/Util/ImGuiUtil.cs b/ChatTwo/Util/ImGuiUtil.cs index 3e8b177..4609bf9 100755 --- a/ChatTwo/Util/ImGuiUtil.cs +++ b/ChatTwo/Util/ImGuiUtil.cs @@ -200,11 +200,11 @@ internal static class ImGuiUtil internal static void HelpText(string text) { var colour = ImGui.GetStyle().Colors[(int) ImGuiCol.TextDisabled]; + + using (TextWrapPos()) using (ImRaii.PushColor(ImGuiCol.Text, colour)) { - ImGui.PushTextWrapPos(); ImGui.TextUnformatted(text); - ImGui.PopTextWrapPos(); } } @@ -215,15 +215,11 @@ internal static class ImGuiUtil var push = dalamudOrange != null; var color = dalamudOrange ?? Vector4.Zero; + + using (TextWrapPos(wrap)) using (ImRaii.PushColor(ImGuiCol.Text, color, push)) { - if (wrap) - ImGui.PushTextWrapPos(); - ImGui.TextUnformatted(text); - - if (wrap) - ImGui.PopTextWrapPos(); } } @@ -442,9 +438,15 @@ internal static class ImGuiUtil return new EndUnconditionally(ImGui.PopTextWrapPos, true); } - public static ImRaii.IEndObject TextWrapPos(float wrapLocalPosX) + public static ImRaii.IEndObject TextWrapPos(bool condition) { - ImGui.PushTextWrapPos(wrapLocalPosX); + if (!condition) + return new EndUnconditionally(Nop, false); + + ImGui.PushTextWrapPos(); return new EndUnconditionally(ImGui.PopTextWrapPos, true); } + + // Used to avoid pops if condition is false for Push. + private static void Nop() { } }