public EditorIntSliderField(string label, int value, int min, int max, EventCallback <ChangeEvent <int> > callback) { sliderInt = new SliderInt(label, min, max, SliderDirection.Horizontal); sliderInt.name = nameof(sliderInt); sliderInt.value = value; labelElement.StylePadding(0, 8, 0, 0); Add(sliderInt); integerField = new IntegerField(); integerField.name = nameof(integerField); integerField.StyleWidth(64); integerField.style.paddingLeft = 4; integerField.style.marginRight = 0; integerField.value = value; integerField.RegisterValueChangedCallback(callback); integerField.RegisterValueChangedCallback((callbackChangedSlider) => { sliderInt.value = callbackChangedSlider.newValue; }); sliderInt.Add(integerField); sliderInt.RegisterValueChangedCallback((callbackSlide) => { integerField.value = callbackSlide.newValue; }); }
public static IntegerField CollectionSizeField <TProperty, TContainer, TValue>( TProperty property, ref TContainer container, ref TValue value, InspectorVisitorContext visitorContext) where TProperty : ICollectionProperty <TContainer, TValue> { var field = new IntegerField { name = "CollectionSize", label = "Size", bindingPath = string.Empty, isDelayed = true }; field.SetValueWithoutNotify(property.GetCount(ref container)); SetTooltip(property.Attributes, field); var parent = visitorContext.Parent; visitorContext.Parent.contentContainer.Add(field); field.RegisterValueChangedCallback(evt => { visitorContext.Binding.SetCount(parent, Mathf.Clamp(evt.newValue, 0, int.MaxValue)); }); return(field); }
}//generar la barra de botones de la ventana del editor private void GenerateSecondaryToolbar() { Toolbar l_secondaryToolbar = new Toolbar(); Button l_generateRandomDungeonButton = new Button(); l_generateRandomDungeonButton.text = "Generate Random Dungeon"; l_generateRandomDungeonButton.clickable.clicked += () => GenerateRandomDungeon(); l_secondaryToolbar.Add(l_generateRandomDungeonButton); IntegerField l_maxNumberOfRoomsIntField = new IntegerField(); l_maxNumberOfRoomsIntField.tooltip = "Max Number of Rooms instantiated on the dungeon"; l_maxNumberOfRoomsIntField.label = "Max number of rooms"; l_maxNumberOfRoomsIntField.RegisterValueChangedCallback(evt => m_numberOfRoomsToGenerate = evt.newValue); l_secondaryToolbar.Add(l_maxNumberOfRoomsIntField); IntegerField l_maxNumberOfFloorsField = new IntegerField(); l_maxNumberOfFloorsField.tooltip = "Max Number of floors on the dungeon"; l_maxNumberOfFloorsField.label = "Max number of floors"; l_maxNumberOfFloorsField.RegisterValueChangedCallback(evt => m_numberOfFloorsToGenerate = evt.newValue); l_secondaryToolbar.Add(l_maxNumberOfFloorsField); Button l_clearAllNodesOnGrapButton = new Button(); l_clearAllNodesOnGrapButton.text = "Clear All"; l_clearAllNodesOnGrapButton.clickable.clicked += () => ClearAllNodesOnGraph(); l_secondaryToolbar.Add(l_clearAllNodesOnGrapButton); rootVisualElement.Add(l_secondaryToolbar); }//barra generacion aleatoria
public void BindElements() { m_BoneNameField = this.Q <TextField>("BoneNameField"); m_BoneDepthField = this.Q <IntegerField>("BoneDepthField"); m_BoneNameField.RegisterValueChangedCallback(BoneNameChanged); m_BoneDepthField.RegisterValueChangedCallback(BoneDepthChanged); }
public IListElement() { Resources.Templates.ListElement.Clone(this); Resources.Templates.ListElementDefaultStyling.AddStyles(this); binding = this; m_Size = new IntegerField(); m_Size.AddToClassList(UssClasses.ListElement.Size); m_Size.RegisterValueChangedCallback(CountChanged); m_Size.RegisterCallback <KeyDownEvent>(TrapKeys); m_Size.isDelayed = true; var toggle = this.Q <Toggle>(); var toggleInput = toggle.Q(className: UssClasses.Unity.ToggleInput); toggleInput.AddToClassList(UssClasses.ListElement.ToggleInput); toggle.Add(m_Size); m_AddItemButton = new Button(OnAddItem) { text = "+ Add Element" }; m_AddItemButton.AddToClassList(UssClasses.ListElement.AddItemButton); m_ContentRoot = new VisualElement(); m_ContentRoot.name = "properties-list-content"; m_PaginationElement = new PaginationElement(); Add(m_PaginationElement); Add(m_ContentRoot); Add(m_AddItemButton); }
internal VisualElement CreateGUI( ValueChangedCallback valueChangedCallback, int fieldToDraw, string labelName, out VisualElement propertyFloatField, int indentLevel = 0) { var integerField = new IntegerField { value = fieldToDraw }; if (valueChangedCallback != null) { integerField.RegisterValueChangedCallback(evt => { valueChangedCallback(evt.newValue); }); } propertyFloatField = integerField; var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel)); defaultRow.Add(propertyFloatField); defaultRow.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyRow")); return(defaultRow); }
void LoadTemplate() { AddToClassList("timeField"); m_FieldName = new Label(); m_FieldName.AddToClassList("timeFieldNameLabel"); Add(m_FieldName); var inputContainer = new VisualElement(); inputContainer.AddToClassList("timeFieldInputContainer"); Add(inputContainer); m_SecondsField = new FloatField("Seconds"); m_SecondsField.AddToClassList("timeInput"); m_SecondsField.RegisterValueChangedCallback(OnTimeInSecondsChanged); inputContainer.Add(m_SecondsField); m_FrameField = new IntegerField("Frame"); m_FrameField.AddToClassList("timeInput"); m_FrameField.RegisterValueChangedCallback(OnFrameChanged); inputContainer.Add(m_FrameField); SyncToViewModeSetting(); RegisterCallback <AttachToPanelEvent>(OnAttachToPanel); RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel); }
public ContentBox() { m_TextContainer = new VisualElement(); m_TextContainer.AddToClassList("box-model-content-text-container"); m_WidthTextField = new IntegerField(); m_WidthTextField.AddToClassList("box-model-textfield"); m_HeightTextField = new IntegerField(); m_HeightTextField.AddToClassList("box-model-textfield"); m_XLabel = new Label("x"); m_TextContainer.Add(m_WidthTextField); m_TextContainer.Add(m_XLabel); m_TextContainer.Add(m_HeightTextField); m_WidthTextField.value = 0; m_HeightTextField.value = 0; m_WidthTextField.RegisterValueChangedCallback(OnWidthChanged); m_HeightTextField.RegisterValueChangedCallback(OnHeightChanged); Add(m_TextContainer); // Sync styles values schedule.Execute(SyncValues).Every(100); }
public IntegerSlider() : base() { slider.RegisterValueChangedCallback(evt => { field.value = value = evt.newValue; }); slider.style.minWidth = 50; field.RegisterValueChangedCallback(evt => { slider.value = value = evt.newValue; }); field.style.minWidth = 80; }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var field = new UIntField { label = property.displayName, value = (uint)property.longValue }; //Binding does not work on this custom UI Element field that we have created, so we need to use the change event field.RegisterValueChangedCallback(evt => { field.value = evt.newValue; property.longValue = evt.newValue; property.serializedObject.ApplyModifiedProperties(); }); // Create a surrogate integer field to detect and pass along external change events (non UI event) on the underlying serialized property. var surrogateField = new IntegerField(); field.Add(surrogateField); surrogateField.style.display = DisplayStyle.None; surrogateField.bindingPath = property.propertyPath; surrogateField.RegisterValueChangedCallback(evt => { evt.StopImmediatePropagation(); field.value = UIntField.ClampInput(property.longValue); }); return(field); }
protected override void DrawNode(ModuleGraphView graphView) { Debug.Log(Script.SceneIndex); var inputPort = graphView.GeneratePort <float>(this, Direction.Input, Port.Capacity.Multi); inputPort.portName = "Input"; inputContainer.Add(inputPort); AddToClassList("action"); var outputPort = graphView.GeneratePort <float>(this, Direction.Output); outputPort.portName = "Output"; outputContainer.Add(outputPort); IntegerField intField = new IntegerField("Scene Index", 2); intField.value = Script.SceneIndex; intField.RegisterValueChangedCallback(evt => { var temp = evt.newValue < 0 ? 0 : evt.newValue > 99 ? 99 : evt.newValue; intField.SetValueWithoutNotify(temp); Script.SceneIndex = temp; graphView.SetDirty(); }); extensionContainer.Add(intField); graphView.RefreshNode(this); graphView.AddElement(this); }
void AddField(Vector4 initialValue, int index, string subLabel) { var dummy = new VisualElement { name = "dummy" }; var label = new Label(subLabel); dummy.Add(label); Add(dummy); var field = new IntegerField { userData = index, value = (int)initialValue[index] }; var dragger = new FieldMouseDragger <int>(field); dragger.SetDragZone(label); field.Q("unity-text-input").RegisterCallback <KeyDownEvent>(evt => { // Record Undo for input field edit if (m_UndoGroup == -1) { m_UndoGroup = Undo.GetCurrentGroup(); m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name); } // Handle scaping input field edit if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1) { Undo.RevertAllDownToGroup(m_UndoGroup); m_UndoGroup = -1; evt.StopPropagation(); } // Dont record Undo again until input field is unfocused m_UndoGroup++; this.MarkDirtyRepaint(); }); // Called after KeyDownEvent field.RegisterValueChangedCallback(evt => { // Only true when setting value via FieldMouseDragger // Undo recorded once per dragger release if (m_UndoGroup == -1) { m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name); } var value = m_Get(); if (value[index] != (float)evt.newValue) { value[index] = (float)evt.newValue; m_Set(value); m_Node.Dirty(ModificationScope.Node); } }); // Reset UndoGroup when done editing input field & update title field.Q("unity-text-input").RegisterCallback <FocusOutEvent>(evt => { m_Node.owner.owner.isDirty = true; m_UndoGroup = -1; }); Add(field); }
private VisualElement CreateSampleItemInt(SampleItemInt item) { var field = new IntegerField(nameof(SampleItemInt.IntValue)); field.value = item.IntValue; field.RegisterValueChangedCallback(e => item.IntValue = e.newValue); return(field); }
private VisualElement CreateInt(IDictionary dictionary, string key) { var field = new IntegerField(key); field.value = (int)dictionary[key]; field.RegisterValueChangedCallback(e => dictionary[key] = e.newValue); return(field); }
private VisualElement CreateInt(IList list, int index) { var field = new IntegerField(); field.value = (int)list[index]; field.RegisterValueChangedCallback(e => list[index] = e.newValue); return(field); }
public override VisualElement Build() { var root = new Foldout { text = DisplayName }; var majorField = new IntegerField { bindingPath = nameof(Version.Major), label = ObjectNames.NicifyVariableName(nameof(Version.Major)) }; majorField.RegisterCallback <ChangeEvent <int>, IntegerField>(ClampEditingValue, majorField); majorField.RegisterValueChangedCallback(OnMajorChanged); root.Add(majorField); var minorField = new IntegerField { bindingPath = nameof(Version.Minor), label = ObjectNames.NicifyVariableName(nameof(Version.Minor)) }; minorField.RegisterCallback <ChangeEvent <int>, IntegerField>(ClampEditingValue, minorField); minorField.RegisterValueChangedCallback(OnMinorChanged); root.Add(minorField); var usage = GetAttribute <SystemVersionUsageAttribute>(); if (usage?.IncludeBuild ?? true) { var buildField = new IntegerField { bindingPath = nameof(Version.Build), label = ObjectNames.NicifyVariableName(nameof(Version.Build)) }; buildField.RegisterCallback <ChangeEvent <int>, IntegerField>(ClampEditingValue, buildField); buildField.RegisterValueChangedCallback(OnBuildChanged); root.Add(buildField); } if (usage?.IncludeRevision ?? true) { var revisionField = new IntegerField { bindingPath = nameof(Version.Revision), label = ObjectNames.NicifyVariableName(nameof(Version.Revision)) }; revisionField.RegisterCallback <ChangeEvent <int>, IntegerField>(ClampEditingValue, revisionField); revisionField.RegisterValueChangedCallback(OnRevisionChanged); root.Add(revisionField); } if (IsReadOnly) { root.contentContainer.SetEnabled(false); } return(root); }
public void SetData(WidgetDataLaunchCommandElement data) { _widgetData = data; _nameLabel.text = data.GameConsoleInvokable.DisplayName; _activeToggle.value = data.Active; _paramsContainer.Clear(); int paramIndex = 0; foreach (IGameConsoleParameter param in data.GameConsoleInvokable.Parameters) { if (param.Type == typeof(bool)) { var field = new Toggle(); bool.TryParse(TryPopParam(), out bool val); field.value = val; field.RegisterValueChangedCallback((evt) => OnParameterModified()); _paramsContainer.Add(field); } else if (param.Type == typeof(int)) { var field = new IntegerField(); int.TryParse(TryPopParam(), out int val); field.value = val; field.RegisterValueChangedCallback((evt) => OnParameterModified()); _paramsContainer.Add(field); } else if (param.Type == typeof(float)) { var field = new FloatField(); float.TryParse(TryPopParam(), out float val); field.value = val; field.RegisterValueChangedCallback((evt) => OnParameterModified()); _paramsContainer.Add(field); } else { var field = new TextField(); field.value = TryPopParam(); field.RegisterValueChangedCallback((evt) => OnParameterModified()); _paramsContainer.Add(field); } } _nameLabel.SetEnabled(data.Active); foreach (var item in _paramsContainer.Children()) { item.SetEnabled(data.Active); } OnParameterModified(); string TryPopParam() { if (data.Parameters == null) { return(default);
public static VisualElement GetElementOfIntField(int startValue, string fieldName, Action <object> setValue, Action <object> getValue) { IntegerField field = new IntegerField(fieldName); field.SetValueWithoutNotify(startValue); field.RegisterValueChangedCallback(s => setValue.Invoke(s.newValue)); getValue += o => field.SetValueWithoutNotify((int)o); return(field); }
protected void BindBaseCreateElements(Button cancelButton, Button createButton, TextField nameField, IntegerField countField, Toggle maxCountToggle) { cancelButton.clickable.clicked += OnCancelClicked; createButton.clickable.clicked += OnCreateClicked; if (GetDefaultName != null) { m_CurrentName = GetDefaultName(); } m_NameField = nameField; m_NameField.isDelayed = true; m_NameField.SetValueWithoutNotify(m_CurrentName); m_NameIsCustom = false; m_NameField.RegisterValueChangedCallback(evt => { if (evt.newValue.Length > 0) { m_CurrentName = evt.newValue; m_NameIsCustom = true; } else if (GetDefaultName != null) { m_CurrentName = GetDefaultName(); m_NameField?.SetValueWithoutNotify(m_CurrentName); m_NameIsCustom = false; } if (NameChanged != null) { NameChanged(m_CurrentName); } }); maxCountToggle.RegisterValueChangedCallback(evt => { m_CountField.value = evt.newValue ? 1 : 0; m_CountField.SetEnabled(evt.newValue); }); m_CountField = countField; m_CountField.RegisterValueChangedCallback(evt => { var newValue = evt.newValue; if (newValue < 0) { newValue = 0; m_CountField.SetValueWithoutNotify(newValue); } var maxEnabled = newValue > 0; maxCountToggle.SetValueWithoutNotify(maxEnabled); m_CountField.SetEnabled(maxEnabled); CountChanged?.Invoke(newValue); }); }
public static void RenderIntProperty( VisualElement container, string name, object value, Action <object> setter) { var field = new IntegerField(name); field.SetValueWithoutNotify((int)value); field.MarkDirtyRepaint(); field.RegisterValueChangedCallback(evt => setter(evt.newValue)); container.Add(field); }
void Init() { IntegerField field = new IntegerField() { value = config.value != null ? (int)config.value : 0, }; field.RegisterValueChangedCallback((e) => { config.OnValueChanged(e.newValue); MarkDirtyRepaint(); }); Add(field); }
private VisualElement CreateSampleItemInt(SampleItemInt item, string key) { var foldout = new Foldout(); foldout.text = key; var field = new IntegerField(nameof(SampleItemInt.IntValue)); field.value = item.IntValue; field.RegisterValueChangedCallback(e => item.IntValue = e.newValue); foldout.Add(field); return(foldout); }
public UnsignedLongField() : base(null, null) { // Set up styling AddToClassList("UdonValueField"); // Create Char Editor and listen for changes IntegerField field = new IntegerField(); field.RegisterValueChangedCallback( e => value = Convert.ToUInt64(e.newValue)); Add(field); }
//---------------------------------------------------------------------------------------------------------------------- void InitDefaultSISPlayableAssetFPSField(VisualElement parent) { //fps VisualElement fieldContainer = UIElementsUtility.AddElement <VisualElement>(parent, /*className=*/ "field-container"); SISUserSettings userSettings = SISUserSettings.GetInstance(); int defaultSISPlayableAssetFPS = userSettings.GetDefaultSISPlayableAssetFPS(); IntegerField defaultSISPlayableAssetFPSField = UIElementsUtility.AddField <IntegerField, int>(fieldContainer, Contents.DEFAULT_SIS_PLAYABLE_ASSET_FPS, defaultSISPlayableAssetFPS); defaultSISPlayableAssetFPSField.RegisterValueChangedCallback((ChangeEvent <int> evt) => { userSettings.SetDefaultSISPlayableAssetFPS(evt.newValue); userSettings.SaveUserSettings(); }); }
public void Reset() { var property = ListElement.ListProperty; Clear(); if (property.isArray) { Controls.DeleteAllButton.SetEnabled(property.arraySize > 0); var endProperty = property.GetEndProperty(); property.NextVisible(true); int arrayIndex = 0; do { if (SerializedProperty.EqualContents(property, endProperty)) { break; } switch (property.propertyType) { case SerializedPropertyType.ArraySize: var field = new IntegerField { bindingPath = property.propertyPath }; field.SetValueWithoutNotify(property.intValue); // This avoids the OnValueChanged/Rebind feedback loop. field.style.display = ListElement.ShowSize ? DisplayStyle.Flex : DisplayStyle.None; field.RegisterValueChangedCallback(UpdateList); field.label = "Size"; Add(field); break; default: var newItemSection = Controls.ItemSection; newItemSection.Q <PropertyField>()?.BindProperty(property); (newItemSection as ItemSection).Index = arrayIndex++; Add(newItemSection); break; } } while (property.NextVisible(false)); property.Reset(); } else { Add(new Label("Error, Bound item is not a list or array")); } }
public FoldoutNumberField() { // Used for its dragger. var toggleInput = toggle.Q(className: "unity-toggle__input"); m_DraggerIntegerField = new IntegerField(" "); m_DraggerIntegerField.name = "dragger-integer-field"; m_DraggerIntegerField.AddToClassList(k_DraggerFieldUssClassName); m_DraggerIntegerField.RegisterValueChangedCallback(OnDraggerFieldUpdate); toggleInput.Add(m_DraggerIntegerField); m_TextField = new TextField(); m_TextField.isDelayed = true; // only updates on Enter or lost focus m_TextField.AddToClassList(textUssClassName); header.hierarchy.Add(m_TextField); }
public VFXIntSliderField() { m_Slider = new Slider(0, 1, SliderDirection.Horizontal); m_Slider.AddToClassList("textfield"); m_Slider.RegisterValueChangedCallback(evt => ValueChanged(evt.newValue)); var integerField = new IntegerField(); integerField.RegisterValueChangedCallback(ValueChanged); integerField.name = "Field"; m_Field = integerField; Add(m_Slider); Add(integerField); RegisterCallBack(); }
protected VisualElement AddParameterElement(string text, int parameter, int?parameterWidth = null, EventCallback <ChangeEvent <int> > callback = null) { var integerField = new IntegerField(text) { value = parameter }; Add(integerField); integerField.labelElement.style.minWidth = new StyleLength(StyleKeyword.Auto); if (!(parameterWidth is null)) { integerField.contentContainer.style.width = (int)parameterWidth; } integerField.RegisterValueChangedCallback(callback); return(integerField); }
public PercentSlider(string label) : base(label) { AddToClassList(s_UssClassName); styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(s_UssPath)); var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(s_UxmlPath); template.CloneTree(this); visualInput = this.Q(s_VisualInputName); mSlider = this.Q <SliderInt>(s_SliderName); mField = this.Q <IntegerField>(s_FieldName); mSlider.RegisterValueChangedCallback(OnSubFieldValueChange); mField.RegisterValueChangedCallback(OnSubFieldValueChange); }
private void LinkSliderToIntegerField(Slider slider, IntegerField field) { slider.RegisterValueChangedCallback((evt) => { if (!evt.newValue.Equals(field.value)) { field.value = Mathf.RoundToInt(evt.newValue); } }); field.RegisterValueChangedCallback((evt) => { if (!evt.newValue.Equals((int)slider.value)) { slider.value = evt.newValue; } }); }