FairyGUI.GList.ScrollToView C# (CSharp) Method

ScrollToView() public method

Scroll the list to make an item with certain index visible.
public ScrollToView ( int index, bool ani, bool setFirst ) : void
index int Item index
ani bool True to scroll smoothly, othewise immdediately.
setFirst bool If true, scroll to make the target on the top/left; If false, scroll to make the target any position in view.
return void
        public void ScrollToView(int index, bool ani, bool setFirst)
        {
            if (_virtual)
            {
                if (_numItems == 0)
                    return;

                CheckVirtualList();

                if (index >= _virtualItems.Count)
                    throw new Exception("Invalid child index: " + index + ">" + _virtualItems.Count);

                if (_loop)
                    index = Mathf.FloorToInt(_firstIndex / _numItems) * _numItems + index;

                Rect rect;
                ItemInfo ii = _virtualItems[index];
                if (_layout == ListLayoutType.SingleColumn || _layout == ListLayoutType.FlowHorizontal)
                {
                    float pos = 0;
                    for (int i = 0; i < index; i += _curLineItemCount)
                        pos += _virtualItems[i].size.y + _lineGap;
                    rect = new Rect(0, pos, _itemSize.x, ii.size.y);
                }
                else if (_layout == ListLayoutType.SingleRow || _layout == ListLayoutType.FlowVertical)
                {
                    float pos = 0;
                    for (int i = 0; i < index; i += _curLineItemCount)
                        pos += _virtualItems[i].size.x + _columnGap;
                    rect = new Rect(pos, 0, ii.size.x, _itemSize.y);
                }
                else
                {
                    int page = index / (_curLineItemCount * _curLineItemCount2);
                    rect = new Rect(page * viewWidth + (index % _curLineItemCount) * (ii.size.x + _columnGap),
                        (index / _curLineItemCount) % _curLineItemCount2 * (ii.size.y + _lineGap),
                        ii.size.x, ii.size.y);
                }

                setFirst = true;//因为在可变item大小的情况下,只有设置在最顶端,位置才不会因为高度变化而改变,所以只能支持setFirst=true
                if (this.scrollPane != null)
                    scrollPane.ScrollToView(rect, ani, setFirst);
                else if (parent != null && parent.scrollPane != null)
                    parent.scrollPane.ScrollToView(this.TransformRect(rect, parent), ani, setFirst);
            }
            else
            {
                GObject obj = GetChildAt(index);
                if (this.scrollPane != null)
                    scrollPane.ScrollToView(obj, ani, setFirst);
                else if (parent != null && parent.scrollPane != null)
                    parent.scrollPane.ScrollToView(obj, ani, setFirst);
            }
        }

Same methods

GList::ScrollToView ( int index ) : void
GList::ScrollToView ( int index, bool ani ) : void

Usage Example

示例#1
0
 static public int ScrollToView(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             FairyGUI.GList self = (FairyGUI.GList)checkSelf(l);
             System.Int32   a1;
             checkType(l, 2, out a1);
             self.ScrollToView(a1);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 3)
         {
             FairyGUI.GList self = (FairyGUI.GList)checkSelf(l);
             System.Int32   a1;
             checkType(l, 2, out a1);
             System.Boolean a2;
             checkType(l, 3, out a2);
             self.ScrollToView(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             FairyGUI.GList self = (FairyGUI.GList)checkSelf(l);
             System.Int32   a1;
             checkType(l, 2, out a1);
             System.Boolean a2;
             checkType(l, 3, out a2);
             System.Boolean a3;
             checkType(l, 4, out a3);
             self.ScrollToView(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
All Usage Examples Of FairyGUI.GList::ScrollToView