Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Multiline max font size + alignment issues

A topic by Neon Specter created 19 days ago Views: 257 Replies: 5
Viewing posts 1 to 6
(1 edit)

I've started converting some of my text from TMP to STM and I'm running into two issues:

  1. I can't figure out how to set a max font size.  In TMP, there's min and max auto-size font sizes; in STM I only see min.  Sometimes it stays at or below the font size I set, but sometimes it seems to randomly switch to a huge font size that's much bigger that what I set (e.g. 42 --> 70+).
  2. Middle alignment is slightly off as shown in the screenshots.  I can fix it by applying a Y offset of 0.2, but I doubt that will always be the same, so it would be much better if it were correct by default.

STM:

TMP:

Settings:


Developer

Hello!


1. This isn't TMP, so I've got my own approach to text size... The best fit system (Apart from Multiline - more on that later) was meant for text with manual linebreaks only, like small UI elements. So the other options on the "best fit" enum control how the text acts - Always will resize text to always fit in the area, SquishAlways does the same but only on the X axis. OverLimit will only make text smaller if it goes over the bounds of the box, and SquishOverLimit does the same but only on the X axis. I believe this look for limits both horizontally *and* vertically, but it's mostly made for fitting in a horizontal area.

So for these, minSize just makes it so text can't shrink down forever, and "size" effectively works as your maximum size, since that is the goal size for the text. I'm not sure how you'd be getting a random huge font size with this, though...? (Could be related to multiline...) Aside from that, I'm not sure what the problem is with my approach to text sizing?


2. This is probably because of the "multilineBETA" best fit mode you have assigned. If your option there has just one line - please use another best fit mode! I left the "BETA" tag on there because I wasn't satisfied with it - there are alignment issues with different anchor settings, and it just wasn't the result I wanted for automatically resizing text that still had automatic linebreaks. You *might* get a better automatic alignment with it if you set it to top left anchor/alignment and parent that inside another object, but if you're only doing one line of text like in the above screenshots - don't use this best fit option! You'll have much better control over how big you actually want text to appear on-screen.

What I need is for the text to always remain within the text area, so:  auto-wrap + auto-resize whenever it becomes too long and would extend beyond the text area (same behavior as TMP's auto-size + Normal text wrapping mode).  What you've described for auto-size behavior would be fine, but that's not what I'm experiencing (size goes beyond the defined font size), so I guess it's a bug.  The bug occurs with the Always, Squish Always, and MultilineBETA best fit modes.

Developer

Hm, right I think I might see the behaviour that's happening... if I have the rectTransform set to something *taller* than the text, then when it's on one of those best bit modes, it will try to fit the height, not just the width. You could try setting the text's rectTransform to exactly the height you need (either manually or with a contentSizeFitter) and then using another transform to parent that, but I should probably add a setting sometime to control which axes are being considered for best fit. Or I could just... add a maxSize field for this already, augh. Don't know why I didn't just add one before (I think vertical space was not considered for best fit in the past), but I'll add it to the list of things to do! I hope the workaround is an OK immediate fix, though!

I can stick with TMP for now for this specific case, but I'd like to switch to STM eventually because your quad system is much easier to work with than TMP's sprite maps.  The workaround won't work for me because I need line-wrapping.  If I make the text area bigger, I think I could get it to work with MultilineBETA if you add max size - because right now it's OK for multiple lines, but with a single line the font becomes huge.

Developer

I just made a build that adds a maxSize field and some more controls over Multiline best fit. Send me an email through my website with your invoice info, and I'll send it your way to test out! I'm *pretty* sure everythings working as it should, but I'd like to make sure the UX is better.