Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Prevent dragging windows created with EditorWindow.BeginWindows

Discussion in 'Immediate Mode GUI (IMGUI)' started by eses, Sep 20, 2019.

  1. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    1,284
    I created an Editor Window with nodes/boxes that can be dragged with mouse.

    First I tried Regular GUI.Box(es) with style, but then learned about GUI.Window.

    However, these seem to be problematic; If I created an area that I can drag, and then have another area for controls (sidebar on right side of main window), seems like even if the Rect of main area doesn't overlap sidebar Rect, it is possible to click and drag these windows which are drawn behind sidebar.

    Also, I did a small experiment with zooming the view, and seems like even if I do the rendering of Windows inside EditorWindow.BeginWindows / EndWindows which are contained in a code block that has modified matrix, these windows still seem to be draggable like the view wasn't modified (zoomed out/in). However, typical GUI elements like buttons don't do this, their "hit boxes" are on correct position.

    So...
    A.
    Any ideas how to prevent clicking through a panel? Maybe use Event.current.Use somehow?

    B. Is it possible to somehow modify the way these sub windows work? It is quite nice these can be made draggable just by using GUI.DragWindow.

    Any help appreciated, or maybe I should try UIElements instead...

    Edit: I'm talking about these windows:
    https://docs.unity3d.com/ScriptReference/EditorWindow.BeginWindows.html
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    1,284
    I'll answer this myself...

    My solution was (this only fixes the scaling issue):

    Abandon GUI.Window and BeginWindows / EndWindows.

    Replace these windows with GUI.Box.

    Do manual area click detection using Rect.Contains.

    See this thread for more info:
    https://forum.unity.com/threads/show-multiple-editor-sub-windows-gui-window-as-selected.748238/

    This way click detection, multi selection, drag box selection etc will work just fine even with scaled GUI.matrix. Although I have no idea how to properly use GUI.matrix scaling... everything seems to be working OK so far (with certain limitations).
     
    Last edited: Sep 21, 2019
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    1,284
    And answer to question A. "how to prevent clicking through a panel?"

    In input handling code for the main window area, do a check if Event.current.mousePosition is inside the sidebar Rect. If so, exit main area input handling method.
     
    Last edited: Sep 21, 2019