private static T Add <T>(VisualElement parent, PseudoStates pseudo = 0) where T : VisualElement, new() { var element = new T(); element.pseudoStates |= pseudo; if ((pseudo & PseudoStates.Disabled) == PseudoStates.Disabled) { element.SetEnabled(false); } ApplyModificationsToInputs(element, BaseField <int> .inputUssClassName, pseudo); IgnoreAllInputsRecursive(element); var description = pseudo.ToString(); if (pseudo == 0) { description = "Normal"; } if (element is TextElement) { (element as TextElement).text = description; } else if (element is BaseField <bool> ) { (element as BaseField <bool>).label = description; } else if (element is BaseField <float> ) { (element as BaseField <float>).label = description; } else if (element is BaseField <string> ) { (element as BaseField <string>).label = description; } else if (element is BaseField <Vector3> ) { (element as BaseField <Vector3>).label = description; } else if (element is BaseField <Rect> ) { (element as BaseField <Rect>).label = description; } else if (element is Foldout) { var foldout = element as Foldout; foldout.text = description; foldout.value = (pseudo & PseudoStates.Checked) == PseudoStates.Checked; var contents = new Label("Content with Border"); contents.AddToClassList(s_StyleFoldoutClassName); foldout.Add(contents); } parent.Add(element); return(element); }
private static T Add <T>(VisualElement parent, PseudoStates pseudo = 0) where T : VisualElement, new() { var element = new T(); // Pseudo states get cleared on attaching to panel, so this must be done each time that happens. // Doing it just when we create the window doesn't work because when docked, all views docked in the same // place share the panel and get attached/detached as we switch tabs. element.RegisterCallback <AttachToPanelEvent>(evt => { element.pseudoStates |= pseudo; // The children will still attach to panel, so we need to delay the uQuery call until that's done. element.schedule.Execute(() => ApplyModificationsToInputs(element, BaseField <int> .inputUssClassName, pseudo)); }); if ((pseudo & PseudoStates.Disabled) == PseudoStates.Disabled) { element.SetEnabled(false); } IgnoreAllInputsRecursive(element); var description = pseudo.ToString(); if (pseudo == 0) { description = "Normal"; } if (element is TextElement) { (element as TextElement).text = description; } else if (element is BaseField <bool> ) { (element as BaseField <bool>).label = description; } else if (element is BaseField <float> ) { (element as BaseField <float>).label = description; } else if (element is BaseField <string> ) { (element as BaseField <string>).label = description; } else if (element is BaseField <Vector3> ) { (element as BaseField <Vector3>).label = description; } else if (element is BaseField <Rect> ) { (element as BaseField <Rect>).label = description; } else if (element is Foldout) { var foldout = element as Foldout; foldout.text = description; foldout.value = (pseudo & PseudoStates.Checked) == PseudoStates.Checked; var contents = new Label("Content with Border"); contents.AddToClassList(s_StyleFoldoutClassName); foldout.Add(contents); } else if (element is HelpBox) { var helpBox = element as HelpBox; helpBox.text = description; helpBox.messageType = HelpBoxMessageType.Info; } parent.Add(element); return(element); }