Search Unity

Bullet point list

Discussion in 'UGUI & TextMesh Pro' started by artaka, Mar 24, 2015.

  1. artaka

    artaka

    Joined:
    Feb 19, 2013
    Posts:
    128
    Hey all,
    I want to achieve a simple "bullet point list" like layout such as below:
    • Item 1 - long text here that will wrap according to it's window size
    • Item 2 - another long text here
    • Item 3 - etc.
    I'm using an Image for the bullet point and Text right next to it. And just like a simple list, as the width of the window changes, the items' vertical position should change to accommodate for the wrapping of the text. Is there a way to achieve this with existing UI components? I've tried using a combination of Vertical Layout Group and Content Size Fitter but had no success.
    All help is appreciated.
     
    cymballe likes this.
  2. theolagendijk

    theolagendijk

    Joined:
    Nov 12, 2014
    Posts:
    117
    Hi artaka,

    I achieved this effect by using a GameObject with the VerticalLayoutGroup script.
    Screen Shot 2016-05-19 at 10.46.07.png

    Containing per bullet a GameObject with the HorizontalLayoutGroup script.
    Screen Shot 2016-05-19 at 10.48.19.png

    ... with as first child a GameObject with Image script ( for the bullet image ) and LayoutElement script.
    Screen Shot 2016-05-19 at 10.55.52.png

    ... and as second child a GameObject with Text script.



    So in the Scene hierarchy this looks like;
    Screen Shot 2016-05-19 at 10.57.55.png


    Works perfect for me!
    The bullet lists behaves exactly as you would expect. Bullets images and text lines are aligned to the upper left corner of there available space and as the width of the window decreases the bullets vertical positions change to accommodate for the wrapping of the text.

    Hope this helps. Cheers.
     
  3. theolagendijk

    theolagendijk

    Joined:
    Nov 12, 2014
    Posts:
    117
    Here's what that item list looks like in Unity UI;
    Screen Shot 2016-05-19 at 11.03.59.png
     
    artaka likes this.
  4. artaka

    artaka

    Joined:
    Feb 19, 2013
    Posts:
    128
    Thanks theolagendijk! I ended up doing something very similar.
     
  5. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Just in case you would like to achieve the same results more efficiently without having to use a dozen or so objects, here is an example using TextMesh Pro which only uses a single text object.



    upload_2016-5-24_22-18-35.png

    This uses a single TextMesh Pro text object which contains one child since I am using a different font for the Mariko GmbH. This is done by using the <font> tag or in this case <font="Avalon Bold SDF">MARIKO GmbH</font>.

    The lines of text which contain bullets are enclosed in the <margin-left> tag which is this case was <margin-left=1em>... </margin>. This allows indenting them as a block.

    The bullets are done by simply using the UTF16 character \u2022. The indentation of the bullets is done by using the <indent> tag. So in this case the bullets lines are something like "\u2022<indent=3em>The text that will be indented.</indent>". Multiple levels of indentation is also possible.

    Here is another example combining the <indent> and <sprite> tag. Note that changing the size of the RectTransform still results in the correct formatting and word wrapping of the text.

     
    Last edited: May 25, 2016
  6. artaka

    artaka

    Joined:
    Feb 19, 2013
    Posts:
    128
    That's really cool.. Thanks Stephan, I'll look into TextMesh Pro...
     
  7. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Thanks and feel free to reach out to me should you have any questions.
     
  8. twin_digital

    twin_digital

    Joined:
    Jul 26, 2018
    Posts:
    6
    Hi everyone !

    sorry to digger such an old thread but i've had a realy good use of ur solution above and i was wondering if there was anyway to have filled square bullet ? i've tested every utf 16 character that is a square bullet and in every case it's unfilled, as the round bullet is filled is was wondering if i was doing something wrong or anything ? i'm using offical ghotic ttf file !

    thanks :)
     
  9. patSilva

    patSilva

    Joined:
    Mar 25, 2019
    Posts:
    27
    Hey, is there a way to get bullet points to work within an TMP_InputField? all the tags are working but the bullets won't work.

    Sorry for responding to such an old thread

    EDIT: I figured it out the text object that is assigned to the Text Component variable in Input Field needs Parse Escape Characters, under extra settings, to be unchecked in order for it to work.

    EDIT 2: Ok, so that didn't really work. Apparently it only worked if I checked or unchecked it while playing. However keeping it unchecked on start did nothing and keeping it checked did nothing. Is the Input Field doing something to keeop this from happening?
     
    Last edited: Jun 15, 2021
  10. RomanoBG

    RomanoBG

    Joined:
    Dec 21, 2020
    Posts:
    1
    I actually have the same behaviour when adding text dynamically into a regular TMP UGUI field. It only works if I toggle Parse Escape Characters from Off to On at runtime
     
  11. IMD

    IMD

    Joined:
    Mar 21, 2013
    Posts:
    14
    Hi all,

    A little gift...

    I've cooked up a string extension which converts raw text with bullets into marked-up text which TextMeshPro will parse and display with consecutive lines of bulleted text correctly indented...

    Code (CSharp):
    1.        
    2. public static string TPM_MarkupBullets(this string rawText, char findBullet = '•', float indent = 1f, float leftMargin = 1f ) {
    3.             bool isInBullet = false;
    4.             string markedup = String.Format("<margin-left={0}em>", leftMargin);
    5.             string indentLeftTag = String.Format("<indent={0}em>", indent), indentRightTag = "</indent>";
    6.             foreach (char c in rawText) {
    7.                 if (c == findBullet) { markedup += findBullet + indentLeftTag; isInBullet = true; }
    8.                 else if (isInBullet && c == (char)10) { markedup += indentRightTag + c ; isInBullet = false;  }
    9.                 else { markedup += c; }
    10.             }
    11.             if (isInBullet) markedup += indentRightTag;
    12.             markedup += "</margin>";
    13.             return markedup;
    14.         }
    15.  
    Usage example:
    Code (CSharp):
    1.  
    2. [SerializeField] TMP_Text prerequisites;
    3. //...
    4. prerequisites.text = role.EntryRequirements.TPM_MarkupBullets();
    5.  
    Enjoy,
    Isaac
     
    theolagendijk likes this.
  12. tomcarnevale

    tomcarnevale

    Joined:
    Dec 26, 2019
    Posts:
    6
    Works like a charm. Turned it into an editor script (removed extension)



    Code (CSharp):
    1. [MenuItem("Tools/Add Bullet Formatting", false, 4000)]
    2.     static void AddBulletFormatting()
    3.     {
    4.         var go = Selection.gameObjects[0]; //be smarter about this
    5.  
    6.         var text = go.GetComponent<TMP_Text>();
    7.         text.text = TPM_MarkupBullets(text.text, '•', 1, 1);
    8.  
    9.         Undo.RecordObject(go, "Add Bullet Formatting");
    10.  
    11.     }