Pixel-Composer/scripts/string_cut/string_cut.gml

43 lines
792 B
Text
Raw Normal View History

2022-12-12 09:08:03 +01:00
function string_cut(str, w, tail = "...", scale = 1) {
2023-09-11 16:08:58 +02:00
if(string_width(str) * scale <= w) return str;
2022-01-13 05:24:03 +01:00
2023-09-11 16:08:58 +02:00
for( var i = string_length(str) - 1; i > 0; i-- ) {
var subS = string_copy(str, 1, i) + tail;
2023-09-11 16:08:58 +02:00
if(string_width(subS) * scale <= w)
return subS;
2022-01-13 05:24:03 +01:00
}
2023-09-11 16:08:58 +02:00
return "";
2022-01-13 05:24:03 +01:00
}
function string_cut_line(str, w) {
var i = 1;
var ss = "";
var ww = 0;
while(i <= string_length(str) ) {
var _chr = string_char_at(str, i);
ss += _chr;
ww += string_width(_chr);
if(ww > w) {
ww = 0;
ss += "\n";
}
i++;
}
return ss;
2023-06-05 18:27:53 +02:00
}
function string_reduce(str) {
str = string_lower(str);
str = string_replace_all(str, " ", "_");
str = string_replace_all(str, "\\", "");
str = string_replace_all(str, "/", "");
str = string_replace_all(str, "'", "");
return str;
2022-01-13 05:24:03 +01:00
}