Skip to content

Commit

Permalink
table scheme, streamlined settings addition
Browse files Browse the repository at this point in the history
  • Loading branch information
domportera committed Oct 7, 2022
1 parent c22224c commit db28e4c
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 29 deletions.
135 changes: 135 additions & 0 deletions T3/Gui/Windows/SettingsInSettingsWindow.cs
Original file line number Diff line number Diff line change
@@ -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<bool> 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)
//}
};
}
}
78 changes: 49 additions & 29 deletions T3/Gui/Windows/SettingsWindow.cs
Original file line number Diff line number Diff line change
@@ -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()
{
Expand All @@ -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();
}

Expand Down Expand Up @@ -145,5 +125,45 @@ public override List<Window> GetInstances()
{
return new List<Window>();
}

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;
}
}
}

0 comments on commit db28e4c

Please sign in to comment.