public override VisualElement MakeItem() { var element = base.MakeItem(); element.RegisterCallback <MouseDownEvent>(evt => { if (!(evt.target is VisualElement e)) { return; } if (e.GetFirstAncestorOfType <TemplateContainer>() is var container && container.userData is TypeSearcherItem) { if (evt.clickCount != 1) { return; } // Simulate a double-click when single-clicking on an item to immediately select it. using (var newEvt = MouseDownEvent.GetPooled(new Event(evt.imguiEvent) { mousePosition = evt.mousePosition, clickCount = 2 })) { newEvt.target = container; container.SendEvent(newEvt); } }
internal static EventBase CreateEvent(Event systemEvent) { switch (systemEvent.type) { case EventType.MouseMove: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDrag: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDown: return(MouseDownEvent.GetPooled(systemEvent)); case EventType.MouseUp: return(MouseUpEvent.GetPooled(systemEvent)); case EventType.ScrollWheel: return(WheelEvent.GetPooled(systemEvent)); case EventType.KeyDown: return(KeyDownEvent.GetPooled(systemEvent)); case EventType.KeyUp: return(KeyUpEvent.GetPooled(systemEvent)); case EventType.MouseEnterWindow: return(MouseEnterWindowEvent.GetPooled(systemEvent)); case EventType.MouseLeaveWindow: return(MouseLeaveWindowEvent.GetPooled(systemEvent)); default: return(IMGUIEvent.GetPooled(systemEvent)); } }
private void HandleFieldMouseDown(MouseDownEvent evt) { if (focusController.focusedElement == this) { return; // Prevent do-focusing the field on consequent clicks. } // Propagate the event to the parent. var newEvt = MouseDownEvent.GetPooled(evt); newEvt.target = this; SendEvent(newEvt); }
// In order for tests to run without an EditorWindow but still be able to send // events, we sometimes need to force the event type. IMGUI::GetEventType() (native) will // return the event type as Ignore if the proper views haven't yet been // initialized. This (falsely) breaks tests that rely on the event type. So for tests, we // just ensure the event type is what we originally set it to when we sent it. internal static EventBase CreateEvent(Event systemEvent, EventType eventType) { switch (eventType) { case EventType.MouseMove: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDrag: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDown: return(MouseDownEvent.GetPooled(systemEvent)); case EventType.MouseUp: return(MouseUpEvent.GetPooled(systemEvent)); case EventType.ContextClick: return(ContextClickEvent.GetPooled(systemEvent)); case EventType.MouseEnterWindow: return(MouseEnterWindowEvent.GetPooled(systemEvent)); case EventType.MouseLeaveWindow: return(MouseLeaveWindowEvent.GetPooled(systemEvent)); case EventType.ScrollWheel: return(WheelEvent.GetPooled(systemEvent)); case EventType.KeyDown: return(KeyDownEvent.GetPooled(systemEvent)); case EventType.KeyUp: return(KeyUpEvent.GetPooled(systemEvent)); case EventType.DragUpdated: return(DragUpdatedEvent.GetPooled(systemEvent)); case EventType.DragPerform: return(DragPerformEvent.GetPooled(systemEvent)); case EventType.DragExited: return(DragExitedEvent.GetPooled(systemEvent)); case EventType.ValidateCommand: return(ValidateCommandEvent.GetPooled(systemEvent)); case EventType.ExecuteCommand: return(ExecuteCommandEvent.GetPooled(systemEvent)); default: // Layout, Ignore, Used return(IMGUIEvent.GetPooled(systemEvent)); } }
public static void ClickButton(this VisualElement root, string className) { var elView = root.GetElement <Button>(className); var viewClick = elView.clickable; var viewInvoke = viewClick .GetType() .GetMethod( "Invoke", BindingFlags.NonPublic | BindingFlags.Instance ); viewInvoke?.Invoke(viewClick, new object[] { MouseDownEvent.GetPooled() }); }