Beispiel #1
0
        internal void Draw(Func <Rect, T, int, int> onDrawCell,
                           Action <int, int, T> onReorder       = null,
                           Action <T, int> OnRightClick         = null,
                           Action <int, int, T> onBeforeReorder = null,
                           Rect?drawRect = null)
        {
            NeedRepaint = false;

            const float scrollW   = 16f;
            var         rect      = drawRect ?? GetGUILayoutViewRect();
            var         hasScroll = (rect.height > 2f) && (GuiRect.height > rect.height);
            var         counter   = 0;
            var         ch        = 0f;

            if (rect.width > 1f)
            {
                rect = rect.xAdd(Theme.RectOffset);

                GuiRect.x     = rect.x;
                GuiRect.y     = rect.y;
                GuiRect.width = rect.width;
            }

            var x = GuiRect.x;
            var y = GuiRect.y;
            var w = GuiRect.width;
            var h = GuiRect.height;

            MousePos = Event.current.mousePosition;

            if (hasScroll)
            {
                ScrollRect     = GuiRect.h(rect.height);
                ScrollPosition = GUI.BeginScrollView(ScrollRect, ScrollPosition, GuiRect.dw(-scrollW), false, true);
            }

            if (Drag.IsDropping)
            {
                HandleDrop(onReorder, onBeforeReorder);
            }
            else if (Drag.IsDragging)
            {
                HandleDrag();
            }
            if (CacheList == null)
            {
                return;
            }

            for (int i = 0; i < CacheList.Count; i++)               //layout
            {
                T   item  = CacheList[i];
                var info  = GetInfo(item).SetWidth(w - (hasScroll ? scrollW : 0)).SetX(x);
                var first = info.CurrentRect.height == 0;

                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 (item == Drag.Target)
                {
                    continue;
                }
                int newH = DrawCell(i != Drag.DragIdx ? onDrawCell : null,
                                    info.CurrentRect,
                                    item,
                                    (Drag.Target != null && counter >= Drag.DropIdx) ? counter + 1 : counter);                                     //!(info.Selected==true)
                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(30f).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);
                    }
                }

                ch += info.CurrentRect.height;
                counter++;
            }

            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.DropIdx);
                if (newH > 0)
                {
                    dragRect.SetHeight(newH);
                }
            }

            if (hasScroll)
            {
                GUI.EndScrollView();
            }
        }
        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();
            }
        }