private void DoLayout(string[] defaultText, bool isNumeric, NumericMode numericMode = NumericMode.Natural) { if (Components.Count > 0) { Components.Clear(); } columns = maxItemsPerRow == -1 ? defaultText.Length : Mathf.Min(defaultText.Length, maxItemsPerRow); float totalWidth = Size.x / columns; float hSpace = totalWidth * horizontalSpace; float contentWidth = columns == 1 ? totalWidth : totalWidth - hSpace; rows = maxItemsPerRow == -1 ? 1 : Mathf.CeilToInt(defaultText.Length / maxItemsPerRow); float totalHeight = Size.y / rows; float vSpace = totalHeight * verticalSpace; float contentheight = rows == 1 ? totalHeight : totalHeight - vSpace; TextBoxes = new TextBox[defaultText.Length]; Vector2 size = new Vector2(contentWidth, contentheight); int row = 0; int column = 0; for (int i = 0; i < defaultText.Length; i++) { float x; if (column == 0) { x = 0; } else if (column < columns) { x = totalWidth * column + hSpace / 2; } else { x = Size.x - size.x; } float y; if (row == 0) { y = 0; } else if (row < rows) { y = totalHeight * row + vSpace / 2; } else { y = Size.y - size.y; } TextBoxes[i] = DaggerfallUI.AddTextBoxWithFocus(new Rect(new Vector2(x, y), size), defaultText[i], this); TextBoxes[i].Numeric = isNumeric; TextBoxes[i].NumericMode = numericMode; TextBoxes[i].UseFocus = true; TextBoxes[i].Outline.Enabled = enableOutline; if (OnAddTextBoxCallback != null) { OnAddTextBoxCallback(TextBoxes[i]); } if (++column == columns) { row++; column = 0; } } }
/// <summary> /// Setup a multi-control with empty text boxes. /// </summary> /// <param name="size">Number of textboxes.</param> /// <param name="isNumeric">Accept only numeric chars.</param> public void DoLayout(int size, bool isNumeric = false, NumericMode numericMode = NumericMode.Natural) { DoLayout(Enumerable.Range(0, size).Select(x => string.Empty).ToArray(), isNumeric, numericMode); }