[client] msg: allow messages to contain blank lines and separators

This commit is contained in:
Geoffrey McRae 2022-01-09 02:14:01 +11:00
parent b8866a2ce4
commit f9b907a6b1

View File

@ -97,11 +97,24 @@ static int msg_render(void * udata, bool interactive, struct Rect * windowRects,
for(int i = 0; i < lines; ++i) for(int i = 0; i < lines; ++i)
{ {
const char * line = stringlist_at(msg->lines, i); const char * line = stringlist_at(msg->lines, i);
if (line[0] == '\0')
{
igNewLine();
continue;
}
if (line[0] == '-' && line[1] == '\0')
{
igSeparator();
continue;
}
igCalcTextSize(&textSize, line, NULL, false, 0.0); igCalcTextSize(&textSize, line, NULL, false, 0.0);
igSetCursorPosX((igGetWindowWidth() * 0.5f) - (textSize.x * 0.5f)); igSetCursorPosX((igGetWindowWidth() * 0.5f) - (textSize.x * 0.5f));
igText("%s", stringlist_at(msg->lines, i)); igText("%s", stringlist_at(msg->lines, i));
} }
igNewLine();
igCalcTextSize(&textSize, "OK", NULL, false, 0.0); igCalcTextSize(&textSize, "OK", NULL, false, 0.0);
ImGuiStyle * style = igGetStyle(); ImGuiStyle * style = igGetStyle();
textSize.x += (style->FramePadding.x * 2.0f) * 8.0f; textSize.x += (style->FramePadding.x * 2.0f) * 8.0f;
@ -142,10 +155,21 @@ void overlayMsg_show(const char * caption, const char * fmt, va_list args)
msg->lines = stringlist_new(false); msg->lines = stringlist_new(false);
valloc_sprintf(&msg->message, fmt, args); valloc_sprintf(&msg->message, fmt, args);
char * rest = msg->message; char * token = msg->message;
char * token; char * rest = msg->message;
stringlist_clear(msg->lines); do
while((token = strtok_r(rest, "\n", &rest))) {
if (*rest == '\n')
{
*rest = '\0';
stringlist_push(msg->lines, token);
token = rest + 1;
}
++rest;
}
while(*rest != '\0');
if (*token)
stringlist_push(msg->lines, token); stringlist_push(msg->lines, token);
ll_push(l_msg.messages, msg); ll_push(l_msg.messages, msg);