private void DrawItem(SearchItem item, SearchContext context, int index, ref int thumbnailFetched) { var bgStyle = index % 2 == 0 ? Styles.itemBackground1 : Styles.itemBackground2; if (m_SelectedIndex == index) { bgStyle = Styles.selectedItemBackground; } using (new EditorGUILayout.HorizontalScope(bgStyle)) { DrawListThumbnail(item, context, ref thumbnailFetched); using (new EditorGUILayout.VerticalScope()) { var maxWidth = m_DrawItemsWidth - Styles.actionButtonSize - Styles.itemPreviewSize - Styles.itemRowSpacing - Styles.descriptionPadding; var textMaxWidthLayoutOption = GUILayout.MaxWidth(maxWidth); GUILayout.Label(item.provider.fetchLabel(item, context), m_SelectedIndex == index ? Styles.selectedItemLabel : Styles.itemLabel, textMaxWidthLayoutOption); GUILayout.Label(SearchContent.FormatDescription(item, context, maxWidth), m_SelectedIndex == index ? Styles.selectedItemDescription : Styles.itemDescription, textMaxWidthLayoutOption); } if (selectCallback == null && item.provider.actions.Count > 1) { GUILayout.FlexibleSpace(); if (GUILayout.Button(Styles.moreActionsContent, Styles.actionButton)) { ShowItemContextualMenu(item, context); GUIUtility.ExitGUI(); } } } }
private void DrawItem(SearchItem item, Rect itemRect, int itemIndex, ICollection <int> selection) { if (Event.current.type == EventType.Repaint) { bool isItemSelected = selection.Contains(itemIndex); // Draw item background var bgStyle = itemIndex % 2 == 0 ? Styles.itemBackground1 : Styles.itemBackground2; if (isItemSelected) { bgStyle = Styles.selectedItemBackground; } bgStyle.Draw(itemRect, itemRect.Contains(Event.current.mousePosition), false, false, false); // Draw thumbnail var thumbnailRect = DrawListThumbnail(item, itemRect); // Draw label var maxWidth = itemRect.width - Styles.actionButtonSize - Styles.itemPreviewSize - Styles.descriptionPadding; var label = item.provider.fetchLabel(item, context); var labelStyle = isItemSelected ? Styles.selectedItemLabel : Styles.itemLabel; var labelRect = new Rect(thumbnailRect.xMax + labelStyle.margin.left, itemRect.y + labelStyle.margin.top, maxWidth - labelStyle.margin.right, labelStyle.lineHeight); GUI.Label(labelRect, label, labelStyle); labelRect.y = labelRect.yMax + labelStyle.margin.bottom; // Draw description var labelContent = SearchContent.FormatDescription(item, context, maxWidth); labelStyle = isItemSelected ? Styles.selectedItemDescription : Styles.itemDescription; labelRect.y += labelStyle.margin.top; GUI.Label(labelRect, labelContent, labelStyle); } // Draw action dropdown if (searchView.selectCallback == null && searchView.selection.Count <= 1 && item.provider.actions.Count > 1) { var buttonRect = new Rect(itemRect.xMax - Styles.actionButton.fixedWidth - Styles.actionButton.margin.right, itemRect.y, Styles.actionButton.fixedWidth, Styles.actionButton.fixedHeight); buttonRect.y += (itemRect.height - Styles.actionButton.fixedHeight) / 2f; bool actionHover = buttonRect.Contains(Event.current.mousePosition); GUI.Label(buttonRect, Styles.moreActionsContent, actionHover ? Styles.actionButtonHovered : Styles.actionButton); UnityEditor.EditorGUIUtility.AddCursorRect(buttonRect, UnityEditor.MouseCursor.Link); if (Event.current.type == EventType.MouseDown && actionHover) { var contextRect = new Rect(Event.current.mousePosition, new Vector2(1, 1)); searchView.ShowItemContextualMenu(item, context, contextRect); GUIUtility.ExitGUI(); } } }
private static void DrawDescription(SearchContext context, SearchItem item) { var description = SearchContent.FormatDescription(item, context, 2048); GUILayout.Label(description, Styles.previewDescription); }