コード例 #1
0
ファイル: TabsContainer.cs プロジェクト: thomotron/Phinix
        /// <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);
        }
コード例 #2
0
        public HorizontalPaddedContainer(Displayable child, float height)
        {
            this.child  = child;
            this.height = height;

            // Build a horizontally-padded container with the same content
            this.paddedChild = new HorizontalFlexContainer(0f);
            this.paddedChild.Add(new SpacerWidget());
            this.paddedChild.Add(child);
            this.paddedChild.Add(new SpacerWidget());
        }
コード例 #3
0
        public VerticalPaddedContainer(Displayable child, float width)
        {
            this.child = child;
            this.width = width;

            // Build a vertically-padded container with the same content
            this.paddedChild = new VerticalFlexContainer(0f);
            this.paddedChild.Add(new SpacerWidget());
            this.paddedChild.Add(child);
            this.paddedChild.Add(new SpacerWidget());
        }
コード例 #4
0
        /// <summary>
        /// Adds a tab to the container.
        /// </summary>
        /// <param name="label">Label shown on the tab itself</param>
        /// <param name="displayable">Contents of the tab</param>
        public void AddTab(string label, Displayable displayable)
        {
            // Set the current index to where this new tab will be
            int index = tabs.Count;

            // Create a tab record
            TabRecord tab = new TabRecord(label, () =>
            {
                selectedTab = index;
                onTabChange(index);
            }, selectedTab == index);

            // Add the tab to the tab list
            tabs.Add(new TabEntry {
                tab = tab, displayable = displayable
            });
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <summary>
        /// Creates a new <see cref="TradeRow"/> from the given trade ID.
        /// </summary>
        /// <param name="tradeId">Trade ID</param>
        /// <param name="drawAlternateBackground">Whether to draw an alternate, lighter background</param>
        /// <exception cref="Exception">Failed to get other party's display name</exception>
        /// <exception cref="Exception">Failed to get whether the other party has accepted or not</exception>
        public TradeRow(string tradeId, bool drawAlternateBackground = false)
        {
            this.TradeId = tradeId;
            this.DrawAlternateBackground = drawAlternateBackground;

            // Try get the other party's UUID and display name
            if (!Client.Instance.TryGetOtherPartyUuid(tradeId, out otherPartyUuid) ||
                !Client.Instance.TryGetDisplayName(otherPartyUuid, out cachedOtherPartyDisplayName))
            {
                // Failed to get the other party's display name
                throw new Exception("Failed to get the other party's display name.");
            }

            // Try get the other party's accepted state
            if (!Client.Instance.TryGetPartyAccepted(tradeId, otherPartyUuid, out cachedOtherPartyAccepted))
            {
                // Failed to get the other party's accepted state
                throw new Exception("Failed to get whether the other party has accepted or not.");
            }

            // Generate the content
            this.content = generateTradeRow();
        }
コード例 #7
0
 public Container(Displayable child, float width = FLUID, float height = FLUID)
 {
     this.child  = child;
     this.width  = width;
     this.height = height;
 }
コード例 #8
0
 public VerticalScrollContainer(Displayable child, Action <Vector2> onScroll = null)
 {
     this.child    = child;
     this.onScroll = onScroll;
 }
コード例 #9
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;
                }
            }
        }
コード例 #10
0
 /// <summary>
 /// Adds an <see cref="Displayable"/> item to the container.
 /// </summary>
 /// <param name="item">Drawable item to add</param>
 public void Add(Displayable item)
 {
     Contents.Add(item);
 }
コード例 #11
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;
                }
            }
        }
コード例 #12
0
ファイル: MinimumContainer.cs プロジェクト: thomotron/Phinix
 public MinimumContainer(Displayable child, float minWidth = FLUID, float minHeight = FLUID)
 {
     this.child     = child;
     this.minWidth  = minWidth;
     this.minHeight = minHeight;
 }
コード例 #13
0
 public HorizontalPaddedContainer(Displayable child, float height)
 {
     this.child  = child;
     this.height = height;
 }
コード例 #14
0
 public ConditionalContainer(Displayable childIfTrue, Displayable childIfFalse, Func <bool> condition)
 {
     this.childIfTrue  = childIfTrue;
     this.childIfFalse = childIfFalse;
     this.condition    = condition;
 }
コード例 #15
0
 public VerticalScrollContainer(Displayable child, Vector2 scrollPosition, Action <Vector2> onScroll)
 {
     this.scrollPosition = scrollPosition;
     this.child          = child;
     this.onScroll       = onScroll;
 }
コード例 #16
0
 public VerticalPaddedContainer(Displayable child, float width)
 {
     this.child = child;
     this.width = width;
 }