BIM Coordinator Program (INT) April 22, 2024

Find the next step in your career as a Graphisoft Certified BIM Coordinator!

Archicad C++ API
About Archicad add-on development using the C++ API.

how to determine the pixel-width of a widgets text

Anonymous
Not applicable
Hi 🙂

My addon is dynamically creating widgets.
Example:
Buttons are created and the width of the buttons should fit the width of text of the buttons.
The buttons text is not known before so i need to get the pixel width of the text at run time.

I see a way to get the maximum length of the widgets font. (API_FontType.widMax)
("w" is longer than "i"...)
I could multiply that with the number of characters, but perhaps someone has a hint how to determine the exact length of a widget-text?

greetings,
John
1 REPLY 1
Anonymous
Not applicable
John wrote:
Hi 🙂
I see a way to get the maximum length of the widgets font. (API_FontType.widMax)


oh, i think these has nothing to do with the fonts of GUI-Widgets.
I just tried a little bit and choosed 5.4 as standard width of a letter.
Hmm.

Example:
Creation of two labels:
Text of Label1 = "iiiiiiiiii" (10 letters)
Text of Label2 = "wwwwwwwwww" (10 letters)

the labels will look like that:
<_iiiiiiiiii__________>
<_wwwwwwwwww_>

but i'am searching for a way to let them look like that:
<_iiiiiiiiii_>
<_wwwwwwwwww_>

any hints?
Learn and get certified!