public static void RenderDoubleProperty(VisualElement container, string name, object value, Action <object> setter) { var field = new DoubleField(name); field.SetValueWithoutNotify((double)value); field.MarkDirtyRepaint(); field.RegisterValueChangedCallback(evt => setter(evt.newValue)); container.Add(field); }
public DecimalField() : base(null, null) { // Set up styling AddToClassList("UdonValueField"); // Create Char Editor and listen for changes DoubleField field = new DoubleField(); field.RegisterValueChangedCallback( e => value = Convert.ToDecimal(e.newValue)); Add(field); }
public override void Enable() { var floatNode = nodeTarget as FloatNode; DoubleField floatField = new DoubleField { value = floatNode.output }; floatField.RegisterValueChangedCallback((v) => { owner.RegisterCompleteObjectUndo("Updated floatNode output"); floatNode.output = (float)v.newValue; }); controlsContainer.Add(floatField); }
public DoubleNode() { Initialize("Double", DefaultNodePosition); var inputField = new DoubleField { label = "x:", value = 0 }; inputField.labelElement.style.minWidth = 0; inputField.RegisterValueChangedCallback(evt => { CodeGraph.Instance.InvalidateSaveButton(); value = evt.newValue; }); inputContainer.Add(inputField); var valuePort = base.InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(float)); valuePort.portName = "value"; AddOutputPort(valuePort, () => $"{value}d"); Refresh(); }
public GraphElement CreateNode(MathNode mathNode) { if (mathNode is MathOperator) { MathOperator add = mathNode as MathOperator; return(CreateMathNode(mathNode, mathNode.name, add.m_Position, 2, 1)); } else if (mathNode is MathStackNode) { MathStackNode mathStackNode = mathNode as MathStackNode; return(CreateStackNode(mathStackNode, mathStackNode.m_Position)); } else if (mathNode is MathFunction) { MathFunction fn = mathNode as MathFunction; Debug.Assert(fn.parameterCount == fn.parameterNames.Length); Node nodeUI = CreateMathNode(mathNode, mathNode.name, mathNode.m_Position, fn.parameterNames.Length, 1); for (int i = 0; i < fn.parameterNames.Length; ++i) { (nodeUI.inputContainer.ElementAt(i) as Port).portName = fn.parameterNames[i]; } return(nodeUI); } else if (mathNode is IMathBookFieldNode) { IMathBookFieldNode mathBookFieldNode = mathNode as IMathBookFieldNode; SimpleTokenNode tokenNode = new SimpleTokenNode(mathBookFieldNode); tokenNode.SetPosition(new Rect(mathNode.m_Position, Vector2.zero)); tokenNode.RefreshPorts(); tokenNode.visible = true; return(tokenNode); } else if (mathNode is MathConstant) { MathConstant mathConstant = mathNode as MathConstant; Node nodeUI = CreateMathNode( mathNode, mathConstant.name, mathConstant.m_Position, 0, 1); var field = new DoubleField() { value = mathConstant.m_Value }; field.SetEnabled(!(mathConstant is PIConstant)); field.RegisterValueChangedCallback(evt => mathConstant.m_Value = (float)evt.newValue); nodeUI.inputContainer.Add(field); nodeUI.RefreshExpandedState(); return(nodeUI); } else if (mathNode is MathResult) { MathResult mathResult = mathNode as MathResult; Node nodeUI = CreateMathNode( mathNode, "Result", mathResult.m_Position, 1, 0); nodeUI.inputContainer.Add(new Button(() => Debug.Log(mathResult.Evaluate())) { text = "Print result" }); return(nodeUI); } else if (mathNode is MathGroupNode) { MathGroupNode mathGroupNode = mathNode as MathGroupNode; if (mathGroupNode.m_IsScope) { return(CreateScope(mathGroupNode, mathGroupNode.m_Position)); } else { return(CreateGroupNode(mathGroupNode, mathGroupNode.m_Title, mathGroupNode.m_Position)); } } return(null); }
BuilderStyleRow CreateAttributeRow(UxmlAttributeDescription attribute) { var attributeType = attribute.GetType(); // Generate field label. var fieldLabel = BuilderNameUtilities.ConvertDashToHuman(attribute.name); BindableElement fieldElement; if (attribute is UxmlStringAttributeDescription) { // Hard-coded if (attribute.name.Equals("value") && currentVisualElement is EnumField enumField) { var uiField = new EnumField("Value"); if (null != enumField.value) { uiField.Init(enumField.value, enumField.includeObsoleteValues); } else { uiField.SetValueWithoutNotify(null); } uiField.RegisterValueChangedCallback(evt => PostAttributeValueChange(uiField, uiField.value.ToString())); fieldElement = uiField; } else if (attribute.name.Equals("value") && currentVisualElement is TagField tagField) { var uiField = new TagField("Value"); uiField.RegisterValueChangedCallback(evt => PostAttributeValueChange(uiField, uiField.value.ToString())); fieldElement = uiField; } else { var uiField = new TextField(fieldLabel); if (attribute.name.Equals("name") || attribute.name.Equals("view-data-key")) { uiField.RegisterValueChangedCallback(e => { OnValidatedAttributeValueChange(e, BuilderNameUtilities.attributeRegex, BuilderConstants.AttributeValidationSpacialCharacters); }); } else if (attribute.name.Equals("binding-path")) { uiField.RegisterValueChangedCallback(e => { OnValidatedAttributeValueChange(e, BuilderNameUtilities.bindingPathAttributeRegex, BuilderConstants.BindingPathAttributeValidationSpacialCharacters); }); } else { uiField.RegisterValueChangedCallback(OnAttributeValueChange); } if (attribute.name.Equals("text") || attribute.name.Equals("label")) { uiField.multiline = true; uiField.AddToClassList(BuilderConstants.InspectorMultiLineTextFieldClassName); } fieldElement = uiField; } } else if (attribute is UxmlFloatAttributeDescription) { var uiField = new FloatField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlDoubleAttributeDescription) { var uiField = new DoubleField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlIntAttributeDescription) { if (attribute.name.Equals("value") && currentVisualElement is LayerField) { var uiField = new LayerField("Value"); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute.name.Equals("value") && currentVisualElement is LayerMaskField) { var uiField = new LayerMaskField("Value"); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else { var uiField = new IntegerField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } } else if (attribute is UxmlLongAttributeDescription) { var uiField = new LongField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlBoolAttributeDescription) { var uiField = new Toggle(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlColorAttributeDescription) { var uiField = new ColorField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attributeType.IsGenericType && !attributeType.GetGenericArguments()[0].IsEnum && attributeType.GetGenericArguments()[0] is Type) { var desiredType = attributeType.GetGenericArguments()[0]; var uiField = new TextField(fieldLabel) { isDelayed = true }; var completer = new FieldSearchCompleter <TypeInfo>(uiField); uiField.RegisterCallback <AttachToPanelEvent, FieldSearchCompleter <TypeInfo> >((evt, c) => { // When possible, the popup should have the same width as the input field, so that the auto-complete // characters will try to match said input field. c.popup.anchoredControl = ((VisualElement)evt.target).Q(className: "unity-text-field__input"); }, completer); completer.matcherCallback += (str, info) => info.value.IndexOf(str, StringComparison.OrdinalIgnoreCase) >= 0; completer.itemHeight = 36; completer.dataSourceCallback += () => { return(TypeCache.GetTypesDerivedFrom(desiredType) .Where(t => !t.IsGenericType) // Remove UIBuilder types from the list .Where(t => t.Assembly != GetType().Assembly) .Select(GetTypeInfo)); }; completer.getTextFromDataCallback += info => info.value; completer.makeItem = () => s_TypeNameItemPool.Get(); completer.destroyItem = e => { if (e is BuilderAttributeTypeName typeItem) { s_TypeNameItemPool.Release(typeItem); } }; completer.bindItem = (v, i) => { if (v is BuilderAttributeTypeName l) { l.SetType(completer.results[i].type, completer.textField.text); } }; uiField.RegisterValueChangedCallback(e => OnValidatedTypeAttributeChange(e, desiredType)); fieldElement = uiField; uiField.RegisterCallback <DetachFromPanelEvent, FieldSearchCompleter <TypeInfo> >((evt, c) => { c.popup.RemoveFromHierarchy(); }, completer); uiField.userData = completer; } else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum) { var propInfo = attributeType.GetProperty("defaultValue"); var defaultEnumValue = propInfo.GetValue(attribute, null) as Enum; if (defaultEnumValue.GetType().GetCustomAttribute <FlagsAttribute>() == null) { // Create and initialize the EnumField. var uiField = new EnumField(fieldLabel); uiField.Init(defaultEnumValue); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else { // Create and initialize the EnumField. var uiField = new EnumFlagsField(fieldLabel); uiField.Init(defaultEnumValue); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } } else { var uiField = new TextField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } // Create row. var styleRow = new BuilderStyleRow(); styleRow.Add(fieldElement); // Link the field. fieldElement.SetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName, styleRow); fieldElement.SetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName, attribute); // Set initial value. RefreshAttributeField(fieldElement); // Setup field binding path. fieldElement.bindingPath = attribute.name; fieldElement.tooltip = attribute.name; // Context menu. fieldElement.AddManipulator(new ContextualMenuManipulator(BuildAttributeFieldContextualMenu)); return(styleRow); }
BuilderStyleRow CreateAttributeRow(UxmlAttributeDescription attribute) { var attributeType = attribute.GetType(); // Generate field label. var fieldLabel = BuilderNameUtilities.ConvertDashToHuman(attribute.name); BindableElement fieldElement; if (attribute is UxmlStringAttributeDescription) { var uiField = new TextField(fieldLabel); if (attribute.name.Equals("name") || attribute.name.Equals("view-data-key")) { uiField.RegisterValueChangedCallback(e => { OnValidatedAttributeValueChange(e, BuilderNameUtilities.AttributeRegex, BuilderConstants.AttributeValidationSpacialCharacters); }); } else if (attribute.name.Equals("binding-path")) { uiField.RegisterValueChangedCallback(e => { OnValidatedAttributeValueChange(e, BuilderNameUtilities.BindingPathAttributeRegex, BuilderConstants.BindingPathAttributeValidationSpacialCharacters); }); } else { uiField.RegisterValueChangedCallback(OnAttributeValueChange); } if (attribute.name.Equals("text")) { uiField.multiline = true; uiField.AddToClassList(BuilderConstants.InspectorMultiLineTextFieldClassName); } fieldElement = uiField; } else if (attribute is UxmlFloatAttributeDescription) { var uiField = new FloatField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlDoubleAttributeDescription) { var uiField = new DoubleField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlIntAttributeDescription) { var uiField = new IntegerField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlLongAttributeDescription) { var uiField = new LongField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlBoolAttributeDescription) { var uiField = new Toggle(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlColorAttributeDescription) { var uiField = new ColorField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attributeType.IsGenericType && !attributeType.GetGenericArguments()[0].IsEnum && attributeType.GetGenericArguments()[0] is Type) { var uiField = new TextField(fieldLabel); uiField.isDelayed = true; uiField.RegisterValueChangedCallback(e => { OnValidatedTypeAttributeChange(e, attributeType.GetGenericArguments()[0]); }); fieldElement = uiField; } else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum) { var propInfo = attributeType.GetProperty("defaultValue"); var enumValue = propInfo.GetValue(attribute, null) as Enum; // Create and initialize the EnumField. var uiField = new EnumField(fieldLabel); uiField.Init(enumValue); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else { var uiField = new TextField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } // Create row. var styleRow = new BuilderStyleRow(); styleRow.Add(fieldElement); // Link the field. fieldElement.SetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName, styleRow); fieldElement.SetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName, attribute); // Set initial value. RefreshAttributeField(fieldElement); // Setup field binding path. fieldElement.bindingPath = attribute.name; // Tooltip. var label = fieldElement.Q <Label>(); if (label != null) { label.tooltip = attribute.name; } else { fieldElement.tooltip = attribute.name; } // Context menu. fieldElement.AddManipulator(new ContextualMenuManipulator(BuildAttributeFieldContextualMenu)); return(styleRow); }
BuilderStyleRow CreateAttributeRow(UxmlAttributeDescription attribute) { var attributeType = attribute.GetType(); var vea = currentVisualElement.GetVisualElementAsset(); // Generate field label. var fieldLabel = BuilderNameUtilities.ConvertDashToHuman(attribute.name); BindableElement fieldElement = null; if (attribute is UxmlStringAttributeDescription) { var uiField = new TextField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlFloatAttributeDescription) { var uiField = new FloatField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlDoubleAttributeDescription) { var uiField = new DoubleField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlIntAttributeDescription) { var uiField = new IntegerField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlLongAttributeDescription) { var uiField = new LongField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlBoolAttributeDescription) { var uiField = new Toggle(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attribute is UxmlColorAttributeDescription) { var uiField = new ColorField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum) { var propInfo = attributeType.GetProperty("defaultValue"); var enumValue = propInfo.GetValue(attribute, null) as Enum; // Create and initialize the EnumField. var uiField = new EnumField(fieldLabel); uiField.Init(enumValue); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } else { var uiField = new TextField(fieldLabel); uiField.RegisterValueChangedCallback(OnAttributeValueChange); fieldElement = uiField; } // Create row. var styleRow = new BuilderStyleRow(); styleRow.Add(fieldElement); // Link the field. fieldElement.SetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName, styleRow); fieldElement.SetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName, attribute); // Set initial value. RefreshAttributeField(fieldElement); // Setup field binding path. fieldElement.bindingPath = attribute.name; // Tooltip. var label = fieldElement.Q <Label>(); if (label != null) { label.tooltip = attribute.name; } else { fieldElement.tooltip = attribute.name; } // Context menu. fieldElement.AddManipulator(new ContextualMenuManipulator(BuildAttributeFieldContextualMenu)); return(styleRow); }