Search Unity

Horizontal with Fitter.

Discussion in 'UGUI & TextMesh Pro' started by Litwin, Feb 21, 2020.

  1. Litwin

    Litwin

    Joined:
    Aug 15, 2013
    Posts:
    70
    Hello, I am converting the UI of my project from NGUI to UGUI, but there is something that I am unable to accomplish in UGUI (maybe I need to do it in brute force?).

    In NGUI I used a table (since different from Grid, I can have each element with different width).

    Basically my idea is to have an element that is composed of:

    - Background (editbox bg)
    -- Text (value)
    -- Icon (coin icon)
    -- Button (purchase)

    The text has the right pivot.

    The background will increase from the text and the icon will update its position (be at the bottom edge of the left side) and the button will have the fixed position in the position of the background corner on the right side.

    Example: http://prntscr.com/r5sbpw

    The difference with the example, is that I don't want to have a fixed size of the background, I want the text to adjust from the size of the value.

    I checked this topic: https://forum.unity.com/threads/limit-max-width-of-layout-component.316625/

    But apparently it is more complex than I imagined.

    Cheers.
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Does this "table" have multiple rows? If so, does a cell need to have the same width as the cells above and below it (so that the columns make straight lines), or does each row make independent width adjustments ignoring the other rows?

    If it's just one row, or if rows are independent, you can probably use a Horizontal Layout Group for each row. Possibly with a child Horizontal Layout Group for each cell, to control the positioning of the text + icon.

    If you need columns to align, then you can't calculate the width of any individual cell by looking only at that cell or even only at that row; you need to scan the entire table and calculate the best compromise from some sort of god's-eye view. For that, you'll presumably need to write your own custom component.