Thread Tools Display Modes
07/27/14, 10:31 PM   #1
mattmillus
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 13
How to calculate text 'extent'

Say I have a string like "Total Damage", and a given font, such as ZoFontChat. How can I query/calculate the width/height of the resulting text? Since ZoFontChat is not a fixed width font, this is not as simple as counting the number of characters in the string. Any ideas?
  Reply With Quote
07/28/14, 02:10 AM   #2
Harven
 
Harven's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 135
Hey,
use GetTextHeight() and GetTextWidth() methods of label control after SetText().
  Reply With Quote
07/28/14, 07:22 PM   #3
mattmillus
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 13
Thank you Harven, that works very well for label controls, and solved part of the issue!

However the larger issue is when dealing with the chat container window and AddMessageToWindow() function. What I am trying to do is display width formatted text to the chat log. For example, a command /dumpstats, to write the following in the chat window:

[Noob] zone: WTS noob lewtz
STAT BEFORE AFTER
Stat1 670 899
Stat2 1 20

Since different stats will have a different value in the BEFORE column they will misalign AFTER column if simply writing a bunch of spaces, so that is not a very good solution. Anything better I can do?

EDIT: Lol, esoui forums here just removed the extra formatting spaces in my little ghetto table above. In case its not obvious, I am trying to make the data align to the column headers, essentially I want fixed width columns

EDIT2: Alternatively, is there a fixed width font included with the game I could use instead?

Last edited by mattmillus : 07/28/14 at 07:25 PM.
  Reply With Quote
07/29/14, 03:28 AM   #4
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by mattmillus View Post
Thank you Harven, that works very well for label controls, and solved part of the issue!

However the larger issue is when dealing with the chat container window and AddMessageToWindow() function. What I am trying to do is display width formatted text to the chat log. For example, a command /dumpstats, to write the following in the chat window:

[Noob] zone: WTS noob lewtz
STAT BEFORE AFTER
Stat1 670 899
Stat2 1 20

Since different stats will have a different value in the BEFORE column they will misalign AFTER column if simply writing a bunch of spaces, so that is not a very good solution. Anything better I can do?

EDIT: Lol, esoui forums here just removed the extra formatting spaces in my little ghetto table above. In case its not obvious, I am trying to make the data align to the column headers, essentially I want fixed width columns

EDIT2: Alternatively, is there a fixed width font included with the game I could use instead?
If I remmeber right the client can choose wichever Font he wants to use for the Chat. Or what Font Size or chat width for that matter.

I don't think the chat was designed to transmit properly alligned/layed out text.
  Reply With Quote
07/29/14, 04:51 PM   #5
mattmillus
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 13
Thanks for the input. In the end I decided to change the functionality of my addon a bit so as to not need formatted text in the textbuffer controls.

However for anyone else looking to accomplish this in the future, the best solution I found was to set the textbuffer's font to 'Consolas', which actually comes with ESO as part of its built in font package, but is never instantiated from xml. You can make a fonts.xml file for your addon and add "EsoUi/Common/Fonts/consola.ttf"
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » How to calculate text 'extent'


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off