public override void HandleEvent(EventBase evt) { // Capture ChangeEvents so they aren't handled by the parent TextField. if (evt is ChangeEvent <string> ) { evt.StopPropagation(); evt.PreventDefault(); } else { base.HandleEvent(evt); } }
protected override void ExecuteDefaultActionAtTarget(EventBase evt) { base.ExecuteDefaultActionAtTarget(evt); bool hasChanged = false; if (evt.eventTypeId == KeyDownEvent.TypeId()) { KeyDownEvent kde = evt as KeyDownEvent; if ((kde?.character == 3) || // KeyCode.KeypadEnter (kde?.character == '\n')) // KeyCode.Return { // Here we should update the value, but it will be done when the blur event is handled... parent.Focus(); evt.StopPropagation(); evt.PreventDefault(); } else if (!isReadOnly) { hasChanged = true; } } else if (!isReadOnly && evt.eventTypeId == ExecuteCommandEvent.TypeId()) { ExecuteCommandEvent commandEvt = evt as ExecuteCommandEvent; string cmdName = commandEvt.commandName; if (cmdName == EventCommandNames.Paste || cmdName == EventCommandNames.Cut) { hasChanged = true; } } if (!hash128Field.isDelayed && hasChanged) { // Prevent text from changing when the value change // This allow expression (2+2) or string like 00123 to remain as typed in the TextField until enter is pressed m_UpdateTextFromValue = false; try { UpdateValueFromText(); } finally { m_UpdateTextFromValue = true; } } }
internal static void PropagateToIMGUIContainer(VisualElement root, EventBase evt) { //We don't support IMGUIContainers in player if (evt.imguiEvent == null || root.elementPanel.contextType == ContextType.Player) { return; } // Send the event to the first IMGUIContainer that can handle it. if (root.isIMGUIContainer) { var imContainer = root as IMGUIContainer; if (evt.Skip(imContainer)) { // IMGUIContainer have no children. We can return without iterating the children list. return; } // Only permit switching the focus to another IMGUIContainer if the event target was not focusable. bool targetIsFocusable = (evt.target as Focusable)?.focusable ?? false; if (imContainer.SendEventToIMGUI(evt, !targetIsFocusable)) { evt.StopPropagation(); evt.PreventDefault(); } if (evt.imguiEvent.rawType == EventType.Used) { Debug.Assert(evt.isPropagationStopped); } } if (root.imguiContainerDescendantCount > 0) { var childCount = root.hierarchy.childCount; for (int i = 0; i < childCount; i++) { PropagateToIMGUIContainer(root.hierarchy[i], evt); if (evt.isPropagationStopped) { break; } } } }
internal static void PropagateToIMGUIContainer(VisualElement root, EventBase evt) { if (evt.imguiEvent == null) { return; } // Send the event to the first IMGUIContainer that can handle it. // If e.type != EventType.Used, avoid resending the event to the capture as it already had the chance to handle it. var imContainer = root as IMGUIContainer; if (imContainer != null && (evt.imguiEvent.type == EventType.Used || !evt.Skip(root))) { if (evt.Skip(imContainer)) { return; } if (imContainer.SendEventToIMGUI(evt)) { evt.StopPropagation(); evt.PreventDefault(); } if (evt.imguiEvent.type == EventType.Used) { Debug.Assert(evt.isPropagationStopped); } } else { if (root != null) { for (int i = 0; i < root.hierarchy.childCount; i++) { PropagateToIMGUIContainer(root.hierarchy[i], evt); if (evt.isPropagationStopped) { break; } } } } }
void OnPickTargetButton(EventBase eventBase) { var items = DebuggerTracer.GetTargets(m_Store.GetState().currentTracingFrame, (m_Store.GetState().CurrentGraphModel?.AssetModel as Object)?.GetInstanceID() ?? -1) .Select(x => (SearcherItem) new EntitySearcherItem(x)).ToList(); SearcherWindow.Show(EditorWindow.focusedWindow, items, "Entities", i => { if (i == null) { return(true); } var t = ((EntitySearcherItem)i).Entity; m_Store.GetState().currentTracingTarget = t.EntityIndex; UpdateTracingMenu(); return(true); }, eventBase.originalMousePosition); eventBase.StopPropagation(); eventBase.PreventDefault(); }
public void DispatchEvent(EventBase evt, IPanel panel) { if (panel != null) { // Note that here we always overwrite evt.target, even if it's already set. This might be required by // some pre-existing editor content, but it's not standard among the dispatching strategies and should // probably be changed in the future. var leafFocusElement = panel.focusController.GetLeafFocusedElement(); if (leafFocusElement != null) { evt.target = leafFocusElement; if (leafFocusElement.isIMGUIContainer) { IMGUIContainer imguiContainer = (IMGUIContainer)leafFocusElement; if (!evt.Skip(imguiContainer) && imguiContainer.SendEventToIMGUI(evt)) { evt.StopPropagation(); evt.PreventDefault(); } } else { EventDispatchUtilities.PropagateEvent(evt); } } else { evt.target = panel.visualTree; EventDispatchUtilities.PropagateEvent(evt); if (!evt.isPropagationStopped) { EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt); } } } evt.propagateToIMGUI = false; evt.stopDispatch = true; }
void OnPickTargetButton(EventBase eventBase) { State state = m_Store.GetState(); IDebugger debugger = state.CurrentGraphModel.Stencil.Debugger; var targetIndices = debugger.GetDebuggingTargets(state.CurrentGraphModel); var items = targetIndices == null ? null : targetIndices.Select(x => (SearcherItem) new TargetSearcherItem(x, debugger.GetTargetLabel(state.CurrentGraphModel, x))).ToList(); if (items == null || !items.Any()) { items = new List <SearcherItem> { new SearcherItem("<No Object found>") } } ; SearcherWindow.Show(EditorWindow.focusedWindow, items, "Entities", i => { if (i == null || !(i is TargetSearcherItem targetSearcherItem)) { return(true); } state.CurrentTracingTarget = targetSearcherItem.Target; UpdateTracingMenu(); return(true); }, eventBase.originalMousePosition); eventBase.StopPropagation(); eventBase.PreventDefault(); } void OnFrameCounterKeyDown(KeyDownEvent evt) { if (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter) { int frame = m_CurrentFrameTextField.value; frame = Math.Max(0, Math.Min(frame, Time.frameCount)); m_Store.GetState().CurrentTracingFrame = frame; m_Store.GetState().CurrentTracingStep = -1; UpdateTracingMenu(); } }
public void DispatchEvent(EventBase evt, IPanel panel) { if (panel != null) { var leafFocusElement = panel.focusController.GetLeafFocusedElement(); if (leafFocusElement != null) { if (leafFocusElement.isIMGUIContainer) { IMGUIContainer imguiContainer = (IMGUIContainer)leafFocusElement; if (!evt.Skip(imguiContainer) && imguiContainer.SendEventToIMGUI(evt)) { evt.StopPropagation(); evt.PreventDefault(); } if (!evt.isPropagationStopped && evt.propagateToIMGUI) { evt.skipElements.Add(imguiContainer); EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt); } } else { evt.target = panel.focusController.GetLeafFocusedElement(); EventDispatchUtilities.PropagateEvent(evt); if (!evt.isPropagationStopped && evt.propagateToIMGUI) { EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt); } } } else { EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt); } } evt.propagateToIMGUI = false; evt.stopDispatch = true; }
public void DispatchEvent(EventBase evt, IPanel panel) { if (panel != null) { if (panel.focusController.GetLeafFocusedElement() != null) { IMGUIContainer imguiContainer = panel.focusController.GetLeafFocusedElement() as IMGUIContainer; if (imguiContainer != null) { // THINK ABOUT THIS PF: shouldn't we allow for the trickleDown dispatch phase? if (!evt.Skip(imguiContainer) && imguiContainer.SendEventToIMGUI(evt)) { evt.StopPropagation(); evt.PreventDefault(); } } else { evt.target = panel.focusController.GetLeafFocusedElement(); EventDispatchUtilities.PropagateEvent(evt); } } else { evt.target = panel.visualTree; EventDispatchUtilities.PropagateEvent(evt); if (!evt.isPropagationStopped) { EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt); } } } evt.propagateToIMGUI = false; evt.stopDispatch = true; }
void OnPickTargetButton(EventBase eventBase) { State state = m_Store.GetState(); IDebugger debugger = state.CurrentGraphModel.Stencil.Debugger; var targetIndices = debugger.GetDebuggingTargets(state.CurrentGraphModel); var items = targetIndices == null ? null : targetIndices.Select(x => (SearcherItem) new TargetSearcherItem(x, debugger.GetTargetLabel(state.CurrentGraphModel, x))).ToList(); if (items == null || !items.Any()) { items = new List <SearcherItem> { new SearcherItem("<No Object found>") } } ; SearcherWindow.Show(EditorWindow.focusedWindow, items, "Entities", i => { if (i == null || !(i is TargetSearcherItem targetSearcherItem)) { return(true); } state.CurrentTracingTarget = targetSearcherItem.Target; UpdateTracingMenu(); return(true); }, eventBase.originalMousePosition); eventBase.StopPropagation(); eventBase.PreventDefault(); } void OnFrameCounterKeyDown(KeyDownEvent evt) { if (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter) { int frame = m_CurrentFrameTextField.value; frame = Math.Max(0, Math.Min(frame, Time.frameCount)); m_Store.GetState().CurrentTracingFrame = frame; m_Store.GetState().CurrentTracingStep = -1; UpdateTracingMenu(); } } void UpdateTracingMenu(bool force = true) { var state = m_Store.GetState(); if (EditorApplication.isPlaying && state.EditorDataModel.TracingEnabled) { m_PickTargetLabel.text = state.CurrentGraphModel?.Stencil?.Debugger?.GetTargetLabel(state.CurrentGraphModel, state.CurrentTracingTarget); m_PickTargetIcon.style.visibility = Visibility.Hidden; m_PickTargetButton.SetEnabled(true); if (EditorApplication.isPaused || !EditorApplication.isPlaying) { m_FirstFrameTracingButton.SetEnabled(true); m_PreviousFrameTracingButton.SetEnabled(true); m_PreviousStepTracingButton.SetEnabled(true); m_NextStepTracingButton.SetEnabled(true); m_NextFrameTracingButton.SetEnabled(true); m_LastFrameTracingButton.SetEnabled(true); m_CurrentFrameTextField.SetEnabled(true); m_TotalFrameLabel.SetEnabled(true); } else { state.CurrentTracingFrame = Time.frameCount; state.CurrentTracingStep = -1; m_FirstFrameTracingButton.SetEnabled(false); m_PreviousFrameTracingButton.SetEnabled(false); m_PreviousStepTracingButton.SetEnabled(false); m_NextStepTracingButton.SetEnabled(false); m_NextFrameTracingButton.SetEnabled(false); m_LastFrameTracingButton.SetEnabled(false); m_CurrentFrameTextField.SetEnabled(false); m_TotalFrameLabel.SetEnabled(false); } if (!m_LastUpdate.IsRunning) { m_LastUpdate.Start(); } if (force || EditorApplication.isPaused || m_LastUpdate.ElapsedMilliseconds > k_UpdateIntervalMs) { m_CurrentFrameTextField.value = state.CurrentTracingFrame; m_TotalFrameLabel.text = $"/{Time.frameCount.ToString()}"; if (state.CurrentTracingStep != -1) { m_TotalFrameLabel.text += $" [{state.CurrentTracingStep}/{state.MaxTracingStep}]"; } m_LastUpdate.Restart(); } } else { m_LastUpdate.Stop(); state.CurrentTracingFrame = Time.frameCount; state.CurrentTracingStep = -1; m_PickTargetLabel.text = ""; m_PickTargetIcon.style.visibility = StyleKeyword.Null; m_CurrentFrameTextField.value = 0; m_PickTargetButton.SetEnabled(false); m_CurrentFrameTextField.SetEnabled(false); m_TotalFrameLabel.text = "/0"; m_TotalFrameLabel.SetEnabled(false); m_FirstFrameTracingButton.SetEnabled(false); m_PreviousFrameTracingButton.SetEnabled(false); m_PreviousStepTracingButton.SetEnabled(false); m_NextStepTracingButton.SetEnabled(false); m_NextFrameTracingButton.SetEnabled(false); m_LastFrameTracingButton.SetEnabled(false); } } void OnFirstFrameTracingButton() { m_Store.GetState().CurrentTracingFrame = 0; m_Store.GetState().CurrentTracingStep = -1; UpdateTracingMenu(); } void OnPreviousFrameTracingButton() { if (m_Store.GetState().CurrentTracingFrame > 0) { m_Store.GetState().CurrentTracingFrame--; m_Store.GetState().CurrentTracingStep = -1; UpdateTracingMenu(); } } void OnPreviousStepTracingButton() { if (m_Store.GetState().CurrentTracingStep > 0) { m_Store.GetState().CurrentTracingStep--; } else { if (m_Store.GetState().CurrentTracingStep == -1) { m_Store.GetState().CurrentTracingStep = m_Store.GetState().MaxTracingStep; } else { if (m_Store.GetState().CurrentTracingFrame > 0) { m_Store.GetState().CurrentTracingFrame--; m_Store.GetState().CurrentTracingStep = m_Store.GetState().MaxTracingStep; } } } UpdateTracingMenu(); } void OnNextStepTracingButton() { if (m_Store.GetState().CurrentTracingStep < m_Store.GetState().MaxTracingStep&& m_Store.GetState().CurrentTracingStep >= 0) { m_Store.GetState().CurrentTracingStep++; } else { if (m_Store.GetState().CurrentTracingStep == -1 && (m_Store.GetState().CurrentTracingFrame < Time.frameCount)) { m_Store.GetState().CurrentTracingStep = 0; } else { if (m_Store.GetState().CurrentTracingFrame < Time.frameCount) { m_Store.GetState().CurrentTracingFrame++; m_Store.GetState().CurrentTracingStep = 0; } } } UpdateTracingMenu(); } void OnNextFrameTracingButton() { if (m_Store.GetState().CurrentTracingFrame < Time.frameCount) { m_Store.GetState().CurrentTracingFrame++; m_Store.GetState().CurrentTracingStep = -1; UpdateTracingMenu(); } } void OnLastFrameTracingButton() { m_Store.GetState().CurrentTracingFrame = Time.frameCount; m_Store.GetState().CurrentTracingStep = -1; UpdateTracingMenu(); } }
static void CancelEvent(EventBase evt) { evt.PreventDefault(); evt.StopImmediatePropagation(); }