IEnumerator<PopupChoices> ShowPopup() { var label = "Enter new project name:"; var choices = new PopupChoices(); choices.NewProjectName = "Untitled"; PmView.InputDialogStates state = PmView.InputDialogStates.None; bool isFirst = true; var popupId = _view.AddPopup(delegate(Rect fullRect) { if (Event.current.type == EventType.KeyDown) { switch (Event.current.keyCode) { case KeyCode.Return: { state = PmView.InputDialogStates.Submitted; break; } case KeyCode.Escape: { state = PmView.InputDialogStates.Cancelled; break; } } } var popupRect = ImguiUtil.CenterRectInRect(fullRect, _settings.PopupSize); _view.DrawPopupCommon(fullRect, popupRect); var contentRect = ImguiUtil.CreateContentRectWithPadding( popupRect, _pmSettings.InputDialog.PanelPadding); GUILayout.BeginArea(contentRect); { GUILayout.Label(label, _pmSettings.InputDialog.LabelStyle); GUI.SetNextControlName("PopupTextField"); choices.NewProjectName = GUILayout.TextField(choices.NewProjectName, 100); GUI.SetNextControlName(""); GUILayout.Space(5); GUILayout.BeginHorizontal(); { choices.DuplicateSettings = GUILayout.Toggle(choices.DuplicateSettings, "", GUILayout.Height(_settings.CheckboxHeight)); GUILayout.Label("Share Project Settings with '{0}'".Fmt(ProjenyEditorUtil.GetCurrentProjectName())); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); if (GUILayout.Button("Submit", GUILayout.MaxWidth(100))) { state = PmView.InputDialogStates.Submitted; } if (GUILayout.Button("Cancel", GUILayout.MaxWidth(100))) { state = PmView.InputDialogStates.Cancelled; } } GUILayout.EndHorizontal(); } GUILayout.EndArea(); if (isFirst) { isFirst = false; // Need to remove focus then regain focus on the text box for it to select the whole contents GUI.FocusControl(""); } else if (string.IsNullOrEmpty(GUI.GetNameOfFocusedControl())) { GUI.FocusControl("PopupTextField"); } }); while (state == PmView.InputDialogStates.None) { yield return null; } _view.RemovePopup(popupId); if (state == PmView.InputDialogStates.Submitted) { yield return choices; } else { // Just return null } }
IEnumerator <PopupChoices> ShowPopup() { var label = "Enter new project name:"; var choices = new PopupChoices(); choices.NewProjectName = "Untitled"; PmView.InputDialogStates state = PmView.InputDialogStates.None; bool isFirst = true; var popupId = _view.AddPopup(delegate(Rect fullRect) { if (Event.current.type == EventType.KeyDown) { switch (Event.current.keyCode) { case KeyCode.Return: { state = PmView.InputDialogStates.Submitted; break; } case KeyCode.Escape: { state = PmView.InputDialogStates.Cancelled; break; } } } var popupRect = ImguiUtil.CenterRectInRect(fullRect, _settings.PopupSize); _view.DrawPopupCommon(fullRect, popupRect); var contentRect = ImguiUtil.CreateContentRectWithPadding( popupRect, _pmSettings.InputDialog.PanelPadding); GUILayout.BeginArea(contentRect); { GUILayout.Label(label, _pmSettings.InputDialog.LabelStyle); GUI.SetNextControlName("PopupTextField"); choices.NewProjectName = GUILayout.TextField(choices.NewProjectName, 100); GUI.SetNextControlName(""); GUILayout.Space(5); GUILayout.BeginHorizontal(); { choices.DuplicateSettings = GUILayout.Toggle(choices.DuplicateSettings, "", GUILayout.Height(_settings.CheckboxHeight)); GUILayout.Label("Share Project Settings with '{0}'".Fmt(ProjenyEditorUtil.GetCurrentProjectName())); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); if (GUILayout.Button("Submit", GUILayout.MaxWidth(100))) { state = PmView.InputDialogStates.Submitted; } if (GUILayout.Button("Cancel", GUILayout.MaxWidth(100))) { state = PmView.InputDialogStates.Cancelled; } } GUILayout.EndHorizontal(); } GUILayout.EndArea(); if (isFirst) { isFirst = false; // Need to remove focus then regain focus on the text box for it to select the whole contents GUI.FocusControl(""); } else if (string.IsNullOrEmpty(GUI.GetNameOfFocusedControl())) { GUI.FocusControl("PopupTextField"); } }); while (state == PmView.InputDialogStates.None) { yield return(null); } _view.RemovePopup(popupId); if (state == PmView.InputDialogStates.Submitted) { yield return(choices); } else { // Just return null } }