+static void DrawElementName(int x, int y, int element)
+{
+ char *element_name = getElementInfoText(element);
+ int font_nr = FONT_TEXT_1;
+ int font_width = getFontWidth(font_nr);
+ int font_height = getFontHeight(font_nr);
+ int max_text_width = SXSIZE - x - ED_SETTINGS_XPOS(0);
+ int max_chars_per_line = max_text_width / font_width;
+ char buffer[max_chars_per_line + 1];
+
+ if (strlen(element_name) <= max_chars_per_line)
+ DrawTextF(x, y, font_nr, element_name);
+ else
+ {
+ int next_pos = max_chars_per_line;
+
+ strncpy(buffer, element_name, max_chars_per_line);
+ buffer[max_chars_per_line] = '\0';
+
+ if (element_name[max_chars_per_line] == ' ')
+ next_pos++;
+ else
+ {
+ int i;
+
+ for (i = max_chars_per_line - 1; i >= 0; i--)
+ if (buffer[i] == ' ')
+ break;
+
+ if (strlen(&element_name[i + 1]) <= max_chars_per_line)
+ {
+ buffer[i] = '\0';
+ next_pos = i + 1;
+ }
+ }
+
+ DrawTextF(x, y - font_height / 2, font_nr, buffer);
+
+ strncpy(buffer, &element_name[next_pos], max_chars_per_line);
+ buffer[max_chars_per_line] = '\0';
+
+ DrawTextF(x, y + font_height / 2, font_nr, buffer);
+ }
+}
+