internal float GetSelectionHeight(AdvancedDropdownDataSource dataSource, Rect buttonRect) { if (state.GetSelectedIndex(dataSource.mainTree) == -1) { return(0); } float heigth = 0; for (int i = 0; i < dataSource.mainTree.children.Count(); i++) { var child = dataSource.mainTree.children.ElementAt(i); var content = GUIContent.Temp(child.name, child.icon); if (state.GetSelectedIndex(dataSource.mainTree) == i) { var diff = (lineStyle.CalcHeight(content, 0) - buttonRect.height) / 2f; return(heigth + diff); } if (child.IsSeparator()) { heigth += Styles.lineSeparator.CalcHeight(content, 0) + Styles.lineSeparator.margin.vertical; } else { heigth += lineStyle.CalcHeight(content, 0); } } return(heigth); }
internal Vector2 CalculateContentSize(AdvancedDropdownDataSource dataSource) { float maxWidth = 0; float maxHeight = 0; bool includeArrow = false; float arrowWidth = Styles.rightArrow.fixedWidth; foreach (var child in dataSource.mainTree.children) { var content = GUIContent.Temp(child.name, child.icon); var a = lineStyle.CalcSize(content); a.x += iconSize.x + 1; if (maxWidth < a.x) { maxWidth = a.x + 1; includeArrow |= child.children.Any(); } if (child.IsSeparator()) { maxHeight += Styles.lineSeparator.CalcHeight(content, maxWidth) + Styles.lineSeparator.margin.vertical; } else { maxHeight += lineStyle.CalcHeight(content, maxWidth); } } if (includeArrow) { maxWidth += arrowWidth; } return(new Vector2(maxWidth, maxHeight)); }
public void Init(Rect buttonRect) { m_ButtonRectScreenPos = EditorGUIUtility.GUIToScreenRect(buttonRect); if (m_State == null) { m_State = new AdvancedDropdownState(); } if (m_DataSource == null) { m_DataSource = new MultiLevelDataSource(); } if (m_Gui == null) { m_Gui = new AdvancedDropdownGUI(m_DataSource); } m_Gui.state = m_State; // Has to be done before calling Show / ShowWithMode buttonRect = GUIUtility.GUIToScreenRect(buttonRect); OnDirtyList(); m_CurrentlyRenderedTree = hasSearch ? m_DataSource.searchTree : m_DataSource.mainTree; ShowAsDropDown(buttonRect, CalculateWindowSize(buttonRect), GetLocationPriority()); if (setInitialSelectionPosition) { m_InitialSelectionPosition = m_Gui.GetSelectionHeight(m_DataSource, buttonRect); } wantsMouseMove = true; SetSelectionFromState(); }
public void Show(Rect rect) { if (m_WindowInstance != null) { m_WindowInstance.Close(); m_WindowInstance = null; } if (m_DataSource == null) { m_DataSource = new CallbackDataSource(BuildRoot); } if (m_Gui == null) { m_Gui = new AdvancedDropdownGUI(m_DataSource); } m_WindowInstance = ScriptableObject.CreateInstance <AdvancedDropdownWindow>(); if (m_MinimumSize != Vector2.zero) { m_WindowInstance.minSize = m_MinimumSize; } m_WindowInstance.state = m_State; m_WindowInstance.dataSource = m_DataSource; m_WindowInstance.gui = m_Gui; m_WindowInstance.windowClosed += (w) => ItemSelected(w.GetSelectedItem()); m_WindowInstance.Init(rect); }
internal Vector2 CalculateContentSize(AdvancedDropdownDataSource dataSource) { float maxWidth = 0; float maxHeight = 0; bool includeArrow = false; float arrowWidth = Styles.rightArrow.fixedWidth; foreach (var child in dataSource.mainTree.children) { var content = child.content; var a = CalcItemSize(content); a.x += iconSize.x + 1; if (maxWidth < a.x) { maxWidth = a.x + 1; includeArrow |= child.children.Any(); } if (child.IsSeparator()) { maxHeight += Styles.lineSeparator.CalcHeight(content, maxWidth) + Styles.lineSeparator.margin.vertical; } else { maxHeight += CalcItemHeight(content, maxWidth); } } if (includeArrow) { maxWidth += arrowWidth; } // other size calculations may rely on m_HeaderRect and m_SearchRect, which wont be populated until the first time they are drawn // so they need to be calculated here if needed. if (m_HeaderRect == default(Rect)) { var headerContent = GUIContent.Temp(dataSource.mainTree.name, dataSource.mainTree.icon); var headerSize = Styles.header.CalcSize(headerContent); if (maxWidth > headerSize.x) { headerSize.x = maxWidth; } headerSize.y = Styles.header.CalcHeight(headerContent, maxWidth); m_HeaderRect = new Rect(0, 0, headerSize.x, headerSize.y); } if (m_SearchRect == default(Rect)) { var controlRectSize = Styles.searchFieldStyle.CalcSize(GUIContent.none); controlRectSize.x = maxWidth; var controlRect = new Rect(0, 0, controlRectSize.x, controlRectSize.y); m_SearchRect = CalculateSearchRect(ref controlRect); } return(new Vector2(maxWidth, maxHeight)); }
public AdvancedDropdownGUI(AdvancedDropdownDataSource dataSource) { m_DataSource = dataSource; }