예제 #1
0
 public ChildGroup(GUIContent header)
 {
     if (null != header)
     {
         _headerItem = new GroupRow(null, new Rect(0, 0, 0, 0)) {Content = header};
     }
 }
예제 #2
0
 public void Add(DraggableItem item)
 {
     if (!_items.Contains(item)) {
         //Debug.Log("ChildGroup Add: " + item);
         _items.Add(item);
     }
 }
예제 #3
0
 public void Add(DraggableItem item)
 {
     if (!_items.Contains(item))
     {
         //Debug.Log("ChildGroup Add: " + item);
         _items.Add(item);
     }
 }
예제 #4
0
        public void AddItem(DraggableItem item)
        {
            if (_groups.Count == 0)
            {
                throw new Exception("Not groups defined");
            }

            _groups[0].Add(item);
        }
예제 #5
0
        public void AddItem(DraggableItem item, int groupIndex)
        {
            if (groupIndex > _groups.Count - 1)
            {
                throw new Exception("Out of bounds exception");
            }

            _groups[groupIndex].Add(item);
        }
예제 #6
0
 public ChildGroup(GUIContent header)
 {
     if (null != header)
     {
         _headerItem = new GroupRow(null, new Rect(0, 0, 0, 0))
         {
             Content = header
         };
     }
 }
예제 #7
0
        private void HandleBounds(DraggableItem data)
        {
            var newIndex = Mathf.Clamp((int)Math.Round((data.Bounds.y) / ElementHeight), 0, Data.RenderingItemsCount - 1);

            if (newIndex != _newIndex)
            {
                //Debug.Log("Flip");
                _newIndex = newIndex;
                Flip(data, newIndex);
            }
        }
예제 #8
0
 public ChildGroup RemoveItem(DraggableItem item)
 {
     //Debug.Log("RemoveItem!");
     foreach (ChildGroup group in _groups)
     {
         if (group.Items.Contains(item))
         {
             group.Remove(item);
             return(group);
         }
     }
     return(null);
 }
예제 #9
0
        private void Flip(DraggableItem data, int index)
        {
            _newIndex = index;

            //Debug.Log("Flip to index: " + index);
            _displayItems.Remove(data);
            _displayItems.Insert(index, data);
            data.Index = index;

            for (int i = 0; i < _displayItems.Count; i++)
            {
                var d = _displayItems[i];
                d.Bounds = d != data ? new Rect(d.Bounds.x, i * ElementHeight, _elementWidth, ElementHeight) : new Rect(d.Bounds.x, d.Bounds.y, _elementWidth, ElementHeight);
            }
        }
예제 #10
0
 public void Remove(DraggableItem item)
 {
     _items.Remove(item);
 }
예제 #11
0
 public void AddItem(DraggableItem item, ChildGroup group)
 {
     group.Add(item);
 }
예제 #12
0
 public void Remove(DraggableItem item)
 {
     _items.Remove(item);
 }
예제 #13
0
        internal void Render()
        {
            //Debug.Log("Render");
            //_draggedItem = null;
            _doRepaint = false;
            bool dropped = false;
            //int index = 0;

            bool dragStart = false;

            //Debug.Log(">" + _height);

            var oldAlignment = GUI.skin.label.alignment;

            _scrollPosition = GUI.BeginScrollView(
                new Rect(0, 0, _width, _height),
                _scrollPosition,
                new Rect(0, 0, _width - ScrollbarWidth, Data.RenderingItemsCount * ElementHeight));

            GUI.skin.box.alignment = TextAnchor.MiddleLeft;

            if (Data.RenderingItemsCount > 0)
            {
                Color color = GUI.color;
                GUI.color = new Color(0.25f, 0.25f, 0.25f);
                GUI.Box(new Rect(0, 0, _width, Data.RenderingItemsCount * ElementHeight), string.Empty, StyleCache.Instance.Background);
                GUI.color = color;
            }

            //Debug.Log("Data.Count: " + Data.Count);
            _count = 0;

            // render rows
            foreach (DraggableItem data in Data.RenderingItems)
            {
                bool previousState = data.Dragging;

                ItemAction action = data.Render();
                if (action != null)
                {
                    switch (action.Type)
                    {
                    case ItemAction.REMOVE:
                        _removedItem      = data;
                        _removedItemIndex = _count;
                        return;

                    case ItemAction.ENABLE:
                        _enabledItem = data;
                        break;

                    case ItemAction.PHASES_CHANGED:
                        _phaseChangedItem = data;
                        break;
                    }
                }

                if (Event.current.type == EventType.Repaint)
                {
                    //GUI.skin = GUI.skin;
                    //_draggingHandle.Draw(new Rect(3, 3, 16, 16), false, false, false, false);
                }

                if (data.Dragging)
                {
                    if (null == _draggedItem)
                    {
                        _oldIndex = data.Index;
                        //Debug.Log("??? " + _oldIndex);
                    }

                    _draggedItem = data;
                    //Debug.Log("*: " + _draggedItem);

                    if (!dragStart)
                    {
                        dragStart = true;
                    }

                    _doRepaint = true;

                    HandleBounds(data);

                    _newIndex = data.Index;
                }
                else if (previousState)
                {
                    dropped = true;
                }

                _count++;
            }

            GUI.skin.box.alignment = oldAlignment;

            GUI.EndScrollView();

            if (null != _draggedItem)
            {
                // bring to front // TODO
                //Data.RemoveItem(_draggedItem);
                //Data.AddItem(_draggedItem);
            }

            if (null != _enabledItem)
            {
                EnabledSignal.Emit(_enabledItem);
                _doRepaint   = true;
                _enabledItem = null;
            }
            else if (null != _phaseChangedItem)
            {
                PhaseChangedSignal.Emit(_phaseChangedItem);
                _doRepaint        = true;
                _phaseChangedItem = null;
            }

            if (dropped)
            {
                //Data.GetGroupAndItemIndex((int)_newIndex, out _newGroupIndex, out _newItemIndex);
                //Debug.Log("Drop to " + _newIndex);

                int groupIndex;
                int itemIndex;
                GetGroupIndex((int)_newIndex, out groupIndex, out itemIndex);

                //Debug.Log(string.Format("**** Result: grp:{0}, item:{1}", groupIndex, itemIndex));

                //CollectionChangedSignal.Emit(_draggedItem, _newItemIndex, _newGroupIndex);
                PositionChangedSignal.Emit(_draggedItem, itemIndex, groupIndex);

                Apply();

                _doRepaint   = true;
                _draggedItem = null;
            }

            if (null != _removedItem)
            {
                int groupIndex;
                int itemIndex;
                GetGroupIndex(_removedItemIndex, out groupIndex, out itemIndex);
                RemoveRow(groupIndex, itemIndex);

                Apply();

                _doRepaint   = true;
                _removedItem = null;
            }
        }
예제 #14
0
 public static void StopDrag()
 {
     _draggedItem = null;
 }
예제 #15
0
        private void Flip(DraggableItem data, int index)
        {
            _newIndex = index;

            //Debug.Log("Flip to index: " + index);
            _displayItems.Remove(data);
            _displayItems.Insert(index, data);
            data.Index = index;

            for (int i = 0; i < _displayItems.Count; i++)
            {
                var d = _displayItems[i];
                d.Bounds = d != data ? new Rect(d.Bounds.x, i * ElementHeight, _elementWidth, ElementHeight) : new Rect(d.Bounds.x, d.Bounds.y, _elementWidth, ElementHeight);
            }
        }
예제 #16
0
 public void AddItem(DraggableItem item, ChildGroup group)
 {
     group.Add(item);
 }
예제 #17
0
        public void AddItem(DraggableItem item)
        {
            if (_groups.Count == 0)
                throw new Exception("Not groups defined");

            _groups[0].Add(item);
        }
예제 #18
0
 public static void StopDrag()
 {
     _draggedItem = null;
 }
예제 #19
0
        public void AddItem(DraggableItem item, int groupIndex)
        {
            if (groupIndex > _groups.Count - 1)
                throw new Exception("Out of bounds exception");

            _groups[groupIndex].Add(item);
        }
예제 #20
0
        internal void Render()
        {
            //Debug.Log("Render");
            //_draggedItem = null;
            _doRepaint = false;
            bool dropped = false;
            //int index = 0;

            bool dragStart = false;

            //Debug.Log(">" + _height);

            var oldAlignment = GUI.skin.label.alignment;
            _scrollPosition = GUI.BeginScrollView(
                new Rect(0, 0, _width, _height),
                _scrollPosition,
                new Rect(0, 0, _width - ScrollbarWidth, Data.RenderingItemsCount * ElementHeight));

            GUI.skin.box.alignment = TextAnchor.MiddleLeft;

            if (Data.RenderingItemsCount > 0)
            {
                Color color = GUI.color;
                GUI.color = new Color(0.25f, 0.25f, 0.25f);
                GUI.Box(new Rect(0, 0, _width, Data.RenderingItemsCount * ElementHeight), string.Empty, StyleCache.Instance.Background);
                GUI.color = color;
            }

            //Debug.Log("Data.Count: " + Data.Count);
            _count = 0;

            // render rows
            foreach (DraggableItem data in Data.RenderingItems)
            {
                bool previousState = data.Dragging;

                ItemAction action = data.Render();
                if (action != null)
                {
                    switch (action.Type)
                    {
                        case ItemAction.REMOVE:
                            _removedItem = data;
                            _removedItemIndex = _count;
                            return;
                        case ItemAction.ENABLE:
                            _enabledItem = data;
                            break;
                        case ItemAction.PHASES_CHANGED:
                            _phaseChangedItem = data;
                            break;
                    }
                }

                if (Event.current.type == EventType.Repaint)
                {
                    //GUI.skin = GUI.skin;
                    //_draggingHandle.Draw(new Rect(3, 3, 16, 16), false, false, false, false);
                }

                if (data.Dragging)
                {
                    if (null == _draggedItem)
                    {
                        _oldIndex = data.Index;
                        //Debug.Log("??? " + _oldIndex);
                    }

                    _draggedItem = data;
                    //Debug.Log("*: " + _draggedItem);

                    if (!dragStart)
                    {
                        dragStart = true;
                    }

                    _doRepaint = true;

                    HandleBounds(data);

                    _newIndex = data.Index;
                }
                else if (previousState)
                {
                    dropped = true;
                }

                _count++;
            }

            GUI.skin.box.alignment = oldAlignment;

            GUI.EndScrollView();

            if (null != _draggedItem)
            {
                // bring to front // TODO
                //Data.RemoveItem(_draggedItem);
                //Data.AddItem(_draggedItem);
            }

            if (null != _enabledItem)
            {
                EnabledSignal.Emit(_enabledItem);
                _doRepaint = true;
                _enabledItem = null;
            }
            else if (null != _phaseChangedItem)
            {
                PhaseChangedSignal.Emit(_phaseChangedItem);
                _doRepaint = true;
                _phaseChangedItem = null;
            }

            if (dropped)
            {
                //Data.GetGroupAndItemIndex((int)_newIndex, out _newGroupIndex, out _newItemIndex);
                //Debug.Log("Drop to " + _newIndex);

                int groupIndex;
                int itemIndex;
                GetGroupIndex((int) _newIndex, out groupIndex, out itemIndex);

                //Debug.Log(string.Format("**** Result: grp:{0}, item:{1}", groupIndex, itemIndex));

                //CollectionChangedSignal.Emit(_draggedItem, _newItemIndex, _newGroupIndex);
                PositionChangedSignal.Emit(_draggedItem, itemIndex, groupIndex);

                Apply();

                _doRepaint = true;
                _draggedItem = null;
            }

            if (null != _removedItem)
            {
                int groupIndex;
                int itemIndex;
                GetGroupIndex(_removedItemIndex, out groupIndex, out itemIndex);
                RemoveRow(groupIndex, itemIndex);

                Apply();
                
                _doRepaint = true;
                _removedItem = null;
            }
        }
예제 #21
0
 public ChildGroup RemoveItem(DraggableItem item)
 {
     //Debug.Log("RemoveItem!");
     foreach (ChildGroup group in _groups)
     {
         if (group.Items.Contains(item))
         {
             group.Remove(item);
             return group;
         }
     }
     return null;
 }
예제 #22
0
 private void HandleBounds(DraggableItem data)
 {
     var newIndex = Mathf.Clamp((int)Math.Round((data.Bounds.y) / ElementHeight), 0, Data.RenderingItemsCount - 1);
     if (newIndex != _newIndex)
     {
         //Debug.Log("Flip");
         _newIndex = newIndex;
         Flip(data, newIndex);
     }
 }