Search Unity

Layout groups and content size fitters with rotating image contents

Discussion in 'UGUI & TextMesh Pro' started by Boliver0482, May 5, 2020.

  1. Boliver0482

    Boliver0482

    Joined:
    Oct 19, 2019
    Posts:
    45
    Hello.

    I have a SMS style renderer built using vertical layout and content size fitters and works as you would expect. Content is either text or an image. Images can be rotated dynamically if the content calls for it.

    The problem I have is that the layout group and content size fitter work on the physical height of an image, not the apparent height following rotation. This results in inappropriate spacing for images which aren't 1:1. Eg. a 1000x500 image is given 500px spacing by the layout group, but if I rotate it by 90 degrees, it is still only given 500px, even though it's actually height on screen is now 1000px.

    Any way around this - hitting dead end.

    Many Thanks.


    Bob.
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Yes, the UI system doesn't like rotation and scale. These values are mostly ignored in UGUI (except for rendering), so they should be avoided if possible.

    Maybe you can derive from Image and override the
    preferredWidth
    and
    preferredHeight
    properties where you change them based on the rotation.
    Or you maybe can add a
    LayoutElement
    and change the preferedWidth / Height of that from another script...
    I didn't played around with that yet but I will take a look and see if I can provide something for my Asset Better UI in the future.
     
  3. Boliver0482

    Boliver0482

    Joined:
    Oct 19, 2019
    Posts:
    45
    Thank you. Am now changing the preferredHeight based on image width, if rotation/flipping requires it. My need is simple here and think that will work.... Appreciate the quick response. Got Better UI in a list to look at in full soon.
     
    Hosnkobf likes this.