From f55d25b088d167d55fa26ea85d55ee392c28ed67 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Wed, 15 Nov 2023 18:38:42 +0100 Subject: [PATCH] Improve tri-state checkboxes. --- Glamourer/Gui/Colors.cs | 6 ++++++ Glamourer/Gui/UiHelpers.cs | 42 +++++++++++++++++++++----------------- OtterGui | 2 +- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/Glamourer/Gui/Colors.cs b/Glamourer/Gui/Colors.cs index 9206498..873ec38 100644 --- a/Glamourer/Gui/Colors.cs +++ b/Glamourer/Gui/Colors.cs @@ -25,6 +25,9 @@ public enum ColorId QuickDesignButton, QuickDesignFrame, QuickDesignBg, + TriStateCheck, + TriStateCross, + TriStateNeutral, } public static class Colors @@ -55,6 +58,9 @@ public static class Colors ColorId.QuickDesignButton => (0x900A0A0A, "Quick Design Bar Button Background", "The color of button frames in the quick design bar." ), ColorId.QuickDesignFrame => (0x90383838, "Quick Design Bar Combo Background", "The color of the combo background in the quick design bar." ), ColorId.QuickDesignBg => (0x00F0F0F0, "Quick Design Bar Window Background", "The color of the window background in the quick design bar." ), + ColorId.TriStateCheck => (0xFF00D000, "Checkmark in Tri-State Checkboxes", "The color of the checkmark indicating positive change in tri-state checkboxes." ), + ColorId.TriStateCross => (0xFF0000D0, "Cross in Tri-State Checkboxes", "The color of the cross indicating negative change in tri-state checkboxes." ), + ColorId.TriStateNeutral => (0xFFD0D0D0, "Dot in Tri-State Checkboxes", "The color of the dot indicating no change in tri-state checkboxes" ), _ => (0x00000000, string.Empty, string.Empty ), // @formatter:on }; diff --git a/Glamourer/Gui/UiHelpers.cs b/Glamourer/Gui/UiHelpers.cs index 8299e43..eb1f1c2 100644 --- a/Glamourer/Gui/UiHelpers.cs +++ b/Glamourer/Gui/UiHelpers.cs @@ -9,6 +9,7 @@ using Glamourer.Unlocks; using ImGuiNET; using Lumina.Misc; using OtterGui; +using OtterGui.Classes; using OtterGui.Raii; using Penumbra.GameData.Enums; using Penumbra.GameData.Structs; @@ -71,15 +72,26 @@ public static class UiHelpers } public static DataChange DrawMetaToggle(string label, bool currentValue, bool currentApply, out bool newValue, - out bool newApply, - bool locked) + out bool newApply, bool locked) { - var flags = currentApply ? currentValue ? 3 : 0 : 2; - bool ret; + var flags = (sbyte)(currentApply ? currentValue ? 1 : -1 : 0); using var style = ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemInnerSpacing); using (var disabled = ImRaii.Disabled(locked)) { - ret = ImGui.CheckboxFlags("##" + label, ref flags, 3); + if (new TristateCheckbox(ColorId.TriStateCross.Value(), ColorId.TriStateCheck.Value(), ColorId.TriStateNeutral.Value()).Draw("##" + label, flags, out flags)) + { + (newValue, newApply) = flags switch + { + -1 => (false, true), + 0 => (true, false), + _ => (true, true), + }; + } + else + { + newValue = currentValue; + newApply = currentApply; + } } ImGuiUtil.HoverTooltip($"This attribute will be {(currentApply ? currentValue ? "enabled." : "disabled." : "kept as is.")}"); @@ -87,21 +99,13 @@ public static class UiHelpers ImGui.SameLine(); ImGui.TextUnformatted(label); - if (ret) + return (currentApply != newApply, currentValue != newValue) switch { - (newValue, newApply, var change) = (currentValue, currentApply) switch - { - (false, false) => (false, true, DataChange.ApplyItem), - (false, true) => (true, true, DataChange.Item), - (true, false) => (false, false, DataChange.Item), // Should not happen - (true, true) => (false, false, DataChange.Item | DataChange.ApplyItem), - }; - return change; - } - - newValue = currentValue; - newApply = currentApply; - return DataChange.None; + (true, true) => DataChange.ApplyItem | DataChange.Item, + (true, false) => DataChange.ApplyItem, + (false, true) => DataChange.Item, + _ => DataChange.None, + }; } public static (EquipFlag, CustomizeFlag) ConvertKeysToFlags() diff --git a/OtterGui b/OtterGui index b09bbcc..f55733a 160000 --- a/OtterGui +++ b/OtterGui @@ -1 +1 @@ -Subproject commit b09bbcc276363bc994d90b641871e6280898b6e5 +Subproject commit f55733a96fdc9f82c9bbf8272ca6366079aa8e32