Ejemplo n.º 1
0
        /// <summary>
        /// Gets the height of the item.
        /// </summary>
        /// <returns>The item height.</returns>
        /// <param name="item">Item.</param>
        float CalculateItemHeight(TItem item)
        {
            if (defaultItemLayoutGroup == null)
            {
                defaultItemLayoutGroup = DefaultItemCopy.GetComponent <LayoutGroup>();
            }

            float height = 0f;

            if (!IsCanCalculateHeight || ForceAutoHeightCalculation)
            {
                if (defaultItemLayoutGroup != null)
                {
                    DefaultItemCopy.gameObject.SetActive(true);

                    SetData(DefaultItemCopy, item);

                    Utilites.UpdateLayout(defaultItemLayoutGroup);

                    height = LayoutUtility.GetPreferredHeight(DefaultItemCopyRect);

                    DefaultItemCopy.gameObject.SetActive(false);
                }
            }
            else
            {
                SetData(DefaultItemCopy, item);

                height = (DefaultItemCopy as IListViewItemHeight).Height;
            }

            return(height);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Init this instance.
        /// </summary>
        public void Init()
        {
            canvas = Utilites.FindTopmostCanvas(transform).GetComponent <Canvas>();

            Utilites.UpdateLayout(transform.parent.GetComponent <LayoutGroup>());
            transform.parent.GetComponentsInChildren <Splitter>().ForEach(x => x.InitSizes());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the layout.
        /// </summary>
        public void UpdateLayout()
        {
            Utilites.UpdateLayout(Layout);

            if (fitter != null)
            {
                fitter.SetLayoutHorizontal();
                fitter.SetLayoutVertical();
            }
        }
Ejemplo n.º 4
0
        void Start()
        {
            layout = GetComponent <LayoutGroup>();
            if (layout != null)
            {
                Utilites.UpdateLayout(layout);
            }

            Init();
        }
Ejemplo n.º 5
0
        void Start()
        {
            var layout = GetComponent <HorizontalOrVerticalLayoutGroup>();

            if (layout)
            {
                Utilites.UpdateLayout(layout);
            }

            Init();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UIWidgets.StandardLayoutBridge"/> class.
        /// </summary>
        /// <param name="layout">Layout.</param>
        /// <param name="defaultItem">Default item.</param>
        /// <param name="updateContentSizeFitter">Update ContentSizeFitter on direction change.</param>
        public StandardLayoutBridge(HorizontalOrVerticalLayoutGroup layout, RectTransform defaultItem, bool updateContentSizeFitter = true)
        {
            Utilites.UpdateLayout(layout);

            Layout                  = layout;
            DefaultItem             = defaultItem;
            UpdateContentSizeFitter = updateContentSizeFitter;

            isHorizontal = layout is HorizontalLayoutGroup;

            var firstFillerGO        = new GameObject("FirstFiller");
            var firstFillerTransform = firstFillerGO.transform as RectTransform;

            if (firstFillerTransform == null)
            {
                firstFillerTransform = firstFillerGO.AddComponent <RectTransform>();
            }
            firstFillerTransform.SetParent(Layout.transform, false);
            firstFillerTransform.localScale = Vector3.one;
            FirstFiller = firstFillerGO.AddComponent <LayoutElement>();

            var lastFillerGO        = new GameObject("LastFiller");
            var lastFillerTransform = lastFillerGO.transform as RectTransform;

            if (lastFillerTransform == null)
            {
                lastFillerTransform = lastFillerGO.AddComponent <RectTransform>();
            }
            lastFillerTransform.SetParent(Layout.transform, false);
            lastFillerTransform.localScale = Vector3.one;
            LastFiller = lastFillerGO.AddComponent <LayoutElement>();

            var size = GetItemSize();

            if (IsHorizontal)
            {
                firstFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y);
                lastFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y);
            }
            else
            {
                firstFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size.x);
                lastFillerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size.x);
            }

            fitter = Layout.GetComponent <ContentSizeFitter>();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Updates the page buttons.
        /// </summary>
        protected virtual void UpdatePageButtons()
        {
            if (SRDefaultPage == null)
            {
                return;
            }

            DefaultPages.RemoveAll(IsNullComponent);

            if (DefaultPages.Count == Pages)
            {
                return;
            }

            if (DefaultPages.Count < Pages)
            {
                DefaultPagesCache.RemoveAll(IsNullComponent);

                Enumerable.Range(DefaultPages.Count, Pages - DefaultPages.Count).ForEach(AddComponent);

                if (SRNextPage != null)
                {
                    SRNextPage.SetPage(Pages - 1);
                    SRNextPage.transform.SetAsLastSibling();
                }
            }
            else
            {
                var to_cache = DefaultPages.GetRange(Pages, DefaultPages.Count - Pages);                //.OrderByDescending<ScrollRectPage,int>(GetPageNumber);

                to_cache.ForEach(x => x.gameObject.SetActive(false));
                DefaultPagesCache.AddRange(to_cache);
                DefaultPages.RemoveRange(Pages, DefaultPages.Count - Pages);

                if (SRNextPage != null)
                {
                    SRNextPage.SetPage(Pages - 1);
                }
            }

            Utilites.UpdateLayout(DefaultPage.parent.GetComponent <LayoutGroup>());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Raises the drag event.
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void OnDrag(PointerEventData eventData)
        {
            if (!processDrag)
            {
                return;
            }
            if (canvas == null)
            {
                throw new MissingComponentException(gameObject.name + " not in Canvas hierarchy.");
            }
            Cursor.SetCursor(CursorTexture, CursorHotSpot, Utilites.GetCursorMode());

            Vector2 p1;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, eventData.position, CurrentCamera, out p1);
            Vector2 p2;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(RectTransform, eventData.position - eventData.delta, CurrentCamera, out p2);
            var delta = p1 - p2;

            if (delta.x > 0)
            {
                leftTarget.preferredWidth  = Mathf.Min(leftTarget.preferredWidth + delta.x, widthLimit - rightTarget.minWidth);
                rightTarget.preferredWidth = widthLimit - leftTarget.preferredWidth;
            }
            else
            {
                rightTarget.preferredWidth = Mathf.Min(rightTarget.preferredWidth - delta.x, widthLimit - leftTarget.minWidth);
                leftTarget.preferredWidth  = widthLimit - rightTarget.preferredWidth;
            }

            if (layout != null)
            {
                Utilites.UpdateLayout(layout);
            }

            if (OnDragUpdate)
            {
                CalculateWidths();
                Resize();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the height of the item.
        /// </summary>
        /// <returns>The item height.</returns>
        /// <param name="item">Item.</param>
        float CalculateItemHeight(string item)
        {
            if (defaultItemLayoutGroup == null)
            {
                defaultItemLayoutGroup = DefaultItemCopy.GetComponent <LayoutGroup>();
            }

            float height = 0f;

            if (defaultItemLayoutGroup != null)
            {
                DefaultItemCopy.gameObject.SetActive(true);

                DefaultItemCopy.SetData(item);
                Utilites.UpdateLayout(defaultItemLayoutGroup);

                height = LayoutUtility.GetPreferredHeight(DefaultItemCopyRect);

                DefaultItemCopy.gameObject.SetActive(false);
            }

            return(height);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Updates the layout.
 /// </summary>
 protected void UpdateLayout()
 {
     Utilites.UpdateLayout(GetComponent <LayoutGroup>());
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Updates the layout.
 /// </summary>
 public void UpdateLayout()
 {
     Utilites.UpdateLayout(Layout);
 }