From db28e4c24f50ae04b8a847d6f1b80f6583e531cc Mon Sep 17 00:00:00 2001 From: Dom Date: Sun, 2 Oct 2022 05:59:39 -0400 Subject: [PATCH] table scheme, streamlined settings addition --- T3/Gui/Windows/SettingsInSettingsWindow.cs | 135 +++++++++++++++++++++ T3/Gui/Windows/SettingsWindow.cs | 78 +++++++----- 2 files changed, 184 insertions(+), 29 deletions(-) create mode 100644 T3/Gui/Windows/SettingsInSettingsWindow.cs diff --git a/T3/Gui/Windows/SettingsInSettingsWindow.cs b/T3/Gui/Windows/SettingsInSettingsWindow.cs new file mode 100644 index 0000000000..b36d8ff9ac --- /dev/null +++ b/T3/Gui/Windows/SettingsInSettingsWindow.cs @@ -0,0 +1,135 @@ +using System; +using ImGuiNET; +using T3.Gui.UiHelpers; + +namespace T3.Gui.Windows +{ + public partial class SettingsWindow + { + class UIControlledSetting + { + public string label; + public string tooltip; + public Func imguiFunc; + public Action OnValueChanged; + } + + static readonly UIControlledSetting[] userInterfaceSettings = new UIControlledSetting[] + { + new UIControlledSetting() + { + label = "UI Scale", + imguiFunc = () => ImGui.DragFloat("##UiScaleFactor", ref UserSettings.Config.UiScaleFactor, 0.01f, 0.5f, 3f) + }, + + new UIControlledSetting() + { + label = "Warn before Lib modifications", + imguiFunc = () => ImGui.Checkbox("##WarnBeforeLibEdit", ref UserSettings.Config.WarnBeforeLibEdit) + }, + + new UIControlledSetting() + { + label = "Use arc connections", + imguiFunc = () => ImGui.Checkbox("##UseArcConnections", ref UserSettings.Config.UseArcConnections) + }, + + new UIControlledSetting() + { + label = "Use Jog Dial Control", + imguiFunc = () => ImGui.Checkbox("##UseJogDialControl", ref UserSettings.Config.UseJogDialControl) + }, + + new UIControlledSetting() + { + label = "Scroll smoothing", + imguiFunc = () => ImGui.DragFloat("##ScrollSmoothing", ref UserSettings.Config.ScrollSmoothing) + }, + + new UIControlledSetting() + { + label = "Show Graph thumbnails", + imguiFunc = () => ImGui.Checkbox("##ShowThumbnails", ref UserSettings.Config.ShowThumbnails) + }, + + new UIControlledSetting() + { + label = "Drag snapped nodes", + imguiFunc = () => ImGui.Checkbox("##SmartGroupDragging", ref UserSettings.Config.SmartGroupDragging) + }, + + new UIControlledSetting() + { + label = "Snap strength", + imguiFunc = () => ImGui.DragFloat("##SnapStrength", ref UserSettings.Config.SnapStrength) + }, + + new UIControlledSetting() + { + label = "Click threshold", + imguiFunc = () => ImGui.DragFloat("##ClickThreshold", ref UserSettings.Config.ClickThreshold) + }, + + new UIControlledSetting() + { + label = "Timeline Raster Density", + imguiFunc = () => ImGui.DragFloat("##TimeRasterDensity", ref UserSettings.Config.TimeRasterDensity, 0.01f) + }, + + new UIControlledSetting() + { + label = "Fullscreen Window Swap", + tooltip = "Swap main and second windows when fullscreen", + imguiFunc = () => ImGui.Checkbox("##SwapMainAnd2ndWindowsWhenFullscreen", ref UserSettings.Config.SwapMainAnd2ndWindowsWhenFullscreen) + }, + }; + + static readonly UIControlledSetting[] spaceMouseSettings = new UIControlledSetting[] + { + new UIControlledSetting() + { + label = "Smoothing", + imguiFunc = () => ImGui.DragFloat("##SpaceMouseDamping", ref UserSettings.Config.SpaceMouseDamping, 0.01f, 0.01f, 1f) + }, + + new UIControlledSetting() + { + label = "Move Speed", + imguiFunc = () => ImGui.DragFloat("##SpaceMouseMoveSpeedFactor", ref UserSettings.Config.SpaceMouseMoveSpeedFactor, 0.01f, 0, 10f) + }, + + new UIControlledSetting() + { + label = "Rotation Speed", + imguiFunc = () => ImGui.DragFloat("##SpaceMouseRotationSpeedFactor", ref UserSettings.Config.SpaceMouseRotationSpeedFactor, 0.01f, 0, 10f) + } + }; + + static readonly UIControlledSetting[] additionalSettings = new UIControlledSetting[] + { + new UIControlledSetting() + { + label = "Gizmo size", + imguiFunc = () => ImGui.DragFloat("##GizmoSize", ref UserSettings.Config.GizmoSize) + }, + + new UIControlledSetting() + { + label = "Tooltip delay", + imguiFunc = () => ImGui.DragFloat("##TooltipDelay", ref UserSettings.Config.TooltipDelay) + }, + + //new SettingInfo() + //{ + // label = "Show Title", + // imguiFunc = () => ImGui.Checkbox("##ShowTitleAndDescription", ref UserSettings.Config.ShowTitleAndDescription) + //}, + + //new SettingInfo() + //{ + // label = "Show Timeline", + // imguiFunc = () => ImGui.Checkbox("##ShowTimeline", ref UserSettings.Config.ShowTimeline) + //} + }; + } +} \ No newline at end of file diff --git a/T3/Gui/Windows/SettingsWindow.cs b/T3/Gui/Windows/SettingsWindow.cs index b61e205435..c23168e945 100644 --- a/T3/Gui/Windows/SettingsWindow.cs +++ b/T3/Gui/Windows/SettingsWindow.cs @@ -1,13 +1,16 @@ -using System.Collections.Generic; +using System.Collections.Generic; +using System.Threading.Channels; +using System.Windows.Forms; using ImGuiNET; using T3.Gui.Commands; using T3.Gui.Graph; using T3.Gui.TypeColors; using T3.Gui.UiHelpers; +using System.Numerics; namespace T3.Gui.Windows { - public class SettingsWindow : Window + public partial class SettingsWindow : Window { public SettingsWindow() { @@ -22,46 +25,23 @@ public SettingsWindow() protected override void DrawContent() { var changed = false; + ImGui.NewLine(); if (ImGui.TreeNode("User Interface")) { - if (ImGui.DragFloat("UI Scale", ref UserSettings.Config.UiScaleFactor, 0.01f, 0.5f, 3f)) - { - changed = true; - } - changed |= ImGui.Checkbox("Warn before Lib modifications", ref UserSettings.Config.WarnBeforeLibEdit); - changed |= ImGui.Checkbox("Use arc connections", ref UserSettings.Config.UseArcConnections); - changed |= ImGui.Checkbox("Use Jog Dial Control", ref UserSettings.Config.UseJogDialControl); - changed |= ImGui.DragFloat("Scroll smoothing", ref UserSettings.Config.ScrollSmoothing); - changed |= ImGui.Checkbox("Show Graph thumbnails", ref UserSettings.Config.ShowThumbnails); - changed |= ImGui.Checkbox("Drag snapped nodes", ref UserSettings.Config.SmartGroupDragging); - ImGui.Separator(); - changed |= ImGui.DragFloat("Snap strength", ref UserSettings.Config.SnapStrength); - changed |= ImGui.DragFloat("Click threshold", ref UserSettings.Config.ClickThreshold); - changed |= ImGui.DragFloat("Keyboard scroll speed", ref UserSettings.Config.KeyboardScrollAcceleration); - - changed |= ImGui.DragFloat("Timeline Raster Density", ref UserSettings.Config.TimeRasterDensity, 0.01f); - - changed |= ImGui.Checkbox("Swap Main & 2nd windows when fullscreen", ref UserSettings.Config.SwapMainAnd2ndWindowsWhenFullscreen); - - + changed |= DrawSettingsTable("##UserInterfaceTable", userInterfaceSettings); ImGui.TreePop(); } if (ImGui.TreeNode("Space Mouse")) { - changed |= ImGui.DragFloat("Smoothing", ref UserSettings.Config.SpaceMouseDamping, 0.01f, 0.01f, 1f); - changed |= ImGui.DragFloat("Move Speed", ref UserSettings.Config.SpaceMouseMoveSpeedFactor, 0.01f, 0, 10f); - changed |= ImGui.DragFloat("Rotation Speed", ref UserSettings.Config.SpaceMouseRotationSpeedFactor, 0.01f, 0, 10f); + changed |= DrawSettingsTable("##SpaceMouseTable", spaceMouseSettings); ImGui.TreePop(); } if (ImGui.TreeNode("Additional settings")) { - //ImGui.Checkbox("Show Timeline", ref UserSettings.Config.ShowTimeline); - //ImGui.Checkbox("Show Title", ref UserSettings.Config.ShowTitleAndDescription); - changed |= ImGui.DragFloat("Gizmo size", ref UserSettings.Config.GizmoSize); - changed |= ImGui.DragFloat("Tooltip delay", ref UserSettings.Config.TooltipDelay); + changed |= DrawSettingsTable("##AdditionalSettings", additionalSettings); ImGui.TreePop(); } @@ -145,5 +125,45 @@ public override List GetInstances() { return new List(); } + + bool DrawSettingsTable(string tableID, UIControlledSetting[] settings) + { + ImGui.NewLine(); + bool changed = false; + if (ImGui.BeginTable(tableID, 2, ImGuiTableFlags.BordersInnerH | ImGuiTableFlags.SizingFixedSame | ImGuiTableFlags.PadOuterX)) + { + foreach (UIControlledSetting setting in settings) + { + ImGui.TableNextRow(); + ImGui.TableNextColumn(); + ImGui.Indent(); + ImGui.Text(setting.label); + ImGui.Unindent(); + + if (!string.IsNullOrEmpty(setting.tooltip)) + { + if (ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled)) + { + ImGui.SetTooltip(setting.tooltip); + } + } + + ImGui.TableNextColumn(); + + bool valueChanged = setting.imguiFunc.Invoke(); + if(valueChanged && setting.OnValueChanged != null) + { + setting.OnValueChanged.Invoke(); + } + + changed |= valueChanged; + } + } + + ImGui.EndTable(); + ImGui.NewLine(); + + return changed; + } } } \ No newline at end of file