public void DoText(Vector2 position, TextDrawData data) { if (Mode == ImguiMode.Render) { SpriteBatch.DrawString(data.Font, data.Text, position, data.Color); } }
public bool DoTextButton(Vector2 position, TextDrawData textData, Color background) { Vector2 padding = new Vector2(6f, 3f); Vector2 size = textData.Font.MeasureString(textData.Text) + 2f * padding; switch (Mode) { case ImguiMode.Update: { return(Input.GetMode(position, size) == InputMouseMode.Clicked); } case ImguiMode.Render: { Color backgroundColor = background; InputMouseMode mouseMode = Input.GetMode(position, size); // Shift the color for Hover and Down { int change = 60; if (mouseMode == InputMouseMode.Hover) { backgroundColor = PushColor(backgroundColor, change); } else if (mouseMode == InputMouseMode.Down) { backgroundColor = PushColor(backgroundColor, -change); } } // Draw bars around the box. Vector2 barSize = new Vector2(3); { int change = 60; Color barColor = PushColor(backgroundColor, change); // Top DrawFilledBox(position, size.X, barSize.Y, barColor); // Left DrawFilledBox(position + new Vector2(0f, barSize.Y), barSize.X, size.Y - barSize.Y, barColor); barColor = PushColor(backgroundColor, -change); // Bottom DrawFilledBox(position + new Vector2(barSize.X, size.Y - barSize.Y), size.X - barSize.X, barSize.Y, barColor); // Right DrawFilledBox(position + new Vector2(size.X - barSize.X, barSize.Y), barSize.X, size.Y - 2f * barSize.Y, barColor); } DrawFilledBox(position + barSize, size.X - 2 * barSize.X, size.Y - 2 * barSize.Y, backgroundColor); SpriteBatch.DrawString(textData.Font, textData.Text, position + padding, textData.Color); return(false); } default: throw new Exception("Case not handled"); } }
public int DoDropDown(ref bool isOpen, TextDrawData textData, List <string> options, int selectedIndex) { Debug.Assert(scroll == null); int dropDownHeight = textData.Font.LineSpacing; if (isOpen) { dropDownHeight += options.Count * textData.Font.LineSpacing; } Debug.Assert(dropDownHeight <= GetRemainingHeight()); int result = imgui.DoDropDown(currentPosition, Width, dropDownHeight, ref isOpen, textData, options, selectedIndex); currentPosition.Y += dropDownHeight; return(result); }
public void DoText(TextDrawData data) { int itemHeight = data.Font.LineSpacing; if (scroll == null) { imgui.DoText(currentPosition, data); currentPosition.Y += itemHeight; } else { if (scroll.ScrollIt(itemHeight, currentPosition)) { imgui.DoText(currentPosition, data); currentPosition.Y += itemHeight; } } }
public int DoDropDown(Vector2 position, int width, int height, ref bool isOpen, TextDrawData textData, List <string> options, int selectedIndex) { // Note(ian): Do this first so that the click for the text button doesn't get picked up again here. int result = -1; if (Mode == ImguiMode.Update && isOpen) { if (Input.GetMode(position, new Vector2(width, height)) == InputMouseMode.Clicked) { float yOffset = Input.Mouse.Y - position.Y; int optionStart = textData.Font.LineSpacing; int i; for (i = 0; i < options.Count; i++) { if (optionStart < yOffset && yOffset <= optionStart + textData.Font.LineSpacing) { result = i; isOpen = false; } optionStart += textData.Font.LineSpacing; } } } Panel dropDown = new Panel(this, position, width, height); dropDown.DoText(textData); position.X += textData.Font.MeasureString(textData.Text).X; if (DoTextButton(position, new TextDrawData("v", textData.Font, textData.Color), Color.DarkMagenta)) { isOpen = !isOpen; } // TODO(ian): Can we get the button width somehow? position.X += 25; DoText(position, new TextDrawData(options[selectedIndex], textData.Font, textData.Color)); position.Y += textData.Font.LineSpacing; if (isOpen) { // TODO(ian): Add some spacing and a border for the drop down. // Todo(ian): Draw and update here. int dropDownScrollValue = 0;// TODO(ian): where do i get this from? dropDown.BeginScrollableSection(dropDownScrollValue); foreach (string category in options) { dropDown.DoText(new TextDrawData(category, textData.Font, textData.Color)); } dropDown.EndScrollableSection(ref dropDownScrollValue); } return(result); }