internal void Draw(Func <Rect, T, int, int> onDrawCell, Action <int, int, T> onReorder = null, Action <T, int, vlbGUIList <T> > OnRightClick = null, Action <int, int, T> onBeforeReorder = null, Rect?drawRect = null) { NeedRepaint = false; const float scrollW = 16f; var rect = drawRect ?? (Theme.AllowScroll ? GuiX.FlexibleSpace() : GuiX.Height(GuiRect.height)); var hasScroll = (rect.height > 2f) && (GuiRect.height > rect.height); var counter = 0; var ch = 0f; if (!Event.current.xIsLayout() && Event.current.xIsNotUsed()) //rect.width > 1f { rect = rect.xAdd(Theme.RectOffset); GuiRect.x = rect.x; GuiRect.y = rect.y; GuiRect.width = rect.width; MousePos = Event.current.mousePosition; //Debug.Log(Event.current + ":" + GuiRect); } var x = GuiRect.x; var y = GuiRect.y; var w = GuiRect.width; var h = GuiRect.height; if (hasScroll) { ScrollRect = GuiRect.h(rect.height); ScrollPosition = GUI.BeginScrollView(ScrollRect, ScrollPosition, GuiRect.dw(-scrollW), false, true); } //Debug.Log("----> " + x + ":" + y + ":" + w + ":" + h + ":" + Event.current + ":" + hasScroll); //Debug.Log("--------------------------> " + Event.current); if (Drag.IsDropping) { HandleDrop(onReorder, onBeforeReorder); } else if (Drag.IsDragging) { HandleDrag(); } if (CacheList == null) { return; } for (int i = 0; i < CacheList.Count; i++) //layout //var willLog = i < 5 && CacheList.Count == 12; { T item = CacheList[i]; var info = GetInfo(i, item).SetWidth(w - (hasScroll ? scrollW : 0)).SetX(x); var first = info.CurrentRect.height == 0; /*if (RectMap[CacheList[i]] == RectMap[CacheList[0]]) { * Debug.Log("Invalid <" + i + ">" + string.IsNullOrEmpty((string)(object)item) + ":" + CacheList[0]); * }*/ //Debug.Log(i + " CHECK :: " + CacheList[0] + ":" + (RectMap[CacheList[0]] == RectMap[CacheList[i]])); //info._logChange = i == 0; //if (i == 0) Debug.Log(item.GetHashCode() + " Before :: " + info.CurrentRect); if (first) { info.SetY(y); //.SetHeight(Theme.CellHeight); } info.AnimateStep(); if (!Drag.IsDragging) { if (Drag.IsDropping && counter == Drag.DropIdx) { if (item != Drag.Target) { LIInfo animx = Drag.Info; animx.TweenY(y + ch); ch += animx.CurrentRect.height; } } if (item != Drag.Target) { if (Event.current.type == EventType.layout) { info.SetY(y + ch); } else { info.TweenY(y + ch); } } } //if (i == 0) Debug.Log(item.GetHashCode() + " After :: " + info.CurrentRect); if (item == Drag.Target) { continue; } //if (i == 0) Debug.Log("Before ::" + info.CurrentRect); var newH = DrawCell(i != Drag.DragIdx ? onDrawCell : null, info.CurrentRect, item, i, (Drag.Target != null && counter >= Drag.DropIdx) ? counter + 1 : counter); //!(info.Selected==true) //if (i == 0) Debug.Log("After ::" + info.CurrentRect); if (newH > 0) { if (first) { info.SetHeight(newH); } else { info.TweenH(newH); } } if (info.IsAnimate && !NeedRepaint) { NeedRepaint = true; } if (!Drag.IsDragging && !Drag.IsDropping) { if (info.CanDrag && info.CurrentRect.w(Theme.DragWidth).h(20f).xLMB_isDown().noModifier) { StartDrag(i); } else if (info.Selected != null && info.CurrentRect.xLMB_isDown().noModifier) { info.Selected = !info.Selected; } if (OnRightClick != null && info.CurrentRect.xRMB_isDown().noModifier) { OnRightClick(item, i, this); } } ch += info.CurrentRect.height; counter++; //if (willLog) Debug.Log(counter + ":" + ch + "::::" + info.CurrentRect); //T item0 = CacheList[0]; //var info0 = GetInfo(item0); //Debug.Log(i + " Last ---> " + info0.CurrentRect); } /*if (Drag.IsDragging) { * //DEBUG * GUI.DrawTexture(GuiRect, Color.yellow.xAlpha(0.2f).xGetTexture2D()); * GUI.DrawTexture(new Rect(MousePos.x, MousePos.y, 10, 10), Color.red.xAlpha(0.2f).xGetTexture2D()); * }*/ if (Drag.IsDragging) { ch += Drag.Info.CurrentRect.height; } if (ch != h && ch > 0) { GuiRect.height = ch; NeedRepaint = true; } if (Drag.Target != null) { LIInfo dragRect = Drag.Info; int newH = DrawCell(onDrawCell, Drag.IsDragging ? MouseDragRect : dragRect.CurrentRect, (T)Drag.Target, Drag.DragIdx, Drag.DropIdx); if (newH > 0) { dragRect.SetHeight(newH); } } if (hasScroll) { GUI.EndScrollView(); } }
//internal void Reset() { //} //void SetCategory(int idx) { // Category = idx; // CategoryTitle = null; //} internal void Draw(Action <string> onSearch) { var evt = Event.current; rect = GuiX.FlexibleSpace().dy(2f); //Debug.Log("----> "+ rect + ":" + evt); //GUI.BeginGroup(rect, "", EditorStyles.toolbar); //GUILayout.BeginHorizontal(); //GUILayoutUtility.GetRect(rect.width, rect.height); //GUILayout.EndHorizontal(); if (TextFieldStyle == null) { TextFieldStyle = new GUIStyle("ToolbarSeachTextFieldPopup"); // {fixedHeight = 14f}; CloseBtnStyle = new GUIStyle("ToolbarSeachCancelButton"); EmptyBtnStyle = new GUIStyle("ToolbarSeachCancelButtonEmpty"); //ToolbarBtnStyle = new GUIStyle(EditorStyles.toolbarPopup) {fixedWidth = CatWidth /*, alignment = TextAnchor.MiddleCenter*/}; } var r2 = rect; GUI.SetNextControlName(gID); if (gainFocus) { GUI.FocusControl(gID); EditorGUI.FocusTextInControl(gID); if (focus && evt.type == EventType.repaint) { gainFocus = false; } } focus = GUI.GetNameOfFocusedControl() == gID; if (focus) { //ESC is down without any modifier if (evt.type == EventType.KeyDown) { Debug.Log("--->" + evt.keyCode); } if (KeyCode.Escape.xKey_isDown().noModifier) { StopSearch(); } if (KeyCode.Return.xKey_isDown().noModifier&& !string.IsNullOrEmpty(SearchTerm)) { if (onSearch != null) { onSearch(SearchTerm);//, CategoryList[Category] } else { Debug.Log(string.Format("Search for <{0}> has no handler", SearchTerm)); } Event.current.Use(); } } else { //normal click without any modifier if (rect.xLMB_isDown().noModifier) { StartSearch(); } //TODO : Support Validate / ExecuteCommand //if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "Find") { // Event.current.Use(); // return; //} else if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "Find") { // focusSearchBox = true; //} } SearchTerm = EditorGUI.TextField(r2.dw(-20f), SearchTerm ?? "", TextFieldStyle); if (GUI.Button(r2.xHzSubRectsRight(20f)[0], string.Empty, SearchTerm == string.Empty ? EmptyBtnStyle : CloseBtnStyle)) { StopSearch(); } //EditorGUI.BeginChangeCheck(); //GUI.Button(r2.xSlide(1f).dy(-2).w(CatWidth), CategoryTitle ?? (CategoryTitle = CategoryList[Category].Split('&')[0]), ToolbarBtnStyle); //if (EditorGUI.EndChangeCheck()) { // var cm = new GenericMenu(); // for (var i = 0; i < CategoryList.Length; i++) { // var idx = i; // cm.xAdd(CategoryList[i], () => SetCategory(idx)); // } // cm.ShowAsContext(); // //EditorUtility.DisplayCustomMenu(r2, CategoryList.ToGUIContent(), Category, null, null); //} //GUI.EndGroup(); }