Old 07-19-2018, 10:04 AM   #1
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default Q: Width of text string, in pixels?

If I am using a proportional font, e.g. 'Calibri'', in a lua script is there a way to determine the width of a string, in pixels (not characters)?

I have tried using various "average character width" values but none are fully satisfactory.

Perhaps there is a gfx.function that updates gfx.x and gfx.y? gfx.printf() must be able to deal with character widths, so why can't it tell tell me?

Why do I need it: i want to position a graphic 10 pixels after the end of the string.
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Old 07-19-2018, 10:10 AM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

There is gfx.measurestr to get the width/height of a string with the current font without drawing it (if you're using gfx.printf you'll have to switch to Lua's string.format).

gfx.drawstr, gfx.drawchar an gfx.printf all modify gfx.x andgfx.y.

Last edited by cfillion; 07-19-2018 at 10:16 AM.
cfillion is offline   Reply With Quote
Old 07-19-2018, 10:14 AM   #3
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default

Thank you - I tried all sorts of search terms, but not "measure"
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Old 07-19-2018, 05:19 PM   #4
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Possibly helpful: https://forum.cockos.com/showpost.ph...8&postcount=18
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 07-20-2018, 02:38 AM   #5
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default

Yep, thank you - that is similar to what I had done.

(Maybe I should read all of your thread. )
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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

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

Forum Jump


All times are GMT -7. The time now is 01:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.