Пример #1
0
        public static SearchTerm TermFor([NotNull] string category)
        {
            if (!CachedTerms.TryGetValue(category, out SearchTerm term))
            {
                CachedTerms.Add(category, term = new SearchTerm(category));
            }

            return(term);
        }
Пример #2
0
 /// <summary>
 /// Queue up an embedding of a search input filter for the next invocation of <see cref="ThingFilterUI.DoThingFilterConfigWindow"/>.
 /// </summary>
 /// <param name="term"><see cref="SearchTerm"/> to use.</param>
 /// <param name="watermark">Use this parameter to change the search boxes default watermark/seach hint</param>
 public static void QueueNextInvocationSearch([NotNull] SearchTerm term, string watermark = null)
 {
     FilterSearch_InjectSearchBox.searchOptions.Enqueue(
         new SearchOptions
     {
         Term      = term,
         Watermark = watermark
     });
     FilterSearch_InjectSearchBox.showSearchCount++;
 }
        private static void DoSearchBlock(Rect area, SearchTerm term, string weatermark = null, GUIStyle style = null)
        {
            float scale     = area.height / SearchDefaultHeight;
            float clearSize = SearchClearDefaultSize * Math.Min(1, scale);

            Rect clearSearchRect   = new Rect(area.xMax - 4f - clearSize, area.y + (area.height - clearSize) / 2, clearSize, clearSize);
            bool shouldClearSearch = Widgets.ButtonImage(clearSearchRect, Widgets.CheckboxOffTex);

            Rect   searchRect = area;
            string watermark  = (term.Value != string.Empty || term.Focused) ? term.Value : (weatermark ?? RSACoreKeys.RSACore_SearchWatermark.Translate());

            bool escPressed     = Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape;
            bool clickedOutside = !Mouse.IsOver(searchRect) && Event.current.type == EventType.MouseDown;

            if (!term.Focused)
            {
                GUI.color = new Color(1f, 1f, 1f, 0.6f);
            }

            GUI.SetNextControlName(term.ControlName);
            string searchInput = GUI.TextField(searchRect, watermark, style ?? DefaultSearchBoxStyle);

            GUI.color = Color.white;

            if (term.Focused)
            {
                term.Value = searchInput;
            }

            if ((GUI.GetNameOfFocusedControl() == term.ControlName || term.Focused) && (escPressed || clickedOutside))
            {
                GUIUtility.keyboardControl = 0;
                term.Focused = false;
            }
            else if (GUI.GetNameOfFocusedControl() == term.ControlName && !term.Focused)
            {
                term.Focused = true;
            }

            if (shouldClearSearch)
            {
                term.Value = string.Empty;
            }
        }