HUD Text width area limit

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:

But example 2, how it should be

[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 :stuck_out_tongue:

--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]
		local width = surface.GetTextSize( NewText )
		if(width > max_width) then
			table.insert(DataText, "
" .. ArrayText[idx])
			NewText = ArrayText[idx]
			table.insert(DataText, ArrayText[idx])
		local t = string.Implode(" ", DataText)
		local w, h = surface.GetTextSize(t)
		if h > max_height then 
			table.insert(DataText, "...") 
	local t = string.Trim(string.Implode(" ", DataText))
	return t

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 "
'. Would that be efficient, and working?