public void GoToStep(int index) { // Set the active step's context frame up mContextFrame.First.ClearChildWidgets(); mContextFrame.First.AddChildWidget(mSteps[index].ContextFrame, mContextSizePosition); // Setup the progress bar mProgressFrame.First.ClearChildWidgets(); float verticalOffset = 0.0f; for (int i = 0; i < mSteps.Count; ++i) { FixedPosition nextStepPosition = new FixedPosition(0.0f, verticalOffset); if (i == index) { // Draw the active step as whatever frame has been provided mProgressFrame.First.AddChildWidget(mSteps[i].ProgressFrame, nextStepPosition); mSteps[i].Enabled = true; verticalOffset += mSteps[i].ProgressFrame.Size.y; } else { // Draw the non-active steps as label-buttons string stepLabel = (i + 1) + ". " + mSteps[i].Name; Button progressLabelButton = new Button("ProgressLabel" + i, mProgressLabelSize, mProgressLabelStyle, stepLabel); SetupGoToStepButton(progressLabelButton, index, i); progressLabelButton.Enabled = mSteps[i].Enabled; mProgressFrame.First.AddChildWidget(progressLabelButton, nextStepPosition); verticalOffset += mProgressLabelHeight; } } }
public void SetPositionsWithBorderPadding(IEnumerable <IWidget> widgets, int rows, int columns, int startingIndex, int horizontalFramePadding, int verticalFramePadding, int innerButtonPadding) { if (widgets == null) { throw new ArgumentNullException("widgets"); } mGridWidgets = new List <IWidget>(widgets); if (mGridWidgets.Count == 0) { return; } if (rows < 1 || columns < 1) { throw new ArgumentOutOfRangeException("Rows(" + rows + ") and columns(" + columns + ") must be greater than 0."); } if (mGridWidgets.Count < 1) { throw new ArgumentException("mGridWidgets is empty."); } if (startingIndex < 0 || startingIndex > mGridWidgets.Count) { throw new ArgumentOutOfRangeException("startingIndex(" + startingIndex + ") must be positive and less than mGridWidgets.Count(" + mGridWidgets.Count + "."); } mRows = rows; mColumns = columns; Vector2 gridPosition = Vector2.zero; int endIndex = startingIndex + (rows * columns); if (endIndex > mGridWidgets.Count) { endIndex = mGridWidgets.Count; } mActiveWidgets.Clear(); int i = 0; for (int index = startingIndex; index < endIndex; ++index) { IWidget widget = mGridWidgets[index]; float xPosition = (i % columns) * (widget.Size.x + innerButtonPadding) + horizontalFramePadding; float yPosition = (i / columns) * (widget.Size.y + innerButtonPadding) + verticalFramePadding; gridPosition = new Vector2(xPosition, yPosition); IGuiPosition elementPosition = new FixedPosition(gridPosition); KeyValuePair <IWidget, IGuiPosition> elementPair = new KeyValuePair <IWidget, IGuiPosition>(mGridWidgets[index], elementPosition); mActiveWidgets.Add(elementPair); i++; } SetCurrentPage(startingIndex); }
public static FixedPosition BuildFixedPosition(string x, string y, XmlNode node) { FixedPosition result = null; if (x == null) { throw new ArgumentNullException("x"); } if (y == null) { throw new ArgumentNullException("y"); } if (node == null) { throw new ArgumentNullException("node"); } try { GuiAnchor localAnchor = BuildAnchor(node, "anchor"); if (node.Attributes["parentAnchor"] != null) { GuiAnchor parentAnchor = BuildAnchor(node, "parentAnchor"); result = new FixedPosition(new Vector2(float.Parse(x), float.Parse(y)), localAnchor, parentAnchor); } else { result = new FixedPosition(new Vector2(float.Parse(x), float.Parse(y)), localAnchor); } } catch (FormatException) { throw new GuiConstructionException("Attempted to create a FixedPosition IGuiPosition from a node that doesn't parse to (float) X, (float) Y."); } return(result); }
public void SetPositions(IEnumerable <IWidget> widgets, int rows, int columns, int startingIndex) { if (widgets == null) { throw new ArgumentNullException("widgets"); } mGridWidgets = new List <IWidget>(widgets); if (mGridWidgets.Count == 0) { return; } if (rows < 1 || columns < 1) { throw new ArgumentOutOfRangeException("Rows(" + rows + ") and columns(" + columns + ") must be greater than 0."); } if (mGridWidgets.Count < 1) { throw new ArgumentException("mGridWidgets is empty."); } if (startingIndex < 0 || startingIndex > mGridWidgets.Count) { throw new ArgumentOutOfRangeException("startingIndex(" + startingIndex + ") must be positive and less than mGridWidgets.Count(" + mGridWidgets.Count + "."); } if (columns > 1) { mGridElementWidth = (this.InternalSize.x) / columns; } else { mGridElementWidth = (this.InternalSize.x); } if (rows > 1) { mGridElementHeight = (this.InternalSize.y) / rows; } else { mGridElementHeight = (this.InternalSize.y); } mRows = rows; mColumns = columns; Vector2 gridPosition = Vector2.zero; int endIndex = startingIndex + (rows * columns); if (endIndex > mGridWidgets.Count) { endIndex = mGridWidgets.Count; } mActiveWidgets.Clear(); int i = 0; for (int index = startingIndex; index < endIndex; ++index) { float xPosition = (i % columns) * mGridElementWidth; float yPosition = (i / columns) * mGridElementHeight; gridPosition = new Vector2(xPosition, yPosition); IGuiPosition elementPosition = new FixedPosition(gridPosition); KeyValuePair <IWidget, IGuiPosition> elementPair = new KeyValuePair <IWidget, IGuiPosition>(mGridWidgets[index], elementPosition); mActiveWidgets.Add(elementPair); i++; } SetCurrentPage(startingIndex); }