public void AddItem(string text, object userData = null, string toolTip = "") { if (selectMultiple) { var frame = new GUIFrame(new RectTransform(new Point(button.Rect.Width, button.Rect.Height), listBox.Content.RectTransform) { IsFixedSize = false }, style: "ListBoxElement") { UserData = userData, ToolTip = toolTip }; new GUITickBox(new RectTransform(new Vector2(1.0f, 0.8f), frame.RectTransform, anchor: Anchor.CenterLeft) { MaxSize = new Point(int.MaxValue, (int)(button.Rect.Height * 0.8f)) }, text) { UserData = userData, ToolTip = toolTip, OnSelected = (GUITickBox tb) => { List <string> texts = new List <string>(); selectedDataMultiple.Clear(); selectedIndexMultiple.Clear(); int i = 0; foreach (GUIComponent child in ListBox.Content.Children) { var tickBox = child.GetChild <GUITickBox>(); if (tickBox.Selected) { selectedDataMultiple.Add(child.UserData); selectedIndexMultiple.Add(i); texts.Add(tickBox.Text); } i++; } button.Text = string.Join(", ", texts); // TODO: The callback is called at least twice, remove this? OnSelected?.Invoke(tb.Parent, tb.Parent.UserData); return(true); } }; } else { new GUITextBlock(new RectTransform(new Point(button.Rect.Width, button.Rect.Height), listBox.Content.RectTransform) { IsFixedSize = false }, text, style: "ListBoxElement") { UserData = userData, ToolTip = toolTip }; } }
private bool OnClicked(GUIComponent component, object obj) { if (wasOpened) { return(false); } wasOpened = true; Dropped = !Dropped; if (Dropped) { if (Enabled) { OnDropped?.Invoke(this, userData); } if (parent.children[parent.children.Count - 1] != this) { parent.children.Remove(this); parent.children.Add(this); } } return(true); }
private bool OnClicked(GUIComponent component, object obj) { if (wasOpened) { return(false); } wasOpened = true; Dropped = !Dropped; if (Dropped && Enabled) { OnDropped?.Invoke(this, userData); listBox.UpdateScrollBarSize(); } return(true); }
private bool OnClicked(GUIComponent component, object obj) { if (wasOpened) { return(false); } wasOpened = true; Dropped = !Dropped; if (Dropped && Enabled) { OnDropped?.Invoke(this, userData); listBox.UpdateScrollBarSize(); GUI.KeyboardDispatcher.Subscriber = this; } else if (GUI.KeyboardDispatcher.Subscriber == this) { GUI.KeyboardDispatcher.Subscriber = null; } return(true); }