public static void OnToggleChanged(this Toggle toggle, EventCallback <ChangeEvent <bool> > callback) { #if UNITY_2018_3_OR_NEWER toggle.RegisterValueChangedCallback(callback); #else toggle.OnToggle(() => callback(ChangeEvent <bool> .GetPooled(!toggle.value, toggle.value))); #endif }
public static void SendChangeEvent <T>(this VisualElement element, T previous, T current) { using (var changeEvent = ChangeEvent <T> .GetPooled(previous, current)) { changeEvent.target = element; element.SendEvent(changeEvent); } }
private void OnFieldValueChanged(ChangeEvent <TType> evt) { using (ChangeEvent <TType> newEvent = ChangeEvent <TType> .GetPooled(evt.previousValue, evt.newValue)) { newEvent.target = this; SendEvent(newEvent); } }
private void SendChangeEvent(AnimationCurve newValue) { using (ChangeEvent <AnimationCurve> pooled = ChangeEvent <AnimationCurve> .GetPooled(this.value, newValue)) { pooled.target = this; this.value = newValue; UIElementsUtility.eventDispatcher.DispatchEvent(pooled, base.panel); } }
public void SetValueAndNotify(Gradient newValue) { using (ChangeEvent <Gradient> pooled = ChangeEvent <Gradient> .GetPooled(this.value, newValue)) { pooled.target = this; this.value = newValue; UIElementsUtility.eventDispatcher.DispatchEvent(pooled, base.panel); } }
void OnControlChange(ChangeEvent <U> e) { e.StopPropagation(); using (ChangeEvent <U> evt = ChangeEvent <U> .GetPooled(e.previousValue, e.newValue)) { evt.target = this; SendEvent(evt); } }
public override void SetValueAndNotify(Gradient newValue) { using (ChangeEvent <Gradient> evt = ChangeEvent <Gradient> .GetPooled(value, newValue)) { evt.target = this; value = newValue; UIElementsUtility.eventDispatcher.DispatchEvent(evt, panel); } }
private void SendChangeEvent(AnimationCurve newValue) { using (ChangeEvent <AnimationCurve> evt = ChangeEvent <AnimationCurve> .GetPooled(value, newValue)) { evt.target = this; value = newValue; UIElementsUtility.eventDispatcher.DispatchEvent(evt, panel); } }
internal void AddElement(Progress.Item item) { m_DetailsFoldoutToggle.visible = true; SubTaskInitialization(item); if (dataSource.running) { m_DetailsFoldoutToggle.SetValueWithoutNotify(true); ToggleDetailsFoldout(ChangeEvent <bool> .GetPooled(false, true)); } }
void OnToggleValueChanged(ChangeEvent <bool> e) { var element = e.target as VisualElement; var index = (int)element.userData; var choice = m_FilteredChoices[index]; m_State[choice.TypeId] = e.newValue; if (choice.TypeId < 0) { foreach (var eventTypeId in m_GroupedEvents[choice.Group]) { m_State[eventTypeId] = e.newValue; } } else if (choice.TypeId == 0) { foreach (var c in m_Choices) { m_State[c.TypeId] = e.newValue; } } // All toggling if (m_State.Where(s => s.Key > 0).All(s => s.Value)) { m_State[0] = true; } else if (m_State.Where(s => s.Key > 0).Any(s => !s.Value)) { m_State[0] = false; } // Group toggling if (choice.TypeId != 0) { if (m_GroupedEvents[choice.Group].All(id => m_State[id])) { var group = m_Choices.First(c => c.TypeId < 0 && c.Group == choice.Group); m_State[group.TypeId] = true; } else if (m_GroupedEvents[choice.Group].Any(id => !m_State[id])) { var group = m_Choices.First(c => c.TypeId < 0 && c.Group == choice.Group); m_State[group.TypeId] = false; } } FilterEvents(value); using (var evt = ChangeEvent <string> .GetPooled(null, null)) { evt.target = this; SendEvent(evt); } }
void SendCollapseEvent() { m_Collapsed = !m_Collapsed; EnableInClassList(k_UssClassName + "--collapsed", m_Collapsed); using (var e = ChangeEvent <bool> .GetPooled(!m_Collapsed, m_Collapsed)) { e.target = this; SendEvent(e); } }
public void SetValueAndNotify(Object newValue) { if (newValue != value) { using (ChangeEvent <Object> evt = ChangeEvent <Object> .GetPooled(value, newValue)) { evt.target = this; value = newValue; UIElementsUtility.eventDispatcher.DispatchEvent(evt, panel); } } }
public void SetValueAndNotify(T newValue) { if (!EqualityComparer <T> .Default.Equals(m_Value, newValue)) { using (ChangeEvent <T> evt = ChangeEvent <T> .GetPooled(value, newValue)) { evt.target = this; value = newValue; UIElementsUtility.eventDispatcher.DispatchEvent(evt, panel); } } }
public void SetValueAndNotify(T newValue) { if (!EqualityComparer <T> .Default.Equals(value, newValue)) { using (ChangeEvent <T> evt = ChangeEvent <T> .GetPooled(value, newValue)) { evt.target = this; SetValueWithoutNotify(newValue); SendEvent(evt); } } }
public void SetValueAndNotify(UnityEngine.Object newValue) { if (newValue != this.value) { using (ChangeEvent <UnityEngine.Object> pooled = ChangeEvent <UnityEngine.Object> .GetPooled(this.value, newValue)) { pooled.target = this; this.value = newValue; UIElementsUtility.eventDispatcher.DispatchEvent(pooled, base.panel); } } }
public void SetValueAndNotify(T newValue) { if (!EqualityComparer <T> .Default.Equals(this.m_Value, newValue)) { using (ChangeEvent <T> pooled = ChangeEvent <T> .GetPooled(this.value, newValue)) { pooled.target = this; this.value = newValue; UIElementsUtility.eventDispatcher.DispatchEvent(pooled, base.panel); } } }
public void SetValueAndNotify(T newValue) { if (!EqualityComparer <T> .Default.Equals(newValue, value)) { using (ChangeEvent <T> evt = ChangeEvent <T> .GetPooled(value, newValue)) { value = newValue; if (m_valueCallback != null) { m_valueCallback(evt); } } } }
public override void SetValueAndNotify(T newValue) { if (!EqualityComparer <T> .Default.Equals(value, newValue)) { using (ChangeEvent <T> evt = ChangeEvent <T> .GetPooled(value, newValue)) { evt.target = this; value = newValue; UIElementsUtility.eventDispatcher.DispatchEvent(evt, panel); } } else if (!isDelayed && m_UpdateTextFromValue) { // Value is the same but the text might not be in sync // In the case of an expression like 2+2, the text might not be equal to the result text = ValueToString(m_Value); } }
public override VisualElement CreateElement(Type type, object initial) { var colorField = new ColorField(); if (initial.GetType() == typeof(Color)) { colorField.value = (Color)initial; } else if (initial.GetType() == typeof(Color32)) { colorField.value = (Color32)initial; colorField.RegisterValueChangedCallback(evt => { using ChangeEvent <Color32> evt2 = ChangeEvent <Color32> .GetPooled(evt.previousValue, evt.newValue); evt.currentTarget.SendEvent(evt2); }); } return(colorField); }
static VisualElement BuildEnumEditor(IConstantEditorBuilder builder, EnumValueReference enumConstant) { void TriggerOnValueChange(Enum newEnumValue) { var oldValue = enumConstant; var newValue = new EnumValueReference(newEnumValue); using (var evt = ChangeEvent <EnumValueReference> .GetPooled(oldValue, newValue)) builder.OnValueChanged(evt); } Type enumType = enumConstant.EnumType.Resolve(); VisualElement editor = enumType == typeof(KeyCode) ? BuildSearcherEnumEditor(enumConstant, enumType, TriggerOnValueChange) : BuildEnumFieldEditor(enumConstant, TriggerOnValueChange); editor?.SetEnabled(!builder.ConstantIsLocked); return(editor); }
void OnToggleChanged(ChangeEvent <bool> evt) { if (evt.target is Toggle t) { evt.StopPropagation(); if (evt.newValue == false) { t.SetValueWithoutNotify(true); return; } var currentSelectedItem = default(Toggle); var newSelectedItem = default(Toggle);; var list = m_ToggleQuery.ToList(); foreach (var toggle in list) { if (currentSelectedItem != null && newSelectedItem != null) { break; } if (ReferenceEquals(t, toggle)) { newSelectedItem = toggle; } if (toggle.value && !ReferenceEquals(t, toggle)) { toggle.SetValueWithoutNotify(false); currentSelectedItem = toggle; } } using (var newEvent = ChangeEvent <Toggle> .GetPooled(currentSelectedItem, newSelectedItem)) { newEvent.target = this; SendEvent(newEvent); } } }
static InlineFloatEditor MakeVectorEditor <T, V, F>(this IConstantEditorBuilder builder, IVectorType <T, V> vectorType, Func <string, V, F> makeField) where F : BaseField <V> { var editor = new InlineFloatEditor(); for (int i = 0; i < vectorType.FieldNames.Count; i++) { var field = makeField(vectorType.FieldNames[i], vectorType.GetField(i)); editor.Add(field); var fieldIndex = i; // apparently safer... field.RegisterValueChangedCallback(evt => { var oldValue = vectorType.Value; vectorType.SetField(fieldIndex, evt.newValue); using (ChangeEvent <T> other = ChangeEvent <T> .GetPooled(oldValue, vectorType.Value)) builder.OnValueChanged(other); }); } return(editor); }
void SetValue(string value, bool notify) { string cleanValue = StyleSheetUtilities.GetCleanVariableName(value); if (m_Value == cleanValue) { return; } var oldValue = m_Value; m_Value = cleanValue; if (panel != null && notify) { using (ChangeEvent <string> evt = ChangeEvent <string> .GetPooled(oldValue, cleanValue)) { evt.target = this; SendEvent(evt); } } m_Field.SetValueWithoutNotify(m_Value); UpdatePlaceholderLabelVisibility(); }
static void Dispatch <T>(IConstantEditorBuilder builder, T oldValue, T newValue) { using (ChangeEvent <T> other = ChangeEvent <T> .GetPooled(oldValue, newValue)) builder.OnValueChanged(other); }
public static void TriggerOnValueChanged <T>(this IConstantEditorBuilder builder, T oldValue, T newValue) { using (ChangeEvent <T> other = ChangeEvent <T> .GetPooled(oldValue, newValue)) builder.OnValueChanged(other); }