예제 #1
0
        /// <inheritdoc />
        public override void Draw(Rect inRect)
        {
            // We calculate the overflowed size the children will take
            // Only supports x-overflow at the moment
            float widthChild  = child.CalcWidth(inRect.height);
            float heightChild = inRect.height - SCROLL_BAR_WIDTH;

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

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

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

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

            // Stop scrolling
            Widgets.EndScrollView();

            // Invoke the scroll callback
            onScroll?.Invoke(scrollPosition);
        }
예제 #2
0
 /// <inheritdoc />
 public override float CalcWidth(float height)
 {
     if (IsFluidWidth)
     {
         return(FLUID);
     }
     else
     {
         return(Math.Max(minWidth, child.CalcWidth(height)));
     }
 }
예제 #3
0
 /// <inheritdoc />
 public override void Draw(Rect inRect)
 {
     // Check if the child is non-fluid and smaller than the allocated space
     if (!child.IsFluidWidth && inRect.width > child.CalcWidth(inRect.height))
     {
         // Draw the child with padding on either side
         paddedChild.Draw(inRect);
     }
     else
     {
         // Just draw the child, there's no padding to be done here
         child.Draw(inRect);
     }
 }
예제 #4
0
        /// <inheritdoc />
        public override void Draw(Rect inRect)
        {
            // Check if the child is non-fluid and smaller than the allocated space
            if (!child.IsFluidWidth && inRect.width > child.CalcWidth(inRect.height))
            {
                // Create a flex container to hold the child and spacers
                HorizontalFlexContainer row = new HorizontalFlexContainer(0f);

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

                // Draw the container
                row.Draw(inRect);
            }
            else
            {
                // Just draw the child, there's no padding to be done here
                child.Draw(inRect);
            }
        }
예제 #5
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 width taken up by fixed-width elements
            float fixedWidth = Contents.Where(item => !item.IsFluidWidth).Sum(item => item.CalcWidth(container.height));

            // Divvy out the remaining width to each fluid element
            float remainingWidth = container.width - fixedWidth;

            remainingWidth -= (Contents.Count - 1) * spacing; // Remove spacing between each element
            int   fluidItems    = Contents.Count(item => item.IsFluidWidth);
            float widthPerFluid = remainingWidth / fluidItems;

            // Draw each item
            float xOffset = 0f;

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

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

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

                // Increment the x offset by the item's width
                xOffset += rect.width;

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