aboutsummaryrefslogtreecommitdiffstats
path: root/src/gwin/gwin_widget.c
diff options
context:
space:
mode:
authorAndrew Hannam <Andrew Hannam>2016-07-10 10:42:21 +1000
committerAndrew Hannam <Andrew Hannam>2016-07-10 10:42:21 +1000
commit9ac3c368b4de8e2f38bad56262c75d3310c8814b (patch)
tree973fb9bf591398e6826a25f64e9975cc5f06a51b /src/gwin/gwin_widget.c
parented9b268d5bce5fe6d703bc785034191312782db0 (diff)
downloaduGFX-9ac3c368b4de8e2f38bad56262c75d3310c8814b.tar.gz
uGFX-9ac3c368b4de8e2f38bad56262c75d3310c8814b.tar.bz2
uGFX-9ac3c368b4de8e2f38bad56262c75d3310c8814b.zip
Add gwinPrintg() and fix null pointer handling in sprintg()
Diffstat (limited to 'src/gwin/gwin_widget.c')
-rw-r--r--src/gwin/gwin_widget.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/gwin/gwin_widget.c b/src/gwin/gwin_widget.c
index 2965e7c6..483a63b3 100644
--- a/src/gwin/gwin_widget.c
+++ b/src/gwin/gwin_widget.c
@@ -530,6 +530,44 @@ void gwinSetText(GHandle gh, const char *text, bool_t useAlloc) {
_gwinUpdate(gh);
}
+#if GFX_USE_GFILE && GFILE_NEED_PRINTG && GFILE_NEED_STRINGS
+ #include <stdarg.h>
+
+ void gwinPrintg(GHandle gh, const char * fmt, ...) {
+ char *str;
+ va_list va;
+ int size;
+
+ if (!(gh->flags & GWIN_FLG_WIDGET))
+ return;
+
+ // Dispose of the old string
+ if ((gh->flags & GWIN_FLG_ALLOCTXT)) {
+ gh->flags &= ~GWIN_FLG_ALLOCTXT;
+ if (gw->text) {
+ gfxFree((void *)gw->text);
+ gw->text = "";
+ }
+ }
+
+ // Alloc the new text
+ va_start (va, fmt);
+
+ size = vsnprintg(0, 0, fmt, va) + 1; //determine the buffer size required
+
+ if ((str = gfxAlloc(size))) {
+ gh->flags |= GWIN_FLG_ALLOCTXT;
+ vsnprintg(str, size, fmt, va);
+ gw->text = (const char *)str;
+ } else
+ gw->text = "";
+
+ va_end (va);
+
+ _gwinUpdate(gh);
+ }
+#endif
+
const char *gwinGetText(GHandle gh) {
if (!(gh->flags & GWIN_FLG_WIDGET))
return 0;