-
Notifications
You must be signed in to change notification settings - Fork 324
PoC for device flag clarity #2039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,136 @@ | ||||||
using UnityEditor; | ||||||
using UnityEditor.IMGUI.Controls; | ||||||
|
||||||
#if UNITY_EDITOR | ||||||
|
||||||
namespace UnityEngine.InputSystem.Editor | ||||||
{ | ||||||
public class DeviceFlagsTreeView : TreeView | ||||||
{ | ||||||
private InputDevice m_Device; | ||||||
|
||||||
private enum ColumnId | ||||||
{ | ||||||
Name, | ||||||
Value, | ||||||
COUNT | ||||||
} | ||||||
|
||||||
public static DeviceFlagsTreeView Create(InputDevice device, ref TreeViewState treeState, ref MultiColumnHeaderState headerState) | ||||||
{ | ||||||
if (treeState == null) | ||||||
treeState = new TreeViewState(); | ||||||
|
||||||
var newHeaderState = CreateHeaderState(); | ||||||
if (headerState != null) | ||||||
MultiColumnHeaderState.OverwriteSerializedFields(headerState, newHeaderState); | ||||||
headerState = newHeaderState; | ||||||
|
||||||
var header = new MultiColumnHeader(headerState); | ||||||
return new DeviceFlagsTreeView(treeState, header, device); | ||||||
} | ||||||
|
||||||
private static MultiColumnHeaderState CreateHeaderState() | ||||||
{ | ||||||
var columns = new MultiColumnHeaderState.Column[(int)ColumnId.COUNT]; | ||||||
|
||||||
columns[(int)ColumnId.Name] = new MultiColumnHeaderState.Column() | ||||||
{ | ||||||
width = 320, | ||||||
minWidth = 60, | ||||||
headerContent = new GUIContent("Name"), | ||||||
canSort = false | ||||||
}; | ||||||
columns[(int)ColumnId.Value] = new MultiColumnHeaderState.Column() | ||||||
{ | ||||||
width = 80, | ||||||
minWidth = 60, | ||||||
headerContent = new GUIContent("Value"), | ||||||
canSort = false | ||||||
}; | ||||||
|
||||||
return new MultiColumnHeaderState(columns); | ||||||
} | ||||||
|
||||||
private DeviceFlagsTreeView(TreeViewState state, MultiColumnHeader multiColumnHeader, InputDevice device) | ||||||
: base(state, multiColumnHeader) | ||||||
{ | ||||||
m_Device = device; | ||||||
Reload(); | ||||||
} | ||||||
|
||||||
private void AddFlag(TreeViewItem root, InputDevice.DeviceFlags flag) | ||||||
{ | ||||||
root.AddChild(new FlagItem() | ||||||
{ | ||||||
id = 1, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each FlagItem is assigned the same id, which may result in duplicate IDs in the tree view. Consider generating unique ids for each flag, for example by hashing the flag value or using an incremental counter.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
depth = 1, | ||||||
displayName = "", | ||||||
Flag = flag | ||||||
}); | ||||||
} | ||||||
|
||||||
protected override TreeViewItem BuildRoot() | ||||||
{ | ||||||
var root = new TreeViewItem { id = 0, depth = -1, displayName = "Root" }; | ||||||
|
||||||
AddFlag(root, InputDevice.DeviceFlags.Native); | ||||||
AddFlag(root, InputDevice.DeviceFlags.Remote); | ||||||
|
||||||
AddFlag(root, InputDevice.DeviceFlags.CanRunInBackground); | ||||||
AddFlag(root, InputDevice.DeviceFlags.CanRunInBackgroundHasBeenQueried); | ||||||
|
||||||
AddFlag(root, InputDevice.DeviceFlags.UpdateBeforeRender); | ||||||
AddFlag(root, InputDevice.DeviceFlags.HasStateCallbacks); | ||||||
AddFlag(root, InputDevice.DeviceFlags.HasControlsWithDefaultState); | ||||||
AddFlag(root, InputDevice.DeviceFlags.HasDontResetControls); | ||||||
AddFlag(root, InputDevice.DeviceFlags.HasEventMerger); | ||||||
AddFlag(root, InputDevice.DeviceFlags.HasEventPreProcessor); | ||||||
|
||||||
AddFlag(root, InputDevice.DeviceFlags.DisabledInFrontend); | ||||||
AddFlag(root, InputDevice.DeviceFlags.DisabledInRuntime); | ||||||
AddFlag(root, InputDevice.DeviceFlags.DisabledWhileInBackground); | ||||||
AddFlag(root, InputDevice.DeviceFlags.DisabledStateHasBeenQueriedFromRuntime); | ||||||
|
||||||
return root; | ||||||
} | ||||||
|
||||||
protected override void RowGUI(RowGUIArgs args) | ||||||
{ | ||||||
var columnCount = args.GetNumVisibleColumns(); | ||||||
for (var i = 0; i < columnCount; ++i) | ||||||
{ | ||||||
var item = (FlagItem)args.item; | ||||||
ColumnGUI(args.GetCellRect(i), item.Flag, args.GetColumn(i)); | ||||||
} | ||||||
} | ||||||
|
||||||
private unsafe void ColumnGUI(Rect cellRect, InputDevice.DeviceFlags flag, int column) | ||||||
{ | ||||||
CenterRectUsingSingleLineHeight(ref cellRect); | ||||||
|
||||||
switch (column) | ||||||
{ | ||||||
case (int)ColumnId.Name: | ||||||
GUI.Label(cellRect, flag.ToString()); | ||||||
break; | ||||||
case (int)ColumnId.Value: | ||||||
{ | ||||||
var isSet = ((m_Device.m_DeviceFlags & flag) != 0); | ||||||
if (isSet) | ||||||
GUI.Label(cellRect, "true", EditorStyles.boldLabel); | ||||||
else | ||||||
GUI.Label(cellRect, "false"); | ||||||
} | ||||||
break; | ||||||
} | ||||||
} | ||||||
|
||||||
private class FlagItem : TreeViewItem | ||||||
{ | ||||||
public InputDevice.DeviceFlags Flag; | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
#endif // UNITY_EDITOR |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Typo found in the label text "DisabledWWhileInBackground". It should likely be corrected to "DisabledWhileInBackground".
Copilot uses AI. Check for mistakes.