Search Unity

Drawing on IMGUIContainer clips over menu bar

Discussion in 'UIElements' started by Cence99, Sep 13, 2019.

  1. Cence99


    Apr 14, 2013
    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


    Unity Technologies

    Jan 7, 2019
    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 :

    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 :

    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.