/// <summary> /// A list box with a textbox as the drop down text, a button for the toggle, /// and some text to display the currently selected line. /// </summary> /// <param name="dropDownIcon">The icon to use to the right of the text for displaying the textbox.</param> /// <param name="scrollTexture">The icon to use for the scroll bar.</param> /// <param name="font">The font to use for both the textbox and the text.</param> /// <param name="items">The items to place in the textbox.</param> /// <param name="selectedLine">The default selected line for the textbox.</param> public ListBox(Texture dropDownIcon, Texture scrollTexture, BMFont font, string[] items, int selectedLine = 0) { this.items = items; this.dropDownToggle = new Button(dropDownIcon); this.dropDownToggle.RelativeTo = Corner.TopRight; this.dropDownToggle.Position = new Point(0, (this.Size.Y - this.dropDownToggle.Size.Y) / 2); this.AddElement(dropDownToggle); this.dropDownBox = new TextBox(font, scrollTexture, selectedLine); foreach (var item in items) { dropDownBox.WriteLine(item); } dropDownBox.CurrentLine = 0; this.dropDownBox.AllowSelection = true; dropDownToggle.OnMouseClick = new OnMouse((o, e) => { dropDownVisible = !dropDownVisible; if (dropDownVisible) { Parent.AddElement(dropDownBox); dropDownBox.AllowScrollBar = (items.Length > 4); } else { Parent.RemoveElement(dropDownBox); dropDownBox.AllowScrollBar = false; } }); dropDownBox.OnSelectionChanged = new OnMouse((o, e) => text.String = dropDownBox.SelectedLineText); dropDownToggle.OnLoseFocus = new OnFocus(OnLoseFocusInternal); dropDownBox.OnLoseFocus = new OnFocus(OnLoseFocusInternal); this.OnLoseFocus = new OnFocus(OnLoseFocusInternal); // need to wait until after dropDownBox is initialized this.Font = font; this.SelectedLine = selectedLine; this.AddElement(text); }
private void BuildVAOs() { // we're about the replace the VAO objects, so clear them first for (int i = 0; i < vaos.Count; i++) { vaos[i].Dispose(); vaos[i] = null; } vaos.Clear(); // check if we should show the scrollbar if (lines.Count > MaximumLines && allowScrollBar && scrollBar != null) { if (scrollBar.Name == null || !UserInterface.Elements.ContainsKey(scrollBar.Name)) { Parent.AddElement(scrollBar); } } else if (Parent != null && scrollBar != null) { Parent.RemoveElement(scrollBar); } // now build the VAO objects for (int i = CurrentLine; i <= MaximumLines + CurrentLine; i++) { if (i >= lines.Count || i < 0) { break; } if (lines[i].Count == 0) { continue; } var current = lines[i][0]; string contents = ""; for (int j = 0; j < lines[i].Count; j++) { if (current.Color != lines[i][j].Color || current.Font != lines[i][j].Font) { if (contents.Length != 0) { BuildVAO(current, contents); } current = lines[i][j]; contents = lines[i][j].Text; } else { contents += lines[i][j].Text; } } if (contents.Length != 0) { BuildVAO(current, contents); } } CalculateVisibilityTime(); dirty = false; }