From 13988a736869dcc0889c52e4939c2fd32ee88622 Mon Sep 17 00:00:00 2001 From: Stefano Cecere Date: Tue, 19 Nov 2019 19:02:07 +0100 Subject: [PATCH] [feature] add toolbar to EditorWindow with NodeGraph title and zoom slider --- Scripts/Editor/NodeEditorGUI.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index c41afd08..1edc5917 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -30,6 +30,7 @@ private void OnGUI() { DrawNodes(); DrawSelectionBox(); DrawTooltip(); + DrawToolbar(); graphEditor.OnGUI(); // Run and reset onLateGUI @@ -85,6 +86,28 @@ public void DrawGrid(Rect rect, float zoom, Vector2 panOffset) { GUI.DrawTextureWithTexCoords(rect, gridTex, new Rect(tileOffset, tileAmount)); GUI.DrawTextureWithTexCoords(rect, crossTex, new Rect(tileOffset + new Vector2(0.5f, 0.5f), tileAmount)); } + + private void DrawToolbar() { + GUILayout.BeginHorizontal(EditorStyles.toolbar); + { + GUILayout.Space(2); + GUILayout.Label(graph.name, EditorStyles.boldLabel); + GUILayout.Space(10); + + // Draw scale bar + GUILayout.Label("Scale", EditorStyles.miniLabel); + var newZoom = GUILayout.HorizontalSlider( + zoom, 1f, 5f, GUILayout.MinWidth(40), GUILayout.MaxWidth(100) + ); + GUILayout.Label(zoom.ToString("0.0#x"), EditorStyles.miniLabel, GUILayout.Width(30)); + if (Math.Abs(newZoom - zoom) > Mathf.Epsilon) { + zoom = newZoom; + } + + GUILayout.FlexibleSpace(); + } + GUILayout.EndHorizontal(); + } public void DrawSelectionBox() { if (currentActivity == NodeActivity.DragGrid) { @@ -524,4 +547,4 @@ private void DrawTooltip() { } } } -} \ No newline at end of file +}