Layout groups and content size fitters with rotating image contents

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.

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.

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.

1 Like