Hello is there something like DrawRect maybe DrawTextRect
Because sometimes long text goes out of the hud area
Example screen how is it right now:
[QUOTE]|______________________|
This is a very long text and goes out of the area[/QUOTE]
But example 2, how it should be
[QUOTE]
|______________________|
this is a very long text and
doesn't goes out of the
area.[/QUOTE]
[lua]Width = Width - surface.GetTextSize() ?[/lua]
And seriously, reading what you wrote is painful and your 'schemes' are both the same for the outgoing text and for the non-outgoing text, so what's the point in general ?
Why it is painful? If you mean my grammar is wrong so correct it or I don't learn it.
I use http.fetch to get some information from other websides. I parse it and if the text is too long so it goes out of the roundbox area.
So I want limit my text and make new line if is too long. But your code I guess is only for Rect function. Like DrawRect.
Well, I didn't find any useful thing (in the wiki). So I wrote my own function. Your codeline also gave my an idea.
But if you still have better one or ideas so write down :P
[CODE]
--wrap if text too long
local function wraptext(text, max_width, max_height, font)
--after words
local ArrayText = string.Explode(" ", text, false)
local idx = 0
local DataText = {}
local NewText = ""
while(idx < #ArrayText) do
idx = idx + 1
NewText = NewText .. " " .. ArrayText[idx]
surface.SetFont(font)
local width = surface.GetTextSize( NewText )
if(width > max_width) then
table.insert(DataText, "\n" .. ArrayText[idx])
--resets
NewText = ArrayText[idx]
else
table.insert(DataText, ArrayText[idx])
end
local t = string.Implode(" ", DataText)
local w, h = surface.GetTextSize(t)
if h > max_height then
table.insert(DataText, "...")
break
end
end
local t = string.Trim(string.Implode(" ", DataText))
return t
end
[/CODE]
Well, you basically want to do so the text doesn't go out of the screen right ?
All you have to do is add TextSize to the X pos of the text (this will also look like it's aligned to the right)
Huge bump, but still relevant, I want a tip on doing something like OP said
A defined width and text width can't go above it, adds a new line on last words that didn't go through line width so..
I've thought of string.Split, checking width of every word and adding them all, and them adding a new line using "\n'. Would that be efficient, and working?
Sorry, you need to Log In to post a reply to this thread.