Search Unity

Bug IMGUIContainer not respecting USS defined overflow rules

Discussion in 'UI Toolkit' started by diesoftgames, May 14, 2019.

  1. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    I imagine this is pressing the boundaries a bit, but I need to use IMGUI to do some stuff we can't do with UXML and USS alone (drawing edges between nodes in my graph editor) and I discovered that IMGUIContainers don't get clipped along with other contents based on the overflow rules of their parents. Here's an example:
    Screen Shot 2019-05-14 at 11.56.08 AM.png
    Everything done with strictly UIElements is clipped to that graph paper looking square because that parent has "overflow: hidden;" set, but the IMGUIContainer green lines (which are nested in as children of that same parent) seem to be be able to go wherever they please.

    It would be great if they respected the USS overflow, but I imagine that's a can of worms. Is there maybe some way I can workaround this issue? Thanks for any advice.
     
  2. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,003
    Hi,

    IMGUI content generated by IMGUIContainers should be clipped by VisualElements that have "overflow: hidden" set, but this relies on the IMGUI clipping system (which uses an alpha mask). I suspect that you are drawing the green lines using a material/shader that's not IMGUI-aware, and hence won't be clipped. If that's not the case please let us know.

    One short-term suggestion: you can draw these kind of lines by adding rectangular VisualElements and rotating them through the `transform` property, like so:

    Code (CSharp):
    1.         var greenLine = new VisualElement() {
    2.             style = {
    3.                 width = 100, height = 4,
    4.                 backgroundColor = Color.green
    5.             }
    6.         };
    7.         greenLine.transform.rotation = Quaternion.AngleAxis(45.0f, Vector3.forward);
    8.  
    Note that we will provide a new custom mesh API for VisualElement in 2019.3, which will simplify to generate that kind of content!
     
    diesoftgames likes this.
  3. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    Yes I'm just generating a Texture2D and then using GUI.DrawTexture. BUT transform would be much nicer. I was looking in the USS support for rotation and never though to just see if I could rotate the visual element itself >___<

    Thank you!
     
  4. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    A quick follow-up question: is there a way I can change the VisualElement's pivot point? (in this case to rotate around the center instead of the upper-left corner)
     
  5. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,003
    No, not at this time at least.

    A way around this is to add the element to a new (empty) parent, offset the element by (-w/2, -h/2) and then rotate the parent. However, this adds a lot of intermediate elements.
     
  6. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    122
    Yeah that'll probably still be a simpler solution than calculating the appropriate post-rotation offset, so I'll go with that. Thanks again!