ref: d68acf09fc4454cb4642034dd5e4275c6971ac05
parent: 67f793f1975245b9db8ac0e0797d6339f2ce96db
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Jan 12 17:40:09 EST 2020
mu_render: compare strings (not just commands) to decide whether an update is needed
--- a/microui.c
+++ b/microui.c
@@ -1437,7 +1437,8 @@
if (memcmp(&mu_ctx.screen, &screen->r, sizeof(mu_ctx.screen)) != 0)
mu_ctx.screen = screen->r;
else if (mu_ctx.oldcmdsnum == mu_ctx.cmdsnum && memcmp(mu_ctx.oldcmds, mu_ctx.cmds, mu_ctx.cmdsnum*sizeof(mu_Command)) == 0)
- return 0;
+ if (mu_ctx.oldstrnum == mu_ctx.strnum && memcmp(mu_ctx.oldstr, mu_ctx.str, mu_ctx.strnum) == 0)
+ return 0;
if (mu_ctx.oldcmdsmax != mu_ctx.cmdsmax && (mu_ctx.oldcmds = realloc(mu_ctx.oldcmds, mu_ctx.cmdsmax*sizeof(mu_Command))) == nil)
sysfatal("couldn't allocate memory for old cmds");
@@ -1444,6 +1445,12 @@
mu_ctx.oldcmdsmax = mu_ctx.cmdsmax;
mu_ctx.oldcmdsnum = mu_ctx.cmdsnum;
memmove(mu_ctx.oldcmds, mu_ctx.cmds, mu_ctx.cmdsnum*sizeof(mu_Command));
+
+ if (mu_ctx.oldstrmax != mu_ctx.strmax && (mu_ctx.oldstr = realloc(mu_ctx.oldstr, mu_ctx.strmax)) == nil)
+ sysfatal("couldn't allocate memory for old strings");
+ mu_ctx.oldstrmax = mu_ctx.strmax;
+ mu_ctx.oldstrnum = mu_ctx.strnum;
+ memmove(mu_ctx.oldstr, mu_ctx.str, mu_ctx.strnum);
draw(screen, screen->r, mu_style.colors[MU_COLOR_BG], nil, ZP);
--- a/microui.h
+++ b/microui.h
@@ -207,8 +207,8 @@
Rectangle screen;
/* buffers */
- char *str;
- int strmax, strnum;
+ char *str, *oldstr;
+ int strmax, strnum, oldstrmax, oldstrnum;
mu_Container **root;
int rootmax, rootnum;