private void OnOptionsGUI(float anim, FuzzyOptionNode parent) { var hasHeader = !string.IsNullOrEmpty(parent.option.headerLabel); var headerHeight = hasHeader ? Styles.headerHeight : 0; var searchFieldHeight = tree.searchable ? LudiqStyles.searchFieldOuterHeight : 0; var levelPosition = new Rect ( position.width * (1 - anim) + 1, searchFieldHeight + headerHeight, position.width - 2, height - (searchFieldHeight + 1) - headerHeight ); if (e.type == EventType.MouseDown && e.button == (int)MouseButton.Right && levelPosition.Contains(e.mousePosition)) { SelectParent(); e.Use(); } GUILayout.BeginArea(levelPosition); if (parent.isLoading) { LudiqGUI.BeginVertical(); LudiqGUI.FlexibleSpace(); LudiqGUI.BeginHorizontal(); LudiqGUI.FlexibleSpace(); LudiqGUI.LoaderLayout(); LudiqGUI.FlexibleSpace(); LudiqGUI.EndHorizontal(); LudiqGUI.Space(16); LudiqGUI.BeginHorizontal(); LudiqGUI.Space(10); var progressBarPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(19), GUILayout.ExpandWidth(true)); if (showProgress) { EditorGUI.ProgressBar(progressBarPosition, progress, progressText); } LudiqGUI.Space(10); LudiqGUI.EndHorizontal(); LudiqGUI.Space(LudiqGUI.loaderSize * 1.5f); LudiqGUI.FlexibleSpace(); LudiqGUI.EndVertical(); Repaint(); } else { parent.scroll = GUILayout.BeginScrollView(parent.scroll); EditorGUIUtility.SetIconSize(new Vector2(IconSize.Small, IconSize.Small)); var selectedOptionPosition = default(Rect); foreach (var node in parent.children) { node.EnsurePositionable(); if (e.type == EventType.Layout || e.type == EventType.Repaint) { minOptionWidth = Mathf.Max(minOptionWidth, Mathf.Min(node.width, Styles.maxOptionWidth)); } } for (var i = 0; i < parent.children.Count; i++) { var node = parent.children[i]; var isSeparator = node.option is FuzzySeparator; var optionPosition = GUILayoutUtility.GetRect(IconSize.Small, isSeparator ? Styles.separator.fixedHeight : Styles.optionHeight, GUILayout.ExpandWidth(true)); if (((e.type == EventType.MouseMove && GUIUtility.GUIToScreenPoint(e.mousePosition) != lastMouseMovePosition) || e.type == EventType.MouseDown) && parent.selectedIndex != i && optionPosition.Contains(e.mousePosition)) { parent.selectedIndex = i; Repaint(); lastMouseMovePosition = GUIUtility.GUIToScreenPoint(e.mousePosition); } var optionIsSelected = false; if (i == parent.selectedIndex) { optionIsSelected = true; selectedOptionPosition = optionPosition; } // Clipping if (optionPosition.yMax < parent.scroll.y || optionPosition.yMin > parent.scroll.y + levelPosition.height) { continue; } EditorGUI.BeginDisabledGroup(node.option.mode == FuzzyOptionMode.Branch && node.hasChildren == false); node.EnsureDrawable(); if (e.type == EventType.Repaint) { using (LudiqGUI.color.Override(node.dim ? LudiqGUI.color.value.WithAlphaMultiplied(0.66f) : LudiqGUI.color.value)) { if (node.option is FuzzySeparator) { Styles.separator.Draw(optionPosition, node.label, false, false, false, false); var linePosition = new Rect(optionPosition.x, optionPosition.yMax - 1, optionPosition.width, 1); Styles.separatorLine.Draw(linePosition, GUIContent.none, false, false, false, false); } else { Styles.optionBackground.Draw(optionPosition, GUIContent.none, false, false, optionIsSelected, optionIsSelected); float x = Styles.optionBackground.padding.left; var spaced = false; foreach (var icon in node.icons) { if (icon == null) { continue; } var iconPosition = new Rect ( optionPosition.x + x, optionPosition.y + Styles.optionBackground.padding.top, IconSize.Small, IconSize.Small ); GUI.DrawTexture(iconPosition, icon[IconSize.Small]); x += IconSize.Small; x += Styles.spaceBetweenIcons; spaced = true; } if (spaced) { x -= Styles.spaceBetweenIcons; x += Styles.spaceAfterIcons; } var foregroundPosition = optionPosition; foregroundPosition.x += x; foregroundPosition.width -= x; Styles.optionForeground.Draw(foregroundPosition, node.label, false, false, optionIsSelected, optionIsSelected); } } } var right = optionPosition.xMax; if (node.option.mode == FuzzyOptionMode.Branch) { right -= 13; var rightArrowPosition = new Rect(right, optionPosition.y + 4, 13, 13); if (e.type == EventType.Repaint) { Styles.rightArrow.Draw(rightArrowPosition, false, false, false, false); } } if (node.option.mode == FuzzyOptionMode.Leaf && tree.selected.Contains(node.option.value) && !isSeparator) { right -= 16; var checkPosition = new Rect(right, optionPosition.y + 4, 12, 12); if (e.type == EventType.Repaint) { Styles.check.Draw(checkPosition, false, false, false, false); } } EditorGUI.EndDisabledGroup(); if (tree.favorites != null && tree.CanFavorite(node.option) && (optionIsSelected || tree.favorites.Contains(node.option))) { right -= 19; var starPosition = new Rect(right, optionPosition.y + 2, IconSize.Small, IconSize.Small); EditorGUI.BeginChangeCheck(); var isFavorite = tree.favorites.Contains(node.option); isFavorite = GUI.Toggle(starPosition, isFavorite, GUIContent.none, Styles.star); if (EditorGUI.EndChangeCheck()) { if (isFavorite) { tree.favorites.Add(node.option); } else { tree.favorites.Remove(node.option); } tree.OnFavoritesChange(); ExecuteTask(() => UpdateFavorites()); } } if (e.type == EventType.MouseUp && e.button == (int)MouseButton.Left && optionPosition.Contains(e.mousePosition)) { e.Use(); parent.selectedIndex = i; SelectChild(node); } } EditorGUIUtility.SetIconSize(default(Vector2)); GUILayout.EndScrollView(); if (scrollToSelected && e.type == EventType.Repaint) { scrollToSelected = false; var lastRect = GUILayoutUtility.GetLastRect(); if (selectedOptionPosition.yMax - lastRect.height > parent.scroll.y) { var scroll = parent.scroll; scroll.y = selectedOptionPosition.yMax - lastRect.height; parent.scroll = scroll; Repaint(); } if (selectedOptionPosition.y < parent.scroll.y) { var scroll = parent.scroll; scroll.y = selectedOptionPosition.y; parent.scroll = scroll; Repaint(); } } } GUILayout.EndArea(); }
private void OnOptionsGUI(FuzzyOptionNode parent, float scrollViewHeight) { if (parent.isLoading || (tree.showBackgroundWorkerProgress && BackgroundWorker.hasProgress)) { LudiqGUI.BeginVertical(); LudiqGUI.FlexibleSpace(); LudiqGUI.BeginHorizontal(); LudiqGUI.FlexibleSpace(); LudiqGUI.LoaderLayout(); LudiqGUI.FlexibleSpace(); LudiqGUI.EndHorizontal(); LudiqGUI.Space(16); LudiqGUI.BeginHorizontal(); LudiqGUI.Space(10); var progressBarPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(19), GUILayout.ExpandWidth(true)); if (tree.showBackgroundWorkerProgress && BackgroundWorker.hasProgress) { EditorGUI.ProgressBar(progressBarPosition, BackgroundWorker.progressProportion, BackgroundWorker.progressLabel); } else if (showProgress) { EditorGUI.ProgressBar(progressBarPosition, progress, progressText); } LudiqGUI.Space(10); LudiqGUI.EndHorizontal(); LudiqGUI.FlexibleSpace(); LudiqGUI.EndVertical(); Repaint(); return; } parent.scroll = GUILayout.BeginScrollView(parent.scroll); EditorGUIUtility.SetIconSize(new Vector2(IconSize.Small, IconSize.Small)); var selectedOptionPosition = default(Rect); if (e.type == EventType.Repaint) { minOptionWidth = 0; } foreach (var node in parent.children) { node.EnsureDrawable(); minOptionWidth = Mathf.Max(minOptionWidth, Mathf.Min(node.width, Styles.maxOptionWidth)); } for (var i = 0; i < parent.children.Count; i++) { var node = parent.children[i]; var optionPosition = GUILayoutUtility.GetRect(IconSize.Small, Styles.optionHeight, GUILayout.ExpandWidth(true)); if (((e.type == EventType.MouseMove && GUIUtility.GUIToScreenPoint(e.mousePosition) != lastMouseMovePosition) || e.type == EventType.MouseDown) && parent.selectedIndex != i && optionPosition.Contains(e.mousePosition)) { parent.selectedIndex = i; Repaint(); lastMouseMovePosition = GUIUtility.GUIToScreenPoint(e.mousePosition); } var optionIsSelected = false; if (i == parent.selectedIndex) { optionIsSelected = true; selectedOptionPosition = optionPosition; } // Clipping if (optionPosition.yMax < parent.scroll.y || optionPosition.yMin > parent.scroll.y + scrollViewHeight) { continue; } if (e.type == EventType.Repaint) { node.style.Draw(optionPosition, node.label, false, false, optionIsSelected, optionIsSelected); } var right = optionPosition.xMax; if (node.hasChildren) { right -= 13; var rightArrowPosition = new Rect(right, optionPosition.y + 4, 13, 13); if (e.type == EventType.Repaint) { Styles.rightArrow.Draw(rightArrowPosition, false, false, false, false); } } if (!node.hasChildren && tree.selected.Contains(node.option.value)) { right -= 16; var checkPosition = new Rect(right, optionPosition.y + 4, 12, 12); if (e.type == EventType.Repaint) { Styles.check.Draw(checkPosition, false, false, false, false); } } if (tree.favorites != null && tree.CanFavorite(node.option.value) && (optionIsSelected || tree.favorites.Contains(node.option.value))) { right -= 19; var starPosition = new Rect(right, optionPosition.y + 2, IconSize.Small, IconSize.Small); EditorGUI.BeginChangeCheck(); var isFavorite = tree.favorites.Contains(node.option.value); isFavorite = GUI.Toggle(starPosition, isFavorite, GUIContent.none, Styles.star); if (EditorGUI.EndChangeCheck()) { if (isFavorite) { tree.favorites.Add(node.option.value); } else { tree.favorites.Remove(node.option.value); } tree.OnFavoritesChange(); UpdateFavorites(); } } if (e.type == EventType.MouseDown && e.button == (int)MouseButton.Left && optionPosition.Contains(e.mousePosition)) { e.Use(); parent.selectedIndex = i; SelectChild(node); } } EditorGUIUtility.SetIconSize(default(Vector2)); GUILayout.EndScrollView(); if (scrollToSelected && e.type == EventType.Repaint) { scrollToSelected = false; var lastRect = GUILayoutUtility.GetLastRect(); if (selectedOptionPosition.yMax - lastRect.height > parent.scroll.y) { var scroll = parent.scroll; scroll.y = selectedOptionPosition.yMax - lastRect.height; parent.scroll = scroll; Repaint(); } if (selectedOptionPosition.y < parent.scroll.y) { var scroll = parent.scroll; scroll.y = selectedOptionPosition.y; parent.scroll = scroll; Repaint(); } } }
private void Draw() { if (Event.current.type == EventType.Layout) { UpdateDrawnElements(); } LudiqGUI.BeginVertical(Styles.background); LudiqGUI.BeginHorizontal(Styles.tipArea, GUILayout.Height(Styles.tipHeight)); LudiqGUI.BeginVertical(); LudiqGUI.FlexibleSpace(); LudiqGUI.LoaderLayout(); LudiqGUI.FlexibleSpace(); LudiqGUI.EndVertical(); if (drawnTip != null) { LudiqGUI.Space(Styles.spaceBetweenSpinnerAndTip); LudiqGUI.BeginVertical(); LudiqGUI.FlexibleSpace(); GUILayout.Label("<b>Tip:</b> " + drawnTip, Styles.tip); LudiqGUI.FlexibleSpace(); LudiqGUI.EndVertical(); } LudiqGUI.EndHorizontal(); if (drawnTasks.Count > 0) { var first = true; foreach (var task in drawnTasks) { if (!first) { GUILayout.Space(Styles.spaceBetweenTasks); } if (Event.current.type == EventType.Layout) { task.animatedRatio = Mathf.MoveTowards(task.animatedRatio, task.ratio, progressAnimationSpeed * repaintDeltaTime); } LudiqGUI.BeginVertical(Styles.task); GUILayout.Label(task.title + $" <color=#{ColorPalette.unityForegroundDim.ToHexString()}>({task.elapsed.TotalSeconds:###0.0} seconds)</color>", Styles.taskTitle); var progressBarPosition = EditorGUILayout.GetControlRect(); EditorGUI.ProgressBar(progressBarPosition, task.animatedRatio, null); if (task.stepsHaveStarted) { var currentItemPosition = new Rect ( progressBarPosition.x + (int)(task.animatedRatio * progressBarPosition.width) - 1, progressBarPosition.y, Mathf.Max(3, Mathf.CeilToInt((1f / task.totalSteps) * (progressBarPosition.width)) + 1), progressBarPosition.height ); if (Event.current.type == EventType.Repaint) { var opacity = Mathf.Lerp(0.25f, 0.25f, (Mathf.Sin((float)EditorApplication.timeSinceStartup * 3) + 1) / 2); using (LudiqGUI.color.Override(LudiqGUI.color.value.WithAlphaMultiplied(opacity))) { Styles.currentItemFill.Draw(currentItemPosition, false, false, false, false); } } LudiqGUI.DrawEmptyRect(currentItemPosition, Styles.currentItemBorder); if (Event.current.type == EventType.Repaint) { Styles.currentItemText.Draw(progressBarPosition, new GUIContent(task.currentStepLabel), false, false, false, false); } } LudiqGUI.EndVertical(); first = false; } } LudiqGUI.EndVertical(); }