Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Image Auto Size

Discussion in 'UIElements' started by NoxNorthwind, Sep 12, 2019.

  1. NoxNorthwind


    Jun 19, 2016
    Hi all,

    I messed around with UIElements a bit and I want to show an image in an editor window. For this image I have a special class for getting the Asset and it appears on screen all good there.

    However, (maybe I'm just too used to css and html?) I made the style for the image to be:
    Width: 50px;
    Height: Auto;
    The original image is 300x125 (weird I know) so I would expect the image element to be 50x~20.8 but what I get is a container 50x125... Why the image's 125 - Shouldn't it scale accordingly? I use: "scaleMode = ScaleMode.ScaleToFit;". Is it because I don't assign the image in the uxml?
    Do I need a flex container for this? If so I don't consider this intuitive and I'm kinda stuck with this...
    I didn't find a thread for it so far so I guess I'm just doing something terribly wrong...

    Many thanks in advance!

    Sorry for the black boxes...

    imageUIElement.png ussUIElement.png uxmlUIElement.png
  2. jonathanma_unity


    Unity Technologies

    Jan 7, 2019
    Hi NoxNorthwind,

    The scaleMode does not affect the measured dimension of the image.
    Bascially, if width or height are auto they will take the size of the asset regardless of the scale mode.