[Add] Dynamically change width of dialogues msg and yesno if text is long.
This commit is contained in:
parent
28e164cfba
commit
d77aa5cee8
@ -147,6 +147,7 @@ static void toolkit_drawOutline(double x, double y, double w,
|
|||||||
static void toolkit_drawRect(double x, double y, double w, double h,
|
static void toolkit_drawRect(double x, double y, double w, double h,
|
||||||
glColour* c, glColour* lc);
|
glColour* c, glColour* lc);
|
||||||
// Dialogues..
|
// Dialogues..
|
||||||
|
static glFont* dialogue_getSize(char* msg, int* w, int* h);
|
||||||
static void dialogue_alertClose(char* str);
|
static void dialogue_alertClose(char* str);
|
||||||
static void dialogue_msgClose(char* str);
|
static void dialogue_msgClose(char* str);
|
||||||
static void dialogue_YesNoClose(char* str);
|
static void dialogue_YesNoClose(char* str);
|
||||||
@ -1420,12 +1421,28 @@ static void dialogue_alertClose(char* str) {
|
|||||||
window_destroy(window_get("Warning"));
|
window_destroy(window_get("Warning"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static glFont* dialogue_getSize(char* msg, int* w, int* h) {
|
||||||
|
glFont* font;
|
||||||
|
|
||||||
|
font = &gl_smallFont; // Try to use smallfont.
|
||||||
|
(*h) = gl_printHeight(font, (*w)-40, msg);
|
||||||
|
if(strlen(msg) > 100) {
|
||||||
|
// Make font bigger for large text area's.
|
||||||
|
font = &gl_defFont;
|
||||||
|
(*h) = gl_printHeight(font, (*w)-40, msg);
|
||||||
|
if((*h) > 200) (*w) += MIN((*h)-200, 600); // Too big, so we make it wider.
|
||||||
|
(*h) = gl_printHeight(font, (*w)-40, msg);
|
||||||
|
}
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
// Display an alert popup with only an OK button and a message.
|
// Display an alert popup with only an OK button and a message.
|
||||||
static unsigned int msg_wid = 0;
|
static unsigned int msg_wid = 0;
|
||||||
void dialogue_msg(char* caption, const char* fmt, ...) {
|
void dialogue_msg(char* caption, const char* fmt, ...) {
|
||||||
char msg[4096];
|
char msg[4096];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int h;
|
int w, h;
|
||||||
|
glFont* font;
|
||||||
|
|
||||||
if(msg_wid) return;
|
if(msg_wid) return;
|
||||||
|
|
||||||
@ -1437,14 +1454,15 @@ void dialogue_msg(char* caption, const char* fmt, ...) {
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
h = gl_printHeight(&gl_smallFont, 260, msg);
|
w = 300; // Default width.
|
||||||
|
font = dialogue_getSize(msg, &w, &h);
|
||||||
|
|
||||||
// Create the window.
|
// Create the window.
|
||||||
msg_wid = window_create(caption, -1, -1, 300, 90+h);
|
msg_wid = window_create(caption, -1, -1, w, 110+h);
|
||||||
window_addText(msg_wid, 20, -30, 260, h, 0, "txtMsg",
|
window_addText(msg_wid, 20, -40, w-40, h, 0, "txtMsg",
|
||||||
&gl_smallFont, &cBlack, msg);
|
font, &cBlack, msg);
|
||||||
|
|
||||||
window_addButton(msg_wid, 135, 20, 50, 30, "btnOK", "OK",
|
window_addButton(msg_wid, (w-50)/2, 20, 50, 30, "btnOK", "OK",
|
||||||
dialogue_msgClose);
|
dialogue_msgClose);
|
||||||
|
|
||||||
toolkit_loop();
|
toolkit_loop();
|
||||||
@ -1463,7 +1481,8 @@ static unsigned int yesno_wid = 0;
|
|||||||
int dialogue_YesNo(char* caption, const char* fmt, ...) {
|
int dialogue_YesNo(char* caption, const char* fmt, ...) {
|
||||||
char msg[4096];
|
char msg[4096];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int h;
|
int w, h;
|
||||||
|
glFont* font;
|
||||||
|
|
||||||
if(yesno_wid) return -1;
|
if(yesno_wid) return -1;
|
||||||
|
|
||||||
@ -1475,19 +1494,19 @@ int dialogue_YesNo(char* caption, const char* fmt, ...) {
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the text height.
|
w = 300;
|
||||||
h = gl_printHeight(&gl_smallFont, 260, msg);
|
font = dialogue_getSize(msg, &w, &h);
|
||||||
|
|
||||||
// Create window.
|
// Create window.
|
||||||
yesno_wid = window_create(caption, -1, -1, 300, h+90);
|
yesno_wid = window_create(caption, -1, -1, w, h+110);
|
||||||
// Text.
|
// Text.
|
||||||
window_addText(yesno_wid, 20, -30, 260, h, 0, "txtYesNo",
|
window_addText(yesno_wid, 20, -40, w-40, h, 0, "txtYesNo",
|
||||||
&gl_smallFont, &cBlack, msg);
|
font, &cBlack, msg);
|
||||||
// Buttons.
|
// Buttons.
|
||||||
window_addButton(yesno_wid, 300/2-50-10, 20, 50, 30, "btnYes", "Yes",
|
window_addButton(yesno_wid, w/2-50-10, 20, 50, 30, "btnYes", "Yes",
|
||||||
dialogue_YesNoClose);
|
dialogue_YesNoClose);
|
||||||
|
|
||||||
window_addButton(yesno_wid, 300/2+50+10, 20, 50, 30, "btnNo", "No",
|
window_addButton(yesno_wid, w/2+50+10, 20, 50, 30, "btnNo", "No",
|
||||||
dialogue_YesNoClose);
|
dialogue_YesNoClose);
|
||||||
|
|
||||||
// Tricky secondary loop.
|
// Tricky secondary loop.
|
||||||
|
Loading…
Reference in New Issue
Block a user