/// <inheritdoc /> protected override float DrawLabel(Rect rect, object currentValue, Action <object> changeValueCallback, GUIContent label) { INamedData nameable = currentValue as INamedData; List <EditorReportEntry> reports = GetValidationReports(currentValue); if (reports.Count > 0) { Rect warningRect = rect; warningRect.width = 20; rect.x += 20; GUI.Label(warningRect, AddValidationInformation(new GUIContent(), reports)); } if (currentValue.GetType() != typeof(IStepData)) { DrawName(rect, nameable); } else { DrawRenameable(rect, nameable, changeValueCallback); } return(rect.height); }
public virtual GUIContent GetLabel(object value, Type declaredType) { INamedData nameable = value as INamedData; if (nameable == null || string.IsNullOrEmpty(nameable.Name)) { return(new GUIContent(string.Empty)); } return(new GUIContent(nameable.Name)); }
private void DrawName(Rect rect, INamedData nameable) { GUIStyle labelStyle = new GUIStyle(EditorStyles.label) { fontStyle = FontStyle.Bold, fontSize = 12, padding = new RectOffset(4, 0, 0, 0) }; EditorGUI.LabelField(rect, GetTypeNameLabel(nameable, nameable.GetType()), labelStyle); }
/// <inheritdoc /> protected override float DrawLabel(Rect rect, object currentValue, Action <object> changeValueCallback, GUIContent label) { INamedData nameable = currentValue as INamedData; Rect nameRect = rect; nameRect.width = EditorGUIUtility.labelWidth; Rect typeRect = rect; typeRect.x += EditorGUIUtility.labelWidth; typeRect.width -= EditorGUIUtility.labelWidth; GUIStyle textFieldStyle = new GUIStyle(EditorStyles.textField) { fontStyle = FontStyle.Bold, fontSize = 12 }; string newName = EditorGUI.DelayedTextField(nameRect, nameable.Name, textFieldStyle); GUIStyle labelStyle = new GUIStyle(EditorStyles.label) { fontStyle = FontStyle.Bold, fontSize = 12 }; EditorGUI.LabelField(typeRect, GetTypeNameLabel(nameable, nameable.GetType()), labelStyle); if (newName != nameable.Name) { string oldName = nameable.Name; nameable.Name = newName; ChangeValue(() => { nameable.Name = newName; return(nameable); }, () => { nameable.Name = oldName; return(nameable); }, changeValueCallback); } return(rect.height); }
private void DrawRenameable(Rect rect, INamedData nameable, Action <object> changeValueCallback) { Rect nameRect = rect; nameRect.width = EditorGUIUtility.labelWidth; Rect typeRect = rect; typeRect.x += EditorGUIUtility.labelWidth; typeRect.width -= EditorGUIUtility.labelWidth; GUIStyle textFieldStyle = new GUIStyle(EditorStyles.textField) { fontStyle = FontStyle.Bold, fontSize = 12 }; string newName = EditorGUI.DelayedTextField(nameRect, nameable.Name, textFieldStyle); GUIStyle labelStyle = new GUIStyle(EditorStyles.label) { fontStyle = FontStyle.Bold, fontSize = 12, padding = new RectOffset(4, 0, 0, 0) }; EditorGUI.LabelField(typeRect, GetTypeNameLabel(nameable, nameable.GetType()), labelStyle); if (newName != nameable.Name) { string oldName = nameable.Name; nameable.Name = newName; ChangeValue(() => { nameable.Name = newName; return(nameable); }, () => { nameable.Name = oldName; return(nameable); }, changeValueCallback); } }
public static ChangeNamePopup Open(INamedData nameable, Rect labelPosition, Vector2 offset) { if (instance != null) { instance.Close(); } instance = CreateInstance <ChangeNamePopup>(); instance.nameable = nameable; instance.newName = nameable.Name; instance.position = new Rect(labelPosition.x - offset.x, labelPosition.y - offset.y, labelPosition.width, labelPosition.height); instance.ShowPopup(); instance.Focus(); AssemblyReloadEvents.beforeAssemblyReload += () => { instance.Close(); instance.IsClosed = true; }; return(instance); }