View Single Post
Old 05-12-2016, 05:55 AM   #23
Human being with feelings
X-Raym's Avatar
Join Date: Apr 2013
Location: France
Posts: 6,029

it doesn't work for me =/

In my Region clock script I already face this issue, it was for the whole gfx.window, and I came out with this solution

function CenterAndResizeText(string)
  gfx.setfont(1, font_name, 100)

  str_w, str_h = gfx.measurestr(string)
  fontsizefit=(gfx.w/(str_w+50))*100 -- new font size needed to fit.
  fontsizefith=((gfx.h-gfx.y)/(str_h+50))*100 -- new font size needed to fit in vertical.

  font_size =  math.min(fontsizefit,fontsizefith)
  gfx.setfont(1, font_name, font_size)

  str_w, str_h = gfx.measurestr(string)
  gfx.x = gfx.w/2-str_w/2
  gfx.y = gfx.y
The process is a bit different as you can see there is no loops.

It works pretty fine but the text is not exactly centered vertically and horizontally in most case.
X-Raym is offline   Reply With Quote