浏览代码

update inspector window

/zxw-devTools
guanghuispark 3 年前
当前提交
cf9944aa
共有 13 个文件被更改,包括 1217 次插入101 次删除
  1. 7
      com.unity.uiwidgets.devtools/Editor/v2/main.cs
  2. 21
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/diagnostics_node.cs
  3. 243
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_controller.cs
  4. 112
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_screen.cs
  5. 305
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_service.cs
  6. 141
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree.cs
  7. 197
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree_flutter.cs
  8. 1
      com.unity.uiwidgets.devtools/Editor/v2/src/theme.cs
  9. 13
      com.unity.uiwidgets/Runtime/widgets/ticker_provider.cs
  10. 10
      com.unity.uiwidgets.devtools/Editor/v2/src/ui/colors.cs
  11. 187
      com.unity.uiwidgets.devtools/Editor/v2/src/ui/icons.cs
  12. 81
      com.unity.uiwidgets.devtools/Editor/v2/src/ui/label.cs

7
com.unity.uiwidgets.devtools/Editor/v2/main.cs


using System.Collections.Generic;
using Unity.UIWidgets.DevTools.config_specific.framework_initialize;
using Unity.UIWidgets.Editor;
using Unity.UIWidgets.widgets;

{
CreateWindow<EditorWindowDevtools>();
}
protected override void onEnable()
{
AddFont("Material Icons", new List<string> {"MaterialIcons-Regular.ttf"}, new List<int> {0});
}
protected override void main()
{
var preferences = new PreferencesController();

21
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/diagnostics_node.cs


using System.Linq;
using NUnit.Framework;
using Unity.UIWidgets.async;
using Unity.UIWidgets.DevTools.ui;
using Unity.UIWidgets.widgets;
class RemoteDiagnosticsNode : DiagnosticableTree {
public class RemoteDiagnosticsNode : DiagnosticableTree {
public RemoteDiagnosticsNode(
Dictionary<string, object> json,
FutureOr inspectorService,

this.json = json;
this.inspectorService = inspectorService;
this.isProperty = isProperty;
this.parent = parent;
}
RemoteDiagnosticsNode parent;

public readonly Dictionary<string, object> json;
List<RemoteDiagnosticsNode> _children;
static readonly CustomIconMaker iconMaker = new CustomIconMaker();
// Future<Dictionary<string, InstanceRef>> _valueProperties;

}
string name
public string name
{
get
{

public string type => getStringMember("type");
public string widgetRuntimeType => getStringMember("widgetRuntimeType");
string getStringMember(string memberName) {
return JsonUtils.getStringMember(json, memberName);

return json.ContainsKey("children") || _children != null || !hasChildren;
}
}
public Widget icon {
get
{
if (isProperty) return null;
return iconMaker.fromWidgetName(widgetRuntimeType);
}
}
InspectorSourceLocation _creationLocation;

243
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_controller.cs


using System;
using System.Text.RegularExpressions;
using Unity.UIWidgets.async;
using UnityEngine;
namespace Unity.UIWidgets.DevTools.inspector
{

// @required this.inspectorService,
InspectorService inspectorService,
// @required this.treeType,
FlutterTreeType treeType= FlutterTreeType.widget,
InspectorController parent = null,
bool isSummaryTree = true,
VoidCallback onExpandCollapseSupported = null,

this.inspectorService = inspectorService;
_treeGroups = new InspectorObjectGroupManager(inspectorService, "tree");
// _selectionGroups =
// new InspectorObjectGroupManager(inspectorService, "selection");
// _refreshRateLimiter = RateLimiter(refreshFramesPerSecond, refresh);
// _refreshRateLimiter = RateLimiter(refreshFramesPerSecond, refresh);
//
// D.assert(inspectorTree != null);
inspectorTree.config = new InspectorTreeConfig(
summaryTree: isSummaryTree,
treeType: treeType,
// onNodeAdded: _onNodeAdded,
// onHover: highlightShowNode,
// onSelectionChange: selectionChanged,
// onExpand: _onExpand,
onClientActiveChange: _onClientChange
);
if (isSummaryTree) {
details = new InspectorController(
inspectorService: inspectorService,
inspectorTree: detailsTree,
treeType: treeType,
parent: this,
isSummaryTree: false
);
} else {
details = null;
}
// flutterIsolateSubscription = serviceManager.isolateManager
// .getSelectedIsolate((IsolateRef flutterIsolate) => {
// // Any time we have a new isolate it means the previous isolate stopped.
// onIsolateStopped();
// });
//
// _checkForExpandCollapseSupport();
// _checkForLayoutExplorerSupport();
//
// // This logic only needs to be run once so run it in the outermost
// // controller.
// if (parent == null) {
// // If select mode is available, enable the on device inspector as it
// // won't interfere with users.
// addAutoDisposeListener(_supportsToggleSelectWidgetMode, () => {
// if (_supportsToggleSelectWidgetMode.value) {
// serviceManager.serviceExtensionManager.setServiceExtensionState(
// extensions.enableOnDeviceInspector.extension,
// true,
// true
// );
// }
// });
// }
InspectorObjectGroupManager _treeGroups;
InspectorController details;
// public readonly FlutterTreeType treeType;
public readonly FlutterTreeType treeType;
// public readonly InspectorService inspectorService;
public readonly InspectorService inspectorService;
int _clientCount = 0;
public readonly bool isSummaryTree;

bool isActive = false;
bool visibleToUser = true;
bool flutterAppFrameReady = false;
bool detailsSubtree => parent != null;
void setVisibleToUser(bool visible) {
if (visibleToUser == visible) {
return;
}
visibleToUser = visible;
details?.setVisibleToUser(visible);
if (visibleToUser) {
if (parent == null) {
maybeLoadUI();
}
} else {
shutdownTree(false);
}
}
void _onClientChange(bool added) {
_clientCount += added ? 1 : -1;
D.assert(_clientCount >= 0);
if (_clientCount == 1) {
setVisibleToUser(true);
setActivate(true);
} else if (_clientCount == 0) {
setVisibleToUser(false);
}
}
Future recomputeTreeRoot(
RemoteDiagnosticsNode newSelection,
RemoteDiagnosticsNode detailsSelection,
bool setSubtreeRoot,
int subtreeDepth = 2
)
{
D.assert(!_disposed);
if (_disposed)
{
return new SynchronousFuture(null);
}
_treeGroups.cancelNext();
try
{
// var group = _treeGroups.next;
var group = new ObjectGroup("inspector",inspectorService);
// var node = detailsSubtree
// ? group.getDetailsSubtree(subtreeRoot, subtreeDepth: subtreeDepth)
// : group.getRoot(treeType);
// RemoteDiagnosticsNode node = null;
// group.getRoot(treeType).then_<RemoteDiagnosticsNode>((v) =>
// {
// node = v;
// if (node == null || group.disposed) {
// return new SynchronousFuture(null);
// }
// _treeGroups.promoteNext();
// // clearValueToInspectorTreeNodeMapping();
// if (node != null) {
// InspectorTreeNode rootNode = inspectorTree.setupInspectorTreeNode(
// node:inspectorTree.createNode(),
// diagnosticsNode: node,
// expandChildren: true,
// expandProperties: false
// );
// inspectorTree.root = rootNode;
// } else {
// inspectorTree.root = inspectorTree.createNode();
// }
// return FutureOr.nil;
// });
RemoteDiagnosticsNode node = group._getRoot(treeType);
if (node == null || group.disposed) {
return new SynchronousFuture(null);
}
_treeGroups.promoteNext();
// clearValueToInspectorTreeNodeMapping();
if (node != null) {
InspectorTreeNode rootNode = inspectorTree.setupInspectorTreeNode(
node:inspectorTree.createNode(),
diagnosticsNode: node,
expandChildren: true,
expandProperties: false
);
inspectorTree.root = rootNode;
} else {
inspectorTree.root = inspectorTree.createNode();
}
// refreshSelection(newSelection, detailsSelection, setSubtreeRoot);
} catch (Exception e) {
Debug.Log(e);
_treeGroups.cancelNext();
return new SynchronousFuture(null);
}
return new SynchronousFuture(null);
}
public Future onForceRefresh() {
D.assert(!_disposed);
if (!visibleToUser || _disposed) {
return Future.value();
}
recomputeTreeRoot(null, null, false);
return Future.value();
// return getPendingUpdateDone();
}
void setActivate(bool enabled) {
if (!enabled) {
// onIsolateStopped();
isActive = false;
return;
}
if (isActive) {
return;
}
isActive = true;
// inspectorService.addClient(this);
maybeLoadUI();
}
void maybeLoadUI() {
if (!visibleToUser || !isActive) {
return;
}
if (flutterAppFrameReady) {
inspectorService.inferPubRootDirectoryIfNeeded();
// updateSelectionFromService(firstFrame: true);
} else {
// var ready = inspectorService.isWidgetTreeReady();
bool ready = true;
flutterAppFrameReady = ready;
if (isActive && ready) {
maybeLoadUI();
}
}
}
void shutdownTree(bool isolateStopped) {
// programaticSelectionChangeInProgress = true;
// _treeGroups?.clear(isolateStopped);
// _selectionGroups?.clear(isolateStopped);
//
// currentShowNode = null;
// selectedNode = null;
// lastExpanded = null;
//
// selectedNode = null;
// subtreeRoot = null;
//
// inspectorTree?.root = inspectorTree?.createNode();
// details?.shutdownTree(isolateStopped);
// programaticSelectionChangeInProgress = false;
// valueToInspectorTreeNode?.clear();
}
// public override void dispose() {
// D.assert(!_disposed);
// _disposed = true;

112
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_screen.cs


using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Unity.UIWidgets.DevTools.ui;
using Unity.UIWidgets.ui;
class InspectorScreen : Screen {
class InspectorScreen : Screen
{
"inspector",
title: "Flutter Inspector",
icon: Octicons.deviceMobile
)
"inspector",
title: "Flutter Inspector",
icon: Octicons.deviceMobile
)
public override Widget build(BuildContext context)
{
// var isFlutterApp = serviceManager.connectedApp.isFlutterAppNow;

// }
return new InspectorScreenBody();
}
public class InspectorScreenBody : StatefulWidget {
public InspectorScreenBody(){}
public class InspectorScreenBody : StatefulWidget
{
public InspectorScreenBody()
{
}
public override State createState()
{

{
bool _layoutExplorerSupported = false;
bool _expandCollapseSupported = false;
bool connectionInProgress = false;
InspectorService inspectorService;
public override void initState() {
public override void initState()
{
void _onExpandCollapseSupported() {
setState(() => {
_expandCollapseSupported = true;
});
void _onExpandCollapseSupported()
{
setState(() => { _expandCollapseSupported = true; });
void _onLayoutExplorerSupported() {
setState(() => {
_layoutExplorerSupported = true;
});
void _onLayoutExplorerSupported()
{
setState(() => { _layoutExplorerSupported = true; });
setState(() => {
setState(() => { connectionInProgress = true; });
try
{
// Init the inspector service, or return null.
// ensureInspectorDependencies();
// ensureInspectorServiceDependencies();
inspectorService = new InspectorService();
// InspectorService.create(service).catchError((e) => null);
}
finally
{
setState(() => { connectionInProgress = false; });
}
if (inspectorService == null)
{
return;
}
setState(() =>
{
// inspectorController?.dispose();
summaryTreeController = new InspectorTreeControllerFlutter();
detailsTreeController = new InspectorTreeControllerFlutter();

// inspectorService: inspectorService,
// treeType: FlutterTreeType.widget,
inspectorService: inspectorService,
treeType: FlutterTreeType.widget,
_refreshInspector();
void _refreshInspector()
{
inspectorController?.onForceRefresh();
}
public override Widget build(BuildContext context)
{

return new Column(
children: new List<Widget>
{
new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: new List<Widget>
{
new SizedBox(width: ThemeUtils.denseSpacing),
new Container(
height: Theme.of(context).buttonTheme.height,
child: new OutlineButton(
onPressed: _refreshInspector,
child: new MaterialIconLabel(
Icons.refresh,
"Refresh Tree",
includeTextWidth: 750
)
)
),
new Spacer()
}),
new SizedBox(height: ThemeUtils.denseRowSpacing),
initialFractions: new List<float?>{0.33f, 0.67f},
initialFractions: new List<float?> {0.33f, 0.67f},
children: new List<Widget>
{
summaryTree,

)
}
);
}
}
}
}
}

305
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_service.cs


using System;
using System.Collections.Generic;
using System.ComponentModel;
using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.widgets;
// public class ObjectGroup
// {
// public ObjectGroup(
// string debugName,
// InspectorService inspectorService
// )
// {
// groupName = $"{debugName}_${InspectorService.nextGroupId}";
// InspectorService.nextGroupId++;
// }
//
// /// Object group all objects in this arena are allocated with.
// public readonly string groupName;
// public readonly InspectorService inspectorService;
// bool disposed = false;
// }
public enum FlutterTreeType {
widget,
renderObject
}
public class ObjectGroup
{
public ObjectGroup(
string debugName,
InspectorService inspectorService
)
{
groupName = $"{debugName}_${InspectorService.nextGroupId}";
InspectorService.nextGroupId++;
}
/// Object group all objects in this arena are allocated with.
public readonly string groupName;
public readonly InspectorService inspectorService;
public bool disposed = false;
public Future dispose() {
// var disposeComplete = invokeVoidServiceMethod("disposeGroup", groupName);
// disposed = true;
// return disposeComplete;
return new SynchronousFuture(null);
}
public Future<RemoteDiagnosticsNode> getRoot(FlutterTreeType type) {
// There is no excuse to call this method on a disposed group.
D.assert(!disposed);
switch (type) {
case FlutterTreeType.widget:
return getRootWidget();
case FlutterTreeType.renderObject:
return getRootRenderObject();
}
throw new Exception("Unexpected FlutterTreeType");
}
public RemoteDiagnosticsNode _getRoot(FlutterTreeType type) {
// There is no excuse to call this method on a disposed group.
D.assert(!disposed);
switch (type) {
case FlutterTreeType.widget:
return _getRootWidget();
case FlutterTreeType.renderObject:
return null;
}
throw new Exception("Unexpected FlutterTreeType");
}
RemoteDiagnosticsNode _getRootWidget() {
// return invokeServiceMethodReturningNode('getRootWidgetSummaryTree');
Dictionary<string, object> widgetTree = new Dictionary<string, object>();
widgetTree["hasChildren"] = true;
widgetTree["name"] = "inspector";
widgetTree["children"] = new List<Widget>()
{
new Text("text1"),
new Text("text2"),
new Text("text3"),
new Text("text4"),
new Text("text5"),
};
widgetTree["properties"] = new List<object>()
{
"properties_1",
"properties_2",
"properties_3",
"properties_4",
"properties_5",
};
return new RemoteDiagnosticsNode(widgetTree,
inspectorService: FutureOr.value(inspectorService),
true,
null);
}
Future<RemoteDiagnosticsNode> getRootWidget() {
// return invokeServiceMethodReturningNode('getRootWidgetSummaryTree');
Dictionary<string, object> widgetTree = new Dictionary<string, object>();
widgetTree["children"] = new List<Widget>()
{
new Text("text1"),
new Text("text2"),
new Text("text3"),
new Text("text4"),
new Text("text5"),
};
widgetTree["properties"] = new List<object>()
{
"properties_1",
"properties_2",
"properties_3",
"properties_4",
"properties_5",
};
return Future.value(FutureOr.value(new RemoteDiagnosticsNode(widgetTree,
inspectorService: FutureOr.value(inspectorService),
true,
null))).to<RemoteDiagnosticsNode>();
}
Future<RemoteDiagnosticsNode> getRootRenderObject()
{
return Future.value(FutureOr.value(null)).to<RemoteDiagnosticsNode>();
}
public Future<RemoteDiagnosticsNode> getDetailsSubtree(
RemoteDiagnosticsNode node,
int subtreeDepth = 2
) {
if (node == null) return null;
// var args = new Dictionary<string,object>(){
// {"objectGroup", groupName},
// {"arg", node.dartDiagnosticRef.id},
// {"subtreeDepth", subtreeDepth.ToString()},
// };
// return parseDiagnosticsNodeDaemon(invokeServiceMethodDaemonParams(
// "getDetailsSubtree",
// args
// ));
return Future.value(FutureOr.value("enpty")).to<RemoteDiagnosticsNode>();
}
}
class InspectorObjectGroupManager {
public InspectorObjectGroupManager(
InspectorService inspectorService,
string debugName)
{
this.inspectorService = inspectorService;
this.debugName = debugName;
}
public InspectorService inspectorService;
public string debugName;
ObjectGroup _current;
ObjectGroup _next;
Completer _pendingNext;
// Future<void> pendingUpdateDone {
// if (_pendingNext != null) {
// return _pendingNext.future;
// }
// if (_next == null) {
// // There is no pending update.
// return Future.value();
// }
//
// _pendingNext = Completer();
// return _pendingNext.future;
// }
//
public ObjectGroup current {
get
{
// _current ??= inspectorService.createObjectGroup(debugName);
return _current;
}
}
public ObjectGroup next {
get
{
// _next ??= inspectorService.createObjectGroup(debugName);
return _next;
}
}
//
// void clear(bool isolateStopped) {
// if (isolateStopped) {
// // The Dart VM will handle GCing the underlying memory.
// _current = null;
// _setNextNull();
// } else {
// clearCurrent();
// cancelNext();
// }
// }
public void promoteNext() {
clearCurrent();
_current = _next;
_setNextNull();
}
void clearCurrent() {
if (_current != null) {
_current.dispose();
_current = null;
}
}
public void cancelNext() {
if (_next != null) {
_next.dispose();
_setNextNull();
}
}
void _setNextNull() {
_next = null;
if (_pendingNext != null) {
_pendingNext.complete();
_pendingNext = null;
}
}
}
public class InspectorService
{
public static int nextGroupId = 0;
public Future<string> inferPubRootDirectoryIfNeeded()
{
var group = createObjectGroup("temp");
var root = group.getRoot(FlutterTreeType.widget);
return Future.value("aaa").to<string>();
}
ObjectGroup createObjectGroup(string debugName) {
return new ObjectGroup(debugName, this);
}
// static Future<InspectorService> create(VmService vmService) async {
// assert(_inspectorDependenciesLoaded);
// assert(serviceManager.hasConnection);
// assert(serviceManager.service != null);
// final inspectorLibrary = EvalOnDartLibrary(
// inspectorLibraryUriCandidates,
// vmService,
// );
//
// final libraryRef = await inspectorLibrary.libraryRef.catchError(
// (_) => throw FlutterInspectorLibraryNotFound(),
// test: (e) => e is LibraryNotFound,
// );
// final libraryFuture = inspectorLibrary.getLibrary(libraryRef, null);
// final library = await libraryFuture;
// Future<Set<String>> lookupFunctionNames() async {
// for (ClassRef classRef in library.classes) {
// if ('WidgetInspectorService' == classRef.name) {
// final classObj = await inspectorLibrary.getClass(classRef, null);
// final functionNames = <String>{};
// for (FuncRef funcRef in classObj.functions) {
// functionNames.add(funcRef.name);
// }
// return functionNames;
// }
// }
// // WidgetInspectorService is not available. Either this is not a Flutter
// // application or it is running in profile mode.
// return null;
// }
//
// final supportedServiceMethods = await lookupFunctionNames();
// if (supportedServiceMethods == null) return null;
// return InspectorService(
// vmService,
// inspectorLibrary,
// supportedServiceMethods,
// );
// }
//
}
}

141
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree.cs


using System.Collections.Generic;
using System.Linq;
using uiwidgets;
using Unity.UIWidgets.async;
using Unity.UIWidgets.DevTools.inspector;
using UnityEditor.Graphs;
using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.DevTools.inspector
{

public static readonly float columnWidth = 16.0f;
public static readonly float verticalPadding = 10.0f;
public static readonly float rowHeight = 24.0f;
public static bool isLight = false;
public static Color selectedRowBackgroundColor
{
get
{
return isLight
? Color.fromARGB(255, 202, 191, 69)
: Color.fromARGB(255, 99, 101, 103);
}
}
public static Color hoverColor
{
get
{
return isLight ? Colors.yellowAccent : Color.fromARGB(255, 70, 73, 76);
}
}
abstract class InspectorTreeController
abstract class InspectorTreeController
{
public abstract void setState(VoidCallback fn);
public abstract InspectorTreeNode createNode();

InspectorTreeNode _root;
// InspectorTreeConfig config
// {
// get
// {
// return _config;
// }
// }
//
// InspectorTreeConfig _config;
bool _disposed = false;
InspectorObjectGroupManager _treeGroups;
public InspectorTreeConfig config
{
get
{
return _config;
}
set
{
_config = value;
}
}
InspectorTreeConfig _config;
public InspectorTreeNode hover => _hover;
InspectorTreeNode _hover;
public InspectorTreeRow getCachedRow(int index) {
Debug.Log("getCachedRow");

// }
// cachedRows[index] ??= root.getRow(index);
// return cachedRows[index];
return null;
return new InspectorTreeRow();
}
float horizontalPadding

}
public float getDepthIndent(int? depth) {
return (depth.Value + 1) * InspectorTreeUtils.columnWidth + horizontalPadding;
return ((depth??0) + 1) * InspectorTreeUtils.columnWidth + horizontalPadding;
}
void removeNodeFromParent(InspectorTreeNode node) {

});
}
InspectorTreeNode setupInspectorTreeNode(
public InspectorTreeNode setupInspectorTreeNode(
InspectorTreeNode node,
RemoteDiagnosticsNode diagnosticsNode,
bool expandChildren = false,

// config.onNodeAdded(node, diagnosticsNode);
// }
if (diagnosticsNode.hasChildren ||
diagnosticsNode.inlineProperties.isNotEmpty()) {
if (diagnosticsNode.childrenReady || !diagnosticsNode.hasChildren) {
bool styleIsMultiline =
expandPropertiesByDefault(diagnosticsNode.style.Value);
setupChildren(
diagnosticsNode,
node,
node.diagnostic.childrenNow,
expandChildren: expandChildren && styleIsMultiline,
expandProperties: expandProperties && styleIsMultiline
);
} else {
node.clearChildren();
node.appendChild(createNode());
}
}
// if (diagnosticsNode.hasChildren ||
// diagnosticsNode.inlineProperties.isNotEmpty()) {
// if (diagnosticsNode.childrenReady || !diagnosticsNode.hasChildren) {
// bool styleIsMultiline =
// expandPropertiesByDefault(diagnosticsNode.style.Value);
// setupChildren(
// diagnosticsNode,
// node,
// node.diagnostic.childrenNow,
// expandChildren: expandChildren && styleIsMultiline,
// expandProperties: expandProperties && styleIsMultiline
// );
// } else {
// node.clearChildren();
// node.appendChild(createNode());
// }
// }
return node;
}

}
}
}
}
public delegate void OnClientActiveChange(bool added);
class InspectorTreeConfig {
public InspectorTreeConfig(
bool summaryTree = false,
FlutterTreeType treeType = FlutterTreeType.widget,
// NodeAddedCallback onNodeAdded,
OnClientActiveChange onClientActiveChange = null,
VoidCallback onSelectionChange = null
// TreeEventCallback onExpand,
// TreeEventCallback onHover
)
{
this.summaryTree = summaryTree;
this.treeType = treeType;
this.onSelectionChange = onSelectionChange;
this.onClientActiveChange = onClientActiveChange;
}
public readonly bool summaryTree;
public readonly FlutterTreeType treeType;
// public readonly NodeAddedCallback onNodeAdded;
public readonly VoidCallback onSelectionChange;
public readonly OnClientActiveChange onClientActiveChange;
// public readonly TreeEventCallback onExpand;
// public readonly TreeEventCallback onHover;
}
class InspectorTreeNode
{
bool showLinesToChildren {

public readonly List<InspectorTreeNode> _children;
public bool selected = false;
RemoteDiagnosticsNode _diagnostic;
bool allowExpandCollapse = true;
bool isProperty
{

isDirty = true;
}
public bool showExpandCollapse {
get
{
return (diagnostic?.hasChildren == true || children.isNotEmpty()) &&
allowExpandCollapse;
}
}
}
class InspectorTreeRow {

public readonly int? index;
public readonly bool? lineToParent;
bool isSelected
public bool isSelected
{
get
{

}
}

197
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree_flutter.cs


using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.DevTools.ui;
using Unity.UIWidgets.rendering;
using UnityEditor.Graphs;
using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
public static class _InspectorTreeRowWidgetUtils
{
public const float rowHeight = 24.0f;
public const float columnWidth = 16.0f;
public const float chartLineStrokeWidth = 1.0f;
public static Paint _defaultPaint(ColorScheme colorScheme)
{
Paint res = new Paint();
res.color = ColorsUtils.treeGuidelineColor;
res.strokeWidth = chartLineStrokeWidth;
return res;
}
}
class _InspectorTreeRowWidget : StatefulWidget {
public _InspectorTreeRowWidget(

}
}
public readonly InspectorTreeRow row;
public override State createState()

}
class _InspectorTreeRowState : State<_InspectorTreeRowWidget>
class _InspectorTreeRowState : TickerProviderStateMixin<_InspectorTreeRowWidget>
// return new SizedBox(
// height: rowHeight,
// child: InspectorRowContent(
// row: widget.row,
// expandArrowAnimation: expandArrowAnimation,
// controller: widget.inspectorTreeState.controller,
// onToggle: () => {
// setExpanded(!isExpanded);
// }
// )
// );
return null;
return new SizedBox(
height: _InspectorTreeRowWidgetUtils.rowHeight,
child: new InspectorRowContent(
row: widget.row,
expandArrowAnimation: expandArrowAnimation,
controller: widget.inspectorTreeState.controller,
onToggle: () => {
// setExpanded(!isExpanded);
}
)
);
}
}

ScrollController _scrollControllerY;
ScrollController _scrollControllerX;
FocusNode _focusNode;
InspectorTreeControllerFlutter controller
public InspectorTreeControllerFlutter controller
{
get
{

(context2, index) =>{
InspectorTreeRow row = controller.root?.getRow(index);
return new _InspectorTreeRowWidget(
key: null,// new PageStorageKey(row?.node),
key: new PageStorageKey<InspectorTreeNode>(row?.node),
inspectorTreeState: this,
row: row
);

)
);
}
}
class InspectorRowContent : StatelessWidget {
public InspectorRowContent(
InspectorTreeRow row = null,
InspectorTreeControllerFlutter controller = null,
VoidCallback onToggle = null,
Animation<float> expandArrowAnimation = null
)
{
this.row = row;
this.controller = controller;
this.onToggle = onToggle;
this.expandArrowAnimation = expandArrowAnimation;
}
public readonly InspectorTreeRow row;
public readonly InspectorTreeControllerFlutter controller;
public readonly VoidCallback onToggle;
public readonly Animation<float> expandArrowAnimation;
public override Widget build(BuildContext context) {
float currentX = controller.getDepthIndent(row.depth) - _InspectorTreeRowWidgetUtils.columnWidth;
var colorScheme = Theme.of(context).colorScheme;
if (row == null) {
return new SizedBox();
}
Color backgroundColor = null;
if (row.isSelected || row.node == controller.hover) {
backgroundColor = row.isSelected
? InspectorTreeUtils.selectedRowBackgroundColor
: InspectorTreeUtils.hoverColor;
}
var node = row.node;
return new CustomPaint(
painter: new _RowPainter(row, controller, colorScheme),
size: new Size(currentX, _InspectorTreeRowWidgetUtils.rowHeight),
child: new Padding(
padding: EdgeInsets.only(left: currentX),
child: new ClipRect(
child: new Row(
mainAxisSize: MainAxisSize.min,
textBaseline: TextBaseline.alphabetic,
children: new List<Widget>{
node.showExpandCollapse
? new SizedBox(child:
new InkWell(
onTap: null,//onToggle,
child: new RotationTransition(
turns: expandArrowAnimation,
child: new Icon(
Icons.expand_more,
size: ThemeUtils.defaultIconSize
)
)
))
: new SizedBox(
width: ThemeUtils.defaultSpacing, height: ThemeUtils.defaultSpacing),
new DecoratedBox(
decoration: new BoxDecoration(
color: backgroundColor
),
child: new InkWell(
onTap: () => {
// controller.onSelectRow(row);
// controller.requestFocus();
},
child: new Container(
height: _InspectorTreeRowWidgetUtils.rowHeight,
padding: EdgeInsets.symmetric(horizontal: 4.0f),
child: new Text(node.ToString())// new DiagnosticsNodeDescription(node.diagnostic)
)
)
),
}
)
)
)
);
}
}
class _RowPainter : AbstractCustomPainter {
public _RowPainter(InspectorTreeRow row, InspectorTreeController controller, ColorScheme colorScheme)
{
this.row = row;
this.controller = controller;
this.colorScheme = colorScheme;
}
public readonly InspectorTreeController controller;
public readonly InspectorTreeRow row;
public readonly ColorScheme colorScheme;
public override void paint(Canvas canvas, Size size) {
float currentX = 0;
var paint = _InspectorTreeRowWidgetUtils._defaultPaint(colorScheme);
if (row == null) {
return;
}
InspectorTreeNode node = row.node;
bool showExpandCollapse = node.showExpandCollapse;
foreach (int tick in row.ticks) {
currentX = controller.getDepthIndent(tick) - _InspectorTreeRowWidgetUtils.columnWidth * 0.5f;
// Draw a vertical line for each tick identifying a connection between
// an ancestor of this node and some other node in the tree.
canvas.drawLine(
new Offset(currentX, 0.0f),
new Offset(currentX, _InspectorTreeRowWidgetUtils.rowHeight),
paint
);
}
// If this row is itself connected to a parent then draw the L shaped line
// to make that connection.
if (row.lineToParent.Value) {
currentX = controller.getDepthIndent(row.depth - 1) - _InspectorTreeRowWidgetUtils.columnWidth * 0.5f;
float width = showExpandCollapse ? _InspectorTreeRowWidgetUtils.columnWidth * 0.5f : _InspectorTreeRowWidgetUtils.columnWidth;
canvas.drawLine(
new Offset(currentX, 0.0f),
new Offset(currentX, _InspectorTreeRowWidgetUtils.rowHeight * 0.5f),
paint
);
canvas.drawLine(
new Offset(currentX, _InspectorTreeRowWidgetUtils.rowHeight * 0.5f),
new Offset(currentX + width, _InspectorTreeRowWidgetUtils.rowHeight * 0.5f),
paint
);
}
}
public override bool shouldRepaint(CustomPainter oldDelegate) {
// if (oldDelegate is _RowPainter) {
// return ((_RowPainter)oldDelegate).colorScheme.isLight != colorScheme.isLight;
// }
return true;
}
}

1
com.unity.uiwidgets.devtools/Editor/v2/src/theme.cs


public const float defaultIconSize = 16.0f;
public const float buttonMinWidth = 36.0f;
public const float denseRowSpacing = 6.0f;
public const float denseSpacing = 8.0f;
public const float defaultSpacing = 16.0f;
public static readonly NeverScrollableScrollPhysics defaultTabBarViewPhysics = new NeverScrollableScrollPhysics();

13
com.unity.uiwidgets/Runtime/widgets/ticker_provider.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.scheduler;

// in AutomaticKeepAliveClientWithTickerProviderStateMixin, remember to keep the copy up to date
public abstract class TickerProviderStateMixin<T> : State<T>, TickerProvider where T : StatefulWidget {
HashSet<Ticker> _tickers;
public Animation<float> expandArrowAnimation;
public override void initState() {
base.initState();
expandArrowAnimation = new CurvedAnimation(curve: Curves.easeInOutCubic, parent: new AnimationController(
duration: new TimeSpan(0,0,0,0,200),
vsync: this,
value: 0.0f
));
}
public Ticker createTicker(TickerCallback onTick) {
_tickers = _tickers ?? new HashSet<Ticker>();

10
com.unity.uiwidgets.devtools/Editor/v2/src/ui/colors.cs


using uiwidgets;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.DevTools.ui
{
public static class ColorsUtils
{
public static Color treeGuidelineColor => Color.fromARGB(255, 200, 200, 200);
}
}

187
com.unity.uiwidgets.devtools/Editor/v2/src/ui/icons.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.DevTools.ui;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEditor;
using Image = Unity.UIWidgets.widgets.Image;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.DevTools.ui
{
public static class IconsUtils
{
public static Image createImageIcon(string url, float size = ThemeUtils.defaultIconSize) {
return new Image(
image: new AssetImage(url),
height: size,
width: size
);
}
}
class CustomIcon : StatelessWidget {
public CustomIcon(
IconKind kind = null,
string text = null,
bool isAbstract = false
)
{
this.kind = kind;
this.text = text;
this.isAbstract = isAbstract;
}
public readonly IconKind kind;
public readonly string text;
public readonly bool isAbstract;
Image baseIcon => kind.icon;
public override Widget build(BuildContext context) {
return new Container(
width: baseIcon.width,
height: baseIcon.height,
child: new Stack(
alignment: AlignmentDirectional.center,
children: new List<Widget>{
baseIcon,
new Text(
text,
textAlign: TextAlign.center,
style: new TextStyle(fontSize: 9, color: new Color(0xFF231F20))
),
}
)
);
}
}
class CustomIconMaker {
Dictionary<string, CustomIcon> iconCache = new Dictionary<string, CustomIcon>();
CustomIcon getCustomIcon(string fromText,
IconKind kind = null, bool isAbstract = false) {
if (kind == null)
{
kind = IconKind.classIcon;
}
if (fromText?.isEmpty() != false) {
return null;
}
string text = toUpperCase(fromText[0].ToString());
string mapKey = $"{text}_{kind.name}_{isAbstract}";
return iconCache.putIfAbsent(mapKey, () => {
return new CustomIcon(kind: kind, text: text, isAbstract: isAbstract);
});
}
string toUpperCase(string str)
{
if (str != null)
{
string retStr = string.Empty;
for (int i = 0; i < str.Length; i++)
{
if (str[i]>='a'&&str[i]<='z')
{
retStr += (char)(str[i] - 'a' + 'A');
continue;
}
retStr += str[i];
}
return retStr;
}
return "str is null";
}
public CustomIcon fromWidgetName(string name) {
if (name == null) {
return null;
}
bool isPrivate = name.StartsWith("_");
while (name.isNotEmpty() && !isAlphabetic(name[0])) {
name = name.Substring(1);
}
if (name.isEmpty()) {
return null;
}
return getCustomIcon(
name,
kind: isPrivate ? IconKind.method : IconKind.classIcon
);
}
CustomIcon fromInfo(String name) {
if (name == null) {
return null;
}
if (name.isEmpty()) {
return null;
}
return getCustomIcon(name, kind: IconKind.info);
}
bool isAlphabetic(int _char) {
return (_char < '0' || _char > '9') &&
_char != '_' &&
_char != '$';
}
}
class IconKind {
public IconKind(string name, Image icon, Image abstractIcon = null)
{
this.name = name;
this.icon = icon;
abstractIcon = abstractIcon ?? icon;
}
public static IconKind classIcon = new IconKind(
"class",
IconsUtils.createImageIcon("icons/custom/class.png"),
IconsUtils.createImageIcon("icons/custom/class_abstract.png")
);
public static IconKind field = new IconKind(
"fields",
IconsUtils.createImageIcon("icons/custom/fields.png")
);
public static IconKind _interface = new IconKind(
"interface",
IconsUtils.createImageIcon("icons/custom/interface.png")
);
public static IconKind method = new IconKind(
"method",
IconsUtils.createImageIcon("icons/custom/method.png"),
IconsUtils.createImageIcon("icons/custom/method_abstract.png")
);
public static IconKind property = new IconKind(
"property",
IconsUtils.createImageIcon("icons/custom/property.png")
);
public static IconKind info = new IconKind(
"info",
IconsUtils.createImageIcon("icons/custom/info.png")
);
public readonly string name;
public readonly Image icon;
public readonly Image abstractIcon;
}
}

81
com.unity.uiwidgets.devtools/Editor/v2/src/ui/label.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.DevTools.ui
{
public static class LabelUtils
{
public static bool _showLabelText(BuildContext context, double includeTextWidth) {
return includeTextWidth == null ||
MediaQuery.of(context).size.width > includeTextWidth;
}
}
class ImageIconLabel : StatelessWidget {
public ImageIconLabel(Image icon, string text, float minIncludeTextWidth = 100)
{
this.icon = icon;
this.text = text;
this.minIncludeTextWidth = minIncludeTextWidth;
}
public readonly Image icon;
public readonly string text;
public readonly float minIncludeTextWidth;
public override Widget build(BuildContext context)
{
List<Widget> temp = new List<Widget>();
temp.Add(icon);
if (LabelUtils._showLabelText(context, minIncludeTextWidth))
{
temp.Add(new Padding(
padding: EdgeInsets.only(left: 8.0f),
child: new Text(text)
));
}
return new Row(
children: temp
);
}
}
class MaterialIconLabel : StatelessWidget {
public MaterialIconLabel(IconData iconData, string text, float includeTextWidth = 10)
{
this.iconData = iconData;
this.text = text;
this.includeTextWidth = includeTextWidth;
}
public readonly IconData iconData;
public readonly string text;
public readonly float includeTextWidth;
public override Widget build(BuildContext context)
{
List<Widget> temp = new List<Widget>();
temp.Add(new Icon(iconData, size: 18.0f));
if (LabelUtils._showLabelText(context, includeTextWidth))
{
temp.Add(
new Padding(
padding: EdgeInsets.only(left: 8.0f),
child: new Text(text)
)
);
}
return new Row(
children: temp
);
}
}
}
正在加载...
取消
保存