Jump to content

Problem with displaying character in table.


Fizo

Recommended Posts

Hello, I have very simple problem but,I haven't idea how to solution this. If I typeing data to my table,and then displaying characters have diffrent sparation. 

CuPpHAK.png

This image shows my problem. This text meaning in English "example message". 

Thanks of lot for help.

My Code: 

 for i,v in ipairs(value) do
  dxDrawText(v,screenW * 0.8318, screenH * 0.4852, screenW * 0.055*i/3, screenH * 0.5157, tocolor(255, 255, 255, 255),2, "default", "center", "center", false, 	 false, false, false, false)
 end

 

Edited by Fizo
Link to comment
for i,v in ipairs(value) do
        local width_char = dxGetTextWidth(v)
        dxDrawText(v,screenW * 0.8318, screenH * 0.4852, screenW * 0.055*width_char/i/2, screenH * 0.5157, tocolor(255, 255, 255, 255),2, "default","center", "center", false, false, false, false, false)
 end

I have problem because i don't kown how to implement this. I'm trying but unsuccessfully

38 minutes ago, IIYAMA said:

That is obvious, every character has a different width so the spaces are different as well.

Pick a font which has the same character width for every character.

Or use this function: https://wiki.multitheftauto.com/wiki/DxGetTextWidth

 

Edited by Fizo
Link to comment
  • Moderators
local textInProgress = ""
for i,v in ipairs(value) do
        local wordWidth = dxGetTextWidth(textInProgress)
		textInProgress = textInProgress .. v

        dxDrawText(v,screenW * 0.8318 + wordWidth, screenH * 0.4852, screenW * 0.8318 + wordWidth + 10, screenH * 0.5157, tocolor(255, 255, 255, 255),2, "default","left", "center", false, false, false, false, false)
end

 

Something like this. Do not align the X axis with center, because dxDrawText is working with a bounding box and not with `width` properties.

 

Required Arguments

  • text: the text to draw
  • left: the absolute X coordinate of the top left corner of the text
  • top: the absolute Y coordinate of the top left corner of the text

Optional Arguments

  • right: the absolute X coordinate of the right side of the text bounding box. Used for text aligning, clipping and word breaking.
  • bottom: the absolute Y coordinate of the bottom side of the text bounding box. Used for text aligning, clipping and word breaking.

 

Edited by IIYAMA
Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...