aboutsummaryrefslogtreecommitdiffstats
path: root/widget.c
diff options
context:
space:
mode:
Diffstat (limited to 'widget.c')
-rw-r--r--widget.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/widget.c b/widget.c
new file mode 100644
index 0000000..8a77b8f
--- /dev/null
+++ b/widget.c
@@ -0,0 +1,28 @@
+#include <stdio.h>
+
+#include "microui.h"
+#include "widget.h"
+
+void
+init_field(Field *f) {
+ f->buf[0] = '\0';
+ f->value = 0.0;
+}
+
+/* field draws a Field widget and updates its value.
+ * It returns MU_RES_CHANGE if the value has changed. */
+int
+field(mu_Context *ctx, Field *f) {
+ double value;
+ int changed = 0;
+ if (mu_textbox(ctx, f->buf, sizeof(f->buf)) & MU_RES_CHANGE) {
+ if (sscanf(f->buf, "%lf", &value) == 1) {
+ f->value = value;
+ changed = 1;
+ } else if (f->buf[0] == '\0') {
+ f->value = 0.0;
+ changed = 1;
+ }
+ }
+ return changed ? MU_RES_CHANGE : 0;
+}