Search Unity

Bad position of child elements

Discussion in 'UGUI & TextMesh Pro' started by Neterea Studios, Dec 3, 2014.

  1. Neterea Studios

    Neterea Studios

    Joined:
    May 7, 2013
    Posts:
    23
    Hi,

    Some extra option is needed.

    I seem not to find a way to align a text element properly on a UI configuration. This is done in order to have a good resizing layout.

    I have a Panel with a Horizontal Layout Group component. Inside, as children, I have a set of buttons with the option "Preserve Aspect" enabled on the Image script component. And finally, I have a text component as child of button element.

    The images are simple images (they are not sliced).

    The thing is I want to align the text on a especific place of the image and this seems to be impossible with the default behaviour. I try to do this placing the anchors to have a relative distancre from the borders, but this distance doesn't mach the image details when scaling at different resolutions. I can accomplish this if the "Preserve Aspect" option is not set, but in this case the image is deformed (not desired).

    The problem is that the Text element always computes its position according to the rect transform of the parent (button). There is no diffence if the "Preserve Aspect" is set or not. I don't know if this is ok (well... it's ok with the current model but...). If the image script alters the visual size of the representation to visually not deform the image this information should be used in its children. If not... there is no way to position things relatively to this image.

    I think that if "Preserve Aspect" is not set... full rect transform is ok. If "Preserve Aspect" is set, the information calculated to preserve the aspect should be the new rect transform. If this is not the case, some mechanism must be done to preserve relations after an aspect adjustment is done.

    Is there a solution for this? Or at least an alternative way to accomplish an aligment once the "Preserve Aspect" options is set?

    Thanks.
     
    Last edited: Dec 3, 2014
  2. Neterea Studios

    Neterea Studios

    Joined:
    May 7, 2013
    Posts:
    23
    Ok, I posted too fast...

    It solved the problem with a solution that is throwing warnings, so I will need to ensure that they are just warnings and the behavior will be ok and not undefined.

    I added an Aspect Ratio Fitter to the buttons. I stopped looking for a solution around this in the past, because unity gives me a message saying that "Parent has a type of layout group component. A child of a layout component group should not have a Aspect Ratio Fitter component, since is should be driven by the layout group".

    After adding the Aspect Ratio Fitter with Aspect Mode "Width Controls Height", I uncheked the "Child Force Expand" for Height.

    I think having an aspect fitter based on width and for the layout not controlling the height should be compatible...
     
    Last edited: Dec 3, 2014