Beispiel #1
0
 private static string FetchEvaluatedDescription(SearchItem item, SearchContext context)
 {
     if (!item.options.HasFlag(SearchItemOptions.Compacted))
     {
         return(item.description);
     }
     return($"{item.GetLabel(context, true)} > {item.value}");
 }
 [SearchSelector("label", priority: 1)] static object GetSearchItemLabel(SearchItem item) => item.GetLabel(item.context);
Beispiel #3
0
        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 isSelected     = selection.Contains(index);
            var isHovered      = canHover && itemRect.Contains(evt.mousePosition);

            Texture2D thumbnail          = null;
            var       shouldFetchPreview = SearchSettings.fetchPreview;

            if (shouldFetchPreview)
            {
                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 && !AssetPreview.IsLoadingAssetPreviews())
                    {
                        item.preview = thumbnail;
                    }
                }
            }

            if (!thumbnail)
            {
                thumbnail = item.thumbnail;
                if (!thumbnail && item.provider.fetchThumbnail != null)
                {
                    thumbnail = item.provider.fetchThumbnail(item, context);
                    if (thumbnail && !shouldFetchPreview && !AssetPreview.IsLoadingAssetPreviews())
                    {
                        item.thumbnail = thumbnail;
                    }
                }
            }

            var thumbnailRect = new Rect(itemRect.x + itemPadding, itemRect.y + itemPadding, itemSize, itemSize);

            Styles.gridItemBackground.Draw(thumbnailRect, thumbnail ?? Icons.quicksearch, isHovered, false, isSelected, false);

            var labelRect = new Rect(
                itemRect.x + itemPadding, itemRect.yMax - itemLabelHeight - itemPadding,
                itemRect.width - itemPadding * 2f, itemLabelHeight - itemPadding);
            var originalItemLabel = item.GetLabel(context, true);
            var itemLabel         = originalItemLabel;
            var textRectWidth     = (labelRect.width - Styles.gridItemLabel.padding.horizontal - 18) * 2f;
            var maxCharLength     = Utils.GetNumCharactersThatFitWithinWidth(Styles.gridItemLabel, originalItemLabel, textRectWidth);

            if (originalItemLabel.Length > maxCharLength)
            {
                maxCharLength = Math.Max(0, maxCharLength - 3);
                itemLabel     = originalItemLabel.Substring(0, maxCharLength / 2) + "\u2026" + originalItemLabel.Substring(originalItemLabel.Length - maxCharLength / 2);
            }
            else
            {
                var labelSize = Styles.gridItemLabel.CalcSize(new GUIContent(itemLabel));
                labelSize.x += 2;
                labelSize.y += 2;
                if (labelSize.x < labelRect.width)
                {
                    var c = labelRect.center;
                    labelRect = new Rect(c.x - labelSize.x / 2.0f, labelRect.y, labelSize.x, labelSize.y);
                }
            }
            Styles.gridItemLabel.Draw(labelRect, new GUIContent(itemLabel, originalItemLabel), false, false, isSelected || isHovered, isSelected);
        }