Ejemplo n.º 1
0
        /// <inheritdoc />
        public override void Draw(Rect inRect)
        {
            // Calculate the overflowed size the children will take
            // Only supports y-overflow at the moment
            float widthChild  = inRect.width - SCROLL_BAR_WIDTH;
            float heightChild = child.CalcHeight(widthChild);

            if (heightChild == FLUID)
            {
                // If the child is height-fluid, we attribute all available space
                heightChild = inRect.height;
            }

            // Create an inner container that will hold the scrollable content
            Rect viewRect = new Rect(inRect.xMin, inRect.yMin, widthChild, heightChild);

            // Get a copy of the current scroll position
            Vector2 previousScrollPosition = new Vector2(scrollPosition.x, scrollPosition.y);

            // Begin scrolling
            Widgets.BeginScrollView(inRect, ref scrollPosition, viewRect);

            // Draw the contents
            child.Draw(viewRect);

            // Stop scrolling
            Widgets.EndScrollView();

            // Check if the scroll position changed
            if (!scrollPosition.Equals(previousScrollPosition))
            {
                // Invoke the scroll callback
                onScroll?.Invoke(scrollPosition);
            }
        }
Ejemplo n.º 2
0
 /// <inheritdoc />
 public override float CalcHeight(float width)
 {
     if (IsFluidHeight)
     {
         return(FLUID);
     }
     else
     {
         return(Math.Max(minHeight, child.CalcHeight(width)));
     }
 }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public override float CalcHeight(float width)
        {
            // We can't determine a height if the child is fluid
            if (child.IsFluidHeight)
            {
                return(FLUID);
            }

            // Compensate for the scrollbar width
            return(child.CalcHeight(width) + SCROLL_BAR_WIDTH);
        }
Ejemplo n.º 4
0
 /// <inheritdoc />
 public override void Draw(Rect inRect)
 {
     // Check if the child is non-fluid and smaller than the allocated space
     if (!child.IsFluidHeight && inRect.height > child.CalcHeight(inRect.width))
     {
         // Draw the child with padding above and below
         paddedChild.Draw(inRect);
     }
     else
     {
         // Just draw the child, there's no padding to be done here
         child.Draw(inRect);
     }
 }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public override void Draw(Rect inRect)
        {
            // Check if the child is non-fluid and smaller than the allocated space
            if (!child.IsFluidHeight && inRect.height > child.CalcHeight(inRect.width))
            {
                // Create a flex container to hold the child and spacers
                VerticalFlexContainer column = new VerticalFlexContainer(0f);

                // Sandwich the child between two spacers
                column.Add(new SpacerWidget());
                column.Add(child);
                column.Add(new SpacerWidget());

                // Draw the container
                column.Draw(inRect);
            }
            else
            {
                // Just draw the child, there's no padding to be done here
                child.Draw(inRect);
            }
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public override void Draw(Rect container)
        {
            // Don't do anything if there's nothing to draw
            if (Contents.Count == 0)
            {
                return;
            }

            // Get the height taken up by fixed-height elements
            float fixedHeight = Contents.Where(item => !item.IsFluidHeight).Sum(item => item.CalcHeight(container.width));

            // Divvy out the remaining height to each fluid element
            float remainingHeight = container.height - fixedHeight;

            remainingHeight -= (Contents.Count - 1) * spacing; // Remove spacing between each element
            int   fluidItems     = Contents.Count(item => item.IsFluidHeight);
            float heightPerFluid = remainingHeight / fluidItems;

            // Draw each item
            float yOffset = 0f;

            for (int i = 0; i < Contents.Count; i++)
            {
                Displayable item = Contents[i];
                Rect        rect;

                // Give fluid items special treatment
                if (item.IsFluidHeight)
                {
                    // Give the item a container with a share of the remaining height
                    rect = new Rect(
                        x: container.xMin,
                        y: container.yMin + yOffset,
                        width: container.width,
                        height: heightPerFluid
                        );
                }
                else
                {
                    // Give the item a container with fixed width and dynamic height
                    rect = new Rect(
                        x: container.xMin,
                        y: container.yMin + yOffset,
                        width: container.width,
                        height: item.CalcHeight(container.width)
                        );
                }

                // Draw the item
                item.Draw(rect);

                // Increment the y offset by the item's height
                yOffset += rect.height;

                // Add spacing to the y offset if applicable
                if (i < Contents.Count - 1)
                {
                    yOffset += spacing;
                }
            }
        }