private static void DisplayHelp(ref Rect intelliRect, List <CodeCompletion> help, bool IsSelectable, ref Vector2 scroll) { const float lineHeight = 18.5f; intelliRect.height = Mathf.Min(lineHeight * help.Count, 150); scroll = GUI.BeginScrollView(intelliRect, scroll, new Rect(0, 0, 250, lineHeight * help.Count)); GUI.Box(new Rect(0, -15, intelliRect.width, help.Count * lineHeight + 15), "", GUI.skin.window); GUI.skin.label.richText = true; for (int i = 0; i < help.Count; i++) { var codeCompletion = help[i]; if (codeCompletion.SyntaxHighlightedDetails == null) { codeCompletion.SyntaxHighlightedDetails = RexUIUtils.SyntaxHighlingting(codeCompletion.Details, codeCompletion.Search); } var rect = new Rect(1, i * lineHeight, intelliRect.width, lineHeight); if (IsSelectable && i == RexISM.SelectedHelp) { GUI.Label(rect, string.Format("<b>{0}</b>", codeCompletion.SyntaxHighlightedDetails), GUI.skin.label); GUI.ScrollTo(rect); } else { GUI.Label(rect, codeCompletion.SyntaxHighlightedDetails, GUI.skin.label); } } GUI.skin.label.richText = false; GUI.EndScrollView(); }
/// <summary> /// Displays the <see cref="_expressionHistory"/> at the given width with the given style /// </summary> private void DisplayHistory() { // Draw the foldout and the clear history button. GUILayout.BeginHorizontal(); { showHistory = RexUIUtils.Toggle(showHistory, _texts["history_header"]); if (showHistory) { if (_expressionHistory.Count > 0 && GUILayout.Button(_texts["history_clear"], GUILayout.Width(50))) { _expressionHistory.Clear(); } } } GUILayout.EndHorizontal(); if (!showHistory) { return; } EditorGUILayout.BeginVertical(slimBox); { scroll = EditorGUILayout.BeginScrollView(scroll); var deleteIndex = -1; for (int i = 0; i < _expressionHistory.Count; i++) { var expr = _expressionHistory[i]; var content = _texts.GetText("history_item_" + (expr.IsExpanded ? "hide" : "show"), expr.Code); var isExpaned = GUILayout.Toggle(expr.IsExpanded, content, EditorStyles.foldout); if (isExpaned != expr.IsExpanded) { _expressionHistory.ForEach(e => e.IsExpanded = false); expr.IsExpanded = isExpaned; } if (expr.IsExpanded) { // Draw dropdown var IsDeleted = false; DisplayHistorySelectionToggle(expr.Code, out IsDeleted); if (IsDeleted) { deleteIndex = i; } } GUILayout.Box("", GUILayout.Height(1f), GUILayout.ExpandWidth(true)); } EditorGUILayout.EndScrollView(); if (deleteIndex >= 0) { _expressionHistory.RemoveAt(deleteIndex); } } EditorGUILayout.EndVertical(); }
/// <summary> /// Loads in the Details and converts them to Action and GUI contents. /// </summary> /// <param name="value">Ouput Value of the Expression</param> /// <param name="message">Message from the Expression execute</param> /// <param name="memberDetails"></param> private void LoadInDetails(object value, IEnumerable <MemberDetails> memberDetails) { DisplayMessage = DisplayFieldFor(value, Text); FilteredDetails = Details = (from detail in memberDetails let tooltip = RexUIUtils.SyntaxHighlingting(detail.TakeWhile(i => i.Type != SyntaxType.EqualsOp)) let content = new GUIContent(detail.Name.String, tooltip) let displayAction = DisplayFieldFor(detail.Value, detail.Constant.String) select new { displayAction, content }).ToDictionary(i => i.displayAction, i => i.content); }
/// <summary> /// Display the <see cref="Macros"/> window at the given width using the given style. /// </summary> private void DisplayMacros() { showMacros = RexUIUtils.Toggle(showMacros, _texts["macros_header"]); if (showMacros) { // box begins EditorGUILayout.BeginVertical(slimBox); { // scroll begins scroll4 = EditorGUILayout.BeginScrollView(scroll4); { string deleted = null; foreach (var macro in _macros) { EditorGUILayout.BeginHorizontal(); { // Draw the RUN button if (GUILayout.Button(_texts.GetText("macro_go", tooltipFormat: macro), GUILayout.Width(30))) { // parse, compile & execute Execute(macro); } // Remove the macro if the X button is pressed if (GUILayout.Button(_texts["macro_remove"], GUILayout.Width(20))) { deleted = macro; } // if the label is pressed... then run this code..? // TODO: Highlight this... if (GUILayout.Button(_texts.GetText("select_macro", macro, macro), GUI.skin.label)) { RexISM.Code = macro; RexISM.DisplayHelp = false; } } EditorGUILayout.EndHorizontal(); } if (deleted != null) { _macros = RexMacroHandler.Remove(deleted); } } EditorGUILayout.EndScrollView(); } EditorGUILayout.EndVertical(); } }
/// <summary> /// Displays a single variable, returns true if the varible was deleted else false. /// </summary> /// <param name="VarName">Name of the var. (key of the <see cref="RexHelper.Variables"/>)</param> /// <param name="var">The varible to display. (Value of the <see cref="RexHelper.Variables"/>)</param> private bool DisplayVariable(string VarName, RexHelper.Variable var) { string highlightedString; var type = RexUtils.GetCSharpRepresentation(var.VarType); // Format the code for syntax highlighting using richtext. highlightedString = RexUIUtils.SyntaxHighlingting(type.Concat(new[] { Syntax.Space, Syntax.Name(VarName), Syntax.Space, Syntax.EqualsOp, Syntax.Space }).Concat(RexReflectionUtils.GetSyntaxForValue(var.VarValue))); var shouldDelete = GUILayout.Button(_texts.GetText("remove_variable", tooltipFormat: VarName), GUILayout.Width(20)); // Draw the button as a label. if (GUILayout.Button(_texts.GetText("inspect_variable", highlightedString, VarName), varLabelStyle, GUILayout.ExpandWidth(true))) { var ouput = new OutputEntry(); ouput.LoadObject(var.VarValue); RexHelper.AddOutput(ouput); } return(shouldDelete); }
/// <summary> /// Displays the <see cref="RexHelper.Variables"/> /// </summary> private void DisplayVariables() { showVariables = RexUIUtils.Toggle(showVariables, _texts["variables_header"]); if (showVariables) { // Outer box begins EditorGUILayout.BeginVertical(slimBox); { // Scroll begins scroll2 = EditorGUILayout.BeginScrollView(scroll2); { string deleted = null; foreach (var var in RexHelper.Variables) { EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { var shouldDelete = DisplayVariable(var.Key, var.Value); if (shouldDelete) { deleted = var.Key; } } EditorGUILayout.EndHorizontal(); } if (deleted != null) { RexHelper.Variables.Remove(deleted); } } EditorGUILayout.EndScrollView(); // Scroll ends } EditorGUILayout.EndVertical(); // outer box ends } }
/// <summary> /// Displays the selection screen for Namespaces. /// </summary> private void DisplayScope() { showUsings = RexUIUtils.Toggle(showUsings, _texts["scope_header"]); if (showUsings) { EditorGUILayout.BeginVertical(slimBox); { var useWidth = 25; EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); EditorGUILayout.LabelField(_texts["scope_use"], GUILayout.Width(useWidth)); EditorGUILayout.LabelField(_texts["scope_namespace"], GUILayout.ExpandWidth(false)); EditorGUILayout.EndHorizontal(); usingScroll = EditorGUILayout.BeginScrollView(usingScroll, GUILayout.Height(1), GUILayout.MaxHeight(150)); { var depth = 0; foreach (var n in RexCompileEngine.Instance.NamespaceInfos) { if (n.Depth > depth) { continue; } if (n.Depth < depth) { depth = n.Depth; } EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { for (int i = 0; i < n.Depth; i++) { GUILayout.Space(25f); } var prev = n.Selected; n.Selected = GUILayout.Toggle(n.Selected, "", GUILayout.Width(useWidth)); if (prev != n.Selected) { if (prev) { RexUsingsHandler.Remove(n.Name); } else { RexUsingsHandler.Save(n.Name); } } if (n.HasSubNamespaces) { EditorGUILayout.LabelField(n.Name); } else if (n.DisplaySubNamespaces = EditorGUILayout.Foldout(n.DisplaySubNamespaces, n.Name)) { depth = n.Depth + 1; } //EditorGUILayout.LabelField(n.Assembly.Location); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); } EditorGUILayout.EndVertical(); } }