/// <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); }
/// <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); } }
/// <inheritdoc /> public override void Draw(Rect inRect) { // Do nothing if there's no tabs if (tabs.Count == 0) { return; } // Ok, so for whatever reason the tabs are drawn /above/ whatever region you give them (why?!) // To work around this we just trim the tab height off of the container rect inRect = inRect.BottomPartPixels(inRect.height - TabDrawer.TabHeight); // We draw the top with tabs TabRecord selectedRecord = TabDrawer.DrawTabs(inRect, tabs.Select(e => e.tab).ToList()); // Change the selected record if it was clicked if (selectedRecord != null) { selectedTab = tabs.IndexOf(tabs.Single(tabEntry => tabEntry.tab.label == selectedRecord.label)); onTabChange?.Invoke(selectedTab); } // We draw the selected tab Displayable selectedDisplayable = tabs[selectedTab].displayable; selectedDisplayable.Draw(inRect); }
/// <inheritdoc /> public override void Draw(Rect inRect) { // Draw a background highlight if (DrawAlternateBackground) { Widgets.DrawHighlight(inRect); } // Draw the row content.Draw(inRect); }
/// <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); } }
/// <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); } }
/// <inheritdoc /> public override void Draw(Rect inRect) { if (!IsFluidHeight) { // Clip the rect to the container's height inRect = inRect.TopPartPixels(height); } if (!IsFluidWidth) { // Clip the rect to the container's width inRect = inRect.LeftPartPixels(width); } // Draw the container's contents child.Draw(inRect); }
/// <inheritdoc /> public override void Draw(Rect inRect) { // Do nothing if there's no tabs if (tabs.Count == 0) { return; } // Ok, so for whatever reason the tabs are drawn /above/ whatever region you give them (why?!) // To work around this we just trim the tab height off of the container rect inRect = inRect.BottomPartPixels(inRect.height - TabDrawer.TabHeight); // We draw the top with tabs TabDrawer.DrawTabs(inRect, tabs.Select(e => e.tab).ToList()); // We draw the selected tab Displayable selectedDisplayable = tabs[selectedTab].displayable; selectedDisplayable.Draw(inRect); }
/// <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); } }
/// <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); } }
/// <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; } } }
/// <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; } } }
/// <inheritdoc /> public override void Draw(Rect inRect) { // Draw the container's contents child.Draw(inRect); }