static void FetchAdditionalItemInfo(SearchItem item, Dictionary <string, object> data, FetchOptions fetchOptions, SearchContext context) { if ((fetchOptions & FetchOptions.Label) == FetchOptions.Label) { data["label"] = item.GetLabel(context); } if ((fetchOptions & FetchOptions.Description) == FetchOptions.Description) { data["description"] = item.GetDescription(context); } }
private void DrawGridItem(int index, SearchItem item, Rect itemRect, bool canHover, ICollection <int> selection, Event evt) { var backgroundRect = new Rect(itemRect.x + 1, itemRect.y + 1, itemRect.width - 2, itemRect.height - 2); var itemContent = canHover ? new GUIContent("", item.GetDescription(context, true)) : GUIContent.none; if (selection.Contains(index)) { GUI.Label(backgroundRect, itemContent, Styles.selectedGridItemBackground); } else if (canHover) { GUI.Label(backgroundRect, itemContent, itemRect.Contains(evt.mousePosition) ? Styles.itemGridBackground2 : Styles.itemGridBackground1); } Texture2D thumbnail = null; var shouldFetchPreview = SearchSettings.fetchPreview && itemSize > 64; if (SearchSettings.fetchPreview && itemSize > 64) { thumbnail = item.preview; shouldFetchPreview = !thumbnail && item.provider.fetchPreview != null; if (shouldFetchPreview) { var previewSize = new Vector2(itemSize, itemSize); thumbnail = item.provider.fetchPreview(item, context, previewSize, FetchPreviewOptions.Preview2D | FetchPreviewOptions.Normal); if (thumbnail) { item.preview = thumbnail; } } } if (!thumbnail) { thumbnail = item.thumbnail; if (!thumbnail && item.provider.fetchThumbnail != null) { thumbnail = item.provider.fetchThumbnail(item, context); if (thumbnail && !shouldFetchPreview) { item.thumbnail = thumbnail; } } } if (thumbnail) { var thumbnailRect = new Rect(itemRect.x + itemPadding, itemRect.y + itemPadding, itemSize, itemSize); var dw = thumbnailRect.width - thumbnail.width; var dh = thumbnailRect.height - thumbnail.height; if (dw > 0 || dh > 0) { var scaledWidth = Mathf.Min(thumbnailRect.width, thumbnail.width); var scaledHeight = Mathf.Min(thumbnailRect.height, thumbnail.height); thumbnailRect = new Rect( thumbnailRect.center.x - scaledWidth / 2f, thumbnailRect.center.y - scaledHeight / 2f, scaledWidth, scaledHeight); } GUI.DrawTexture(thumbnailRect, thumbnail, ScaleMode.ScaleToFit, true, 0f, Color.white, 0f, 4f); } var labelRect = new Rect( itemRect.x + itemPadding, itemRect.yMax - itemLabelHeight - itemPadding, itemRect.width - itemPadding * 2f, itemLabelHeight - itemPadding); var maxCharLength = Utils.GetNumCharactersThatFitWithinWidth(Styles.itemLabelGrid, item.GetLabel(context, true), itemRect.width * 2f); var itemLabel = item.GetLabel(context); if (itemLabel.Length > maxCharLength) { maxCharLength = Math.Max(0, maxCharLength - 3); itemLabel = Utils.StripHTML(itemLabel); itemLabel = itemLabel.Substring(0, maxCharLength / 2) + "\u2026" + itemLabel.Substring(itemLabel.Length - maxCharLength / 2); } GUI.Label(labelRect, itemLabel, Styles.itemLabelGrid); }