ATTRIB(InputBox, forbiddenCharacters, string, "")
ATTRIB(InputBox, color, vector, '1 1 1')
ATTRIB(InputBox, colorF, vector, '1 1 1')
- ATTRIB(InputBox, maxLength, float, 255)
+ ATTRIB(InputBox, maxLength, float, 255) // if negative, it counts bytes, not chars
ENDCLASS(InputBox)
void InputBox_Clear_Click(entity btn, entity me);
#endif
for(i = 0; i < strlen(ch); ++i)
if(strstrofs(me.forbiddenCharacters, substring(ch, i, 1), 0) > -1)
return;
- if(strlen(ch) + strlen(me.text) > me.maxLength)
- return;
+ if(me.maxLength > 0)
+ {
+ if(strlen(ch) + strlen(me.text) > me.maxLength)
+ return;
+ }
+ else if(me.maxLength < 0)
+ {
+ if(u8_strsize(ch) + u8_strsize(me.text) > -me.maxLength)
+ return;
+ }
me.setText(me, strcat(substring(me.text, 0, me.cursorPos), ch, substring(me.text, me.cursorPos, strlen(me.text) - me.cursorPos)));
me.cursorPos += strlen(ch);
}
me.TR(me);
me.TD(me, 1, 3.0, box = makeXonoticInputBox(1, "_cl_name"));
box.forbiddenCharacters = "\r\n\\\"$"; // don't care, isn't getting saved
- box.maxLength = 63;
+ box.maxLength = -63; // negativ means encoded length in bytes
label.textEntity = box;
me.TR(me);
me.TD(me, 5, 1, e = makeXonoticColorpicker(box));