Jump to content

Welcome to the Forum!

The best place to exchange builds and ideas! Vote for the best ideas and suggestions here.

Join the Avorion Discord!

Connect with other passionate players and talk about the latest news.
Discord

DLC Avorion Into the Rift Out Now!

Now available on Steam!
Steam
  • 7

API: Add a way to calculate text width & height before rendering/assigning it


Rinart73
 Share

Suggestion

It would be great to have a way of knowing text width & height (height is more important actually) before rendering it or creating an element for it.

-- function getTextDimensions(text, fontSize, maxWidth, fontType, isBold, isItalic, isOutlined, isShadowed)
-- Arguments:
-- string text
-- int fontSize
-- int maxWidth (maximum text width, after exceeding it text should use new lines)
-- FontType fontType (optional, default: FontType.Normal)
-- bool isBold (optional, default: false)
-- bool isItalic (optional, default: false)
-- bool isOutlined (optional, default: false)
-- bool isShadowed (optional, default: false)

local w, h = getTextDimensions("The \\c(0d0)hideout\\c() is located in \\s(45:15)", 15, 400)

Or maybe it would be easier to implement "textWidth" and "textHeight" read-only properties for TextField and Label elements that would tell the actual width and height of their assigned text, so we could instantly resize it after creating.

Why?

Here is an example. Let's say we have multiple rows with various text in a ScrollFrame. If we're using static pre-determined row heights, we will get empty spaces after text or text that goes out of the designated rectangle. Even with auto-resize (shrinking), huge amount of text would look ugly, being too small and unreadable (also auto-shrinking doesn't work with multi-line labels). Having a way to know the actual height of the text would allow to create rows that would fit the text no matter what.

spacer.png

Why not just create this function in Lua?

  1. Because we would have to manually extract relative width for every character in Unicode font (TTF fonts support up to 65535 characters ) for every font (not just vanilla, but the modded ones too!)
  2. And because we would have to re-implement the Unicode Line Breaking Algorithm in Lua (which would have low performance)
Edited by Rinart73
more reasons why this should be done
Link to comment
Share on other sites

0 answers to this suggestion

Recommended Posts

There have been no answers to this suggestion yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...