Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by andrew-rc · May 15, 2015 at 01:59 PM · layout

UI: Horizontal layout of many dynamically-sized Text and Buttons?

Hi all, I want to make a UI that shows a sentence of text, where each word is its own UI element, so I can do effects on individual words (like tween and colour them). Additionally certain words are buttons, the user can click on them to change their content (and it could swap in a word that's much longer than what was there before). Think like an interactive storybook that pulses words as they're narrated.

I've been able to make this using old-school TextMeshes and resizing boxcolliders for buttons, but now I've got to swap over to the new Unity UI system.

Right now my approach is something like this:

  • I attach Words and ButtonWords to an object on the Canvas. It has Horizontal Layout Group and Content Size Fitter components.

  • each Word has a top level Layout Element component with a preferred width (200) and flexible width, and a child Text object (for the content), with a Content Size Fitter

  • each ButtonWord is like a Word, but with an extra child for the Button.

What I usually see is that the spacing of each word looks like it doubles each time. eg. "The Quick Brown Fox" appears as "The.Quick..Brown....Fox".

This is doing my head in :) Do I have to adjust the preferred width of each Word's LayoutElement after i've assigned text (with a rule like 10px per character)? Or should the Content Size Fitter handle that?

Any advice is greatly appreciated!

Thanks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by brikim13 · Apr 16 at 03:03 PM

If your contents' size changes then yes I would try setting the "preferred width" after assigning text. Unity's tool doesn't do a great job when it comes to dynamically laying out children contents.

Are you trying to do something like the following? alt text

If so you can try out using my script. I had the same issue with positioning the UI contents, so I created some tools for it and I think it maybe able to help you too. https://github.com/briankim13/UnityUIHelpers


autolayoutdemosmall.gif (470.6 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Customizing Editor Interface 1 Answer

How to use GUILayoutUtility.GetRect() properly? 1 Answer

uGUI Vertical Layout Group stretching objects 2 Answers

Add Item to GridLayoutGroup using Instantiate 3 Answers

Horizontal Layout Group padding update via script 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges