Beispiel #1
0
 /// <summary>
 /// Returns the minimum of all the vector components as a new vector.
 /// </summary>
 /// <param name="a">First vector.</param>
 /// <param name="b">Second vector.</param>
 /// <returns>Vector consisting of minimum components of the first and second vector.</returns>
 public static Vector3 Min(Vector3 a, Vector3 b)
 {
     return(new Vector3(MathEx.Min(a.x, b.x), MathEx.Min(a.y, b.y), MathEx.Min(a.z, b.z)));
 }
Beispiel #2
0
        /// <inheritdoc/>
        public override void Update()
        {
            int numVisibleEntries = MathEx.CeilToInt(height / (float)entryHeight) + 1;

            numVisibleEntries = MathEx.Min(numVisibleEntries, entries.Count);

            while (visibleEntries.Count < numVisibleEntries)
            {
                TEntry newEntry = new TEntry();
                newEntry.Initialize(this);
                newEntry.panel.SetHeight(entryHeight);

                visibleEntries.Add(newEntry);
                contentsDirty = true;
            }

            while (numVisibleEntries < visibleEntries.Count)
            {
                int lastIdx = visibleEntries.Count - 1;

                visibleEntries[lastIdx].Destroy();
                visibleEntries.RemoveAt(lastIdx);

                contentsDirty = true;
            }

            if (scrollPct != scrollArea.VerticalScroll)
            {
                scrollPct     = scrollArea.VerticalScroll;
                contentsDirty = true;
            }

            if (contentsDirty)
            {
                int newHeight = entries.Count * entryHeight;
                if (scrollToLatest)
                {
                    if (totalHeight > height && scrollPct < 1.0f)
                    {
                        scrollToLatest = false;
                    }
                }
                else
                {
                    if (totalHeight <= height || scrollPct >= 1.0f)
                    {
                        scrollToLatest = true;
                    }
                }

                totalHeight = newHeight;
                int maxScrollOffset = MathEx.Max(0, totalHeight - height - 1);

                int startPos   = MathEx.FloorToInt(scrollPct * maxScrollOffset);
                int startIndex = MathEx.FloorToInt(startPos / (float)entryHeight);

                // Check if we're at the list bottom and the extra element is out of bounds
                if ((startIndex + visibleEntries.Count) > entries.Count)
                {
                    startIndex--; // Keep the extra element at the top always
                }
                topPadding.SetHeight(startIndex * entryHeight);

                for (int i = 0; i < visibleEntries.Count; i++)
                {
                    visibleEntries[i].UpdateContents(startIndex + i, entries[startIndex + i]);
                    visibleEntries[i].panel.SetPosition(0, i * entryHeight);
                }

                int bottomPosition = MathEx.Min(totalHeight, (startIndex + visibleEntries.Count) * entryHeight);
                bottomPadding.SetHeight(totalHeight - bottomPosition);

                if (scrollToLatest)
                {
                    if (newHeight <= height)
                    {
                        scrollArea.VerticalScroll = 0.0f;
                    }
                    else
                    {
                        scrollArea.VerticalScroll = 1.0f;
                    }
                }

                contentsDirty = false;
            }
        }
Beispiel #3
0
        /// <inheritdoc/>
        public override void Update()
        {
            int numVisibleEntries = MathEx.CeilToInt(height / (float)entryHeight) + 1;

            numVisibleEntries = MathEx.Min(numVisibleEntries, entries.Count);

            while (visibleEntries.Count < numVisibleEntries)
            {
                TEntry newEntry = new TEntry();
                newEntry.Initialize(this);
                newEntry.panel.SetHeight(entryHeight);

                visibleEntries.Add(newEntry);
                contentsDirty = true;
            }

            while (numVisibleEntries < visibleEntries.Count)
            {
                int lastIdx = visibleEntries.Count - 1;

                visibleEntries[lastIdx].Destroy();
                visibleEntries.RemoveAt(lastIdx);

                contentsDirty = true;
            }

            if (scrollPct != scrollArea.VerticalScroll)
            {
                scrollPct     = scrollArea.VerticalScroll;
                contentsDirty = true;
            }

            if (contentsDirty)
            {
                int newHeight = entries.Count * entryHeight;
                if (scrollToLatest)
                {
                    if (totalHeight > height && scrollPct < 1.0f)
                    {
                        scrollToLatest = false;
                    }
                }
                else
                {
                    if (totalHeight <= height || scrollPct >= 1.0f)
                    {
                        scrollToLatest = true;
                    }
                }

                totalHeight = newHeight;
                int maxScrollOffset = MathEx.Max(0, totalHeight - height - 1);

                float newScrollPct;
                if (!scrollToLatest)
                {
                    // Calculate the new scroll pct (which will be active after we change the top/bottom padding element
                    // sizes). If we use the existing scroll pct instead then the elements will lag one frame behind, which
                    // can be very noticeable on quickly updating lists.
                    newScrollPct = (scrollPct * scrollArea.Layout.Bounds.height) / totalHeight;
                }
                else
                {
                    newScrollPct = 1.0f;
                }

                int startPos   = MathEx.FloorToInt(newScrollPct * maxScrollOffset);
                int startIndex = MathEx.FloorToInt(startPos / (float)entryHeight);

                // Check if we're at the list bottom and the extra element is out of bounds
                if ((startIndex + visibleEntries.Count) > entries.Count)
                {
                    startIndex--; // Keep the extra element at the top always
                }
                topPadding.SetHeight(startIndex * entryHeight);

                for (int i = 0; i < visibleEntries.Count; i++)
                {
                    visibleEntries[i].UpdateContents(startIndex + i, entries[startIndex + i]);
                }

                int bottomPosition = MathEx.Min(totalHeight, (startIndex + visibleEntries.Count) * entryHeight);
                bottomPadding.SetHeight(totalHeight - bottomPosition);

                if (scrollToLatest)
                {
                    if (newHeight <= height)
                    {
                        scrollArea.VerticalScroll = 0.0f;
                    }
                    else
                    {
                        scrollArea.VerticalScroll = 1.0f;
                    }
                }

                contentsDirty = false;
            }
        }
Beispiel #4
0
 /// <summary>
 /// Calculates an angle between two rotations.
 /// </summary>
 /// <param name="a">First rotation.</param>
 /// <param name="b">Second rotation.</param>
 /// <returns>Angle between the rotations, in degrees.</returns>
 public static Degree Angle(Quaternion a, Quaternion b)
 {
     return(MathEx.Acos(MathEx.Min(MathEx.Abs(Dot(a, b)), 1.0f)) * 2.0f);
 }
Beispiel #5
0
 /// <summary>
 /// Returns the minimum of all the vector components as a new vector.
 /// </summary>
 /// <param name="a">First vector.</param>
 /// <param name="b">Second vector.</param>
 /// <returns>Vector consisting of minimum components of the first and second vector.</returns>
 public static Vector2 Min(Vector2 a, Vector2 b)
 {
     return(new Vector2(MathEx.Min(a.x, b.x), MathEx.Min(a.y, b.y)));
 }