private void Initialize(Rect activatorPosition, IFuzzyOptionTree optionTree, Action <IFuzzyOption> callback) { tree = optionTree; // Port the activator position to screen space activatorPosition.position = GUIUtility.GUIToScreenPoint(activatorPosition.position); this.activatorPosition = activatorPosition; // Create the hierarchy stack = new Stack <FuzzyOptionNode>(); root = new FuzzyOptionNode(new Root(optionTree.header)); ExecuteTask(delegate { optionTree.Prewarm(); Populate(root, optionTree.Root()); // Fit height to children if there is no depth and no search var hasSubChildren = root.children.Any(option => option.hasChildren); if (!optionTree.searchable && !hasSubChildren) { height = 0; if (!string.IsNullOrEmpty(root.option.headerLabel)) { height += Styles.headerHeight; } height += root.children.Count * Styles.optionHeight + 1; } }); // Add favorites favoritesRoot = new FuzzyOptionNode(new FavoritesRoot()); UpdateFavorites(); // Setup the search searchRoot = new FuzzyOptionNode(new SearchRoot()); Search(); // Assign the callback this.callback = callback; // Show and focus the window wantsMouseMove = true; var initialSize = new Vector2(activatorPosition.width, height); this.ShowAsDropDownWithKeyboardFocus(activatorPosition, initialSize); Focus(); }
private void Initialize(IFuzzyOptionTree optionTree, Action <IFuzzyOption> callback) { tree = optionTree; // Create the hierarchy stack = new Stack <FuzzyOptionNode>(); root = new FuzzyOptionNode(new Root(optionTree.header)); ExecuteTask(delegate { optionTree.Prewarm(); Populate(root, optionTree.Root()); // Fit height to children if there is no depth and no search var hasSubChildren = root.children.Any(option => option.hasChildren); if (!optionTree.searchable && !hasSubChildren) { height = 0; if (!string.IsNullOrEmpty(root.option.headerLabel)) { height += Styles.headerHeight; } height += root.children.Count * Styles.optionHeight + 1; } }); // Add favorites favoritesRoot = new FuzzyOptionNode(new FavoritesRoot()); UpdateFavorites(); // Setup the search searchRoot = new FuzzyOptionNode(new SearchRoot()); Search(); // Assign the callback this.callback = callback; // Show and focus the window }
private void Initialize(Rect activatorPosition, IFuzzyOptionTree optionTree, Action <IFuzzyOption> callback) { tree = optionTree; // Activator position is assumed to be in screen space, not GUI space // This lets us properly position fuzzy windows from context menus where no GUI context is available this.activatorPosition = activatorPosition; // Create the hierarchy stack = new List <FuzzyOptionNode>(); root = new FuzzyOptionNode(new Root(optionTree.header)); favoritesRoot = new FuzzyOptionNode(new FavoritesRoot()); stack.Add(root); Styles.Initialize(); ExecuteTask(() => { if (!optionTree.prewarmed) { optionTree.Prewarm(); optionTree.prewarmed = true; } else { optionTree.Rewarm(); } Populate(root, optionTree.Root()); UpdateFavorites(); // Fit height to children if there is no depth and no search var hasSubChildren = root.children.Any(option => option.hasChildren != false); if (!optionTree.searchable && !hasSubChildren) { var height = 0f; if (!string.IsNullOrEmpty(root.option.headerLabel)) { height += Styles.headerHeight; } foreach (var child in root.children) { if (child.option is FuzzySeparator) { height += Styles.separatorHeight; } else { height += Styles.optionHeight; } } this.height = height + 1; } }); // Setup the search Search(); // Assign the callback this.callback = callback; // Show and focus the window wantsMouseMove = true; var initialSize = new Vector2(activatorPosition.width, height); this.ShowAsDropDown(activatorPosition, initialSize); Focus(); }