- Home /
Best way to implement a shared Best Fit setting for uGUI?
"Best Fit" is a very nice convenience option for uGUI text labels. However, in cases where you have a list of elements which are dynamically populated (say, displaying a list of user-created content with the respective titles), simply choosing Best Fit on all text labels produces ugly results, such as seen in the screenshot below (left side):
What I'd like to produce is a component that can both listen and send events to a group of elements (which can be modified per inspector & code in edit mode and runtime). It would basically take a number of "Best Fit" text labels, get the smallest BestFit result, and apply it to all labels. There's a few questions where I hoped someone could share their insights before I get started, however:
High-Level Approach: intuitively I'd say producing sort of a "Layout Group" would lead to the most natural workflow. So you define a parent transform, attach a "BestFit Layout Group" component, and all text labels under it adjust to the smallest one inside the group. Or do you think a different approach would work better?
Getting the transformation value or the actual "real" text size: if I set a text label to Best Fit, the label adjusts but the "original font size" stays the same. Now I know that the text size undergoes a number of transforms - from original size over Best Fit over Canvas Scaler - but is there a clean way of reading out the Best Fit value? I didn't really find anything on the documentation.
Can you see any logical fallacies that would make this an unfeasible task? I don't think there's any cases in which such an algorithm could not determine a result, but maybe someone thinks of something I didn't, so please don't hesitate.
Is there already a functionality like this available? I looked through the documentation and everything, but maybe I did overlook some way of doing it (without hacky workarounds).
Thanks for your answers!
Your answer
Follow this Question
Related Questions
UI Only Updates As Intended When Editing Through Scene 0 Answers
Which layout and how? 0 Answers
How can i create a conversion like whatsapp in unity3d 0 Answers
Multiple Cars not working 1 Answer