Skip to content

Commit 41d5c68

Browse files
committed
Fix text overflow in various places
- Add a new string_truncate function that automatically adds ellipses (...) when necessary - Replace in-place check for the string width in three different places of the code (datapack preview, song/pattern folder) - Truncate recent file names in the greeting window + menu (the latter is still not fixed, there's something wrong with the menu width calculation) - Width of the 'Song info' window now adapts to the MIDI file name as well
1 parent 2c1f748 commit 41d5c68

File tree

9 files changed

+42
-7
lines changed

9 files changed

+42
-7
lines changed

Minecraft Note Block Studio.yyp

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/control_draw/control_draw.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ if (draw_tab("File")) {
989989
for (b = 0; b < 11; b += 1) {
990990
if (recent_song[b] = "") break
991991
c = floor(date_second_span(recent_song_time[b], date_current_datetime()))
992-
str += seconds_to_str(c) + "$" + clean(filename_name(recent_song[b])) + "|"
992+
str += seconds_to_str(c) + "$" + string_truncate(clean(filename_name(recent_song[b])), 310) + "|"
993993
}
994994
show_menu_ext("file", 0, 19, icon(icons.NEW)+"Ctrl + N$New song|"+
995995
icon(icons.OPEN)+"Ctrl+O$Open song...|Recent songs...|\\|" + str + condstr(recent_song[0] != "", "-|Clear recent songs") + condstr(recent_song[0] = "", "^!No recent songs") + "|/|-|"+

scripts/dat_preview/dat_preview.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ if (string_lettersdigits(name) = "") {
2121
}
2222
}
2323

24-
return string_maxwidth(preview, 350) + condstr(string_width(preview) > 350, "...")
24+
return string_truncate(preview, 350)

scripts/draw_window_greeting/draw_window_greeting.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ for (a = 0; a < 11; a += 1) {
118118
}
119119
}
120120
draw_sprite(spr_frame5, theme * 3 + m, b, c)
121-
draw_text(b + 2 + (m = 2), c + 1 + (m = 2), filename_name(recent_song[a]))
121+
draw_text(b + 2 + (m = 2), c + 1 + (m = 2), string_truncate(filename_name(recent_song[a]), 220))
122122
draw_set_halign(fa_right)
123123
draw_text(b + 316 + (m = 2), c + 1 + (m = 2), seconds_to_str(floor(date_second_span(recent_song_time[a], date_current_datetime()))))
124124
draw_set_halign(fa_left)

scripts/draw_window_preferences/draw_window_preferences.gml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ if (selected_tab = 0) {
100100
refreshrate=1
101101
}
102102

103-
draw_text(x1 + 22, y1 + 260, "Song folder: " + string_maxwidth(songfolder, 360) + condstr(string_width(songfolder) > 360, "..."))
103+
draw_text(x1 + 22, y1 + 260, "Song folder: " + string_truncate(songfolder, 360))
104104
popup_set_window(x1 + 22, y1 + 260, 430, 18, songfolder)
105105
if (draw_button2(x1 + 22, y1 + 276, 76, "Open")) {
106106
if (!directory_exists_lib(songfolder)) {
@@ -116,7 +116,7 @@ if (selected_tab = 0) {
116116
}
117117
if (draw_button2(x1 + 22 + 84 + 84, y1 + 276, 96, "Use default")) songfolder = songs_directory
118118

119-
draw_text(x1 + 22, y1 + 310, "Pattern folder: " + string_maxwidth(patternfolder, 360) + condstr(string_width(patternfolder) > 360, "..."))
119+
draw_text(x1 + 22, y1 + 310, "Pattern folder: " + string_truncate(patternfolder, 360))
120120
popup_set_window(x1 + 22, y1 + 300, 430, 18, patternfolder)
121121
if (draw_button2(x1 + 22, y1 + 326, 76, "Open")) {
122122
if (!directory_exists_lib(patternfolder)) {

scripts/draw_window_songinfo/draw_window_songinfo.gml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// draw_window_songinfo()
2-
var x1, y1, a, b, n, str, w, h, yy, w1, w2, w3, w4, col, r, g, b, str2, cut;
2+
var x1, y1, a, b, n, str, w, h, yy, w1, w2, w3, w4, w5, w6, col, r, g, b, str2, cut;
33
with (obj_popup) instance_destroy()
44
global.popup = 0
55
if (song_name = "" && window = w_songinfo) {window = 0 return 0}
@@ -12,16 +12,22 @@ if (str[0] = "") str[0] = "Untitled song"
1212

1313
str[1] = song_author
1414
str[2] = song_orauthor
15+
str[3] = song_midi
1516
draw_set_font(fnt_info_big)
1617
w = max(string_width(str[0]) + 32, 400)
1718
draw_set_font(fnt_info_med_bold)
1819
w2 = string_width(str[1])
1920
w4 = string_width(str[2])
21+
draw_set_font(fnt_mainbold)
22+
w6 = string_width(str[3])
2023
draw_set_font(fnt_info_med)
2124
w1 = string_width("Created by ")
2225
w3 = string_width("Originally created by ")
23-
w = max(w1 + w2, w)
26+
draw_set_font(fnt_main)
27+
w5 = string_width("Imported from ")
28+
w = max(w1 + w2 + 32, w)
2429
w = max(w3 + w4 + 32, w)
30+
w = max(w5 + w6 + 32, w)
2531
draw_set_font(fnt_main)
2632
var songdescwrap, songdeschei;
2733
songdescwrap = string_word_wrap(song_desc, 216)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// string_truncate(str, maxwidth)
2+
// Truncates a string to maxwidth and adds ellipses (...) at the end
3+
4+
var str, maxwidth
5+
str = argument0
6+
maxwidth = argument1
7+
8+
if (string_width(str) > maxwidth) {
9+
return string_maxwidth(str, maxwidth) + "..."
10+
}
11+
return str

scripts/string_truncate/string_truncate.yy

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

views/8f90c88c-a49b-4a15-b19e-952f818913ff.yy

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)