public static void DropdownButton(string id, ref int selected, IReadOnlyList <DropdownOption> options) { ImGui.PushID(id); bool clicked = false; string text = $"{options[selected].Icon} {options[selected].Name} "; var textSize = ImGui.CalcTextSize(text); var cpos = ImGuiNative.igGetCursorPosX(); var cposY = ImGuiNative.igGetCursorPosY(); clicked = ImGui.Button($"{options[selected].Icon} {options[selected].Name} "); var style = ImGui.GetStyle(); var tPos = new Vector2(cpos, cposY) + new Vector2(textSize.X + style.FramePadding.X, textSize.Y); Theme.TinyTriangle(tPos.X, tPos.Y); if (clicked) { ImGui.OpenPopup(id + "#popup"); } if (ImGui.BeginPopup(id + "#popup")) { ImGui.MenuItem(id, false); for (int i = 0; i < options.Count; i++) { var opt = options[i]; if (Theme.IconMenuItem(opt.Icon, opt.Name, true)) { selected = i; } } ImGui.EndPopup(); } ImGui.PopID(); }
public static void DropdownButton(string id, ref int selected, IReadOnlyList <DropdownOption> options) { ImGui.PushID(id); bool clicked = false; const string PADDING = " "; string text = PADDING + ImGuiExt.IDSafe(options[selected].Name) + " "; var w = ImGui.CalcTextSize(text).X; clicked = ImGui.Button(text); ImGui.SameLine(); var cpos = ImGuiNative.igGetCursorPosX(); var cposY = ImGuiNative.igGetCursorPosY(); Theme.TinyTriangle(cpos - 15, cposY + 15); ImGuiNative.igSetCursorPosX(cpos - w - 13); ImGuiNative.igSetCursorPosY(cposY + 2); Theme.Icon(options[selected].Icon, Color4.White); ImGui.SameLine(); ImGuiNative.igSetCursorPosY(cposY); ImGui.SetCursorPosX(cpos - 6); ImGui.Dummy(Vector2.Zero); if (clicked) { ImGui.OpenPopup(id + "#popup"); } if (ImGui.BeginPopup(id + "#popup")) { ImGui.MenuItem(id, false); for (int i = 0; i < options.Count; i++) { var opt = options[i]; if (Theme.IconMenuItem(opt.Name, opt.Icon, Color4.White, true)) { selected = i; } } ImGui.EndPopup(); } ImGui.PopID(); }