HUD Groups

by Forum_account
An easy way to manage screen objects.
ID:330233
 
I've made myself a little HudOutput control, expanding on HudLabel.
HudOutput
parent_type = /HudLabel

var text_log[0] // a text log
var lines = 0 // the number of available lines

proc
add_text(text)
var wrap_length = __width - __padding * 2
var newline = "\n"
var caption = ""

// Calculate the available lines
lines = round(__height / font.line_height)

// Wrap the text and add each line to the text_log
text_log += break_lines(font.wrap_text(text, wrap_length))

// Trim off the top
text_log.len > lines && text_log.Cut(1, text_log.len - lines + 1)

// Form the end result
for(var/t in text_log)
caption += t + newline

// Set the caption
caption(caption)

proc
break_lines(text)
var newline = "\n"
var n = findtext(text, newline)
var lines[0]
while(n)
lines += copytext(text, 1, n)
text = copytext(text, n + 1)
n = findtext(text, newline)
if(!n) lines += text
return list() + (lines.len && lines || text)


However, the default behavior of the HudLabel trims off text that exceeds its width, in this line:
HudLabel
proc
caption(c)

__caption = c

c = font.cut_text(c, __width - __padding * 2) // <--- This line needs to be omitted
// because I do my own fitting

caption.set_text(c)
__caption_width = font.text_width(c)

__set()


Basically, the HudOutput receives text, wraps it, and trims it.
I'm also wondering though if I even need to be using a HudLabel for this in the first place.
I'm not sure how much else the hud label does. Since its caption proc is simple you can just copy the code (calling __set, etc.) from it to your output control's code.