Search Unity

Drawing on IMGUIContainer clips over menu bar

Discussion in 'UI Toolkit' started by ShadyMike, Sep 13, 2019.

  1. ShadyMike

    ShadyMike

    Joined:
    Apr 14, 2013
    Posts:
    60
    Hello there,

    I am drawing arrows using IMGUI in a IMGUIContainer. However, since my custom editor supports panning and zooming, the arrows clip over the menu bar, which I want to avoid.




    In the following image, the blue selected IMGUIContainer is the default one, while the VisualElement called AIEditorCanvas is the IMGUIContainer class in which I draw the arrows. The latter has a width and height of 0 though, as it only really acts as the parent of all the nodes and as a canvas to draw the arrows.



    Setting overflow to hidden leads to all my arrows disappearing, since the container has a size of 0. I cannot make the canvas the size of the window, as it is being transformed by the user, i.e. panning and zooming leads to the canvas moving or scaling, and together with it, all its children (the nodes). Giving the canvas a fixed size would lead to arrows not being drawn outside the canvas, which could be the case in a big tree.

    My problem is a bit specific and complicated to follow along, but I appreciate any advice on how to go about this. I am sure that I am misunderstanding a few aspects of IMGUIContainers here.

    Thanks in advance!
     
  2. jonathanma_unity

    jonathanma_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    229
    Hi Cence99,
    Since your IMGUIContainer has a size of 0 you cannot rely on it to handle the clipping. You may want to try calling GUI.BeginGroup() before drawing anything : https://docs.unity3d.com/ScriptReference/GUI.BeginGroup.html

    I may as well add that the approach you're taking might not be the easiest one, so you may want to consider another way to resolve your problem. If you are on 2019.3 I'd recommend using the generateVisualContent callback instead of IMGUI : https://docs.unity3d.com/2019.3/Doc...ents.VisualElement-generateVisualContent.html

    If not you can add a VisualElement that act as a viewport (maybe AIEditorBackground) that is not affected by zoom/pan and set "overflow: hidden" on it.
     
  3. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    @jonathanma_unity Do you have any source code examples for that?

    I'd like to point out that the official docs for IMGUIContainer are literally useless - even now in late 2020: https://docs.unity3d.com/Manual/UIE-IMGUI.html talks about things without ever documenting ANYTHING, and the script docs are missing entirely (it's just a list of method names: https://docs.unity3d.com/ScriptReference/UIElements.IMGUIContainer.html - someone wrote literally 5 words as the sum total of the docs for that class :(. The doc for the Constructor is particularly hilarious: "Constructor" <-- are Unity staff trolling us now? ).